Saturday, June 21, 2014

SWAP SPACE MANAGEMENT IN LINUX
=======================================

What is Swap Space?


Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM 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.




There are 2 ways to add/remove the swap space in Linux.


  • One way is to add the swap space if u have any free disks.
  • Second way is to add the swap space by creating a file on hard disk and making it as a swap space.
First method i have not tried it,as i don't have any free disks.

"free -m"  will the details of the free memory in mb in which it shows the free swap space as well.


Creating a swap file

To add a swap file:
  1. Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 512 MB swap file is 65536.
  2. At a terminal with root privileges (sudo -s), type the following command with count being equal to the desired block size:
    dd if=/dev/zero of=/swapfile bs=1024 count=524288
  3. Setup the swap file with the command:
    mkswap /swapfile
  4. To enable the swap file immediately but not automatically at boot time:
    swapon /swapfile
  5. To enable it at boot time, edit /etc/fstab to include the following entry:
    /swapfile swap swap defaults 0 0
    The next time the system boots, it enables the new swap file.
  6. After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat /proc/swaps or free.




No comments:

Post a Comment