New option to name reserved pages.

This commit is contained in:
David Carlier
2022-04-03 07:54:57 +01:00
committed by Matthew Parkinson
parent 848a7b1499
commit bf54eeb7be
2 changed files with 29 additions and 0 deletions

View File

@@ -6,6 +6,7 @@
# include <string.h>
# include <sys/mman.h>
# include <sys/prctl.h>
# include <syscall.h>
extern "C" int puts(const char* str);
@@ -38,7 +39,32 @@ namespace snmalloc
{
void* p = PALPOSIX<PALLinux>::reserve(size);
if (p)
{
madvise(p, size, MADV_DONTDUMP);
# ifdef SNMALLOC_PAGEID
# ifndef PR_SET_VMA
# define PR_SET_VMA 0x53564d41
# define PR_SET_VMA_ANON_NAME 0
# endif
/**
*
* If the kernel is set with CONFIG_ANON_VMA_NAME
* the reserved pages would appear as follow
*
* 7fa5f0ceb000-7fa5f0e00000 rw-p 00000000 00:00 0 [anon:snmalloc]
* 7fa5f0e00000-7fa5f1800000 rw-p 00000000 00:00 0 [anon:snmalloc]
*
*/
prctl(
PR_SET_VMA,
PR_SET_VMA_ANON_NAME,
(unsigned long)p,
size,
(unsigned long)"snmalloc");
# endif
}
return p;
}