Commit cf50f395 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] overcommit root margin

From: Dave Hansen <haveblue@us.ibm.com>

This patch makes vm_enough_memory(), more likely return failure when
overcommit_memory==0 and !CAP_SYS_ADMIN.  I'm not sure it's worth having
another tunable just for this.

I also reworked the documentation a bit.  It should be a lot clearer to
read now.
parent 4a3fbc84
...@@ -35,17 +35,20 @@ See Documentation/filesystems/proc.txt ...@@ -35,17 +35,20 @@ See Documentation/filesystems/proc.txt
overcommit_memory: overcommit_memory:
This value contains a flag that enables memory overcommitment. This value contains a flag that enables memory overcommitment.
When this flag is 0, the kernel checks before each malloc()
to see if there's enough memory left. If the flag is nonzero, When this flag is 0, the kernel attempts to estimate the amount
the system pretends there's always enough memory. of free memory left when userspace requests more memory.
When this flag is 1, the kernel pretends there is always enough
memory until it actually runs out.
When this flag is 2, the kernel uses a "strict overcommit"
policy that attempts to prevent any overcommit of memory.
This feature can be very useful because there are a lot of This feature can be very useful because there are a lot of
programs that malloc() huge amounts of memory "just-in-case" programs that malloc() huge amounts of memory "just-in-case"
and don't use much of it. and don't use much of it.
A value of 2 introduces a new "strict overcommit" policy
that attempts to prevent any overcommit of memory.
The default value is 0. The default value is 0.
See Documentation/vm/overcommit-accounting and See Documentation/vm/overcommit-accounting and
......
...@@ -3,7 +3,9 @@ The Linux kernel supports three overcommit handling modes ...@@ -3,7 +3,9 @@ The Linux kernel supports three overcommit handling modes
0 - Heuristic overcommit handling. Obvious overcommits of 0 - Heuristic overcommit handling. Obvious overcommits of
address space are refused. Used for a typical system. It address space are refused. Used for a typical system. It
ensures a seriously wild allocation fails while allowing ensures a seriously wild allocation fails while allowing
overcommit to reduce swap usage. This is the default. overcommit to reduce swap usage. root is allowed to
allocate slighly more memory in this mode. This is the
default.
1 - No overcommit handling. Appropriate for some scientific 1 - No overcommit handling. Appropriate for some scientific
applications. applications.
......
...@@ -90,6 +90,12 @@ int vm_enough_memory(long pages) ...@@ -90,6 +90,12 @@ int vm_enough_memory(long pages)
*/ */
free += atomic_read(&slab_reclaim_pages); free += atomic_read(&slab_reclaim_pages);
/*
* Leave the last 3% for root
*/
if (!capable(CAP_SYS_ADMIN))
free -= free / 32;
if (free > pages) if (free > pages)
return 1; return 1;
vm_unacct_memory(pages); vm_unacct_memory(pages);
......
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