Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

It sounds quite counter-productive to me to cache pages that are swapped out. If you swap pages in, what is the advantage to first cache them in memory, only to have to than move them to the right place? Even if pages are swapped in proactively, doesn't it make more sense to "just" swap them in? Doesn't in fact caching swap is just a waste of resources?

share|improve this question
    
You, ma'am/sir, get extra goody points from me for your questions. Wish I could up-vote twice. –  Eli Frey Aug 14 '10 at 6:19

3 Answers 3

up vote 8 down vote accepted

After some more research, I have found that the term SwapCached in /proc/meminfo is misleading. In fact, it relates to the number of bytes that are simultaneous in memory and swap, such that if these pages are not dirty, they do not need to be swapped out.

share|improve this answer
    
That's pretty much equivalent to being cached, though, isn't it? I mean, WRT the kernel's memory management system, "cached" means "both on disk and in RAM", right? –  SamB Sep 4 '12 at 16:47

The point of having pages duplicated between swap and RAM is to avoid waiting for the disk if either:

  1. Something needs to read from them

  2. They need to be evicted to make room for something else

If they were only in swap, case 1. would mean waiting for them to come in from disk; if they were only in RAM, case 2. would mean waiting for them to go out to disk.

(Of course, case 2 is actually a little more complicated, since it's obviously cheaper to evict such pages, so the kernel probably evicts them preferentially, but the point should be clear.)

share|improve this answer

Never even heard of this one and it doesn't make a lot of sense to me either. I still think the good old rule of making sure it just doesn't swap at all (except of course the reservations) is best. Now, theoretically, the caching of stuff in direct available memory which takes a while to load from something as slow as a disk, has an apparent advantage. But if you're able to cache to-be-swapped pages, why again swap in the first place?

share|improve this answer

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.