![]() |
![]() ![]() GNU/Linux Desktop Survival Guide by Graham Williams |
![]() |
|||
If you run many applications at once, each of them is using RAM. Thus it is not difficult to fill up RAM, in which case your computer would probably stop being able to do anything. Linux uses the idea of swap memory to extend RAM with disk space, so that even if all your applications are using more memory than available in RAM you can still continue working! Swap partitions and swap files can be considered as extra (but slower) RAM! The real solution for improving such situations is to install more RAM.
If you are running out of swap memory you can add more by creating a swap file on disk. Swapping to a file is a little less efficient than swapping to a dedicated swap partition as the kernel needs to access the new swap file through the file system. But since this swap file is only called upon when you've run out of RAM and then swap memory on a dedicated partition, the additional performance hit is not much compared to that of swapping itself.
Have a look at what memory you have available:
# free total used free shared buffers cached Mem: 256216 252208 4008 118100 56996 46944 -/+ buffers/cache: 148268 107948 Swap: 224900 51268 173632 |
# swapon -s Filename Type Size Used Priority /dev/hda5 partition 498920 258728 -1 |
Next create a file without holes and a multiple of 4K in size (in this
example, adding about 256MB):
# dd if=/dev/zero of=/extra-swap bs=1024 count=262144 262144+0 records in 262144+0 records out |
# dd if=/dev/zero of=/extra-swap bs=1M count=512 |
Now mark the new swap file as a swap file by writing a signature to
its beginning which contains some administrative information used by
the kernel:
# mkswap /extra-swap Setting up swapspace version 1, size = 268431360 bytes |
Tell the kernel about the new swap file:
# swapon /extra-swap |
# free total used free shared buffers cached Mem: 256216 252448 3768 118100 56996 46944 -/+ buffers/cache: 148508 107708 Swap: 487036 51268 435768 |
To remove the swap file from usage:
# swapoff /extra-swap |
/extra-swap none swap sw 0 0 |