Commit 2e3aca17 authored by Frank Hirtz's avatar Frank Hirtz Committed by Linus Torvalds

[PATCH] Display committed memory limit and available in meminfo

The following patch will have the committed memory limit (per the current
overcommit ratio) and the amount of memory remaining under this limit
displayed in meminfo.

It's presently somewhat difficult to use the strict memory overcommit
settings as it's somewhat difficult to determine the amount of memory
remaining under the cap.  This patch would make using strict overcommit a
good bit simpler.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 40d79955
...@@ -394,7 +394,9 @@ Dirty: 968 kB ...@@ -394,7 +394,9 @@ Dirty: 968 kB
Writeback: 0 kB Writeback: 0 kB
Mapped: 280372 kB Mapped: 280372 kB
Slab: 684068 kB Slab: 684068 kB
Committed_AS: 1576424 kB CommitLimit: 7669796 kB
Committed_AS: 100056 kB
CommitAvail: 7569740 kB
PageTables: 24448 kB PageTables: 24448 kB
ReverseMaps: 1080904 ReverseMaps: 1080904
VmallocTotal: 112216 kB VmallocTotal: 112216 kB
...@@ -434,19 +436,43 @@ VmallocChunk: 111088 kB ...@@ -434,19 +436,43 @@ VmallocChunk: 111088 kB
Writeback: Memory which is actively being written back to the disk Writeback: Memory which is actively being written back to the disk
Mapped: files which have been mmaped, such as libraries Mapped: files which have been mmaped, such as libraries
Slab: in-kernel data structures cache Slab: in-kernel data structures cache
Committed_AS: An estimate of how much RAM you would need to make a CommitLimit: Based on the overcommit ratio ('vm.overcommit_ratio'),
99.99% guarantee that there never is OOM (out of memory) this is the total amount of memory currently available to
for this workload. Normally the kernel will overcommit be allocated on the system. This limit is only adhered to
memory. That means, say you do a 1GB malloc, nothing if strict overcommit accounting is enabled (mode 2 in
happens, really. Only when you start USING that malloc 'vm.overcommit_memory').
memory you will get real memory on demand, and just as The CommitLimit is calculated with the following formula:
much as you use. So you sort of take a mortgage and hope CommitLimit = ('vm.overcommit_ratio' * Physical RAM) + Swap
the bank doesn't go bust. Other cases might include when For example, on a system with 1G of physical RAM and 7G
you mmap a file that's shared only when you write to it of swap with a `vm.overcommit_ratio` of 30 it would
and you get a private copy of that data. While it normally yield a CommitLimit of 7.3G.
is shared between processes. The Committed_AS is a For more details, see the memory overcommit documentation
guesstimate of how much RAM/swap you would need in vm/overcommit-accounting.
worst-case. Committed_AS: The amount of memory presently allocated on the system.
The committed memory is a sum of all of the memory which
has been allocated by processes, even if it has not been
"used" by them as of yet. A process which malloc()'s 1G
of memory, but only touches 300M of it will only show up
as using 300M of memory even if it has the address space
allocated for the entire 1G. This 1G is memory which has
been "committed" to by the VM and can be used at any time
by the allocating application. With strict overcommit
enabled on the system (mode 2 in 'vm.overcommit_memory'),
allocations which would exceed the CommitLimit (detailed
above) will not be permitted. This is useful if one needs
to guarantee that processes will not fail due to lack of
memory once that memory has been successfully allocated.
CommitAvail: Based on the current overcommit ratio
('vm.overcommit_ratio'), this is the amount of memory
currently available to be allocated under the overcommit
limit (the CommitLimit above). This is calculated as:
CommitAvail = CommitLimit - Committed_AS
This limit is only enforced if strict overcommit accounting
is enabled (mode 2 in 'vm.overcommit_memory'). CommitAvail
may be a negative number if strict accounting is not enabled
and the system's memory is currently overcommitted.
For more details, see the memory overcommit documentation
in vm/overcommit-accounting.
PageTables: amount of memory dedicated to the lowest level of page PageTables: amount of memory dedicated to the lowest level of page
tables. tables.
ReverseMaps: number of reverse mappings performed ReverseMaps: number of reverse mappings performed
......
...@@ -22,6 +22,10 @@ The overcommit policy is set via the sysctl `vm.overcommit_memory'. ...@@ -22,6 +22,10 @@ The overcommit policy is set via the sysctl `vm.overcommit_memory'.
The overcommit percentage is set via `vm.overcommit_ratio'. The overcommit percentage is set via `vm.overcommit_ratio'.
The current overcommit limit, amount used, and amount remaining below
the limit are viewable in /proc/meminfo as CommitLimit, Committed_AS, and
CommitAvail respectively.
Gotchas Gotchas
------- -------
......
...@@ -153,12 +153,14 @@ static int meminfo_read_proc(char *page, char **start, off_t off, ...@@ -153,12 +153,14 @@ static int meminfo_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data) int count, int *eof, void *data)
{ {
struct sysinfo i; struct sysinfo i;
int len, committed; int len;
struct page_state ps; struct page_state ps;
unsigned long inactive; unsigned long inactive;
unsigned long active; unsigned long active;
unsigned long free; unsigned long free;
unsigned long vmtot; unsigned long vmtot;
unsigned long committed;
unsigned long allowed;
struct vmalloc_info vmi; struct vmalloc_info vmi;
get_page_state(&ps); get_page_state(&ps);
...@@ -171,6 +173,8 @@ static int meminfo_read_proc(char *page, char **start, off_t off, ...@@ -171,6 +173,8 @@ static int meminfo_read_proc(char *page, char **start, off_t off,
si_meminfo(&i); si_meminfo(&i);
si_swapinfo(&i); si_swapinfo(&i);
committed = atomic_read(&vm_committed_space); committed = atomic_read(&vm_committed_space);
allowed = ((totalram_pages - hugetlb_total_pages())
* sysctl_overcommit_ratio / 100) + total_swap_pages;
vmtot = (VMALLOC_END-VMALLOC_START)>>10; vmtot = (VMALLOC_END-VMALLOC_START)>>10;
vmi = get_vmalloc_info(); vmi = get_vmalloc_info();
...@@ -198,7 +202,9 @@ static int meminfo_read_proc(char *page, char **start, off_t off, ...@@ -198,7 +202,9 @@ static int meminfo_read_proc(char *page, char **start, off_t off,
"Writeback: %8lu kB\n" "Writeback: %8lu kB\n"
"Mapped: %8lu kB\n" "Mapped: %8lu kB\n"
"Slab: %8lu kB\n" "Slab: %8lu kB\n"
"Committed_AS: %8u kB\n" "CommitLimit: %8lu kB\n"
"Committed_AS: %8lu kB\n"
"CommitAvail: %8ld kB\n"
"PageTables: %8lu kB\n" "PageTables: %8lu kB\n"
"VmallocTotal: %8lu kB\n" "VmallocTotal: %8lu kB\n"
"VmallocUsed: %8lu kB\n" "VmallocUsed: %8lu kB\n"
...@@ -220,7 +226,9 @@ static int meminfo_read_proc(char *page, char **start, off_t off, ...@@ -220,7 +226,9 @@ static int meminfo_read_proc(char *page, char **start, off_t off,
K(ps.nr_writeback), K(ps.nr_writeback),
K(ps.nr_mapped), K(ps.nr_mapped),
K(ps.nr_slab), K(ps.nr_slab),
K(allowed),
K(committed), K(committed),
K(allowed - committed),
K(ps.nr_page_table_pages), K(ps.nr_page_table_pages),
vmtot, vmtot,
vmi.used, vmi.used,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment