cilium/ebpf

[RFC] Name memory regions allocated with mmap (prctl PR_SET_VMA_ANON_NAME)

alban opened this issue · 2 comments

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:

xref inspektor-gadget/inspektor-gadget#3541 (comment)

cc @burak-ok

Interesting, this could help with the new Map.Memory() API as well. Would be nice to see the names show up in pmap.