Swapspace is a one-size-fits-all approach to managing swap space on GNU/Linux systems. Looking for existing products that might do the job, 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
looked 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 questions during installation
-
actively 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