Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I read about swap:
"It is possible to run a Linux system without a swap space, and the system will run well if you have a large amount of memory -- but if you run out of physical memory then the system will crash, as it has nothing else it can do, so it is advisable to have a swap space, especially since disk space is relatively cheap."
Linux kernel uses swap (if available) even when having enough memory. When you have idle application just sitting in RAM doing nothing it is good thing to move it to swap so it does not occupy usable RAM.
Look for "swappiness" kernel parameter for more details.
I'm not up on the latest kernel designs, but the historical reason that you needed swap even if you had full memory was that systems would swap out unused processes even if memory wasn't needed. One justification for that would be to make more room for disk caching, another might be to make room for memory that active processes might soon request.
Perhaps someone who is up on current design can tell us where it is now?
the historical reason that you needed swap even if you had full memory was that systems would swap out unused processes even if memory wasn't needed.
That isn't just historical. That is current design and it is a good design. But the word "needed" is misleading. I don't think Linux ever needed swap when there is enough ram. It may make good use of swap if available even if there is enough ram.
One justification for that would be to make more room for disk caching,
That is the usual reason.
another might be to make room for memory that active processes might soon request.
I think inactive dirty pages of anonymous memory can be written to the swap file without being discarded from the page cache. So if the process owning those pages suddenly starts using them again, they are still in ram. But if some other process uses a lot of memory (or file I/O using a lot of file caching) the ram is available immediately by dropping those inactive pages from the page cache. So an unnecessary write to the swap file when there wasn't a system load might do nothing or it might save the time needed to do the write later when the load is higher.
There's also the good advice that the kernel probably knows better than you do when it comes to managing memory.
On the other hand: you don't want tons of swap. For example, now that memory is no longer limited to 4 GB, you could theoretically have many gigabytes of swap available for paging, but paging a very large process is not necessarily what you want. I may not be using BigApp for a while, but when I do switch to it, I don't want to wait for it to be paged in.
But - then we go back to my switching to OtherBigApp and having to wait because what I asked it to do needs memory that BigApp has tied up.
Until we have so much fast ram that we never need all of it, there will always be trade-offs. I expect we'll see that day eventually - we already see it with hard drives (at least for most of us). I imagine that a future post here might begin "Back in the days when nobody had enough RAM to run all their apps..."
Last edited by pcunix; 11-26-2009 at 09:58 AM.
The right question is not that, the right question is "why not to use swap when it increases performance even if it's by a small edge?" Is really that little file (you don't even need a partition) really bothering you that much?
It's a recurrent topic so I bookmarked one explanation some time ago,