input license here

Instructions to coordinate swap partition for linux


1.What is Swap?


Swap is virtual ram memory used when the physical ram of the server or vps is full or used in parallel with the physical ram memory to increase the memory capacity of the system.


2.Steps to create swap on centos system


B1.Check current swap partition on centos


swapon -s



B2.Check free disk space


df -h



B3. Check system ram.


free -m



B4.Create a swap partition


sudo dd if=/dev/zero of=/swapfile bs=1024 count=14336k



The above command is used to create a 14GB swap partition. Swap capacity will usually double the physical ram. Depending on how much disk system is left, we will customize it accordingly.


B5. Create swap partition


mkswap /swapfile



B6. Enable swap


swapon /swapfile



B6. Check the swap partition




B7. Set swap automatically enabled on reboot in the file /etc/fstab


echo /swapfile none swap defaults 0 0 >> /etc/fstab


B8 Re-authorize the swapfile file, only root has the right to edit the file


chown root:root /swapfile


chmod 600 /swapfile


B9.Configuring priority mode using swappiness


+swappiness = 0: swap is only used when RAM is used up.


+swappiness = 10: swap is used when RAM is 10%


+swappiness = 60: swap is used when the RAM is 60%.


+swappiness = 100: swap is preferred as RAM.


check the system's swap file usage
cat /proc/sys/vm/swappiness



edit parameter swappiness
sysctl vm.swappiness=10



Để giử nguyên thông số mỗi khi khởi động lại cần chỉnh sửa lại tham số trong file /etc/sysctl.conf
vi /etc/sysctl.conf
thêm dòng sau voà cuối file
vm.swappiness = 10


Reboot the system and check



To disable swap you can use the following command


swapoff /swapfile


Delete swap


rm -f /swapfile


Good luck
Thanh Tung-Technical staff
BKNS


Related Posts
Diệp Quân
Nguyen Manh Cuong is the author and founder of the vmwareplayerfree blog. With over 14 years of experience in Online Marketing, he now runs a number of successful websites, and occasionally shares his experience & knowledge on this blog.
SHARE

Related Posts

Subscribe to get free updates

Post a Comment

Sticky