Changeset 92

Show
Ignore:
Timestamp:
07/03/05 04:53:35 (4 years ago)
Author:
jtv
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • README

    r90 r92  
    1111swapspace finds, during normal system usage, that more virtual memory is needed, 
    1212it will automatically claim space from the hard disk.  Conversely, swap space 
    13 that is no longer needed is freed up for regular use by the filesystem. 
     13that is no longer needed is freed up again for regular use by the filesystem. 
    1414 
    1515This means that with swapspace installed, sizing the system's available swap 
    1616space during installation is no longer a life-or-death choice.  It now becomes 
    17 practical to run GNU/Linux off just a single, big partition with no disk space 
     17practical to run GNU/Linux off just a single, big partition--with no disk space 
    1818lost to regrettable installation decisions.  The system should also be able to 
    1919handle the occasional memory-intensive task that takes much more swap space than 
    2020was originally foreseen, without leaving the same swap space unused and unusable 
    2121during normal operation. 
     22 
     23Swapspace is made available for use under the GNU General Public License (GPL). 
     24See the file COPYING for details. 
    2225 
    2326 
     
    3235example, all alternatives we have found will unnecessarily allocate several 
    3336chunks of memory in dealing with low-memory situations.  Allocation failure will 
    34 typically crash these programs, whereas swapspace avoids all dynamic memory 
    35 allocation except as is done internally by the system in setting up swap files
     37typically crash these programs, whereas swapspace categorically avoids all 
     38reliance on dynamically allocated memory
    3639 
    3740User-friendliness primarily means that no silly questions are asked of the user. 
    3841The daemon tries to be sensible and figure out what is needed at runtime, by 
    39 itself, and without user intervention.  It is by no means perfect in this 
    40 regard, but it is a priority for future improvement. 
     42itself, and without user intervention. 
    4143 
    4244The swapspace daemon has been in production use for several months on various 
    434532-bit architectures before it was first released to the public, and has been 
    4446tested with swapfiles larger than can be addressed in 32 bits.  Some statistics 
    45 for one test on a 32-bit PC with one gigabyte of memory: 
     47for one test on a 32-bit PC with 1 gigabyte of memory: 
    4648 
    4749        Number of swapfiles     25 
    48         Largest swapfile        >5 GB 
     50        Largest swapfile        5.6 GB 
    4951        Total swap allocated    44 GB 
     52 
     53After this point the hard disk filled up with swap files, making it impossible 
     54to allocate more.  The program has provisions to deal with this case robustly 
     55and fairly gracefully.  After most of the virtual memory was freed up again, it 
     56started steadily deallocating swap files before settling in a more realistic 
     57state. 
    5058 
    5159 
     
    5361 
    5462In its current form, swapspace is probably not a good choice for systems that 
    55 need to remain responsive at all times; the creation a large new swapfile can 
    56 take as long as half a minute and occupy quite a lot of the system's attention. 
     63need to remain responsive at all times; depending on the system and the 
     64cicrumstances, the creation a large new swapfile can take as long as half a 
     65minute and occupy quite a lot of the system's attention.  The program attempts 
     66to minimize the frequency of allocations, but cannot avoid them altogether while 
     67still being useful. 
    5768 
    58 We are hoping to address this shortcoming in the future, but since the problem 
    59 appears to be caused mostly by system code, it's hard to be sure that this is 
    60 really possible. 
     69We are hoping to address this shortcoming in the future.  Since the problem 
     70appears to be caused mostly by system code, however, it's hard to be sure that 
     71this is really possible. 
    6172 
    6273 
    6374Where to start 
    6475 
    65 To build and install from source, enter the main swapspace directory and run 
    66 "make".  Some editing of the Makefile may, but generally shouldn't, be required 
    67 as long as gcc is used as the C compiler; the program code is written in 
    68 standard C99.  The easiest mode of installation is by running "make install" 
    69 with root privileges. 
     76The program is available both as a source archive and as a Debian package built 
     77from that same source archive. 
     78 
     79To build and install from source, enter the main swapspace source directory and 
     80run "make".  Some editing of the Makefile may, but generally shouldn't, be 
     81required as long as gcc is used as the C compiler.  The program code is written 
     82in standard C99 (the 1999 edition of the C standard), plus one POSIX extension. 
     83The easiest mode of installation is by running "make install" with root 
     84privileges. 
    7085 
    7186See the provided manpage for details on how to run swapspace for troubleshooting 
     
    7792not currently ensure that swapspace is run on system startup. 
    7893 
    79 Swapspace is made available for use under the GNU General Public License (GPL). 
    80 See the file COPYING for details. 
    8194 
     95Technical details: Installation 
     96 
     97The installation procedure creates a directory /var/lib/swapspace, which must be 
     98accessible to the system's superuser (root) only; granting any kind of access 
     99for this directory to an untrusted user is likely to constitute a serious 
     100security hole. 
     101 
     102According to the Filesystem Hierarchy Standard, other appropriate places for 
     103this kind of file might be /var/tmp or /var/run.  The former was not deemed 
     104appropriate because it is accessible to all users, and the latter because most 
     105system administrators would probably expect it to occupy very little space and 
     106may confine it to a partition that isn't large enough to hold useful swap space. 
     107 
     108Also, files in /var/lib survive reboots whereas those in /var/tmp and /var/run 
     109need not.  Obviously any data in swap files can be safely erased on reboot (it's 
     110even tempting to think that that would be safer, though I don't think it really 
     111is).  But consider a system consistently short on physical memory: during boot, 
     112swapspace will see the swapfiles left by the previous session, and reinstate 
     113them immediately at very little cost, ready for use when they are needed.  If 
     114they had been erased during reboot, swapspace would have to allocate new ones on 
     115disk when it recognized the need for more virtual memory, which takes much more 
     116time and resources. 
     117 
     118Technical details: Algorithm 
     119 
     120Choices of allocation and deallocation are driven by a "finite state machine" 
     121consisting of four states: steady, hungry, overfed, and diet.  The program will 
     122alternate through these states as circumstances dictate, applying different 
     123policies depending on current state.  This was done to achieve a good tradeoff 
     124between willingness to free up unused swap space on the one hand, and avoidance 
     125of "thrashing" between deallocation and re-allocation of swapfiles on the other. 
     126 
     127For those interested, here is a quick description of these states and their 
     128associated policies: 
     129 
     130Steady - normal operation; no additional swap space is needed, nor do we have 
     131more than is needed.  However, the program can go into the hungry or overfed 
     132states at the drop of a hat. 
     133 
     134Hungry - more swap space was recently allocated.  The program is willing to 
     135allocate even more if needed, but it will not consider dropping unneeded swap 
     136files.  After a certain timeout period, the program reverts to the steady state. 
     137 
     138Overfed - significantly more virtual memory is available than is needed.  If 
     139this situation persists for a certain timeout period, a swapfile is deallocated 
     140and the program returns to the steady state. 
     141 
     142Diet - a recent allocation attempt has run into resource limits, e.g. because 
     143the filesystem used for swap files was full.  No more swapspace can be allocated 
     144but excess files can be freed up very rapidly.  Afer timeout, reverts to steady. 
     145 
     146State information can be queried by sending the program the SIGUSR1 signal (see 
     147"man 7 signal" to get the number for your architecture) which will cause it to 
     148log debug information to the system's daemon log and/or standard output, as 
     149appropriate.  The program can also be made to log state transitions by starting 
     150it with the -v or --verbose option. 
     151 
  • TODO

    r90 r92  
    1 For some reason it seems to be impossible to enter the "diet" state right now
     1More documentation; find better source format
    22 
    3 After allocating 44 GB in 25 swapfiles of up to 5.8 GB (all decimally rounded 
    4 from byte counts, not binary gigabytes) the program keeps attempting to allocate 
    5 the same swapfile.  It logs a notice "Allocating swapfile" but the only thing 
    6 that follows is a transition to "hungry." 
     3Work on "eviction policy."  Delete swapfile with largest free space? 
    74 
    8 In one case an "Error writing swapfile" was logged, with the errno of "No space 
    9 left on device," but the result was the same.  Except that until this happened, 
    10 the program seemed to loop in a state where it was unresponsive to a decrease in 
    11 memory requirements.  It should have gone into "overfed" by then, I think. 
     5Custom signals can interrupt creation/decommissioning of swapfiles.  I'm not 
     6sure this is a bad thing, but it might create a risk of leaking files. 
    127 
     8Experiment with different ways of writing data to swapfiles--which is the least 
     9cache-intrusive? 
     10 
     11Try to detect situations where the next swapfile will fill up the disk, and 
     12don't try to allocate.  As a side effect, this may make swapspace respect the 
     13filesystem's conservative measurement of free disk space, which seems proper. 
     14See coreutils "df" source code for how to find this information. 
     15 
     16Describe the algorithm's finite state machine in Dot. 
     17 
     18Adaptive cooldown times: recognize pattern of consistent policy reversals too 
     19close to timeout or too soon after decision is made. 
     20 
     21Test handling of too many swapfiles. 
     22 
     23Test rollover of swapfile numbering, and skipping of occupied slots.  
     24 
     25Allow saving of behaviour model (initially, just cooldown time) so as to reduce 
     26warmup time. 
     27 
     28Rephrase "meekness" as "elasticity". 
     29 
     30Document -v|--verbose and any other forgotten options. 
     31