Individual processes in cgroup for distinct swappiness

Hi,

I have been using Leap 15 (and now 15.1) since the beginning and I see that it already comes with a pre-configured cgroup tree with system.slice, user.slice, etc

I would like to change the swappiness of a specific process (probably by his PID) without having to re-mount cgroups from scratch. That is, keeping the default cgroup tree that is shipped with Leap 15.1 (except maybe for creating a new subfolder into /sys/fs/cgroup/memory ).

One option I saw may help is through

 systemctl set-property --runtime ...

But I haven’t found any command to set the swappiness, just the maximum size of the swap file.

Thank you all in advance.

IMO…
Traditional documentation describes how you can manage swappiness of processes running in a cgroup, here is one serverfault discussion that includes an example how to set the swappiness of the chosen cgroup
https://serverfault.com/questions/529476/moving-a-process-to-and-from-swap

Nowadays though…
I’d take advantage of the fact that Linux containers are built on cgroups,
and I’d suggest running your process, application or multiple anything in a Docker container…
You can run just about anything or a collection of somethings in a Docker container, even a single process
And then you can configure resource usage including swappiness for that container
The following documentation provides the bare bones info…
https://docs.docker.com/config/containers/resource_constraints/

Curiously, I looked for similar documentation for LXC but couldn’t find any… I don’t know if you can tune memory for LXC like you can in Docker, at least easily.

TSU

BTW -
If you’re interested in doing what you’re asking about in Docker but haven’t any experience with that before,
The Docker tutorials I wrote modifying official documentation at the time can get you set up and running a single process in a container in no time…

https://en.opensuse.org/User:Tsu2/Docker_Install

Although there is a lot more to Docker today, the above tutorials still cover the most basic things to know and very nearly might be all you need for your use.

TSU

Thank you :slight_smile:

Any chance it could also work for the processes *plasmashell, X, and kwin_x11 *?

I have been tracking down the swap memory usage of these processes under my heavy work load and they always keep swapping. It is hindering my work flow, so that I often find myself having to change back (and even this transition is slowed) to console login in order to manage the system from command line.
To test that it is this respective swapping that is hindering the Desktop Environment’s GUI responsiveness under my work load with heavy swap usage, I specifically killed these 3 processes and restarted them so that they initially were not swapped after this restart. Then, the general GUI responsiveness of the DE come back to normal (for a decent period of time until the kernel start to swap them again).

I don’t know if it’s a good idea to over-ride how individual system services behave automatically…
I don’t know your reasons to be running a “heavy” DE like KDE/Plasma
If you’re willing to consider a “lighter” alternative,
LXQt today is built on the exact same Qt framework as KDE/Plasma but without the heavy overhead, widgets, and misc.
And, if you want to go “ultra-light” you might simply boot into IceWM to run only a bare bones but very functional X11 environment… In fact, I’ve found that running IceWM in my VMs uses no more RAM and hardly any more resources than a text mode only system.

TSU

One last available tool for addressing this type of situation where system buffers and cache have been stuffed full and you want to clear them (essentially reversing the stored locations back into active memory where it can be more volatile)

https://en.opensuse.org/User:Tsu2/free_tool

TSU