4

RHEL 7.2 memory use, per free -m:

              total        used        free      shared  buff/cache   available
Mem:         386564       77941       57186         687      251435      306557
Swap:         13383        2936       16381

we see that used swap is 2936M

so we want to decrease it to min by the following

echo 1 > /proc/sys/vm/swappiness

sysctl -w vm.swappiness=1

echo "vm.swappiness = 1" >> /etc/sysctl.conf

and after 10 min we check again , but still OS used the swap

free -m:

              total        used        free      shared  buff/cache   available
Mem:         386564       77941       57186         687      251435      306557
Swap:         13389        2930       16381

why the actions that we did not take affect immeditly?

Do we need to restart the OS, in order to get swap used to be 0 ?

example

we run vmstat:

 vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 3  0  85740 20255872 2238248 183126400    0    0     7   162    0    0  7  1 92  0  0

we decrease the vm.swappiness=1

and run vmstat after 10min:

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 3  0  85740 20255872 2238248 183126400    0    0     7   162    0    0  7  1 92  0  0
2
  • 1
    Do you know for a fact that Linux would empty the swap when you set swappiness to 1? Because what you are showing is that it does not use further swap space.
    – Kusalananda
    Mar 26, 2019 at 17:58
  • 1
    so you have a total 384GB of RAM according to free; since that is not enough to make a system run... RH 15244 => 1.5 x RAM is over 500gb, better go get a second disk and make the whole thing swap
    – ron
    Mar 27, 2019 at 15:51

2 Answers 2

11

As you’ve been told before (see Why does swappiness not work?), changing swappiness only affects future decisions made by the kernel when it needs to free memory. Reducing it won’t cause the kernel to reload everything that’s been swapped out.

Your vmstat output shows that swap isn’t being actively used, i.e. your current workloads really don’t need the pages which have been swapped out.

There’s no point in trying to micro-manage the kernel’s use of swap in the way you tend to do. Depending on your workload, decide whether you need to favour the page cache or not, adjust swappiness accordingly, then leave the system to run.

If you really want to clear swap, disable it and re-enable it:

swapoff -a && swapon -a
5

free -m is not a reliable source of information about swap use. Instead, please use vmstat before and after the echo commands which temporarily change swappiness.

1) swapoff -a && swapon -a && vmstat
2) do work which requires swapping
3) vmstat

Now you know how much swapping is going on before changing the swappiness. If there's no swapping going on, find other jobs which do swap.

4) use and echo command to change swappiness temporarily
5) swapoff -a && swapon -a && vmstat
6) do work which requires swapping
7) vmstat

8) compare the si and so values.

The values to watch are:

si: Amount of memory swapped in from disk (/s).
so: Amount of memory swapped to disk (/s).

You may also find helpful information in the RHEL 7 Performance Tuning Guide.

Many thanks to Stephen Kitt for reminding me about swapon and swapoff.

4
  • when I run vmstat under swap I see 2224 , this is the swap that OS used?
    – yael
    Mar 26, 2019 at 17:44
  • any I did the procedure on other machine , but vmstat about the swap , and after the procedure are the same values
    – yael
    Mar 26, 2019 at 17:48
  • I add example of vmstat before and after , as you can see the value are the same - how it can be
    – yael
    Mar 26, 2019 at 17:52
  • si and so are the values to look at. Since si and so have not changed, you are not swapping. As per the How To Read Vmstat Output link I provided, "The first line of the report will contain the average values since the last time the computer was rebooted." and not the immediate values.
    – K7AAY
    Mar 26, 2019 at 17:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .