I'm trying to write a program that waits when it sees it's memory is becoming full. It finds out what the current available memory is using /proc/meminfo
. Now I'm trying to test it by running systemd-run --scope -p MemoryMax=100M -p MemorySwapMax=0
but /proc/meminfo
is still returning the old values (which I kind of get why it does that).
Is there another place or way I can retrieve the available memory that does look at the limits set by systemd-run
?.
Thanks in advance!
Systemd uses cgroups.
$ systemd-run -P --user -p MemoryMax=10240000 -p MemorySwapMax=0 bash -c 'd=/sys/fs/cgroup/$(cut -d: -f3 /proc/self/cgroup); tail $d/memory{.swap,}.max'
Running as unit: run-u923.service
==> /sys/fs/cgroup//user.slice/user-1000.slice/[email protected]/app.slice/run-u923.service/memory.swap.max <==
0
==> /sys/fs/cgroup//user.slice/user-1000.slice/[email protected]/app.slice/run-u923.service/memory.max <==
10240000