Re: [systemd-devel] Restricting swap usage for a process managed via systemd

2021-07-04 Thread Mantas Mikulėnas
Looks like your Ubuntu version is using the "hybrid" cgroup mode by
default. Cgroup v2 is indeed *enabled* in your kernel, but not necessarily
*in use* – in the hybrid mode, systemd still mounts all resource
controllers (cpu, memory, etc.) in v1 mode and only sets up its own process
tracking in the v2 tree. See `findmnt`.

You could boot with the systemd.unified_cgroup_hierarchy=1 kernel option to
switch everything to cgroups v2, but if you're using container software
(docker, podman) make sure those are cgroups v2-compatible.

On Sun, Jul 4, 2021 at 10:36 AM Debraj Manna 
wrote:

> Hi
>
> I am trying to restrict the swap usage of a process using MemorySwapMax as
> mentioned in the doc
> 
>  with
> Ubuntu 18.04.
>
> Environment
> 
>
> ubuntu@vrni-platform:/usr/lib/systemd/system$ uname -a
> Linux vrni-platform 4.15.0-143-generic #147-Ubuntu SMP Wed Apr 14 16:10:11 
> UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
>
> ubuntu@vrni-platform:/usr/lib/systemd/system$ systemctl --version
> systemd 237
> +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP 
> +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN 
> -PCRE2 default-hierarchy=hybrid
>
> My systemd unit file looks like below
>
> [Unit]
> Description=My service
> After=network.target
> StartLimitIntervalSec=0
> [Service]
> Type=simple
> Restart=always
> RestartSec=1
> User=support
> MemoryMax=2000M
> KillMode=process
> MemoryAccounting=true
> OOMScoreAdjust=1000
> MemorySwapMax=1M
> ExecStart=/usr/bin/java -cp /home/support -XX:NativeMemoryTracking=summary 
> -Xmx1m MemoryConsumer 100 200 1
>
> MemoryMax is working as expected but MemorySwapMax seems to be not taking 
> effect and I am seeing the process, MemoryConsumer still using swap more than 
> the one specified in MemorySwapMax,
>
> MemorySwapMax documentation states "This setting is supported only if the 
> unified control group hierarchy is used and disables MemoryLimit=."
>
> As mentioned here  I can see 
> cgroup v2 enabled on my setup.
>
> ubuntu@vrni-platform:/tmp/tuk$ sudo mount -t cgroup2 none /tmp/tuk
> ubuntu@vrni-platform:/tmp/tuk$ ls -l /tmp/tuk/
> total 0
> -r--r--r--  1 root root 0 Jul  2 17:13 cgroup.controllers
> -rw-r--r--  1 root root 0 Jul  2 17:13 cgroup.max.depth
> -rw-r--r--  1 root root 0 Jul  2 17:13 cgroup.max.descendants
> -rw-r--r--  1 root root 0 Jun 30 14:42 cgroup.procs
> -r--r--r--  1 root root 0 Jul  2 17:13 cgroup.stat
> -rw-r--r--  1 root root 0 Jul  2 17:13 cgroup.subtree_control
> -rw-r--r--  1 root root 0 Jul  2 17:13 cgroup.threads
> drwxr-xr-x  2 root root 0 Jun 30 14:42 init.scope
> drwxr-xr-x 87 root root 0 Jul  2 15:05 system.slice
> drwxr-xr-x  7 root root 0 Jun 30 15:22 user.slice
> ubuntu@vrni-platform:/tmp/debraj$ sudo umount /tmp/tuk
>
> Can someone suggest what configuration I am missing?
>
>
> ___
> systemd-devel mailing list
> systemd-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>


-- 
Mantas Mikulėnas
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Restricting swap usage for a process managed via systemd

2021-07-04 Thread Debraj Manna
Hi

I am trying to restrict the swap usage of a process using MemorySwapMax as
mentioned in the doc

with
Ubuntu 18.04.

Environment


ubuntu@vrni-platform:/usr/lib/systemd/system$ uname -a
Linux vrni-platform 4.15.0-143-generic #147-Ubuntu SMP Wed Apr 14
16:10:11 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

ubuntu@vrni-platform:/usr/lib/systemd/system$ systemctl --version
systemd 237
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP
+LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS
+KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid

My systemd unit file looks like below

[Unit]
Description=My service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=support
MemoryMax=2000M
KillMode=process
MemoryAccounting=true
OOMScoreAdjust=1000
MemorySwapMax=1M
ExecStart=/usr/bin/java -cp /home/support
-XX:NativeMemoryTracking=summary -Xmx1m MemoryConsumer 100 200 1

MemoryMax is working as expected but MemorySwapMax seems to be not
taking effect and I am seeing the process, MemoryConsumer still using
swap more than the one specified in MemorySwapMax,

MemorySwapMax documentation states "This setting is supported only if
the unified control group hierarchy is used and disables
MemoryLimit=."

As mentioned here  I
can see cgroup v2 enabled on my setup.

ubuntu@vrni-platform:/tmp/tuk$ sudo mount -t cgroup2 none /tmp/tuk
ubuntu@vrni-platform:/tmp/tuk$ ls -l /tmp/tuk/
total 0
-r--r--r--  1 root root 0 Jul  2 17:13 cgroup.controllers
-rw-r--r--  1 root root 0 Jul  2 17:13 cgroup.max.depth
-rw-r--r--  1 root root 0 Jul  2 17:13 cgroup.max.descendants
-rw-r--r--  1 root root 0 Jun 30 14:42 cgroup.procs
-r--r--r--  1 root root 0 Jul  2 17:13 cgroup.stat
-rw-r--r--  1 root root 0 Jul  2 17:13 cgroup.subtree_control
-rw-r--r--  1 root root 0 Jul  2 17:13 cgroup.threads
drwxr-xr-x  2 root root 0 Jun 30 14:42 init.scope
drwxr-xr-x 87 root root 0 Jul  2 15:05 system.slice
drwxr-xr-x  7 root root 0 Jun 30 15:22 user.slice
ubuntu@vrni-platform:/tmp/debraj$ sudo umount /tmp/tuk

Can someone suggest what configuration I am missing?
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel