aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2003-08-31 04:29:56 -0700
committerLinus Torvalds <torvalds@home.osdl.org>2003-08-31 04:29:56 -0700
commitf2c52c438af11611aed213c7b3f1bb9347389782 (patch)
treead18f0b07bd33f6f0e622779ffba3b243022b8a5 /security
parentb1e412a24e0a32a1802c69a934843472ca221321 (diff)
downloadhistory-f2c52c438af11611aed213c7b3f1bb9347389782.tar.gz
[PATCH] vm_enough_memory microoptimisation
From: <ffrederick@prov-liege.be> The expected case is (sysctl_overcommit_memory == 0), so put that first.
Diffstat (limited to 'security')
-rw-r--r--security/capability.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/security/capability.c b/security/capability.c
index cff54dd440fc3a..084d2c807fd4b7 100644
--- a/security/capability.c
+++ b/security/capability.c
@@ -295,12 +295,7 @@ int cap_vm_enough_memory(long pages)
vm_acct_memory(pages);
- /*
- * Sometimes we want to use more memory than we have
- */
- if (sysctl_overcommit_memory == 1)
- return 0;
-
+ /* We estimate memory ourselves (common case) */
if (sysctl_overcommit_memory == 0) {
free = get_page_cache_size();
free += nr_free_pages();
@@ -322,10 +317,16 @@ int cap_vm_enough_memory(long pages)
if (free > pages)
return 0;
+
vm_unacct_memory(pages);
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 += total_swap_pages;