overcommit symbolic constants
Subsystems (7)
PATCH 1/1 overcommit symbolic constants
Played a bit with overcommit the past hour.
Am not entirely satisfied with the no overcommit mode 2 - programs segfault when the system is close to that boundary. So, instead of the somewhat larger patch that I planned to send, just symbolic names for the modes.
Andries
arch/arm/mm/init.c +1 -1
@@ -590,7 +590,7 @@ void __init mem_init(void)* anywhere without overcommit, so turn * it on by default. */ - sysctl_overcommit_memory =1 ; + sysctl_overcommit_memory =OVERCOMMIT_ALWAYS ; } }
arch/arm26/mm/init.c +1 -1
@@ -376,7 +376,7 @@ void __init mem_init(void)* Turn on overcommit on tiny machines */ if (PAGE_SIZE >=16384 && num_physpages <=128 ) { - sysctl_overcommit_memory =1 ; + sysctl_overcommit_memory =OVERCOMMIT_ALWAYS ;printk ("Turning on overcommit\n" ); } }
Documentation/vm/overcommit-accounting +4 -4
@@ -1,4 +1,4 @@ -The Linux kernel supports three overcommit handling modes +The Linux kernel supports the following overcommit handling modes 0 - Heuristic overcommit handling. Obvious overcommits of address space are refused. Used for a typical system. It
@@ -7,10 +7,10 @@ The Linux kernel supports three overcomm allocate slighly more memory in this mode. This is the default. -1 - No overcommit handling. Appropriate for some scientific +1 - Always overcommit. Appropriate for some scientific applications. -2 - (NEW) strict overcommit. The total address space commit +2 - Don't overcommit. The total address space commit for the system is not permitted to exceed swap + a configurable percentage (default is 50) of physical RAM. Depending on the percentage you use, in most situations
@@ -27,7 +27,7 @@ Gotchas The C language stack growth does an implicit mremap. If you want absolute guarantees and run close to the edge you MUST mmap your stack for the -largest size you think you will need. For typical stack usage is does +largest size you think you will need. For typical stack usage this does not matter much but it's a corner case if you really really care In mode 2 the MAP_NORESERVE flag is ignored.
include/linux/mman.h +3 -0
@@ -10,6 +10,9 @@#define MREMAP_MAYMOVE 1#define MREMAP_FIXED 2 +#define OVERCOMMIT_GUESS 0 +#define OVERCOMMIT_ALWAYS 1 +#define OVERCOMMIT_NEVER 2extern int sysctl_overcommit_memory;extern int sysctl_overcommit_ratio;extern atomic_t vm_committed_space;
mm/mmap.c +2 -2
@@ -54,7 +54,7 @@ pgprot_t protection_map[16] = { __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111 }; -int sysctl_overcommit_memory =0 ;/* default is heuristic overcommit */ +int sysctl_overcommit_memory =OVERCOMMIT_GUESS ;/* heuristic overcommit */ int sysctl_overcommit_ratio =50 ;/* default is 50% */ int sysctl_max_map_count =DEFAULT_MAX_MAP_COUNT ;atomic_t vm_committed_space =ATOMIC_INIT (0 );
@@ -882,7 +882,7 @@ munmap_back:return -ENOMEM ;if (accountable && (!(flags &MAP_NORESERVE ) || - sysctl_overcommit_memory >1 )) { + sysctl_overcommit_memory ==OVERCOMMIT_NEVER )) {if (vm_flags &VM_SHARED ) {/* Check memory availability in shmem_file_setup? */ vm_flags |=VM_ACCOUNT ;
mm/nommu.c +1 -1
@@ -30,7 +30,7 @@ unsigned long max_mapnr;unsigned long num_physpages;unsigned long askedalloc, realalloc;atomic_t vm_committed_space =ATOMIC_INIT (0 ); -int sysctl_overcommit_memory;/* default is heuristic overcommit */ +int sysctl_overcommit_memory =OVERCOMMIT_GUESS ;/* heuristic overcommit */ int sysctl_overcommit_ratio =50 ;/* default is 50% */ int sysctl_max_map_count =DEFAULT_MAX_MAP_COUNT ;
security/commoncap.c +2 -2
@@ -314,10 +314,10 @@ int cap_vm_enough_memory(long pages)/* * Sometimes we want to use more memory than we have */ -if (sysctl_overcommit_memory ==1 ) +if (sysctl_overcommit_memory ==OVERCOMMIT_ALWAYS )return 0 ; -if (sysctl_overcommit_memory ==0 ) { +if (sysctl_overcommit_memory ==OVERCOMMIT_GUESS ) {unsigned long n; free =get_page_cache_size ();
security/dummy.c +2 -2
@@ -121,10 +121,10 @@ static int dummy_vm_enough_memory(long p/* * Sometimes we want to use more memory than we have */ -if (sysctl_overcommit_memory ==1 ) +if (sysctl_overcommit_memory ==OVERCOMMIT_ALWAYS )return 0 ; -if (sysctl_overcommit_memory ==0 ) { +if (sysctl_overcommit_memory ==OVERCOMMIT_GUESS ) { free =get_page_cache_size (); free +=nr_free_pages (); free += nr_swap_pages;
security/selinux/hooks.c +2 -2
@@ -1548,10 +1548,10 @@ static int selinux_vm_enough_memory(long/* * Sometimes we want to use more memory than we have */ -if (sysctl_overcommit_memory ==1 ) +if (sysctl_overcommit_memory ==OVERCOMMIT_ALWAYS )return 0 ; -if (sysctl_overcommit_memory ==0 ) { +if (sysctl_overcommit_memory ==OVERCOMMIT_GUESS ) { free =get_page_cache_size (); free +=nr_free_pages (); free += nr_swap_pages;
Quoted 3 lines · On Iau, 2004-09-30 at 14:41, [email protected] wrote:
Played a bit with overcommit the past hour.
Am not entirely satisfied with the no overcommit mode 2 - programs segfault when the system is close to that boundary.
Not really a suprise. Very few programs handle stack growth faults. Hence the docs comment about mmapping stacks privately for critical code.
Quoted 8 lines · Alan Cox
Quoted 3 lines · On Iau, 2004-09-30 at 14:41, [email protected] wrote:
Played a bit with overcommit the past hour.
Am not entirely satisfied with the no overcommit mode 2 - programs segfault when the system is close to that boundary.Not really a suprise. Very few programs handle stack growth faults. Hence the docs comment about mmapping stacks privately for critical code.
Most utilities do not expect to be oom-killed, but they do not expect to be killed by segfault because of stack shortage either. So avoiding the oom-kill and getting segfaults is no improvement in my eyes.
A few days ago I remarked that 2 is no good when there is no swap. OK. So, more modest aim - tighten things only in case there is plenty of swap. I like to return NULL for malloc(), that is something a good program tests for. I hate to fail a stack grow. So, must play a bit more, see whether I can find a mode much stricter than 0 that is still suitable as a general working environment for everybody.
Andries
Quoted 7 lines
A few days ago I remarked that 2 is no good when there is no swap. OK. So, more modest aim - tighten things only in case there is plenty of swap. I like to return NULL for
malloc(), that is something a good program tests for. I hate to fail a stack grow. So, must play a bit more, see whether I can find a mode much stricter than 0 that is still suitable as a general working environment for everybody.
What might work (if you've not already tried it) is to make the initial stack something like 1 or 4Mbytes. Don't map the pages but install a vma of that size. That would pre-reserve address space and perhaps avoid this. I guess if that works then make it a /proc/sys tunable for guaranteed stack.
Quoted 5 lines · Alan Cox
What might work (if you've not already tried it) is to make the initial stack something like 1 or 4Mbytes. Don't map the pages but install a vma of that size. That would pre-reserve address space and perhaps avoid this. I guess if that works then make it a
/proc/systunable for guaranteed stack.
A good and simple idea.
Yes, works entirely satisfactorily in my first few tests.
Andries
Quoted 5 lines · On Thu, 30 Sep 2004 [email protected] wrote:
Played a bit with overcommit the past hour.
Am not entirely satisfied with the no overcommit mode 2 - programs segfault when the system is close to that boundary. So, instead of the somewhat larger patch that I planned to send, just symbolic names for the modes.
Big improvement. And thank you for stamping on that irritating oxymoronic "strict overcommit". Could we add this patch in too?
Documentation/sysctl/vm.txt +1 -1
@@ -47,7 +47,7 @@ of free memory left when userspace reque 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" +When this flag is 2, the kernel uses a "never overcommit" policy that attempts to prevent any overcommit of memory. This feature can be very useful because there are a lot of