Commit 23782705 authored by Andries E. Brouwer's avatar Andries E. Brouwer Committed by Linus Torvalds

[PATCH] 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.
parent 339f152b
The Linux kernel supports three overcommit handling modes The Linux kernel supports the following 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
...@@ -7,10 +7,10 @@ The Linux kernel supports three overcommit handling modes ...@@ -7,10 +7,10 @@ The Linux kernel supports three overcommit handling modes
allocate slighly more memory in this mode. This is the allocate slighly more memory in this mode. This is the
default. default.
1 - No overcommit handling. Appropriate for some scientific 1 - Always overcommit. Appropriate for some scientific
applications. 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 for the system is not permitted to exceed swap + a
configurable percentage (default is 50) of physical RAM. configurable percentage (default is 50) of physical RAM.
Depending on the percentage you use, in most situations Depending on the percentage you use, in most situations
...@@ -27,7 +27,7 @@ Gotchas ...@@ -27,7 +27,7 @@ Gotchas
The C language stack growth does an implicit mremap. If you want absolute 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 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 not matter much but it's a corner case if you really really care
In mode 2 the MAP_NORESERVE flag is ignored. In mode 2 the MAP_NORESERVE flag is ignored.
......
...@@ -590,7 +590,7 @@ void __init mem_init(void) ...@@ -590,7 +590,7 @@ void __init mem_init(void)
* anywhere without overcommit, so turn * anywhere without overcommit, so turn
* it on by default. * it on by default.
*/ */
sysctl_overcommit_memory = 1; sysctl_overcommit_memory = OVERCOMMIT_ALWAYS;
} }
} }
......
...@@ -376,7 +376,7 @@ void __init mem_init(void) ...@@ -376,7 +376,7 @@ void __init mem_init(void)
* Turn on overcommit on tiny machines * Turn on overcommit on tiny machines
*/ */
if (PAGE_SIZE >= 16384 && num_physpages <= 128) { if (PAGE_SIZE >= 16384 && num_physpages <= 128) {
sysctl_overcommit_memory = 1; sysctl_overcommit_memory = OVERCOMMIT_ALWAYS;
printk("Turning on overcommit\n"); printk("Turning on overcommit\n");
} }
} }
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#define MREMAP_MAYMOVE 1 #define MREMAP_MAYMOVE 1
#define MREMAP_FIXED 2 #define MREMAP_FIXED 2
#define OVERCOMMIT_GUESS 0
#define OVERCOMMIT_ALWAYS 1
#define OVERCOMMIT_NEVER 2
extern int sysctl_overcommit_memory; extern int sysctl_overcommit_memory;
extern int sysctl_overcommit_ratio; extern int sysctl_overcommit_ratio;
extern atomic_t vm_committed_space; extern atomic_t vm_committed_space;
......
...@@ -54,7 +54,7 @@ pgprot_t protection_map[16] = { ...@@ -54,7 +54,7 @@ pgprot_t protection_map[16] = {
__S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111 __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_overcommit_ratio = 50; /* default is 50% */
int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT; int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
atomic_t vm_committed_space = ATOMIC_INIT(0); atomic_t vm_committed_space = ATOMIC_INIT(0);
...@@ -907,7 +907,7 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr, ...@@ -907,7 +907,7 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
return -ENOMEM; return -ENOMEM;
if (accountable && (!(flags & MAP_NORESERVE) || if (accountable && (!(flags & MAP_NORESERVE) ||
sysctl_overcommit_memory > 1)) { sysctl_overcommit_memory == OVERCOMMIT_NEVER)) {
if (vm_flags & VM_SHARED) { if (vm_flags & VM_SHARED) {
/* Check memory availability in shmem_file_setup? */ /* Check memory availability in shmem_file_setup? */
vm_flags |= VM_ACCOUNT; vm_flags |= VM_ACCOUNT;
......
...@@ -30,7 +30,7 @@ unsigned long max_mapnr; ...@@ -30,7 +30,7 @@ unsigned long max_mapnr;
unsigned long num_physpages; unsigned long num_physpages;
unsigned long askedalloc, realalloc; unsigned long askedalloc, realalloc;
atomic_t vm_committed_space = ATOMIC_INIT(0); 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_overcommit_ratio = 50; /* default is 50% */
int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT; int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
......
...@@ -314,10 +314,10 @@ int cap_vm_enough_memory(long pages) ...@@ -314,10 +314,10 @@ int cap_vm_enough_memory(long pages)
/* /*
* Sometimes we want to use more memory than we have * Sometimes we want to use more memory than we have
*/ */
if (sysctl_overcommit_memory == 1) if (sysctl_overcommit_memory == OVERCOMMIT_ALWAYS)
return 0; return 0;
if (sysctl_overcommit_memory == 0) { if (sysctl_overcommit_memory == OVERCOMMIT_GUESS) {
unsigned long n; unsigned long n;
free = get_page_cache_size(); free = get_page_cache_size();
......
...@@ -121,10 +121,10 @@ static int dummy_vm_enough_memory(long pages) ...@@ -121,10 +121,10 @@ static int dummy_vm_enough_memory(long pages)
/* /*
* Sometimes we want to use more memory than we have * Sometimes we want to use more memory than we have
*/ */
if (sysctl_overcommit_memory == 1) if (sysctl_overcommit_memory == OVERCOMMIT_ALWAYS)
return 0; return 0;
if (sysctl_overcommit_memory == 0) { if (sysctl_overcommit_memory == OVERCOMMIT_GUESS) {
free = get_page_cache_size(); free = get_page_cache_size();
free += nr_free_pages(); free += nr_free_pages();
free += nr_swap_pages; free += nr_swap_pages;
......
...@@ -1554,10 +1554,10 @@ static int selinux_vm_enough_memory(long pages) ...@@ -1554,10 +1554,10 @@ static int selinux_vm_enough_memory(long pages)
/* /*
* Sometimes we want to use more memory than we have * Sometimes we want to use more memory than we have
*/ */
if (sysctl_overcommit_memory == 1) if (sysctl_overcommit_memory == OVERCOMMIT_ALWAYS)
return 0; return 0;
if (sysctl_overcommit_memory == 0) { if (sysctl_overcommit_memory == OVERCOMMIT_GUESS) {
free = get_page_cache_size(); free = get_page_cache_size();
free += nr_free_pages(); free += nr_free_pages();
free += nr_swap_pages; free += nr_swap_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