LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Why using swap when RAM is available? (https://www.linuxquestions.org/questions/linux-general-1/why-using-swap-when-ram-is-available-490039/)

MasterOfTheWind 10-06-2006 11:22 AM

Why using swap when RAM is available?
 
Hi!

Have always wondered why kernel decides to use the swap space when RAM is not fully filled by application memory? Wouldn't it be better if some of the cached memory was removed and its place filled by the data stored on the swap partition?

In other words, isn't it better to have ALL memory on RAM (even if it means that there is no space left for caching) and nothing on the swap partition than a part of the app memory + cached memory on RAM and some app memory on the swap partition?

Thanks.

pljvaldez 10-06-2006 11:34 AM

I've never seen my swap used when RAM is enabled. Can you post the output of free -lm when this is happening?

jlliagre 10-06-2006 12:18 PM

Quote:

Originally Posted by MasterOfTheWind
Have always wondered why kernel decides to use the swap space when RAM is not fully filled by application memory?

The O/S try to always maintain as small amount or RAM free to ease future allocations.
When a process exits, all it's pages stored in RAM are freed, these free pages aren't filled by pages that are currently swapped out is there is no demand for them, so you can observe what you describes.
Quote:

Wouldn't it be better if some of the cached memory was removed and its place filled by the data stored on the swap partition?
No, why would you like unused pages to fill the precious RAM ?

MasterOfTheWind 10-06-2006 12:45 PM

pljvaldez, here is the output (this is on my oldest laptop - haven't got the new one by my side, but it has the same behavior):

Code:

            total      used      free    shared    buffers    cached
Mem:            60        47        12          0          2        31
Low:            60        47        12
High:            0          0          0
-/+ buffers/cache:        12        47
Swap:          266          3        262

As you see, this is not a problem - only 3mb are located on the swap space.

And jlliagre has already answered why those are not copied back to RAM.

Thanks alot :D


All times are GMT -5. The time now is 11:53 AM.