I'm running Ubuntu 20.04 with systemd 245.
I'm testing out systemd's resource control features; particularly the memory usage controls. The relevant section of my unit file looks like this:
[Unit]
Description=...
...
[Service]
...
MemoryMax=512M
#LimitAS=512M
#LimitDATA=512M
The systemd docs claim that when MemoryMax is reached, the service is killed by the "out of memory killer".
However, if I run code designed to come up against this limit, like this C++ code:
int main()
{
while (true)
char *p = new char[100];
}
Instead what happens (when I watch it in htop) is that the 'RES' memory climbs to 512MB and stops, but the 'VIRT' memory continues to climb and the allocations switch to using swap. The OS eventually kills the application when swap is exhausted.
If I use the LimitAS and/or LimitDATA options instead, the application gets killed when it hits 512MB, as expected.
What's going on here? systemd recommends using MaxMemory over LimitXXX (see here), so why don't they work in the same way?
systemdare you running?/usr/lib/systemd/systemd --versionorsystemctl --version? Note the man page you've linked states forMemoryMax"This setting replaces MemoryLimit=.", so it could be within reason that you're on a version of systemd that isn't usingMemoryMax.