New configure option '--enable-pageid' for Linux

The option makes jemalloc use prctl with PR_SET_VMA to tag memory mappings with
"jemalloc_pg" or "jemalloc_pg_overcommit". This allows to easily identify
jemalloc's mappings in /proc/<pid>/maps. PR_SET_VMA is only available in Linux
5.17 and above.
This commit is contained in:
David Carlier
2022-06-01 22:04:11 +01:00
committed by Alex Lapenkou
parent b950934916
commit 4fc5c4fbac
3 changed files with 59 additions and 0 deletions

View File

@@ -21,6 +21,13 @@
#else
#define PAGES_FD_TAG -1
#endif
#ifdef JEMALLOC_HAVE_PRCTL
#include <sys/prctl.h>
#ifndef PR_SET_VMA
#define PR_SET_VMA 0x53564d41
#define PR_SET_VMA_ANON_NAME 0
#endif
#endif
/******************************************************************************/
/* Data. */
@@ -98,6 +105,22 @@ static int madvise_MADV_DONTNEED_zeroes_pages()
}
#endif
#ifdef JEMALLOC_PAGEID
static int os_page_id(void *addr, size_t size, const char *name)
{
#ifdef JEMALLOC_HAVE_PRCTL
/*
* While parsing `/proc/<pid>/maps` file, the block could appear as
* 7f4836000000-7f4836800000 rw-p 00000000 00:00 0 [anon:jemalloc_pg_overcommit]`
*/
return prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (uintptr_t)addr, size,
(uintptr_t)name);
#else
return 0;
#endif
}
#endif
/******************************************************************************/
/*
* Function prototypes for static functions that are referenced prior to
@@ -162,6 +185,11 @@ os_pages_map(void *addr, size_t size, size_t alignment, bool *commit) {
#endif
assert(ret == NULL || (addr == NULL && ret != addr) || (addr != NULL &&
ret == addr));
#ifdef JEMALLOC_PAGEID
int n = os_page_id(ret, size,
os_overcommits ? "jemalloc_pg_overcommit" : "jemalloc_pg");
assert(n == 0 || (n == -1 && get_errno() == EINVAL));
#endif
return ret;
}