From df046dec97f9c44c4a206662cc834a0ef32f2bf8 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Tue, 17 Mar 2020 13:42:37 -0700 Subject: [PATCH] src: add debug option to report large page stats 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 PR-URL: https://github.com/nodejs/node/pull/32331 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: David Carlier --- src/debug_utils.h | 1 + src/large_pages/node_large_page.cc | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/debug_utils.h b/src/debug_utils.h index 3ecbdea90e2c22..ecc53b0c2b0aa0 100644 --- a/src/debug_utils.h +++ b/src/debug_utils.h @@ -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) \ diff --git a/src/large_pages/node_large_page.cc b/src/large_pages/node_large_page.cc index e3972f52559399..4d4ff1aaf039b6 100644 --- a/src/large_pages/node_large_page.cc +++ b/src/large_pages/node_large_page.cc @@ -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" @@ -97,11 +98,18 @@ struct text_region { static const size_t hps = 2L * 1024 * 1024; -static void PrintWarning(const char* warn) { +template +inline void Debug(Args&&... args) { + node::Debug(&per_process::enabled_debug_list, + DebugCategory::HUGEPAGES, + std::forward(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)); } @@ -152,13 +160,22 @@ struct text_region FindNodeTextRegion() { uintptr_t lpstub_start = reinterpret_cast(&__start_lpstub); if (dl_iterate_phdr(FindMapping, &dl_params) == 1) { + Debug("Hugepages info: start: %p - sym: %p - end: %p\n", + reinterpret_cast(dl_params.start), + reinterpret_cast(dl_params.reference_sym), + reinterpret_cast(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(lpstub_start)); dl_params.end = lpstub_start; + } if (dl_params.start < dl_params.end) { char* from = reinterpret_cast(hugepage_align_up(dl_params.start)); char* to = reinterpret_cast(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) { @@ -261,6 +278,7 @@ struct text_region FindNodeTextRegion() { } } #endif + Debug("Hugepages info: Found %d huge pages\n", nregion.total_hugepages); return nregion; }