Swap used even when ram is available after memory usage spike
Hello,
now, I don't have much experience when it comes to swap, so please forgive me if this post doesn't make sense. Basically, after a memory usage spike and closing down some apps, I noticed that my system still uses swap space even if there's now ram available, even with actively used processes. (Currently using around 1/3rd of ram available, while still using around 180 MiB swap.) Sometimes this makes things in my system extremely slow (really old machine, slow hard drives...). When there is ram available, shouldn't the system put what is in the swap back in the ram? If that's not default behavior, can it be enabled? (Currently using Debian Wheezy as a desktop OS) |
It's expensive to continually run the allocated/free memory chains - so it isn't done unless necessary.
What you can try to force the swap back into memory - the swapoff will simply fail if it won't fit in memory, no damage done. Code:
swapoff /dev/sda? |
Some swap is always in use - at least the way it usually works. Even with my "working" machine (Fedora 18, 6 Gigs of RAM) there is some data stored in the swap.
Changing this behavior is called "changing swappiness". I found something on the internet, but it's for Ubuntu: https://help.ubuntu.com/community/SwapFaq I think it will work for Debian the same way, as Ubuntu is based on Debian (And let's be honest, it IS Debian with a few simplifications in configuration and day to day usage). Hope I could help. |
I do not think swap is used by active processes, swap is only used in case of "out of memory". Pages in use are always located in the main memory. Unused pages will not be copied back to the memory (as long as it was not requested by the system).
|
Thanks for the replies, I'll have a look if anything works.
|
Quote:
Quote:
Quote:
Maybe the swap use makes you imagine the system is slow. Maybe the system is slow for some other reason at the same time swap is in use. But the swap use does not make your system slow. Quote:
Without that extra free memory, when it reads one page from swap, it must write another to swap. With the excess free memory, it can read pages from swap if/when they are used, and not write anything back to swap. |
@johnsfine Thanks for preventing me from trying stupid things.
Then there must be something wrong with the stuff I'm running on my system then... Some day I will find it. |
Quote:
|
Quote:
That would mean those pages were not accessed. If they aren't accessed, then the time it would have taken to access them doesn't matter. The important thing to distinguish here is between space being occupied in swap (no ongoing performance cost and no indication of a problem) vs. continuing swap-in/swap-out activity, which would be a significant performance hit. The OP did not quote the right stats to directly see the level of swap in/out activity. But Linux is pretty reliable about reasonable behavior regarding swap. So we can infer a low swap in/out rate from the free memory. |
I know what Z038 meant; Johnsfine's one-liner comment just there would have been better with some context.
As he pointed out, if the use of swap (mem spike) has passed, then the kernel will only swap pages back into RAM IF it wants them. No affect on system performance by leaving them on swap if not reqd. OTOH, if swap is being actively used, then yes, that will be magnitudes slower than a RAM read/write. :) |
All times are GMT -5. The time now is 06:44 AM. |