|Version 30 (modified by jtv, 7 years ago) (diff)|
Using This Site
This development site is available to the general public. Anyone can submit bug reports, review development history etc., without any need to log in. Only the project developers need to "Login" to the site. See the UsingThisSite page for more information.
Swapspace: a Dynamic Swap Manager for GNU/Linux
What it 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, the usual swap partition can be omitted, or it can be kept quite small. Whenever Swapspace finds during normal system usage that more virtual memory is needed, it will automatically claim space from the hard disk. Conversely, swap space that is no longer needed is freed up again for regular use by the filesystem.
This means that 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 was originally foreseen, without leaving the same swap space unused and unusable during normal operation as is normally the case.
Where it comes from
Both projects are brought to you by the Open Source Department of the Software Industry Promotion Agency, an enterprise by the Thai Ministry of Information and Communication Technology. Our goal is to stimulate effective use of information technology in Thailand. We are hoping to do so by developing Suriyan (Sun) and its sister product Chantra (Moon), which comprises open-source applications for most common desktop computing tasks that run equally well on Microsoft Windows and GNU/Linux. With these projects we also hope to provide a viable alternative to unauthorized or costly use of mostly foreign proprietary software.
The Suriyan system is meant to run on a wide range of hardware from shiny new servers to hand-me-down PCs. Another design parameter is 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 that more and more swap files are needed, it will start creating larger ones to anticipate demand. While demand for swap files is modest, it will stick to smaller ones that can be initialized more quickly and so respond more fluently to present requirements.
Robustness and user-friendliness are the first priorities in developing this program. For example, all alternatives we looked at perversely needed to allocate multiple chunks of memory in dealing with low-memory situations; allocation failure would typically crash these programs. It turned out that none of these allocations were really necessary, and Swapspace manages to avoid them categorically. This kills two birds with one stone when it comes to reliability:
- the program doesn't ask for memory just when the least memory is available;
- it eliminates one of the most important causes of programming bugs as a risk factor.
User-friendliness primarily means that no silly questions are asked of the user. The daemon tries to be sensible and figure out what is needed 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.
The swapspace daemon has been in production use for several months on various 32-bit architectures before it was first released to the public, and has been tested 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.
After this point, when we tried to use up even more memory, the hard disk filled up with swap files so no more could be allocated. The program has provisions to deal with this case robustly and fairly gracefully. It does not like to leave you with a 100% full disk with no room to save your data. After we closed some of the running applications, Swapspace started steadily decommissioning swap files before settling in a more realistic 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.
We've also got some quick ProductComparison notes if you're interested.
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. 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!
We are hoping to bring further improvements in the future. Since the problem appears to be caused mostly by system code, however, it's hard to be sure that this is really possible. It may turn out to be possible for the kernel, with some modifications, to extend an existing swapfile while it is already in use. That would probably help a great deal, but we don't know at the moment how much work it would take.
If you want to know what else needs to be improved, take a look at the active tickets.
Where to start
The program is available both as a source archive and as a Debian package built from that same source archive. The program is available:
- As source code, through anonymous Subversion: svn://thaiopensource.org/srv/svn/swapspace/ (read-only)
- For Swapspace developers only, through encrypted Subversion: svn+ssh://thaiopensource.org/srv/svn/swapspace/
- In source code and as packages for Debian GNU/Linux on the x86 and ppc architectures, through ftp.
- Through http as an alternative to ftp.
- As an online-browsable versioned source tree through WebSVN.
- Through the Browse Source button on this web interface, managed by Trac.
To build and install from source, enter the main swapspace source directory and run make. Some editing of the Makefile may, but generally shouldn't, be required as long as gcc is used as the C compiler. The program code is written in standard C99 (the 1999 edition of the C standard), plus one POSIX extension. The easiest mode of installation is by running make install with root privileges.
See the provided manpage for details on how to run swapspace for troubleshooting or debugging purposes. A sample configuration file is also provided, but the average user should not need to take an interest. An init script is provided to start and stop swapspace as a regular system service.
The "make install" procedure installs the init script in /etc/init.d, but does not currently ensure that Swapspace is run on system startup.
See TechnicalDetails for more about how Swapspace works.
This program was written by Jeroen T. Vermeulen for the Software Industry Promotion Agency ( SIPA). The author can be contacted at jtv@…