How to empty the swap partition in the disk and enlarge the swap partition

Source: Internet
Author: User

1 My system is centos6.x memory has 32G, supposedly should allocate swap partition for 8G but, because of historical reasons, this allocation of swap partition is 4G, but this machine ran MySQL, occupy the swap partition for 1G, resulting in more than swap consumption, Zabbix monitoring has been in the alarm, so to increase the swap partition! The premise is to put this swap down, first to dump the swap partition into memory!



Steps:

First

Sync synchronizes the system buffers to disk

Sync


Second:

echo "3" >/proc/sys/vm/drop_caches

Explanation: The operation to release the cache!

As this is a non-destructive operation, and dirty objects was not freeable, the user should run ' sync ' first in order to M Ake sure all cached objects is freed.


Default is 0


Third: Disable all swaps

Swapoff-a


IV: Using files as swap partitions


1. Create a file to be a swap partition: increase the 1GB size of the swap partition, the command is written as follows, where count equals the number of blocks you want (bs*count= file size).

DD If=/dev/zero of=/root/swapfile bs=1g count=8


2. Format the swap partition file:

Mkswap/root/swapfile

#建立swap的文件系统


3. Enable the Swap partition file:

Swapon/root/swapfile

#启用swap文件


4. Make the system self-enabled when booting, add a line in the file/etc/fstab: (Leave previous comments out)

/root/swapfile swap swap defaults 0 0



V: Restore the mode using the cache

echo "0" >/proc/sys/vm/drop_caches




Real environment, found that MySQL automatic restart, 3306 has a down a while, and the process has been restarted, and then automatic, suspect that swap is all dump into memory, and not enough memory caused! Or MySQL does not use the swap will be down, because of the MySQL configuration, I did not delve into it!




Read:

To free Pagecache:


Echo 1 >/proc/sys/vm/drop_caches

To free dentries and inodes:


Echo 2 >/proc/sys/vm/drop_caches

To free Pagecache, dentries and Inodes:


Echo 3 >/proc/sys/vm/drop_caches

As this is a non-destructive operation, and dirty objects was not freeable, the user should run ' sync ' first in order to M Ake sure all cached objects is freed.




This article is from the "Tridewah operation and maintenance work Road" blog, please be sure to keep this source http://cuidehua.blog.51cto.com/5449828/1773203

How to empty the swap partition in the disk and enlarge the swap partition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.