[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: swap space size



on Thu, Nov 18, 2004 at 04:33:45AM -0800, Karsten M. Self (kmself@ix.netcom.com) wrote:
> on Fri, Oct 22, 2004 at 07:21:20AM +0000, Alexis Huxley (ahuxley@gmx.net) wrote:
> > On 2004-10-21, Gilbert, Joseph <jgilbert@insuresuite.com> wrote:

> > Think about it, if you want to dramatically improve the performance
> > of a system then you add so much memory to it that the system stops
> > swapping. And if it stops swapping, then what purpose does having
> > "two times 'so much'" swap space have? Well, none, 'cos you've
> > deliberately ensured that it won't be used.

> "Swapping" and "swapped" are two different issues.

...having written the above a month or so back, I just ran across a
couple of really good posts from Martin Pool, who's far better aquainted
with Linux Kernel internals than I am.

Abstracted below.  I'd recommend reading the full article.

     Is swap space obsolete?
     Martin Pool
     http://sourcefrog.net/weblog/software/linux-kernel/swap.html

     [...]

     All memory pages on GNU/Linux can be grouped into four classes.
     Firstly, there are kernel pages which are fixed in memory and never
     swapped. (Some other systems have pageable kernels, but at the
     moment the GNU/Linux developers consider it too risky.) Then there
     is program text: the contents of /bin/sh or /lib/libdl-2.3.2.so.
     These are read-only in memory, and so are always exactly the same
     as the file on disk. There are file-backed pages, which might have
     changes in memory that haven't been written out yet. Finally there
     are memory.

     [...]

     The kernel can discard a clean page whenever it needs the memory
     for something else, because it knows it can always get the data
     back from disk. However, dirty pages need to be saved to disk
     before they can be reused. We call this eviction. So flushing pages
     in the background has two purposes: it helps protect data from
     sudden power cuts, and more importantly it means there are plenty
     of clean pages that can be reused when a process needs memory. 

     [...]

     If you don't have swap space, then anonymous mappings can't be
     flushed. They have to stay in memory until they're deleted. The
     kernel can only obtain clean memory and free memory by flushing out
     file-backed pages: programs, libraries, and data files. Not having
     swap space constrains and unbalances the kernel's page allocation.
     However unlikely it is that the data pages will be used again --
     even if they're never used again -- they still need to stay in
     memory sucking up precious RAM. That means the kernel has to do
     more work to write out file-backed pages, and to read them back in
     after they're discarded. The kernel needs to throw out relatively
     valuable file-backed pages, because it has nowhere to write
     relatively worthless anonymous pages.

     Not only this, but flushing pages to swap is actually a bit easier
     and quicker than flushing them to disk: the code is much simpler,
     and there are no directory trees to update. The swap file/partition
     is just an array of pages. This is another reason to give the
     kernel the option of flushing to swap as well as to the filesystem.

     As I write this, my 1024MB machine has 184MB of swap used out of
     1506MB, and only 17MB of memory free. On old-Unix this would
     indicate a perilous situation: with numbers like this it would be
     grinding. But GNU/Linux is perfectly happy with these numbers: the
     disk is idle and it responds well. 

     [...]




You might also want to look at the related:

     Why doesn't free memory go down
     http://sourcefrog.net/weblog/software/linux-kernel/free-mem.html


Peace.

-- 
Karsten M. Self <kmself@ix.netcom.com>        http://kmself.home.netcom.com/
 What Part of "Gestalt" don't you understand?
  TWikIWeThey: An experiment in collective intelligence.  Stupidity.  Whatever.
    Technical docs, discussion, reviews, opinion.
      http://twiki.iwethey.org/

Attachment: signature.asc
Description: Digital signature


Reply to: