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

[PATCH] vm_enough_memory microoptimisation

From: <ffrederick@prov-liege.be>

The expected case is (sysctl_overcommit_memory == 0), so put that first.
parent b1e412a2
...@@ -295,12 +295,7 @@ int cap_vm_enough_memory(long pages) ...@@ -295,12 +295,7 @@ int cap_vm_enough_memory(long pages)
vm_acct_memory(pages); vm_acct_memory(pages);
/* /* We estimate memory ourselves (common case) */
* Sometimes we want to use more memory than we have
*/
if (sysctl_overcommit_memory == 1)
return 0;
if (sysctl_overcommit_memory == 0) { if (sysctl_overcommit_memory == 0) {
free = get_page_cache_size(); free = get_page_cache_size();
free += nr_free_pages(); free += nr_free_pages();
...@@ -322,10 +317,16 @@ int cap_vm_enough_memory(long pages) ...@@ -322,10 +317,16 @@ int cap_vm_enough_memory(long pages)
if (free > pages) if (free > pages)
return 0; return 0;
vm_unacct_memory(pages); vm_unacct_memory(pages);
return -ENOMEM; return -ENOMEM;
} }
/* Kernel assumes allocation */
if (sysctl_overcommit_memory == 1)
return 0;
/* sysctl_overcommit_memory must be 2 which means strict_overcommit*/
allowed = totalram_pages * sysctl_overcommit_ratio / 100; allowed = totalram_pages * sysctl_overcommit_ratio / 100;
allowed += total_swap_pages; allowed += total_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