正德厚生,臻于至善

Linux swap使用率过高解决办法

1、查看占用sawp内存较高进程
for i in `cd /proc;ls |grep "^[0-9]"|awk ' $0 >100'` ;do awk '/Swap:/{a=a+$2}END{print '"$i"',a/1024"M"}' /proc/$i/smaps ;done 2>&1 |sort -k2nr |head

2、如何释放swap内存
(1)对占用swap内存较高的进程进行重启;
(2)关闭swap分区

3、关闭swap分区步骤及注意事项
(1)确保系统空闲内存大于swap已用内存;
(2)可以先清理内存cache,空出足够内存
cat /proc/sys/vm/drop_caches
sync;sync;sync;echo 1 > /proc/sys/vm/drop_caches

(3)关闭swap分区,这个过程需要等待;
swapoff -a
(4)swap分区释放后,恢复swap分区;
swapon -a

(5)恢复内存cache的设置
sync;sync;sync;echo 0 > /proc/sys/vm/drop_caches #适用于EL6

lvm下扩展swap分区方法:
lvextend -L +8G /dev/mapper/vg_root-lv_swap
sync;sync;sync;echo 1 > /proc/sys/vm/drop_caches
swapoff /dev/mapper/vg_root-lv_swap
mkswap  /dev/mapper/vg_root-lv_swap
swapon  /dev/mapper/vg_root-lv_swap

问题1:
# swapoff /dev/mapper/vg_root-lv_swap
swapoff: /dev/mapper/vg_root-lv_swap: swapoff failed: Cannot allocate memory
解决办法:
dd if=/dev/zero of=/xwx_swap bs=1G count=16
mkswap /xwx_swap
swapon /xwx_swap
nohup swapoff /dev/mapper/vg_root-lv_swap &

# swapoff /dev/mapper/vg_root-lv_swap
swapoff: /dev/mapper/vg_root-lv_swap: swapoff failed: Cannot allocate memory
# dd if=/dev/zero of=/xwx_swap bs=1G count=16
16+0 records in
16+0 records out
17179869184 bytes (17 GB) copied, 107.313 s, 160 MB/s
# mkswap /xwx_swap
Setting up swapspace version 1, size = 16777212 KiB
no label, UUID=930ed833-1a9a-404c-9858-d9e4a702a42a
# swapon /xwx_swap
swapon: /xwx_swap: insecure permissions 0644, 0600 suggested.
# swapoff /dev/mapper/vg_root-lv_swap
# mkswap  /dev/mapper/vg_root-lv_swap
mkswap: /dev/mapper/vg_root-lv_swap: warning: wiping old swap signature.
Setting up swapspace version 1, size = 25165820 KiB
no label, UUID=d225c22f-61d1-4b1c-a25b-cb1714b14f8b
# swapon  /dev/mapper/vg_root-lv_swap
# swapoff /xwx_swap
# rm -rf /xwx_swap
赞(0) 打赏
未经允许不得转载:徐万新之路 » Linux swap使用率过高解决办法

评论 抢沙发

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫

微信扫一扫

登录

找回密码

注册