Shuo
Shuo I'm a DBA(Database Administrator), we can share and discuss MySQL, MongoDB, Redis and other databases here, also including learning Python, Shell, Golang together.

Linux swap 内存溢出


Linux swap 内存溢出

一、目的

由于磁盘IO较弱的原因,不再在数据库的实例上进行swap的内存溢出,需要进行关闭。

二、操作

(1)查看内存使用情况

1
free -m

(2)swapoff

执行:

1
swapoff -a

对于磁盘较弱的环境:8GB的swap,使用5GB的情况下,大约花费1小时。

查看swapoff进程:

swapoff速度较慢原因:

  • 磁盘性能
  • The way it works now, swapoff looks at each swapped out memory page in the swap partition, and tries to find all the programs that use it. If it can’t find them right away, it will look at the page tables of every program that’s running to find them. In the worst case, it will check all the page tables for every swapped out page in the partition. That’s right–the same page tables get checked over and over again.

它现在的工作方式是,swapoff 查看交换分区中每个换出的内存页,并尝试找到所有使用它的程序。 如果不能立即找到它们,它将查看正在运行的每个程序的页表以找到它们。 在最坏的情况下,它将检查分区中每个换出页的所有页表。 没错——相同的页表被一遍又一遍地检查。

参考:https://unix.stackexchange.com/questions/45673/how-can-swapoff-be-that-slow

(3)调整/etc/fstab

为避免重启后swap继续打开,需要关闭swap挂载:

1
2
vim /etc/fstab
注释swap所在行

comments powered by Disqus