[kwlug-disc] systemd and cgroup memory limits
Chris Frey
cdfrey at foursquare.net
Sun Aug 21 13:35:36 EDT 2022
I'm hoping that someone here has managed to make this work. So far, it's
been a maze of a twisty little passages, all alike. :-)
I played around with cgroups v1 before, and got it to work great.
But then systemd interfered and moved my processes into the user slice
without me asking. I didn't track down the ultimate reason for that,
but I figured, fine, perhaps there is an official systemd way to do
this instead of using the cg* commands manually.
Here's what I have kinda working so far:
I create limittest.slice in /etc/systemd/system containing:
[Slice]
CPUQuota=10%
MemoryAccounting=yes
MemoryHigh=40M
MemoryMax=80M
MemorySwapMax=20M
The idea being that by the time 20M of swap + 80M of memory are used, it
will trigger OOM.
Then I run a shell:
systemd-run --slice=limittest.slice --uid=cdfrey --shell
Then I run my test program to allocate and write to memory.
But OOM is never called. MemoryMax does limit the memory to 80M and
all further allocations go to swap. If I write to the memory I've
allocated, it dutifully churns through swap to do it. So that's working.
But how do I stop it at 100M max? I'd be happy with OOM killer for now,
but I really like cgroup v1's control over OOM behaviour, so I'm hoping
I can achieve that too.
Thanks!
- Chris
More information about the kwlug-disc
mailing list