ebpf
ebpf copied to clipboard
[RFC] Name memory regions allocated with mmap (prctl PR_SET_VMA_ANON_NAME)
Suggestion
Every time cilium/ebpf uses mmap(MAP_ANONYMOUS), it should give a name to the memory region indicating its purpose (i.e. ring buffer for a specific ebpf map).
share = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
rv = prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME,
share, SIZE, "ebpf map foo");
Use case
Investigate why my application is using too much memory by looking at /proc/pid/maps.
Applications can allocate memory with mmap(MAP_ANONYMOUS) from various libraries. When investigating memory issues, I look at /proc/pid/maps. When the memory regions are anonymous, it is difficult to understand where the allocations are coming from. If cilium/ebpf was labelling the perf ring buffers and other mmap memory region, it would help me understand if I gave too much memory to my ebpf maps, or if the problem is in another library than cilium/ebpf.
This requires:
- Linux 5.17 for https://github.com/torvalds/linux/commit/9a10064f5625d5572c3626c1516e0bebc6c9fe9b
- CONFIG_ANON_VMA_NAME
xref https://github.com/inspektor-gadget/inspektor-gadget/issues/3541#issuecomment-2399429009
cc @burak-ok