Skip to content

Commit

Permalink
src: add debug option to report large page stats
Browse files Browse the repository at this point in the history
This adds the new option `HUGEPAGES` to `NODE_DEBUG_NATIVE` that
causes the code responsible for re-mapping to large pages to output
memory range and page count information to `stderr`.

Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com>
PR-URL: #32331
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
  • Loading branch information
Gabriel Schulhof authored and targos committed Apr 28, 2020
1 parent e67b97e commit df046de
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/debug_utils.h
Expand Up @@ -41,6 +41,7 @@ void FWrite(FILE* file, const std::string& str);
// from a provider type to a debug category.
#define DEBUG_CATEGORY_NAMES(V) \
NODE_ASYNC_PROVIDER_TYPES(V) \
V(HUGEPAGES) \
V(INSPECTOR_SERVER) \
V(INSPECTOR_PROFILER) \
V(CODE_CACHE) \
Expand Down
24 changes: 21 additions & 3 deletions src/large_pages/node_large_page.cc
Expand Up @@ -26,6 +26,7 @@

// Besides returning ENOTSUP at runtime we do nothing if this define is missing.
#if defined(NODE_ENABLE_LARGE_CODE_PAGES) && NODE_ENABLE_LARGE_CODE_PAGES
#include "debug_utils-inl.h"
#include "util.h"
#include "uv.h"

Expand Down Expand Up @@ -97,11 +98,18 @@ struct text_region {

static const size_t hps = 2L * 1024 * 1024;

static void PrintWarning(const char* warn) {
template <typename... Args>
inline void Debug(Args&&... args) {
node::Debug(&per_process::enabled_debug_list,
DebugCategory::HUGEPAGES,
std::forward<Args>(args)...);
}

inline void PrintWarning(const char* warn) {
fprintf(stderr, "Hugepages WARNING: %s\n", warn);
}

static void PrintSystemError(int error) {
inline void PrintSystemError(int error) {
PrintWarning(strerror(error));
}

Expand Down Expand Up @@ -152,13 +160,22 @@ struct text_region FindNodeTextRegion() {
uintptr_t lpstub_start = reinterpret_cast<uintptr_t>(&__start_lpstub);

if (dl_iterate_phdr(FindMapping, &dl_params) == 1) {
Debug("Hugepages info: start: %p - sym: %p - end: %p\n",
reinterpret_cast<void*>(dl_params.start),
reinterpret_cast<void*>(dl_params.reference_sym),
reinterpret_cast<void*>(dl_params.end));

dl_params.start = dl_params.reference_sym;
if (lpstub_start > dl_params.start && lpstub_start <= dl_params.end)
if (lpstub_start > dl_params.start && lpstub_start <= dl_params.end) {
Debug("Hugepages info: Trimming end for lpstub: %p\n",
reinterpret_cast<void*>(lpstub_start));
dl_params.end = lpstub_start;
}

if (dl_params.start < dl_params.end) {
char* from = reinterpret_cast<char*>(hugepage_align_up(dl_params.start));
char* to = reinterpret_cast<char*>(hugepage_align_down(dl_params.end));
Debug("Hugepages info: Aligned range is %p - %p\n", from, to);
if (from < to) {
size_t pagecount = (to - from) / hps;
if (pagecount > 0) {
Expand Down Expand Up @@ -261,6 +278,7 @@ struct text_region FindNodeTextRegion() {
}
}
#endif
Debug("Hugepages info: Found %d huge pages\n", nregion.total_hugepages);
return nregion;
}

Expand Down

0 comments on commit df046de

Please sign in to comment.