What is SWAP and what do I need it for? SWAP is an amount of space in the hard-disk or any conventional file that can be used as a swapping device, which is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the physical memory is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.
Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files. Something you have to bear in mind before starting to create a SWAP partition or SWAP file is its size. If you have n amount of RAM, you need between n and 2*n MB of SWAP. So, I have 1536 MB of RAM and a SWAP partition of 3072 MB. This can depend even on the hard drive you have. If you have a big hard drive you can have 2*n MB of SWAP. How do I add more swap? A question emailed to me was "I didn't add SWAP while installing the system. Is it possible to add SWAP partition and how to do that?". Usually, people think of SWAP as a partition they create while installing the system, but it can be even a file used as a swapping device. If you're considering responsiveness, the best way is to add more RAM. Swapping to a partition or a file won't change anything. Here we are going to learn how to add SWAP to an already installed system. You can do it by adding a SWAP file in just four steps. a- Creating a file the size you want. b- Formatting that file to create a swapping device. c- Adding the swap to the running system. d- Making the change permanent. We will consider as an example a 512 Mb swap need. a- Creating a file the size you want: We will create a /mnt/512Mb.swap swap file. sudo dd if=/dev/zero of=/mnt/512Mb.swap bs=1M count=512 What's important here is count=512, which means we want our file to contain 512 blocks of bs=1M, which means block size = 1 MegaBytes Be careful *not* to do this dd of=/mnt/512Mb.swap bs=1M seek=512 count=0 Though the file grows to 512Mb immediately, it will have holes that makes it unusable. b- Formatting that file to create a swapping device: sudo mkswap /mnt/512Mb.swap c- Adding the swap to the running system: sudo swapon /mnt/512Mb.swap You can see with "cat /proc/meminfo" that your additional swap is now available. d- Making the change permanent: Edit your /etc/fstab: gksudo gedit /etc/fstab and add this line at the end of the file: /mnt/512Mb.swap none swap sw 0 0 At the end save and reboot. -- Swarandeep Singh Director,Event Management & Finance CSI NSIT Students Branch | http://societies.nsitonline.in/csi Undergraduate Student, IT Department NSIT, Delhi University, India
