Does it make sense to have the kernel use a swap partition?

Carsten Haitzler (The Rasterman) raster at
Fri Jul 25 02:19:38 CEST 2008

On Thu, 24 Jul 2008 13:42:28 -0600 "Jim Colton" <jimcolt at> babbled:

one thing many people make a mistake of is thinking top -or free when they say
"free memory" or "used" really gives you an accurate picture. its really
misleading. it is just aws misleading to look at the values of memory usage
ps/top display per process. unless you really know exactly what those
numbers mean - you should probably stick clear of relying on them/quoting them.

the idea of memory usage is a complex topic in a dynamically paged virtual
memory OS (like linux).

things to remember (some of which are already mentioned in this thread):

1. generally it is a good idea to NOT count buffers/cache in memory usage.
cache and buffers are using UNUSED memory to speed disk access up.if the kernel
ever needs that ram it will instantly throw it out (zero cost) and give it to
whatever needs it.
2. unused memory is wasted memory (ok - normally, but in the embedded works
unused memory - if arranged right may mean you can power down some parts of
memory as there is nothing there. as best i know there is nothing in linux that
re-arranged allocated/used pages in a way to free up memory banks so you then
can entirely power them down... though some nuts and bolts are there for
things like memory hotplug - i could be behind the times, but as best i know -
nothing automatically does this so there is no value in freememory for
openmoko. it's just wasted).
3. when looking at the usage for memory for a specific process remember that
its memory space contains not just memory for it, but memory shared between all
apps (eg pages mapping in from libc - the library pretty much every process
uses), so memory pages (which are paged in from disk on demand - and paged out
when not needed WITHOUT using swap as it can pge direct from the filesystem),
are used for all processes, thus you can consider the memory cost of the
mappings of shared libs generally not part of memory usage - as they will just
get paged out without using swap (just a performance hit to page them back in),
and once 1 process uses that library - you begin to pay the cost for it anyway
- more processes using it generally dot involve more memory usage for that lib's
static data pages.
4. with processes - there is virtual memory SPACE - which is just that -
virtual. it means nothing except someone has asked for a big playground. the
actual impact is more the RSS or RES (resident set size). this is the pages of
memory ACTUALLY used. this INCLUDES shared memory.
5. remember that pages of memory from disk will be loaded in AS NEEDED. if an
executable is 10mb - not all 10mb are necessarily used. only the parts of the
executable accessed will be loaded - when needed, and when not used anymore,
thrown away.
6. a rough rule of thumb to look at memory usage of a process is RSS then
subtract SHARED. this "ignores" memory paged from shared libs and executables
(and memory mapped files), but gives you a closer idea of how much actual memory
is "malloc()ed" (and used on the stack) and if given lots of memory pressure,
how much "swap" would be needed to swap out that process. this is not perfectly
accurate as the shared memory is vital to the working of the process, but it's
hard to tell just which shared pages are accessed often enough to really be
considered "required memory".

anyway... this is a rough guide to "memory usage". it is a COMPLEX thing and
quoting the numbers you see in top/ps/free will often be utterly misleading
unless you really know just what those numbers are representing... :)

i hope this helps a bit... (and it actually will make you look at a lot of
processes and linux itself in a different light - these processes and the os
aren't as memory hungry as you think, and 128mb of ram on the freerunner is
quite adequate... for ram... now if we can improve flash IO read rates... the
need for cache becomes less... though it still helps!). :)

> top(1) shows data from the same source as free(1) does.
> /proc/vmstat is the source.
> On Thu, Jul 24, 2008 at 12:14 PM, Nils R Grotnes <nils.grotnes at>
> wrote:
> > Hi Tim.
> >
> > > You're not subtracting buffered and cached data.  Linux aggressively
> > >  buffers written data and caches read data for potential future use.
> > >  This data is easily evicted from ram (usually without requiring
> > >  anything to be written to more permanent storage), thus not negatively
> > >  affecting performance.
> > >
> > >  For various reasons, Linux's accounting of how much ram is in use
> > >  isn't quite accurate, but you'll get a much closer number by running
> > >  'free' in the terminal and looking at the "-/+ buffers/cache" line.
> >
> > Htop is quite good at showing all three uses of memory, well worth a look.
> >
> > Don't know how accurate it is though. Any thoughts on that?
> >
> > Nils
> >
> > _______________________________________________
> > support mailing list
> > support at
> >
> >

Carsten Haitzler (The Rasterman) <raster at>

More information about the support mailing list