overcommit_memory/overcommit_ratio/overcommit_kbytes

来源:互联网 发布:app开发编程 编辑:程序博客网 时间:2024/05/16 11:53

 http://blog.csdn.net/jollyjumper/article/details/24127009

新配的服务器内存128G,但在空余内存还有20G,page cache 60G时jps启动不了,提示java heap space,c中调用malloc无法分配5G以上的内存。

发现是系统参数overcommit_memory和overcommit_ratio搞的鬼。

grep -i commit /proc/meminfo

看到CommitLimit和Committed_As参数。

CommitLimit是一个内存分配上限,CommitLimit= 物理内存 * overcommit_ratio(默认50,即50%) + swap大小

Committed_As是已经分配的内存大小。

overcommit_memory参数就是控制分配内存是否可以超过CommitLimit,默认是0,即启发式的overcommitting handle,会尽量减少swap的使用,root可以分配比一般用户略多的内存。1表示允许超过CommitLimit,2表示不允许超过CommitLimit。

 

Attention:

overcommit_memory is set to 1 for almostall android platform.

 

Following is from Doc of kernel

overcommit_kbytes:

When overcommit_memory is set to 2, thecommitted address space is not permitted to exceed swap plus this amount ofphysical RAM. See below.

Note: overcommit_kbytes is the counterpartof overcommit_ratio. Only one of them may be specified at a time. Setting onedisables the other (which then appears as 0 when read).

==============================================================

overcommit_memory:

This value contains a flag that enablesmemory overcommitment.

When this flag is 0, the kernel attempts toestimate the amount of free memory left when userspace requests more memory.

When this flag is 1, the kernel pretendsthere is always enough memory until it actually runs out.

When this flag is 2, the kernel uses a"never overcommit" policy that attempts to prevent any overcommit ofmemory. Note that user_reserve_kbytes affects this policy.

This feature can be very useful becausethere are a lot of programs that malloc() huge amounts of memory"just-in-case" and don't use much of it.

The default value is 0.

See Documentation/vm/overcommit-accountingand security/commoncap.c::cap_vm_enough_memory() for more information.

==============================================================

overcommit_ratio:

When overcommit_memory is set to 2, thecommitted address space is not permitted to exceed swap plus this percentage ofphysical RAM.  See above.

 

The Linux kernel supports the followingovercommit handling modes

0      -       Heuristic overcommithandling. Obvious overcommits of

                address space are refused. Usedfor a typical system. It

                ensures a seriously wildallocation fails while allowing

                overcommit to reduce swapusage.  root is allowed to

                allocate slightly more memoryin this mode. This is the

                default.

1      -       Always overcommit.Appropriate for some scientific

                applications. Classic exampleis code using sparse arrays

                and just relying on the virtualmemory consisting almost

                entirely of zero pages.

2      -       Don't overcommit. Thetotal address space commit

                for the system is not permittedto exceed swap + a

                configurable amount (default is50%) of physical RAM.

                Depending on the amount youuse, in most situations

                this means a process will notbe killed while accessing

                pages but will receive errorson memory allocation as

                appropriate.

 

                Useful for applications thatwant to guarantee their

                memory allocations will be available in thefuture

                without having to initializeevery page.

 

The current overcommit limit and amountcommitted are viewable in

/proc/meminfo as CommitLimit andCommitted_AS respectively.

 

The overcommit amount can be set via`vm.overcommit_ratio' (percentage)

or `vm.overcommit_kbytes' (absolute value).

overcommit_kbytes is the counterpart ofovercommit_ratio. Only one of them may be specified at a time. Setting onedisables the other (which then appears as 0 when read).

It can be seen from following opertations:

# cat overcommit_ratio                        

50

# cat overcommit_memory

1

# cat overcommit_kbytes

0

#

# echo 910221312 > overcommit_kbytes

# cat overcommit_kbytes

910221312

# cat overcommit_ratio

0

# echo 60 > overcommit_ratio

# cat overcommit_kbytes

0

# cat overcommit_ratio

60

#

 

shell@aaa:/proc/sys/vm # cat /proc/meminfo| grep Commit             

CommitLimit:      475760 kB

Committed_AS:   17275520 kB

 

1|shell@aaa:/proc/sys/vm # cat/proc/meminfo                         

MemTotal:         951520 kB

MemFree:          342824 kB

MemAvailable:     594592 kB

Buffers:            6624 kB

Cached:           278784 kB

SwapCached:            0 kB

Active:           184904 kB

Inactive:         262012 kB

Active(anon):     162288 kB

Inactive(anon):     1648 kB

Active(file):      22616 kB

Inactive(file):   260364 kB

Unevictable:           0 kB

Mlocked:               0 kB

SwapTotal:             0 kB

SwapFree:              0 kB

Dirty:                 0 kB

Writeback:             0 kB

AnonPages:        161564 kB

Mapped:            95544 kB

Shmem:              2440 kB

Slab:              28304 kB

SReclaimable:      11428 kB

SUnreclaim:        16876 kB

KernelStack:        5216 kB

PageTables:         6764 kB

NFS_Unstable:          0 kB

Bounce:                0 kB

WritebackTmp:          0 kB

CommitLimit:      475760 kB

Committed_AS:   17270848 kB

VmallocTotal:    1040016 kB

VmallocUsed:      130164 kB

VmallocChunk:     899220 kB

DirectMap4k:      118784 kB

DirectMap4M:      860160 kB

 

0 0
原创粉丝点击