37

/proc/sys/vm/swappiness is nice, but I want a knob that is per process like /proc/$PID/oom_adj. So that I can make certain processes less likely than others to have any of their pages swapped out. Unlike memlock(), this doesn't prevent a program from being swapped out. And like nice, the user by default can't make their programs less likely, but only more likely to get swapped. I think I had to call this /proc/$PID/swappiness_adj.

asked Mar 28, 2011 at 8:34

2 Answers 2

37
Tino
1,28710 silver badges12 bronze badges
answered Mar 28, 2011 at 12:20
1
  • 3
    Beware, that, according to the RedHat guide, enabling memory-cgroup uses additional memory, 40 byte per page. Consider hugepages to reduce the number of pages in this context, see wiki.debian.org/Hugepages Commented Apr 9, 2016 at 13:35
2

I would like to extend Šimon Tóth's answer with a real life solution that I have developed. I think that it deserves a separate answer.

RedHat 7 - cgroups v1 and systemd

As only since RedHat 8 the cgroups v2 are supported, we need to use cgroups v1 here.

The official guide suggests adding a ExecStartPost that changes memory settings for your service, but it does not work until you make another change that will make /sys/fs/cgroup/memory/system.slice available.

So I ended up with adding this to my service unit file, assuming that the service name is example:

# the first entry is here only to make /sys/fs/cgroup/memory/system.slice path
# available for the next entry
MemoryLimit=64G
# this entry actually effectively disables swap for the service
ExecStartPost=/bin/bash -c \
 "echo 0 > /sys/fs/cgroup/memory/system.slice/example.service/memory.swappiness"
answered Sep 30, 2020 at 16:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.