Why swap is required
According to Redhat, the most suitable size for the swap partition of a Linux system is 1-2 times that of physical memory. But some software on Linux has a large demand for swap partitions, such as the smooth execution of Oracle database software, The swap partition requires at least 400MB of space or more than twice times the physical memory. Of course, when we install Linux, we can directly say that the swap partition is set to a sufficient size, but if you have installed Linux, and then want to install Oracle-like software, But found that the swap partition space is not enough, how to deal with it? in this case, there are two workarounds: one is to create a new swap partition, and the other is to create a swap file. here is a temporary description of creating swap files Create swap files If your hard disk space is already allocated to other partitions, and there is no extra budget to purchase new drives, we can use swap files to increase the virtual swap space, However, execution performance will be worse than the actual swap partition.
1. Check the current swap partition status
# free–m
total used free shared buffers Cached
mem: 1006 84 922 0 11
-/+ buffers/cache: 35 971
swap: 0 0 0
2. Add swap partition file and size
As above, the size of the current swap partition is 0, if you need to increase the size of 1024M.
Determines the size of the new swap file, multiplying the size by the size of the 1024来 decision block. For example, a swap file of size 64MB has a block size of 65536, and at the shell prompt, type the following command as the root user, where count equals the desired block size.
# dd If=/dev/zero Of=/home/swap bs=1m count=1024
1024000+0 Records in
1024000+0 Records out
Format the swap file and format the swap file as an S file system for the system to use
# Mkswap/home/swap
Setting up Swapspace version 1, size = 1023996 KiB
3. Start the Swap partition file
If you want to enable the swap partition file immediately, do the following:
# Swapon/home/swap
To stop using the newly created swap file, simply execute the swapoff/home/swap command.
Check the size of the added swap partition
# free-m
total used free shared buffers Cached
mem: 1006 994 12 0 4 929
-/+ buffers/cache: 60 946
swap: 999 0 999
4. To automatically enable the newly added swap when the system starts again, edit the/etc/fstab file:
# Vi/etc/fstab, add up like the downside
/home/swap Swap swap defaults 0 0
Linux is low on memory, swap partition creation