Version 3 (modified by jtv, 14 years ago) (diff)


A "one size fits all" choice of swap space management was needed for our Debian-based GNU/Linux distribution aimed primarily at Thai SMEs.

Looking for a dynamic solution that didn't require a fixed swap size to be chosen up-front, we came across the well-known swapd 0.2 but it simply didn't work, even in the "improved Debian version." There is also a portable third-party rewrite (swapd 1.2) that did work, but had several shortcomings:

  • required manual configuration
  • recommended compiling a modified kernel
  • used things like malloc() in dealing with memory shortages
  • did not always check for and handle allocation errors
  • was fairly hard to maintain because of portability and C coding style
  • did not appear to have a clear, stable, reasoned-out policy
  • based on the source, seemed prone to "leak" swapfiles on disk

This eliminated swapd as an option. Another candidate was dynswapd. Written in C++, this program would not suffer from segmentation faults as allocations failed--but it still had significant drawbacks:

  • failed to catch any exceptions, so much the same effect as unchecked malloc()
  • needed C++ runtime libraries
  • contained "hidden" allocations through use of C++ standard library
  • was entirely devoid of comments and documentation: just code and copyright notices

The choice to write our own swap manager was not taken lightly; it simply seemed easier to write our own than to adapt what was already there, and facts have borne this out. Based on the same principles as swapd and dynswapd, Swapspace has some positive traits that set it apart from similar daemons:

  • adaptive swapfile sizes; no configuration required, no difficult questiosn during installation
  • tries to avoid repeated logging of unneeded information that might fill up disk partitions
  • no dynamic resource allocation apart from opening files (and reasonable stack usage)
  • maintainable: adding a new configuration option to the code generally takes less than 20 seconds!
  • clearly marked, simple policies for swapfile sizing, allocation/deallocation etc.
  • backs off when disk space runs out, swapfiles get too large, changes are too frequent etc.
  • restartable: rediscovers its own inactive swapfiles on startup, then resumes control over active ones in its dedicated directory
  • makes it easy to decommission all its swap files, or reduce its space usage, on demand