Adding and optimizing system swap partition swap in Ubuntu

Source: Internet
Author: User

To add a swap partition in Ubuntu:
One advantage of adding this partition: The 32-bit system can recognize the memory size (without this partition, only 3 GB can be identified, and 4 GB can be recognized by this partition)
1. Check the status of the current swap partition:
CAT/proc/meminfo
Swaptotal: 0 KB
Swapfree: 0 KB
If the two items above are both 0, there is no swap partition. If the value is not 0, this partition exists.
2. Check the space available in the/root directory:
System> System Management> system monitor> File System
Check the available space. The size of the SWAp partition can be determined based on the available space in the root directory. The larger the available space, the larger the swap can be set, swap partition space is divided from the root directory
At the same time, let's take a look at the system monitor-> system, kernel and memory information to see if the kernel has been upgraded to a memory that can recognize 4 GB or above? If the memory size is 3.8 GB, the kernel recognizes 4 GB memory.
3. If swap partition already exists and the swap partition size needs to be adjusted, perform the following operations first:
A. Find the directory where SWAp. disk is located.
B. CD: Enter the directory where SWAp. disk is located.
C. sudo swapoff swap. Disk
D. sudo RM swap. Disk
4. re-allocate the swap partition size (if there is no swap. Disk directory before, it is recommended to go to the "/" root directory and execute the following command ):
A. sudo dd If =/dev/Zero of = swap. disk BS = 1 m COUNT = 6 K (COUNT = 1 K create 1g swap, if you want to create 6G count = 6 K; this step is slow)
B. sudo mkswap-F swap. Disk
C. sudo Swapon swap. Disk
5. view the situation after swap partition is allocated:
Swaptotal: 6291452 KB
Swapfree: 6291452 KB

 

Steps for optimizing swap partition in Ubuntu:
In ubuntu, the size of the swappiness value is closely related to how to use the swap partition. When swappiness is set to 0, the physical memory is used to the maximum extent, and then the swap space is used. When swappiness is set to 100, the swap partition is actively used, in addition, the data in the memory is promptly moved to the swap space. Two extremes. For Ubuntu's default settings, this value is equal to 60. We recommend that you change it to 10. Specifically:
1. View swappiness in your system
$ CAT/proc/sys/Vm/swappiness
If nothing happens, you should see 60.
2. Change the value of swappiness to 10.
$ Sudo sysctl VM. swappiness = 10
However, this is only temporary modification. After you restart the system, the default value of 60 will be restored. Therefore, we need to do one step:
$ Gksudo gedit/etc/sysctl. conf
Add the following line at the end of this document:
VM. swappiness = 10
Save and restart. OK. Your settings will take effect. You will find that the rabbit running faster now!
Of course, you can use other editors, such as Kate, Vi, Vim, nano ...... You only need to replace gedit with them! Because most people use gnome desktops, gedit is written.

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.