Swap
- 0
- Add a Comment
- No Related Post
Swap
Windows users are familiar with the concept of swap files - the process by which hard drive space is used in lieu of RAM when RAM is maxed out by another process. Linux uses swap space, as well for this paging process.
While considerably slower than physical RAM, the use of swap files allows users to run simultaneously run programs that would not normally fit into your physical RAM. The slower access to data is, in most cases, seen as a reasonable tradeoff.
Linux allows up to 16 swap areas. These can be full partitions or disk files. Given that Intel system create memory pages of 4096 bytes, your swap space should be of a size evenly divisible by 4096. As with Windows, the recommended swap space size is a multiple of 1.5-2 times your existing physical memory.
The free command will display a list of available swap:
| total | used | free | shared | buffers | cached | |
| Mem: | 262144 | 225280 | 36864 | 28514 | 4096 | 63442 |
| +/- buffers: | 157742 | 104402 | ||||
| Swap: | 393216 | 23916 | 106382 | |||
Here we see that there’s actually ample physical RAM available, as indicated by the free column in the Swap row.
Setting up a swap file can be done in the initial setup of your Linux machine. You can also reallocate space for swap using the following command:
dd if=/dev/zero of/swap bs=1024 count=8192
This command creates a swap file rather than a full partition for swap. This creates a new swap file by writing 8192 blocks of data from /dev/zero to the /swap file. The next step in creating this additional swap space is to use the mkswap command:
mkswap -c [device][size]
In this example, [device] is the /swap file you just created and [size] is in 1K blocks. After formatting the new file for swap, be sure to run the sync command just to be sure that the formatting information has been written to the new swap file.
Swap is important in both Windows and Linux. Setting up additional swap space is as simple as creating a new file into which the swap data will be written.
