Not enough swap space solution in Linux6

Source: Internet
Author: User

1, use the partition:

When the OS is installed, a dedicated swap partition is created, and the size of the space must be planned in advance and mount automatically when the system is booted.

This method can only be set when the OS is installed, and once the settings are changed very hard, unless the system is reinstalled.

2. Use Swapfile: (or the entire free partition)

Create a new temporary swapfile or an idle partition, set to swap space when needed, and add up to 8 swapfile.

The size of the swap space, closely related to the CPU, can use up to 2GB of space in the i386 system.

After the system starts, the total capacity of the 2G is increased or decreased as required.

This method is more flexible, but also more convenient, the disadvantage is to start the system after manual setup.

Here are the steps to use Swapfile to increase swap space:

The commands involved:

Free---View the memory status command to display the size and usage of the memory,swap,buffer cache;

DD---read, convert and output data commands;

Mkswap---setting swap area

Swapon---Enable swap area, equivalent to mount

Swapoff---Closed swap area, equivalent to Umount

Steps:

1. Create Swapfile:

Under Root, create swapfile, assuming the current directory is "/", execute the following command:

# dd If=/dev/zero of=swapfile bs=1024 count=500000

A swapfile is created in the root directory with the name "Swapfile", the size is 500M, and the file can be exported to any directory you want.

Personal feel or directly placed in the root directory is better, at a glance, not easy to damage, put in other directories is not;

The options in the command explain:

---of: the path and name of the output interchange file;

---BS: block size, unit byte, generally 1k or 1024 byte;

---count: The total number of blocks is the total size of space, in blocks that are k;

---if: Read the source of free space, why is zero, not clear, first fixed so write it;

2. Set the Swapfile to swap space

# Mkswap Swapfile

3. Enable Swap space, this operation is somewhat similar to the mount operation (personal understanding):

# Swapon Swapfile

Now that the swap space has been increased, you can use the free command to see if the size of the swap space has changed;

4, if no longer use space can choose to turn off swap space, this operation is somewhat similar to the umount operation (Personal understanding)::

# Swapoff Swapfile

Using this method in each system startup requires manual setup, Swapfile, more trouble, workaround:

Append the following to the last line of the/etc/rc.d/rc.local file: (edit this file, of course, with VI ~)

/sbin/swapon/swapfile

Save and exit so that the swap space will automatically load after the system starts;

Summary: In the installation of the OS must be planned after the swap size, usually twice times the memory, but to consider the possibility of increasing memory later, so you can consider setting a little larger, want to install oracle10g in the virtual machine, found that the default swap space does not meet the minimum requirements, Because I allocate the physical memory is 1G, then need to follow the requirements of 2G swap swap space, the default is only 1G swap space.

The steps to add swap space are as follows:

First step: Make sure there is enough space in the system for swap swap space, I am using KVM, ready to add a swap file to a separate file system, add 2G swap files to/opt/image

Step two: Add the swap file and set its size to 2G, using the following command

[[email protected] image]# dd If=/dev/zero of=/opt/image/swap bs=1024 count=2048000

After a while, the following results are returned:

2048000+0 Records in

2048000+0 Records out

2097152000 bytes (2.1 GB) copied, 272.867 seconds, 7.7 mb/s

Step Three: Create (set) Swap space, use command Mkswap

[Email protected] image]# Mkswap/opt/image/swap

Setting up Swapspace version 1, size = 2097147 KB

Fourth step: Check the size of the existing swap space and use the command free

[Email protected] image]# free-m

Total used free shared buffers Cached

mem:1011 989 21 0 1 875

-/+ buffers/cache:112 898

swap:1027 0 1027

Or check the Meminfo file

grep swaptotal/proc/meminfo

Fifth step: Start the newly added 2G swap space, using the command swapon

[Email protected] image]# Swapon/opt/image/swap

Sixth step: Confirm that the newly added 2G swap space is in effect, use the command free

[[email protected] image]# free-m

Total used free shared buffers Cached

mem:1011 995 15 0 4 877

-/+ buffers/cache:113 897

swap:3027 0 3027

Or check the Meminfo file

grep swaptotal/proc/meminfo

Seventh Step: Modify the/etc/fstab file so that the newly added 2G swap space automatically takes effect after the system restarts

At the end of the document, add:

/opt/image/swap swap swap defaults 0 0

My actions

[[email protected] server]# free

Total used free shared buffers Cached

mem:1785856 1753452 32404 0 38592 1036312

-/+ buffers/cache:678548 1107308

swap:2064376 116 2064260

Create swap space file, 1000M

[[email protected]/]# dd If=/dev/zero of=/swapfile bs=1024 count=1000000

1000000+0 Records in

1000000+0 Records out

1024000000 bytes (1.0 GB) copied, 28.5423 seconds, 35.9 MB/s

[Email protected]/]# Mkswap swapfile

Setting up Swapspace version 1, size = 1023995 KB

[[email protected]/]# swapon Swapfile Open

[[email protected]/] #swapoff swapfile off

Delete

Swapoff Swapfile

RM-RF Swapfile


This article is from the "vmware/oracle" blog, make sure to keep this source http://123124432.blog.51cto.com/12616119/1904434

Not enough swap space solution in Linux6

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.