/proc/sys/vm man手册
Manual page proc(5) line 1967 (press h for help or q to quit)
/proc/sys/vm
This directory contains files for memory management tuning, buffer and cache management.
/proc/sys/vm/drop_caches (since Linux 2.6.16)
Writing to this file causes the kernel to drop clean caches, dentries and inodes from
memory, causing that memory to become free.
To free pagecache, use echo 1 > /proc/sys/vm/drop_caches; to free dentries and inodes,
use echo 2 > /proc/sys/vm/drop_caches; to free pagecache, dentries and inodes, use echo
3 > /proc/sys/vm/drop_caches.
Because this is a nondestructive operation and dirty objects are not freeable, the user
should run sync(8) first.
/proc/sys/vm/legacy_va_layout (since Linux 2.6.9)
If nonzero, this disables the new 32-bit memory-mapping layout; the kernel will use the
legacy (2.4) layout for all processes.
/proc/sys/vm/memory_failure_early_kill (since Linux 2.6.32)
Control how to kill processes when an uncorrected memory error (typically a 2-bit error
in a memory module) that cannot be handled by the kernel is detected in the background
by hardware. In some cases (like the page still having a valid copy on disk), the ker‐
nel will handle the failure transparently without affecting any applications. But if
there is no other up-to-date copy of the data, it will kill processes to prevent any
data corruptions from propagating.
The file has one of the following values:
1: Kill all processes that have the corrupted-and-not-reloadable page mapped as soon as
the corruption is detected. Note this is not supported for a few types of pages,
like kernel internally allocated data or the swap cache, but works for the majority
of user pages.
0: Only unmap the corrupted page from all processes and kill only a process that tries
to access it.
The kill is performed using a SIGBUS signal with si_code set to BUS_MCEERR_AO. Pro‐
cesses can handle this if they want to; see sigaction(2) for more details.
This feature is active only on architectures/platforms with advanced machine check han‐
dling and depends on the hardware capabilities.
Applications can override the memory_failure_early_kill setting individually with the
prctl(2) PR_MCE_KILL operation.
Only present if the kernel was configured with CONFIG_MEMORY_FAILURE.
/proc/sys/vm/memory_failure_recovery (since Linux 2.6.32)
Enable memory failure recovery (when supported by the platform)
1: Attempt recovery.
0: Always panic on a memory failure.
Only present if the kernel was configured with CONFIG_MEMORY_FAILURE.
/proc/sys/vm/oom_dump_tasks (since Linux 2.6.25)
Enables a system-wide task dump (excluding kernel threads) to be produced when the ker‐
nel performs an OOM-killing. The dump includes the following information for each task
(thread, process): thread ID, real user ID, thread group ID (process ID), virtual memory
size, resident set size, the CPU that the task is scheduled on, oom_adj score (see the
description of /proc/[pid]/oom_adj), and command name. This is helpful to determine why
the OOM-killer was invoked and to identify the rogue task that caused it.
If this contains the value zero, this information is suppressed. On very large systems
with thousands of tasks, it may not be feasible to dump the memory state information for
each one. Such systems should not be forced to incur a performance penalty in OOM situ‐
ations when the information may not be desired.
If this is set to nonzero, this information is shown whenever the OOM-killer actually
kills a memory-hogging task.
The default value is 0.
/proc/sys/vm/oom_kill_allocating_task (since Linux 2.6.24)
This enables or disables killing the OOM-triggering task in out-of-memory situations.
If this is set to zero, the OOM-killer will scan through the entire tasklist and select
a task based on heuristics to kill. This normally selects a rogue memory-hogging task
that frees up a large amount of memory when killed.
If this is set to nonzero, the OOM-killer simply kills the task that triggered the out-
of-memory condition. This avoids a possibly expensive tasklist scan.
If /proc/sys/vm/panic_on_oom is nonzero, it takes precedence over whatever value is used
in /proc/sys/vm/oom_kill_allocating_task.
The default value is 0.
/proc/sys/vm/overcommit_memory
This file contains the kernel virtual memory accounting mode. Values are:
0: heuristic overcommit (this is the default)
1: always overcommit, never check
2: always check, never overcommit
In mode 0, calls of mmap(2) with MAP_NORESERVE are not checked, and the default check is
very weak, leading to the risk of getting a process "OOM-killed". Under Linux 2.4 any
nonzero value implies mode 1. In mode 2 (available since Linux 2.6), the total virtual
address space on the system is limited to (SS + RAM*(r/100)), where SS is the size of
the swap space, and RAM is the size of the physical memory, and r is the contents of the
file /proc/sys/vm/overcommit_ratio.
/proc/sys/vm/overcommit_ratio
See the description of /proc/sys/vm/overcommit_memory.
/proc/sys/vm/panic_on_oom (since Linux 2.6.18)
This enables or disables a kernel panic in an out-of-memory situation.
If this file is set to the value 0, the kernel's OOM-killer will kill some rogue
process. Usually, the OOM-killer is able to kill a rogue process and the system will
survive.
If this file is set to the value 1, then the kernel normally panics when out-of-memory
happens. However, if a process limits allocations to certain nodes using memory poli‐
cies (mbind(2) MPOL_BIND) or cpusets (cpuset(7)) and those nodes reach memory exhaustion
status, one process may be killed by the OOM-killer. No panic occurs in this case:
because other nodes' memory may be free, this means the system as a whole may not have
reached an out-of-memory situation yet.
If this file is set to the value 2, the kernel always panics when an out-of-memory con‐
dition occurs.
The default value is 0. 1 and 2 are for failover of clustering. Select either accord‐
ing to your policy of failover.
/proc/sys/vm/swappiness
The value in this file controls how aggressively the kernel will swap memory pages.
Higher values increase aggressiveness, lower values decrease aggressiveness. The
default value is 60.
/proc/sys/vm
该目录下的文件用来优化虚拟内存
比较重要的参数如下
justin_$ uname -a
Linux justin 2.6.32-100.26.2.el5 #1 SMP Tue Jan 18 20:11:49 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
Swappiness
justin_$ more swappiness
60
--范围从0—100,因为即便有足够空余物理内存,linux也会将部分长期没有用到的页swap,该值越高则linux越倾向于此;
vfs_cache_pressure
默认值100,用于控制回收cache频率,值越小则越倾向于保留cache,0 表示从不回收cache容易导致out-of-memory
注:cache用于缓存inode/dentry,而buffer用于缓存data
justin_$ more vfs_cache_pressure
100
stat_interval
VM信息更新频率,默认每1秒更新一次
justin_$ more stat_interval
1
hugetlb_shm_group
指定group id,拥有该gid的用户可以使用huge page创建SysV共享内存段;
注:用户可通过2种方式使用huge page
Mmap:使用此API时,如果没有指定MAP_HUGETLB选项,系统必须加载hugetlbfs文件系统到/mnt/huge
SYSV共享内存system call(shmget/shmat):调用此API则需要配置hugetlb_shm_group
如果oracle使用了huge page且通过shm*调用,则将该值设为oracle用户的gid,否则可能会遭遇ORA-27125
ORA-27125: unable to create shared memory segment
Cause: shmget() call failed
Action: contact Oracle support
justin_$ more hugetlb_shm_group
0
http://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
nr_hugepages
huge页的最小数目,需要连续的物理内存;oracle使用hugepage可以降低TLB的开销,节约内存和CPU资源,但要同时设置memlock且保证其大于hugepage;其与11gAMM不兼容;
# - memlock - max locked-in-memory address space (KB)
显然此系统分配了hugepage但没有程序使用
justin_$ more nr_hugepages
5120
justin_$ more /proc/meminfo | grep -i huge
HugePages_Total: 5120
HugePages_Free: 5120
HugePages_Rsvd: 0
HugePages_Surp: 0 –当请求的页数超过nr_hugepages时可额外申请的页数,最大值由nv_overcommit_hugepages参数控制
Hugepagesize: 2048
http://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
nr_overcommit_hugepages
系统可分配最大huge page数= nr_hugepages + nr_overcommit_hugepages
justin_$ more nr_overcommit_hugepages
0
mmap_min_addr
指定用户进程通过mmap可使用的最小虚拟内存地址,以避免其在低地址空间产生映射导致安全问题;如果非0,则不允许mmap到NULL页,而此功能可在出现NULL指针时调试Kernel;mmap用于将文件映射至内存;
该设置意味着禁止用户进程访问low 4k地址空间
justin_$ more mmap_min_addr
4096
http://justanothergeek.chdir.org/2011/01/linux-security-one-year-later.html
https://blogs.oracle.com/ksplice/entry/much_ado_about_null_exploiting1
http://trac.clozure.com/ccl/wiki/PlatformNotes
http://loda.hala01.com/2012/08/android-4-1-jelly-bean%E5%AE%89%E5%85%A8%E6%A9%9F%E5%88%B6%E6%8E%A2%E8%A8%8E-2/
panic_on_oom
用于控制如何处理out-of-memory,可选值包括0/1/2,默认为0
0:当内存不足时内核调用OOM killer杀死一些rogue进程,每个进程描述符都有一个oom_score标示,oom killer会选择oom_score较大的进程
1/2:内存不足时不杀死进程,但具体策略有所差异
justin_$ more panic_on_oom
0
oom_kill_allocating_task
控制如何kill触发OOM的进程,可选值包括0/non-0,受panic_on_oom值影响
0:OOM killer扫描所有的进程寻找oom_score最高的,可通过将其kill释放大量内存
Non-0:kill出发out-of-memory的那个进程,避免进程队列扫描
justin_$ more oom_kill_allocating_task
0
lowmem_reserve_ratio
保留的lowmem,3列分别为DMA/normal/HighMem
justin_$ more lowmem_reserve_ratio
256 256 32
dirty_background_bytes/ dirty_background_ratio
当内存中脏页达到一定数量或比例时,启用pdflush将其刷新至磁盘,两者只能取其一;
[oracle@usuwsoadb05 vm]$ more dirty_background_bytes
0
[oracle@usuwsoadb05 vm]$ more dirty_background_ratio
10
dirty_bytes/ dirty_ratio
当进程的脏数据达到某个临界点则该进程自动将其刷新至磁盘,dirty_ratio是与整个系统内存相除
justin_$ more dirty_bytes
0
justin_$ more dirty_ratio
20
drop_caches
默认为0,可选值包括1/2/3
1:释放页缓存,即buffer
2:是否inode和dentries缓存,即cache
3:包含1和2
注:由于buffer/cache里的值
justin_$ more drop_caches
0
max_map_count
一个进程最多可用于的内存映射区(memory map areas),在调用malloc会用到,由mmap/mprotect生成
Memory map areas are used as a side-effect of calling malloc, directly by mmap and mprotect, and also when loading shared libraries.
大部分程序使用数量不会超过1000,默认值65536
注:该值若太小某些情况下会导致ora-4030,详情参照ID 1325100.1,
当4030跟踪文件的process map dump记录如下,此时max_map_cout设置为65536导致资源不足 ,可适当调大
----- Process Map Dump -----
00400000-0954f000 r-xp 00000000 fd:09 3131376 /e00/oracle/prod/v11.2.0/bin/oracle <<<---Line 1
0974e000-0a2be000 rwxp 0914e000 fd:09 3131376 /e00/oracle/prod/v11.2.0/bin/oracle
0a2be000-0a304000 rwxp 0a2be000 00:00 0
0c8c9000-0c950000 rwxp 0c8c9000 00:00 0 [heap]
60000000-60001000 r-xs 00000000 00:13 9374560 /dev/shm/ora_DSSP_11698195_0
60001000-70000000 rwxs 00001000 00:13 9374560 /dev/shm/ora_DSSP_11698195_0
70000000-80000000 rwxs 00000000 00:13 9374561 /dev/shm/ora_DSSP_11698195_1
80000000-90000000 rwxs 00000000 00:13 9374565 /dev/shm/ora_DSSP_11730964_0
90000000-a0000000 rwxs 00000000 00:13 9374566 /dev/shm/ora_DSSP_11730964_1
a0000000-b0000000 rwxs 00000000 00:13 9374569 /dev/shm/ora_DSSP_11763733_0
b00
2aed84a4f000-2aed86e5f000 rwxp febe2000 00:11 29160 /dev/zero
7fffea3ca000-7fffea418000 rwxp 7ffffffb1000 00:00 0 [stack]
ffffffffff600000-ffffffffffe00000 ---p 00000000 00:00 0 [vdso] <<---End of the map dump at (Line 65537 of the Process Map Dump)
******************* End of process map dump ***********
justin_$ more max_map_count
65530
http://www.enchantedage.com/node/235
http://www.cppblog.com/feixuwu/archive/2011/05/14/146395.html
nr_pdflush_threads
当前pdfflush线程数量,为read-only,系统会根据脏页数自动调整,1秒增加1个直至nr_pdflush_threads_max;
justin_$ more nr_pdflush_threads
0
overcommit_memory
为一个flag,可选值包括0/1/2,用于控制内存过度分配
0:当用户空间请求更多内存时,内核则评估当前空闲内存量,如果足够则分配
1:内核假定系统中始终有足够的内存直至耗尽为止
2:内核采用”never overcommit”策略,以避免内存被耗尽
有很多程序调用malloc()请求大量内存却很少使用,该参数则十分有用
justin_$ more overcommit_memory
0
overcommit_ratio
该值为物理内存比率,当overcommit_memory=2时,进程可使用的swap空间不可超过PM * overcommit_ratio/100
justin_$ more overcommit_ratio
50
page-cluster
一次写入swap的内存页数=2的page-cluster次方,若该值为0则一次写入1个页,为1
justin_$ more page-cluster
3
muahao@aliyun.com