aboutsummaryrefslogtreecommitdiff
path: root/malloc
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-11-01 09:56:08 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-11-07 10:27:20 -0300
commitfee9e40a8da75fad9717668f6dddcc26f3feca2d (patch)
tree318af06cfcad98364192c6b01bb2a0ed6a08b577 /malloc
parent6afce56c197ee83520994a2c94a82c2ca2bce9fa (diff)
downloadglibc-fee9e40a8da75fad9717668f6dddcc26f3feca2d.zip
glibc-fee9e40a8da75fad9717668f6dddcc26f3feca2d.tar.gz
glibc-fee9e40a8da75fad9717668f6dddcc26f3feca2d.tar.bz2
malloc: Decorate malloc maps
Add anonymous mmap annotations on loader malloc, malloc when it allocates memory with mmap, and on malloc arena. The /proc/self/maps will now print: [anon: glibc: malloc arena] [anon: glibc: malloc] [anon: glibc: loader malloc] On arena allocation, glibc annotates only the read/write mapping. Checked on x86_64-linux-gnu and aarch64-linux-gnu. Reviewed-by: DJ Delorie <dj@redhat.com>
Diffstat (limited to 'malloc')
-rw-r--r--malloc/arena.c4
-rw-r--r--malloc/malloc.c5
2 files changed, 9 insertions, 0 deletions
diff --git a/malloc/arena.c b/malloc/arena.c
index 6f03955..d1e214a 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -17,6 +17,7 @@
not, see <https://www.gnu.org/licenses/>. */
#include <stdbool.h>
+#include <setvmaname.h>
#define TUNABLE_NAMESPACE malloc
#include <elf/dl-tunables.h>
@@ -436,6 +437,9 @@ alloc_new_heap (size_t size, size_t top_pad, size_t pagesize,
return 0;
}
+ /* Only considere the actual usable range. */
+ __set_vma_name (p2, size, " glibc: malloc arena");
+
madvise_thp (p2, size);
h = (heap_info *) p2;
diff --git a/malloc/malloc.c b/malloc/malloc.c
index d0bbbf3..78a531b 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -218,6 +218,7 @@
#include <sys/sysinfo.h>
#include <ldsodefs.h>
+#include <setvmaname.h>
#include <unistd.h>
#include <stdio.h> /* needed for malloc_stats */
@@ -2428,6 +2429,8 @@ sysmalloc_mmap (INTERNAL_SIZE_T nb, size_t pagesize, int extra_flags, mstate av)
madvise_thp (mm, size);
#endif
+ __set_vma_name (mm, size, " glibc: malloc");
+
/*
The offset to the start of the mmapped region is stored in the prev_size
field of the chunk. This allows us to adjust returned start address to
@@ -2513,6 +2516,8 @@ sysmalloc_mmap_fallback (long int *s, INTERNAL_SIZE_T nb,
madvise_thp (mbrk, size);
#endif
+ __set_vma_name (mbrk, size, " glibc: malloc");
+
/* Record that we no longer have a contiguous sbrk region. After the first
time mmap is used as backup, we do not ever rely on contiguous space
since this could incorrectly bridge regions. */