Use swap space on centos

Source: Internet
Author: User

Use swap space on centos
Use swap space on centos

  • Use swap space on Linux
    • Learn more about swap space
    • Start to use swap space
      • Create a swap space
      • Specify swap space
      • Enable swap space
      • Disable swap space
    • Enable swap space automatically upon startup

Learn more about swap space

Swap (Swap partition) in centos is similar to Windows virtual memory. When the memory is insufficient, some hard disk space is virtualized into memory, so as to solve the problem of insufficient memory capacity. Android is a Linux-based operating system. Therefore, you can use Swap partitions to improve system running efficiency.

Swap partition: swap, which means "swap" and "Physical Transaction ". When the memory is insufficient, the operating system first saves the data temporarily unused in the memory to the swap space on the hard disk to free up the memory for other programs to run, and Windows virtual memory (pagefile. sys.

Start to use swap space
Note: Create, enable, and disable swap space must be executed under root
1. Create a swap space

The command is as follows:

dd  if=/dev/zero  of=swapfile  bs=1024  count=500000
Assuming that the current directory is "/home", a swap space file named "swapfile" is created under the "/home" directory. The size is 500 mb. The options in the command are described as follows: of: the path and name of the output swap file; bs: block size, in bytes; 1 K in the computer is 1024 bytes; count: the total number of blocks is the total size of space, the Unit is block, that is, k. if: Why is the Read Source Free Space zero? I do not know why the swap space is usually 1-2 times the actual physical memory, for example: the physical memory is 1 GB, And the swap space can be 1 GB to 2 GB.

Note: The swap space cannot be too large!

The read speed of the swap space is much slower than that of the memory. If the swap space is too large and there are too many resources in the swap space, the computer performance will be reduced.
2. Specify the swap space

The command is as follows:

# Swapfile is the absolute path of the swap space # For example, mkswap/home/swapmkswap swapfile
Run the command. When the command cannot be found, please note !!!
Some users do not use root to perform these operations, so the above command cannot be found.

Solution: (these commands are not available in the current Linux Version) 1. Switch to root 2. Specify the absolute path of the command (these commands are under/sbin), for example:

 /sbin/mkswap swapfile

In the following operation, the command cannot be found, as shown in the preceding figure.

3. Enable swap space

The command is as follows:

 swapon  swapfile

Now the operation to increase the swap space is complete. You can run the free command to check whether the swap space size has changed.

*. Disable swap space

If you no longer use space, you can use the following command to disable the swap space:

swapoff  swapfile
Enable swap space automatically upon startup

InAdd the following content to the last line of the/etc/rc. d/rc. local file:

/sbin/swapon /swapfile

Save and exit. After the system is started, the swap space is automatically loaded.

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.