Linux Swap

Linux Swap

For any OS, effective memory management is very important. In OS, physical memory and virtual memory is required to run any process. When system is running out of memory, kernel will move inactive process data into virtual memory to free physical memory. Kernel divides physical memory into chunks called pages. The process of moving active process pages to virtual memory is called swapping. Swap space can be disk partition or file.

Partition id of swap partition is 82

#mkkswap /dev/hda2                                                                  Mark as swap partition

#swapon /dev/hda2                                                                     Activate the swap partition

#swapoff /dev/hda2                                                                     Deactivate the swap partition

#fallocate -l 512m /mnt/512MiB.swap                                        Create file

#dd if=/dev/zero of=/swapfile bs=1024 count=1048576              Create file

#mkswap /swapfile; swapon /swapfile; swapoff /swapfile            Mark as swap file

In linux 2.6 kernel you can tune swapiness kernel parameter. Swapiness value can be 0 to 100; higher values leads to more swap will occur. Default swapiness is 60.

#echo 65 > /proc/sys/vm/swapiness                                            Set swapiness value

priority is a value between -1 and 32767. Higher num‐bers indicate higher priority

#swapon –p 22 /mnt/512MiB.swap                                              Set the swap prioroty

#sysctl -w vm.swappiness=30

#sysctl –a

Be the first to comment on "Linux Swap"

Leave a comment

Your email address will not be published.


*