Public bug reported:
Starting with Plucky (verified not to reproduce on Oracular or Noble),
there is a weirdness in how cgroup's memory.max constraint is taken into
account:
Here is a test case without systemd in the equation (thanks enr0n for coming up
with that):
```
ubuntu@ubuntu:~$ ps -o cgroup $$
CGROUP
0::/user.slice/user-1000.slice/session-4.scope
ubuntu@ubuntu:~$ cat
/sys/fs/cgroup/user.slice/user-1000.slice/session-4.scope/memory.max
max
ubuntu@ubuntu:~$ cat
/sys/fs/cgroup/user.slice/user-1000.slice/session-4.scope/memory.current
3538944
ubuntu@ubuntu:~$ echo 5000000 | sudo tee
/sys/fs/cgroup/user.slice/user-1000.slice/session-4.scope/memory.max
5000000
ubuntu@ubuntu:~$ cat
/sys/fs/cgroup/user.slice/user-1000.slice/session-4.scope/memory.max
4997120
ubuntu@ubuntu:~$ leak-memory
Starting memory consumption in 1.00 MiB steps to maximum 42.0 TiB.
Allocated 10.0 MiB.
Allocated 20.0 MiB.
Allocated 30.0 MiB.
Allocated 40.0 MiB.
Allocated 50.0 MiB.
Allocated 60.0 MiB.
Allocated 70.0 MiB.
...
Allocated 1.88 GiB.
Allocated 1.89 GiB.
Allocated 1.90 GiB.
Allocated 1.91 GiB.
Allocated 1.92 GiB.
Killed
```
Here is my original test case, that makes reproducing the issue a one-liner:
```
❯ systemd-run --scope -p MemoryMax=1M --user leak-memory
Running as unit: run-p222392-i222692.scope; invocation ID:
942b1e8b1e374e82abeff046a62dcbf7
Starting memory consumption in 1.00 MiB steps to maximum 42.0 TiB.
Allocated 10.0 MiB.
Allocated 20.0 MiB.
....
Allocated 470.0 MiB.
zsh: killed systemd-run --scope -p MemoryMax=1M --user leak-memory
```
The issue obviously scales with the value set in MemoryMax.
The only lead I've got for now, is that the value I set in MemoryMax weirdly
correlates to what is reported by oom-kill in the pgtables value:
With 1M:
```
[62584.409068] Memory cgroup out of memory: Killed process 237541 (leak-memory)
total-vm:490024kB, anon-rss:0kB, file-rss:1448kB, shmem-rss:0kB, UID:1000
pgtables:1004kB oom_score_adj:0
```
With 4M:
```
[62693.780200] Memory cgroup out of memory: Killed process 237732 (leak-memory)
total-vm:2058752kB, anon-rss:128kB, file-rss:1512kB, shmem-rss:0kB, UID:1000
pgtables:4072kB oom_score_adj:0
```
In both cases, the reported `total-vm` value is way above the expected limit.
My current system:
❯ uname -rv
6.12.0-12-generic #12-Ubuntu SMP PREEMPT_DYNAMIC Wed Jan 22 16:36:37 UTC 2025
** Affects: linux (Ubuntu)
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2105866
Title:
cgroup: weird calculation for memory limit
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2105866/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs