Skip to content

Commit bf54eeb

Browse files
devnexenmjp41
authored andcommitted
New option to name reserved pages.
1 parent 848a7b1 commit bf54eeb

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ cmake_dependent_option(SNMALLOC_STATIC_LIBRARY "Build static libraries" ON "NOT
2424
cmake_dependent_option(SNMALLOC_MEMCPY_BOUNDS "Perform bounds checks on memcpy with heap objects" OFF "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF)
2525
cmake_dependent_option(SNMALLOC_CHECK_LOADS "Perform bounds checks on the source argument to memcpy with heap objects" OFF "SNMALLOC_MEMCPY_BOUNDS" OFF)
2626
cmake_dependent_option(SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE "Compile for current machine architecture" Off "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF)
27+
cmake_dependent_option(SNMALLOC_PAGEID "Set an id to memory regions" OFF "NOT SNMALLOC_PAGEID" OFF)
2728
if (NOT SNMALLOC_HEADER_ONLY_LIBRARY)
2829
# Pick a sensible default for the thread cleanup mechanism
2930
if (${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
@@ -323,6 +324,8 @@ if(NOT SNMALLOC_HEADER_ONLY_LIBRARY)
323324

324325
target_compile_definitions(${name} PRIVATE
325326
SNMALLOC_CHECK_LOADS=$<IF:$<BOOL:${SNMALLOC_CHECK_LOADS}>,true,false>)
327+
target_compile_definitions(${name} PRIVATE
328+
SNMALLOC_PAGEID=$<IF:$<BOOL:${SNMALLOC_PAGEID}>,true,false>)
326329

327330
install(TARGETS ${name} EXPORT snmallocConfig)
328331

src/snmalloc/pal/pal_linux.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# include <string.h>
88
# include <sys/mman.h>
9+
# include <sys/prctl.h>
910
# include <syscall.h>
1011

1112
extern "C" int puts(const char* str);
@@ -38,7 +39,32 @@ namespace snmalloc
3839
{
3940
void* p = PALPOSIX<PALLinux>::reserve(size);
4041
if (p)
42+
{
4143
madvise(p, size, MADV_DONTDUMP);
44+
# ifdef SNMALLOC_PAGEID
45+
# ifndef PR_SET_VMA
46+
# define PR_SET_VMA 0x53564d41
47+
# define PR_SET_VMA_ANON_NAME 0
48+
# endif
49+
50+
/**
51+
*
52+
* If the kernel is set with CONFIG_ANON_VMA_NAME
53+
* the reserved pages would appear as follow
54+
*
55+
* 7fa5f0ceb000-7fa5f0e00000 rw-p 00000000 00:00 0 [anon:snmalloc]
56+
* 7fa5f0e00000-7fa5f1800000 rw-p 00000000 00:00 0 [anon:snmalloc]
57+
*
58+
*/
59+
60+
prctl(
61+
PR_SET_VMA,
62+
PR_SET_VMA_ANON_NAME,
63+
(unsigned long)p,
64+
size,
65+
(unsigned long)"snmalloc");
66+
# endif
67+
}
4268
return p;
4369
}
4470

0 commit comments

Comments
 (0)