The simple explanation of the rule follows. In the state of equilibrium
- Half the number of memory operations are allocations, the other half is freeing
- For the half that is freeing, half of those operations result in holes being merged (contiguous ones)
This tells us that the ratio of holes to allocated blocks is fifty percent.
In the state of equilibrium there are half as many holes as total allocated blocks. A hole is referred to as a available memory (free memory). If the total allocated memory in blocks is n then the number of holes is n/2.
The total available blocks is 3n/2 and available blocks is n/2. The ratio of free memory to total available memory (assuming block sizes are equal) comes to 1/3. So if you have 256MB of RAM on your system and want it to be available free for the next task you want to run, then you must allocate a swap size of 512MB, so that the ratio of 1/3 is held.
There are of course complications to this simple rule or calculation that I explained above. I will try and explain some of those complexities in the next series of swapping articles.