===============================================

2020-05-14: Site rewrite — disaster struck and I'm having to reconstruct the site from old databases and converting formats by hand. Still, it was time for an update!

I'm no longer maintaining this project. But someone else is. Jacob Adams maintains a fork on Github. Thank you, Jacob, and my apologies for taking so long to find your email at the time.

I think Swapspace has shown itself to be robust, stable, and useful over time. It needed only minimal changes in many years.

Why am I no longer maintaining it myself? When I started it, I had to work out all the hosting myself and that became more work than I could handle: create a Subversion repository, write a project index, configure firewalls, set up and manage mail / web / svn servers, run Trac, organise authentication and authorisation, tweak fonts and images, fight spam, block network attacks, clean up databases, install OS updates, schedule backups and delete old backups. A lot of the work wasn't automated, so I even had to write my own scripts for much of it.

The development world has changed a lot since then, and it's easy to host a project like this on a free service. But I never thought I needed to. Swapspace remained pretty good just as it was. And so... one day I noticed that the svn repo had broken a long time ago, probably in some upgrade, and I no longer had backups from that far back.

So if you like Swapspace, go with Jacob's fork.

What Swapspace does for you

This system daemon for the Linux kernel aims to do away with the need for large, fixed swap partitions or swap files.

When installing a Linux-based system (invariably GNU/Linux) with Swapspace, you can just leave out the usual swap partition, or keep it quite small. Whenever Swapspace finds that your system needs more virtual memory, it will automatically claim space from the hard disk. Conversely, when it sees swap space that is no longer needed, it frees some up again for regular use by the filesystem.

With Swapspace installed, sizing the system's available swap space during installation is no longer a life-or-death choice. It now becomes practical to run GNU/Linux off just a single, big partition — with no disk space lost to regrettable installation choices. The system should also be able to handle the occasional memory-intensive task that takes much more swap space than you saw coming when you set up the system, without leaving the same swap space unused and unusable during normal operation as is normally the case.

Swapspace is free software, made available to you under the GNU General Public License (GPL).

Where it comes from

This software was originally written for the Suriyan project, a Debian-based server system primarily aimed at small and medium-sized enterprises in Thailand.

Suriyan was created by the Open Source Department of the Software Industry Promotion Agency, an enterprise by the Thai Ministry of Information and Communication Technology. The goal is to stimulate effective use of information technology in Thailand.

The Suriyan server system was meant to run on a wide range of hardware from shiny new servers to hand-me-down PCs. Another design parameter was to avoid confronting the user with unnecessary installation choices. To help meet these requirements we developed this program which deals with the limitations of both memory and hard-disk sizes as they arise for any given system.

How it compares

Unlike similar programs such as dynswapd and the older (and more portable) swapd, Swapspace also adapts the sizes of the swap files it creates to meet demand. This means it is less dependent on limits that the kernel may impose on the total number of swapfiles, while reducing the need for manual configuration. If the daemon finds itself needing more and more swap files, it will start creating larger ones to anticipate demand. As long as demand for swap files is modest, it will stick to smaller ones. Small ones initialise more quickly and so they respond more fluently to present requirements.

Robustness and user-friendliness are the first priorities in developing this program.

As an example of robustness, when I looked at the existing alternatives, I found that perversely the first thing they did when they discovered that the system was low on memory, was to allocate some memory! Allocation failure would typically crash these programs. None of these allocations proved to be absolutely necessary. Swapspace avoids them categorically.

User-friendliness mainly means asking the user no silly questions. The Swapspace daemon tries to be sensible and figure out what it needs at runtime, by itself, and without user intervention. You should not have any need to learn about the configuration parameters, or tweak them. They exist mostly for development purposes.

Back in the 32-bit days, before releasing Swapspace to the public, I tested it with swapfiles larger than can be addressed in 32 bits. Some statistics for one test on a 32-bit PC with 1 gigabyte of memory:

Number of swapfiles 25
Largest swapfile 5.6 GB
Total swap allocated 44 GB

In other words, applications on this 1 GB desktop computer took up a whopping (by 2005 standards) 44 GB of memory space without falling over. They weren't very fast, of course, having to swap so much; but they did keep running.

The ultimate limit on swap space turned out to be hard drive space. There was simply no more room to allocate any more. Even in that situation, Swapspace has provisions to handle it robustly and fairly gracefully. It does not like to leave you with a 100% full disk and no room to save your data. After I closed some of the running applications, Swapspace started steadily decommissioning swap files before settling into a more normal state.

Swapspace itself is a small program: about 50 kilobytes on my system — or even less in a special version that only accepts the most basic configuration options and ignores its configuration file. On top of that it allocates no memory at runtime (although the system will allocate some, of course) and probably does not use much stack space.

When not to use it

In its current form, Swapspace is probably not a good choice for systems that need to remain responsive at all times. Depending on the system and the cicrumstances, the creation a large new swapfile can take as long as half a minute and occupy quite a lot of the system's attention. Don't expect your system to be responsive while this is going on. The program minimizes the number of times swapfiles are created, but it wouldn't be very useful if it never created any swapfiles at all!