|
68 | 68 | #ifndef _GNU_SOURCE
|
69 | 69 | #define _GNU_SOURCE
|
70 | 70 | #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 |
71 | 76 | #elif defined(__FreeBSD__)
|
72 | 77 | #include "uv.h" // uv_exepath
|
73 | 78 | #endif // defined(__linux__)
|
@@ -312,6 +317,21 @@ class MemoryMapPointer {
|
312 | 317 | mem_ = nullptr;
|
313 | 318 | size_ = 0;
|
314 | 319 | }
|
| 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 | + } |
315 | 335 | FORCE_INLINE ~MemoryMapPointer() {
|
316 | 336 | if (mem_ == nullptr) return;
|
317 | 337 | if (mem_ == MAP_FAILED) return;
|
@@ -382,6 +402,7 @@ MoveTextRegionToLargePages(const text_region& r) {
|
382 | 402 | #endif
|
383 | 403 |
|
384 | 404 | if (mprotect(start, size, PROT_READ | PROT_EXEC) == -1) goto fail;
|
| 405 | + MemoryMapPointer::SetName(start, size, "nodejs Large Page"); |
385 | 406 |
|
386 | 407 | // We need not `munmap(tmem, size)` on success.
|
387 | 408 | tmem.Reset();
|
|
0 commit comments