SWAP分配策略

陈磊

swap 查询方法:

1 、free 单位KB
2、cat /proc/swaps

swap调整策略

现在服务器内存配置越来越大,以往比较通用的Memory * 1.5的原则基本不再适用,下面是网上收集来的新的分配原则,基于Red Hat Linux的建议,也适合其它Unix。


1)安装系统时难以确定内存的负荷,如何设置交换分区大小

2)系统中物理内存越大,所需交换分区就会越少

因此,在Red Hat Enterprise Linux 5中,以下是设置合适的交换分区大小的规则:

小于等于4G物理内存的系统,至少设置2GB的交换分区

4G〜16G物理内存的系统,至少设置4GB的交换分区

16G〜64G物理内存的系统,至少设置8GB的交换分区

64G〜256G物理内存的系统,至少设置16GB的交换分区


There is no fixed rule to size swap. It depends on the application requirement. The rule of thumb I use is:

if RAM<4GB: swap=2xRAM if RAM is between 4GB - 8GB, swap=RAM if RAM>8GB swap=8GB


The best way is to reserve some disk space for future growth in case you need more swap space and monitor the system.


/var sizing is not related to the physical memory. /var is used to store log, temporary files, spool and core dumps. For example, if the machine is used as mail or print server and it has a lots of messages or print jobs, you need to size /var bigger. Also, when machine crashes, if savecore is enabled, the OS will automatically try to save the kernel dump to /var/crash directory. 10G is kind of overkill but it doesn't hurt as long as you have enough space.