9

In the question Limit memory usage for a single Linux process it was mentioned to change the file /etc/default/grub so that GRUB_CMDLINE_LINUX_DEFAULT contains

GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=memory swapaccount=1"

What does swapaccount=1 do? Is there any risk or drawback in applying that?

Martin Thoma
  • 2,842

2 Answers2

10

Apparently it is/was used to enable swap accounting, i.e. it tells the kernel to monitor and restrict swap usage per control groups (cgroups for short). RedHat seems to have started enabling it by default in RHEL7, so apparently the drawbacks are minimal.

You should check your kernel configuration (typically /boot/config-<kernel_version>). If it includes the line:

CONFIG_MEMCG_SWAP=y

then the potential to track swap usage by cgroups exists, and the swapaccount= boot option is available. Any actual restriction only takes effect if a cgroup with a swap limit is created, and a process is moved into that cgroup.

If it also includes the line:

CONFIG_MEMCG_SWAP_ENABLED=y

then swapaccount=1 is enabled by default, and you would need to use an explicit swapaccount=0 boot option to disable it if desired.

systemd and Docker will use cgroups extensively as part of their normal functionality.

telcoM
  • 96,466
  • 2
    I've seen reports that claim that swapaccount=1 causes 2% performance degration. However, without it you cannot effectively limit swap usage at all and falling too heavy on swap will cause much worse degration than only 2% so I think you should be fine to enable it. I'd expect that 2% performance hit to only affect swapping so for most cases you should only see benefits from using that flag. – Mikko Rantalainen Sep 04 '21 at 14:50
3

FWIW, the kernel command line option swapaccount= has been deprecated as of https://github.com/torvalds/linux/commit/b25806dcd3d5248833f7d2544ee29a701735159f . The kernel now always behaves as if swapaccount=1 is specified.

janneb
  • 131