Solution to insufficient swap space in linux

Source: Internet
Author: User
There are two ways to increase swap space after linux swap space is insufficient: Strictly speaking, there is only one way to add swap after the system is installed, which is the second method in this article, the first method should be to set the swap zone when installing the system. 1. use partition: www.2cto.com...
There are two ways to increase swap space after linux swap space is insufficient: Strictly speaking, there is only one way to add swap after the system is installed, which is the second method in this article, the first method should be to set the swap zone when installing the system. 1. partition: www.2cto.com divides a dedicated swap partition when installing the OS. The size of the swap partition must be planned in advance and automatically mount the partition when the system is started. This method can only be set during OS installation. Once set, it is difficult to change unless you reinstall the system.
2. use swapfile: (or the entire idle partition) to create a temporary swapfile or an idle partition. set it to swap space as needed. a maximum of 8 swapfiles can be added. The swap space is closely related to the CPU. in the i386 system, a maximum of 2 GB space can be used. Increase or decrease the total capacity of 2 GB after the system is started. This method is flexible and convenient. The disadvantage is that it needs to be set manually after the system is started. The following describes how to use swapfile to increase the swap space: the involved command: www.2cto.com free --- view the memory status command, which can display the size and usage of memory, swap, buffer cache, and so on; dd --- read, command to convert and output data; mkswap --- set the swap zone swapon --- enable the swap zone, equivalent to mountswapoff --- disable the swap zone, equivalent to umount step: 1. create swapfile: root permission, create swapfile, if the current directory is "/", run the following command: # dd if =/dev/zero of = swapfile bs = 1024 count = 500000 then a swapfile is created under the root directory, the name is "swapfile" and the size is 500 MB. you can also output the file to any directory you want. in my opinion, it is better to directly store the file in the root directory, it is not easy to mistakenly destroy, but it is not possible to put it in another directory; option solution in the command Description: --- of: path and name of the output swap file; --- bs: block size, in bytes, usually 1 K, that is, 1024 bytes; --- count: the total number of blocks is the total size of the space, and the unit is block (k). --- if: the read source free space. why is it zero? it is not clear. please fix it first; 2. set swapfile to swap space # mkswap swapfile3. enable swap space. this operation is similar to the mount operation (for my personal understanding): # The operation of adding swap space to swapfile has ended, you can use the free command to check whether the swap space size has changed. 4. if you no longer use the space, you can disable the swap space. this operation is similar to the umount operation (for my personal understanding ):: # swapoff swapfile this method requires you to manually set and enable swapfile every time the system is started. it is troublesome. solution: in/etc/rc. d/rc. add the following content to the last line of the local file: (edit this Of course, vi is used ~) /Sbin/swapon/swapfile is saved and exited. after the system is started, the swap space is automatically loaded. conclusion: you must plan the swap size when installing the OS, it is usually twice the memory size, but you need to consider the possibility of increasing the memory in the future, so you can consider setting up a slightly larger number and want to install oracle10g in the virtual machine, the default swap space does not meet the minimum requirements. because the physical memory I allocate is 1 GB, 2 GB swap space is required. by default, only 1 GB swap space is required. To add a swap space, follow these steps: www.2cto.com. Step 1: Make sure that there is sufficient space in the system for swap space. I use KVM, prepare to add a swap file to an independent file system. add 2 GB swap file to/opt/image. Step 2: Add the swap file and set its size to 2 GB, run the following command [root @ sense image] # dd if =/dev/zero of =/opt/image/swap bs = 1024 count = 2048000 over a period of time, the following result is returned: 2048000 + 0 records in2048000 + 0 records out2097152000 bytes (2.1 GB) copied, 272.867 seconds, 7.7 MB/s Step 3: Create (set) swap space, run the command mkswap [root @ sense image] # mkswap/opt/image/swapSetting up swapspace version 1, size = 2097147 kB Step 4: Check the size of the existing swap space, run the free [root @ sense 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 Step 5: start the new 2G swap space, run the swapon [root @ sense image] # Step 6 of swapon/opt/image/swap: check that the newly added 2G swap space has taken effect, run the free [[root @ sense image] # free-m total used free shared buffers cachedMem: 1011 995 15 0 4 877-/+ buffers/cache: 113 897 Swap: 3027 0 3027 or check the meminfo file grep SwapTotal/proc/meminfo Step 7: modify the/etc/fstab file so that the newly added 2G swap space will automatically take effect after the system restarts and add it at the end of the file: /opt/image/swap defaults 0 0 www.2cto.com uninstall my operations [root @ weblogic Server] # free total used free shared buffers cachedMem: 1785856 1753452 32404 0 38592 1036312-/+ buffers/cache: 678548 1107308 Swap: 2064376 116 2064260 create a Swap space file, 1000 M [root @ weblogic/] # dd if =/dev/zero of =/swapfile bs = 1024 count = 10000001000000 + 0 records in1_00 + 0 records out10241_00 bytes (1.0 GB) copied, 28.5423 seconds, 35.9 MB/s [root @ weblogic/] # mkswap swapfileSetting up swapspace version 1, size = 1023995 kB [root @ weblogic/] # swapon swapfile open [root @ weblogic/] # swapoff swapfile close
 
Related Article

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.