In CentOS 7 how do I set the default memory.swappiness for all the systemd cgroups? I can do it per cgroup via the ControlGroupAttribute option, but I would like to override the default of 60 for all the cgroups.
If you want to do this for ALL cgroups, do you want to do this for the whole system? If that's the case, you can set swappiness system wide in "/etc/sysctl.conf". The line you would be editing is "vm.swappiness=" which you can set to anything from 0 to 100.
As a fair warning to anyone moving this value as a way to avoid swapping altogether, setting this very low will almost entirely disable demand paging, which is a very useful way to get idle pages out of RAM and into swap. Yes, it's "swapping", but that's not such a desperate thing as is the old traditional sense of swapping when we run out of memory. Demand paging is especially useful in large databases, and it shouldn't really slow anything down. It certainly beats swapping things out when we're out of memory last second, as demand paging helps to keep that from happening in the first place while the system isn't grinding to a halt, rather than after it is. A setting of 0 for vm.swappiness system wide can cause a system to OOM kill processes when under heavy pressure, potentially bringing the whole system down in a kernel panic.
Also worth mentioning, you must call upon the sysctl.conf file to be read after editing it.
# sysctl -p reads lines that have been modified in /etc/sysctl.conf. vm.swappiness can be changed on a running system this way, or by using procfs thusly:
# echo 50 > /proc/sys/vm/swappiness where 50 is any number from 0 to 100.