linux swap详解

来源:互联网 发布:索爱java论坛 编辑:程序博客网 时间:2024/05/27 20:37

什么是 Swap

Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space

即 Swap 是当物理内存是满的时候,会被使用。当系统需要更多的内存资源,但是内存却满了,这时候不活跃的页会被移动到 Swap 空间。

建议 Swap 使用单独的分区:

  • a swap file
  • a combination of swap partitions and swap files.

Swap 大小的计算公式:

M 等于物理内存大小(GB),S 等于 Swap 大小(GB)

当物理内存小于 2 GB 的时候,Swap 等于物理内存的 2 倍。当物理内存大于 2 GB 的时候,Swap 等于物理内存 + 2 GB

If M < 2    S = M *2Else    S = M + 2

查看 Swap 的方式

查看总体的使用 Swap 的情况:

free -m

查看是哪个进程使用了 Swap:

使用 top 命令,然后再按 f,再按 p ,即可显示哪个进程使用了多少 Swap 空间。然后要释放的话,把那个进程重起下即可。

查看 Swap 使用的哪个分区使用 /sbin/swapon -s 命令。

摘自http://segmentfault.com/a/1190000000702921

0 0
原创粉丝点击