Java code 1. view the system's Swap space using [root @ jumperusr] # freetotalusedfreesharedbufferscachedMem: 513980493640203400143808271780-/+ buffers/cache: 78052435928 Swap: 10522482...
Java code
1. View system Swap space usage
[Root @ jumper usr] # free
Total used free shared buffers cached
Mem: 513980 493640 20340 0 143808 271780
-/+ Buffers/cache: 78052 435928
Swap: 1052248 21256 1030992
2. create a swap file in a suitable space
[Root @ jumper usr] # mkdir swap
[Root @ jumper usr] # cd swap
[Root @ jumper swap] # dd if =/dev/zero of = swapfile bs = 1024 count = 1000000 // increase by 1G
10000 + 0 records in
10000 + 0 records out
[Root @ jumper swap] # ls-al
Total 10024
Drwxr-xr-x 2 root 4096 July 28 14:58.
Drwxr-xr-x 19 root 4096 July 28 14:57 ..
-Rw-r -- 1 root 10240000 July 28 14:58 swapfile
[Root @ jumper swap] # mkswap swapfile
Setting up swapspace version 1, size = 9996 KiB
3. activate the swap file
[Root @ jumper swap] # swapon swapfile
[Root @ jumper swap] # ls-l
Total 10016
-Rw-r -- 1 root 10240000 July 28 14:58 swapfile
[Root @ jumper swap] # free
Total used free shared buffers cached
Mem: 513980 505052 8928 0 143900 282288
-/+ Buffers/cache: 78864 435116
Swap: 1062240 21256 1040984
If you want to enable it at boot, you need to modify the swap lines in the file/etc/fstab:
/Root/swap/swapfile swap defaults 0 0
Author "kevenfeng"