linux上swap的查看与调整

linux上swap的查看与调整

1.查看SWAP

[root@192 oc]# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda3                               partition       8024    104     -1
[root@192 oc]#

 

2.通过DD创建文件

[root@192 oc]# dd if=/dev/zero of=/oc/swap bs=512 count=2000000
2000000+0 records in
2000000+0 records out
1024000000 bytes (1.0 GB) copied, 23.4213 seconds, 43.7 MB/s
[root@192 oc]#
[root@192 oc]# ll
总计 1001012
drwx------ 2 root root      16384 06-03 06:56 lost+found
-rw-r--r-- 1 root root 1024000000 06-12 10:24 swap
drwxr-xr-x 4 root root       4096 06-08 16:15 tmp
[root@192 oc]#

3.转化为swap格式
[root@192 oc]# mkswap /oc/swap
Setting up swapspace version 1, size = 1023995 kB
[root@192 oc]#

[root@192 oc]# free
             total       used       free     shared    buffers     cached
Mem:       1035108    1018168      16940          0      14716     892500
-/+ buffers/cache:     110952     924156
Swap:         8024        104       7920
[root@192 oc]#
启用,加入到swap池中。

[root@192 oc]# swapon /oc/swap

[root@192 oc]# free
             total       used       free     shared    buffers     cached
Mem:       1035108    1018228      16880          0      14748     892592
-/+ buffers/cache:     110888     924220
Swap:      1008016        104    1007912
[root@192 oc]#

 

[root@192 oc]# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda3                               partition       8024    104     -1
/oc/swap                                file            999992  0       -4
[root@192 oc]#

 

从swap池中拿掉

[root@192 oc]# swapoff /oc/swap

[root@192 oc]# free
             total       used       free     shared    buffers     cached
Mem:       1035108    1018780      16328          0      15096     892760
-/+ buffers/cache:     110924     924184
Swap:         8024        104       7920

[root@192 oc]# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda3                               partition       8024    104     -1
[root@192 oc]#

 

开机自动启动:

[root@192 oc]# echo "/oc/swap swap swap defaults 0 0" >> /etc/fstab

[root@192 oc]# cat /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults   

阅读更多
换一批

没有更多推荐了,返回首页