Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alban opened this issue Oct 8, 2024 · 2 comments
Open

Comments

@alban
Copy link
Contributor

alban commented Oct 8, 2024

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

@ti-mo
Copy link
Collaborator

ti-mo commented Oct 10, 2024

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

@ti-mo
Copy link
Collaborator

ti-mo commented Oct 24, 2024

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

Unfortunately, this doesn't seem to work for mmapable bpf maps. Since https://lwn.net/Articles/913935, naming is supported for MAP_SHARED | MAP_ANON, but BPF maps already show up as anon_inode:bpf-map in /proc/self/maps, which likely falls outside of this category.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants