From f2c52c438af11611aed213c7b3f1bb9347389782 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 31 Aug 2003 04:29:56 -0700 Subject: [PATCH] [PATCH] vm_enough_memory microoptimisation From: The expected case is (sysctl_overcommit_memory == 0), so put that first. --- security/capability.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/security/capability.c b/security/capability.c index cff54dd440fc3..084d2c807fd4b 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; -- 2.53.0