libbpf-tools: add cgroup_helpers and oomkill support display cgroup#5384
Open
Rtoax wants to merge 2 commits intoiovisor:masterfrom
Open
libbpf-tools: add cgroup_helpers and oomkill support display cgroup#5384Rtoax wants to merge 2 commits intoiovisor:masterfrom
Rtoax wants to merge 2 commits intoiovisor:masterfrom
Conversation
e957108 to
33f29d3
Compare
Collaborator
|
For this one:
Could you actually show your simple test? This way, people can reproduce the issue easily. |
Rtoax
pushed a commit
to Rtoax/test-linux
that referenced
this pull request
Sep 2, 2025
Link: iovisor/bcc#5384 Signed-off-by: Rong Tao <rtoax@foxmail.com>
Contributor
Author
Yes, thanks, the test code: oom_minimal.c#include <errno.h>
#include <malloc.h>
#include <unistd.h>
#include <stdio.h>
int main(void)
{
void *mem;
for (;;) {
mem = malloc(getpagesize());
if (!mem && errno == ENOMEM) {
fprintf(stderr, "OOMing...\n");
}
*(int *)mem = 1;
/* Just leak the memory */
}
return 0;
}cgroup-oom.sh#!/bin/bash
set -e
readonly pid=$$
readonly CGROUP_NAME=oom-test
[[ -z ${OOMer} ]] && OOMer=oom_minimal
cleanup() {
printf "\n"
sudo rmdir /sys/fs/cgroup/${CGROUP_NAME}/
}
trap cleanup EXIT
sudo mkdir -p /sys/fs/cgroup/${CGROUP_NAME}/
echo ${pid} | sudo tee /sys/fs/cgroup/${CGROUP_NAME}/cgroup.procs
echo $((1024*1024*2)) | sudo tee /sys/fs/cgroup/${CGROUP_NAME}/memory.max
echo $((1024*1024*2)) | sudo tee /sys/fs/cgroup/${CGROUP_NAME}/memory.high
eval ./${OOMer} ${@}compile and runthen |
33f29d3 to
1665706
Compare
Contributor
Author
|
@yonghong-song Thanks a lot, i just submit all changes and add test code above, please review, :) |
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Sep 3, 2025
Using a simple test program (not shown) called OOM, we performed the
following two tests:
1. Allocating unlimited memory
2. Adding the process to a cgroup named oom-memcg and limiting its memory
usage to 200MB.
When we do not print cgroup information, we can only see process information
and cannot see the difference between memcg and non-memcg.
$ sudo ./oomkill
Tracing OOM kills... Ctrl-C to stop.
14:28:23 Triggered by PID 179201 ("oom"), OOM kill of PID 179201 ("oom"), 6114610 pages, loadavg: loadavg: 0.56 0.51 0.38 2/968 179204
14:28:42 Triggered by PID 179212 ("oom"), OOM kill of PID 179212 ("oom"), 51200 pages, loadavg: loadavg: 0.40 0.47 0.37 3/968 179212
The function implemented by this patch can clearly display cgroup information.
$ sudo ./oomkill -c
Tracing OOM kills... Ctrl-C to stop.
14:32:59 Triggered by PID 179879 ("oom"), CGROUP 8309 ("/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/session.slice/org.gnome.Shell@wayland.service"), OOM kill of PID 179879 ("oom"), 6114610 pages, loadavg: loadavg: 0.50 0.38 0.35 4/970 179879
14:33:14 Triggered by PID 179884 ("oom"), CGROUP 122547 ("/sys/fs/cgroup/oom-memcg"), MEMCG 122547 ("/sys/fs/cgroup/oom-memcg"), OOM kill of PID 179884 ("oom"), 51200 pages, loadavg: loadavg: 0.47 0.38 0.35 3/971 179884
Link: iovisor#5384
Signed-off-by: Rong Tao <rongtao@cestc.cn>
1665706 to
86b0c14
Compare
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Oct 1, 2025
Using a simple test program (not shown) called OOM, we performed the
following two tests:
1. Allocating unlimited memory
2. Adding the process to a cgroup named oom-memcg and limiting its memory
usage to 200MB.
When we do not print cgroup information, we can only see process information
and cannot see the difference between memcg and non-memcg.
$ sudo ./oomkill
Tracing OOM kills... Ctrl-C to stop.
14:28:23 Triggered by PID 179201 ("oom"), OOM kill of PID 179201 ("oom"), 6114610 pages, loadavg: loadavg: 0.56 0.51 0.38 2/968 179204
14:28:42 Triggered by PID 179212 ("oom"), OOM kill of PID 179212 ("oom"), 51200 pages, loadavg: loadavg: 0.40 0.47 0.37 3/968 179212
The function implemented by this patch can clearly display cgroup information.
$ sudo ./oomkill -c
Tracing OOM kills... Ctrl-C to stop.
14:32:59 Triggered by PID 179879 ("oom"), CGROUP 8309 ("/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/session.slice/org.gnome.Shell@wayland.service"), OOM kill of PID 179879 ("oom"), 6114610 pages, loadavg: loadavg: 0.50 0.38 0.35 4/970 179879
14:33:14 Triggered by PID 179884 ("oom"), CGROUP 122547 ("/sys/fs/cgroup/oom-memcg"), MEMCG 122547 ("/sys/fs/cgroup/oom-memcg"), OOM kill of PID 179884 ("oom"), 51200 pages, loadavg: loadavg: 0.47 0.38 0.35 3/971 179884
Link: iovisor#5384
Signed-off-by: Rong Tao <rongtao@cestc.cn>
86b0c14 to
374fdfb
Compare
Some tools need to obtain cgroup information. For example, oomkill currently
only supports tracking process information and cannot obtain cgroup
information. It would be better if it could obtain memcg information.
For ease of maintenance, a separate commit is kept just for adding
cgroup_helpers.
Added interfaces:
cgroup_cgroupid_of_path() - Get cgroupid from cgroup absolute path
get_cgroupid_path() - Get cgroup path from cgroupid
Signed-off-by: Rong Tao <rongtao@cestc.cn>
Using a simple test program (not shown) called OOM, we performed the
following two tests:
1. Allocating unlimited memory
2. Adding the process to a cgroup named oom-memcg and limiting its memory
usage to 200MB.
When we do not print cgroup information, we can only see process information
and cannot see the difference between memcg and non-memcg.
$ sudo ./oomkill
Tracing OOM kills... Ctrl-C to stop.
14:28:23 Triggered by PID 179201 ("oom"), OOM kill of PID 179201 ("oom"), 6114610 pages, loadavg: loadavg: 0.56 0.51 0.38 2/968 179204
14:28:42 Triggered by PID 179212 ("oom"), OOM kill of PID 179212 ("oom"), 51200 pages, loadavg: loadavg: 0.40 0.47 0.37 3/968 179212
The function implemented by this patch can clearly display cgroup information.
$ sudo ./oomkill -c
Tracing OOM kills... Ctrl-C to stop.
14:32:59 Triggered by PID 179879 ("oom"), CGROUP 8309 ("/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/session.slice/org.gnome.Shell@wayland.service"), OOM kill of PID 179879 ("oom"), 6114610 pages, loadavg: loadavg: 0.50 0.38 0.35 4/970 179879
14:33:14 Triggered by PID 179884 ("oom"), CGROUP 122547 ("/sys/fs/cgroup/oom-memcg"), MEMCG 122547 ("/sys/fs/cgroup/oom-memcg"), OOM kill of PID 179884 ("oom"), 51200 pages, loadavg: loadavg: 0.47 0.38 0.35 3/971 179884
Link: iovisor#5384
Signed-off-by: Rong Tao <rongtao@cestc.cn>
374fdfb to
3ec6c72
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Using a simple test program (not shown) called OOM, we performed the
following two tests:
usage to 200MB.
When we do not print cgroup information, we can only see process information
and cannot see the difference between memcg and non-memcg.
The function implemented by this patch can clearly display cgroup information.
and add
cgroup_helpers.c.