Skip to content

Commit 243d0d4

Browse files
Gabriel SchulhofMylesBorins
Gabriel Schulhof
authored andcommitted
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 <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>
1 parent 4d173ea commit 243d0d4

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/debug_utils.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void FWrite(FILE* file, const std::string& str);
4040
// from a provider type to a debug category.
4141
#define DEBUG_CATEGORY_NAMES(V) \
4242
NODE_ASYNC_PROVIDER_TYPES(V) \
43+
V(HUGEPAGES) \
4344
V(INSPECTOR_SERVER) \
4445
V(INSPECTOR_PROFILER) \
4546
V(CODE_CACHE) \

src/large_pages/node_large_page.cc

+21-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

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

@@ -97,11 +98,18 @@ struct text_region {
9798

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

100-
static void PrintWarning(const char* warn) {
101+
template <typename... Args>
102+
inline void Debug(Args&&... args) {
103+
node::Debug(&per_process::enabled_debug_list,
104+
DebugCategory::HUGEPAGES,
105+
std::forward<Args>(args)...);
106+
}
107+
108+
inline void PrintWarning(const char* warn) {
101109
fprintf(stderr, "Hugepages WARNING: %s\n", warn);
102110
}
103111

104-
static void PrintSystemError(int error) {
112+
inline void PrintSystemError(int error) {
105113
PrintWarning(strerror(error));
106114
}
107115

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

154162
if (dl_iterate_phdr(FindMapping, &dl_params) == 1) {
163+
Debug("Hugepages info: start: %p - sym: %p - end: %p\n",
164+
reinterpret_cast<void*>(dl_params.start),
165+
reinterpret_cast<void*>(dl_params.reference_sym),
166+
reinterpret_cast<void*>(dl_params.end));
167+
155168
dl_params.start = dl_params.reference_sym;
156-
if (lpstub_start > dl_params.start && lpstub_start <= dl_params.end)
169+
if (lpstub_start > dl_params.start && lpstub_start <= dl_params.end) {
170+
Debug("Hugepages info: Trimming end for lpstub: %p\n",
171+
reinterpret_cast<void*>(lpstub_start));
157172
dl_params.end = lpstub_start;
173+
}
158174

159175
if (dl_params.start < dl_params.end) {
160176
char* from = reinterpret_cast<char*>(hugepage_align_up(dl_params.start));
161177
char* to = reinterpret_cast<char*>(hugepage_align_down(dl_params.end));
178+
Debug("Hugepages info: Aligned range is %p - %p\n", from, to);
162179
if (from < to) {
163180
size_t pagecount = (to - from) / hps;
164181
if (pagecount > 0) {
@@ -261,6 +278,7 @@ struct text_region FindNodeTextRegion() {
261278
}
262279
}
263280
#endif
281+
Debug("Hugepages info: Found %d huge pages\n", nregion.total_hugepages);
264282
return nregion;
265283
}
266284

0 commit comments

Comments
 (0)