Skip to content

Commit 1a7af63

Browse files
devnexentargos
authored andcommitted
src: large page attributing an id on Linux
Using the new PR_SET_VMA_ANON_NAME prctl attribute available since the 5.17 release, when rolling out the process address map appears as ` <start>-<end> r-xp 0000000 00:00 0 [anon:nodejs Large Page] ` PR-URL: #42644 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6b7c35e commit 1a7af63

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/large_pages/node_large_page.cc

+21
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
#ifndef _GNU_SOURCE
6969
#define _GNU_SOURCE
7070
#endif // ifndef _GNU_SOURCE
71+
#include <sys/prctl.h>
72+
#if !defined(PR_SET_VMA)
73+
#define PR_SET_VMA 0x53564d41
74+
#define PR_SET_VMA_ANON_NAME 0
75+
#endif
7176
#elif defined(__FreeBSD__)
7277
#include "uv.h" // uv_exepath
7378
#endif // defined(__linux__)
@@ -312,6 +317,21 @@ class MemoryMapPointer {
312317
mem_ = nullptr;
313318
size_ = 0;
314319
}
320+
static void SetName(void* mem, size_t size, const char* name) {
321+
#if defined(__linux__)
322+
// Available since the 5.17 kernel release and if the
323+
// CONFIG_ANON_VMA_NAME option, we can set an identifier
324+
// to an anonymous mapped region. However if the kernel
325+
// option is not present or it s an older kernel, it is a no-op.
326+
if (mem != MAP_FAILED && mem != nullptr)
327+
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME,
328+
reinterpret_cast<uintptr_t>(mem),
329+
size,
330+
reinterpret_cast<uintptr_t>(name));
331+
#else
332+
(void)name;
333+
#endif
334+
}
315335
FORCE_INLINE ~MemoryMapPointer() {
316336
if (mem_ == nullptr) return;
317337
if (mem_ == MAP_FAILED) return;
@@ -382,6 +402,7 @@ MoveTextRegionToLargePages(const text_region& r) {
382402
#endif
383403

384404
if (mprotect(start, size, PROT_READ | PROT_EXEC) == -1) goto fail;
405+
MemoryMapPointer::SetName(start, size, "nodejs Large Page");
385406

386407
// We need not `munmap(tmem, size)` on success.
387408
tmem.Reset();

0 commit comments

Comments
 (0)