Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is the memory which is transferred to swap due to swappiness still cached in the physical memory (until it is invalidated there)?

share|improve this question
    
This question is partly related to serverfault.com/questions/153946/… –  Ztyx Jul 2 '10 at 11:57
add comment

1 Answer 1

up vote 4 down vote accepted

Yes, the kernel will know the pages are available in both places so it can reallocate the RAM if it needs to (knowing the pages are already copied to disk). If the pages are read back into RAM later they remain on disk too (unless swap space is congested and it need to be used to page out something else).

The amount of data in pages available in both RAM and in swap at any given time can be found in /proc/meminfo under the SwapCached heading.

The kernel is unlikely to write something to swap unless it is about to immediately reallocate the RAM they occupy though. A high swappiness values doesn't mean it will swap things out needlessly - it just means it will be more likely to swap pages out to make room for buffers/cache/similar when needed instead of clearing older blocks from cache.

share|improve this answer
    
+1, One minor edit, most modern kernels will also swap when memory has been idle for a long time, even if it doesn't need the space. –  Chris S Jul 2 '10 at 12:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.