diff options
author | David CARLIER <devnexen@gmail.com> | 2022-04-17 03:24:36 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2022-04-28 07:56:10 +0300 |
commit | 1a7af6364dc47c0d95a28f42a8417c114ad295e0 (patch) | |
tree | 7259c81d7f220e7b40c64981b815695135c194d0 /src | |
parent | 6b7c35e8075380d1431a8bd6feabe0bdab15d2ea (diff) |
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 00000000 00:00 0 [anon:nodejs Large Page]
`
PR-URL: https://github.com/nodejs/node/pull/42644
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/large_pages/node_large_page.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/large_pages/node_large_page.cc b/src/large_pages/node_large_page.cc index eb546c581a1..1dddcb9f6c3 100644 --- a/src/large_pages/node_large_page.cc +++ b/src/large_pages/node_large_page.cc @@ -68,6 +68,11 @@ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif // ifndef _GNU_SOURCE +#include <sys/prctl.h> +#if !defined(PR_SET_VMA) +#define PR_SET_VMA 0x53564d41 +#define PR_SET_VMA_ANON_NAME 0 +#endif #elif defined(__FreeBSD__) #include "uv.h" // uv_exepath #endif // defined(__linux__) @@ -312,6 +317,21 @@ class MemoryMapPointer { mem_ = nullptr; size_ = 0; } + static void SetName(void* mem, size_t size, const char* name) { +#if defined(__linux__) + // Available since the 5.17 kernel release and if the + // CONFIG_ANON_VMA_NAME option, we can set an identifier + // to an anonymous mapped region. However if the kernel + // option is not present or it s an older kernel, it is a no-op. + if (mem != MAP_FAILED && mem != nullptr) + prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, + reinterpret_cast<uintptr_t>(mem), + size, + reinterpret_cast<uintptr_t>(name)); +#else + (void)name; +#endif + } FORCE_INLINE ~MemoryMapPointer() { if (mem_ == nullptr) return; if (mem_ == MAP_FAILED) return; @@ -382,6 +402,7 @@ MoveTextRegionToLargePages(const text_region& r) { #endif if (mprotect(start, size, PROT_READ | PROT_EXEC) == -1) goto fail; + MemoryMapPointer::SetName(start, size, "nodejs Large Page"); // We need not `munmap(tmem, size)` on success. tmem.Reset(); |