Why would some process swap in place of reclaiming free(cached) memory

michi1 at michaelblizek.twilightparadox.com michi1 at michaelblizek.twilightparadox.com
Wed Feb 20 11:31:33 EST 2013


Hi!

On 20:31 Wed 20 Feb     , Soham Chakraborty wrote:
> Hi all,
> 
> I posted this question in linux-mm list as well but it didn't spawn much
> interest. So, I am putting the same question here also. Would love if
> someone can put some traction.
> 
> The question is salivating and simple. When we have free and lotsa cached
> memory in a system (irrespective of distro and kernel), why would some
> process end up in swap space,

Freeing cache memory does not need to be faster than swapping. The cached
files might be accessed more often than memory of some process. It is a
hard balancing act.

> I understand the overcommit mode of vm, the
> default value of 0 and what it does. I also know that the cache might be
> dirty and we don't might not want to allocate free pages thinking that we
> might go under the watermark of low. But, I mainly end up getting this
> question from end users - why would things swap if I have free memory.

I think this might indeed make sense in some cases. If there is lots of
memory used which is never accessed, it could be swapped out early. This
would prevent write activity if memory gets tight later. Also note that there
is a entry "SwapCached" in /proc/meminfo. It might be possible that the pages
swapped out pages are present in both swap *and* memory. Just a possibility...

> I
> guess, technically we can't stop swapping even if we set vm.swappiness to 0
> but well, I think I have said what I need to said. If you need data, I can
> provide those.

Swapping can be prevented.
1) You can disable all swap space in the system
2) Alternatively, you can call mlock() if you only care about few processes.

> ...

	-Michi
-- 
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com



More information about the Kernelnewbies mailing list