question: +swap_pager_getswapspace(16): failed

Oliver Fromme olli at lurza.secnetix.de
Wed Apr 25 14:47:03 UTC 2007


Harald Schmalzbauer wrote:
 > I have a little understanding problem:
 > My box has 128MB memory, far enough for the task.

Are you sure?  I see you're running perl scripts.  Those
can easily (and sometimes unexpectedly) eat a lot of
memory.

 > After a few days I always see some processes dying because:
 > 
 > +swap_pager_getswapspace(2): failed
 > +pid 48211 (perl5.8.8), uid 58, was killed: out of swap space

AFAIK, the kernel selects the largest process for killing
when it runs out of swap.  So your perl was probably quite
large.

 > Why won't for example the 21MB Buf get freed before more swap space gets 
 > requested than available (swap is very low, it's FlashDisk!)?
 > Is there a way to find out what process is swapped?

There's a difference between swapped and paged.  Swapped
means that a process has been _completely_ moved to swap
space.  Such processes had a "W" flag in the state column
of ps(1).  In contrast to that, paging happens on pages,
not on processes.  Note that pages are not uniquely
assigned to one process, but they can be shared between
processes, so it's difficult (or even impossible) to give
clear numbers on the amount of paging per process.

 > Thanks for any hints. My only way to circumvent this problem is to reboot the 
 > machine daily.

I've also set up machines with limited RAM and without
hard disk for swapping.  I never swap onto flash memory,
because flash has a limited number of write cycles (it
suffers from certain wear).  If you have another server
within short network distance, you should consider
remote swapping via NFS.  It's not as slow as it sounds
(depending on the speed of the network and the server),
and at least it's better than nothing.

Otherwise, don't swap (or page) at all.  The folowing
sysctl will optimize your system for that case:

vm.swap_enabled=0
vm.swap_idle_enabled=0
vm.defer_swapspace_pageouts=1
vm.disable_swapspace_pageouts=1
kern.ipc.shm_use_phys=1

You should also build a custom kernel that contains
"options NO_SWAPPING".  Also make sure that you remove
everything from your kernel that you don't need, so more
memory is availale for userland.  In particular, remove
"options UFS_DIRHASH", because the dirhash code can eat
quite a lot of memory.

And of course you should not run any processes that you
don't really need.  But I guess you already know that.

It might also help to set the "R" malloc flag:
# ln -s R /etc/malloc.conf
It can reduce memory fragmentation for processes that
do a lot of small (re)allocations.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"C++ is to C as Lung Cancer is to Lung."
        -- Thomas Funke


More information about the freebsd-stable mailing list