aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2004-02-03 18:49:05 -0800
committerLinus Torvalds <torvalds@home.osdl.org>2004-02-03 18:49:05 -0800
commitc7f6fcf55b7ce3cf61e0953a18e0ab9e70421a47 (patch)
tree6b3390d0a61f5614ac6f54eab1c388c9422db557 /security
parenta9b9b3c5ebb3f8d4814c10baf7176fd8711d063f (diff)
downloadhistory-c7f6fcf55b7ce3cf61e0953a18e0ab9e70421a47.tar.gz
[PATCH] rate limit nr_free_pages
From: Jes Sorensen <jes@trained-monkey.org> nr_free_pages() is expensive, especially on large SMP machines. The patch changes the memory overcommit code so that it only calls nr_free_pages() is we're about to fail the allocation attempt.
Diffstat (limited to 'security')
-rw-r--r--security/commoncap.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/security/commoncap.c b/security/commoncap.c
index 355533d68b9145..f80b1a17bbe4b5 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -321,8 +321,9 @@ int cap_vm_enough_memory(long pages)
return 0;
if (sysctl_overcommit_memory == 0) {
+ unsigned long n;
+
free = get_page_cache_size();
- free += nr_free_pages();
free += nr_swap_pages;
/*
@@ -341,6 +342,18 @@ int cap_vm_enough_memory(long pages)
if (free > pages)
return 0;
+
+ /*
+ * nr_free_pages() is very expensive on large systems,
+ * only call if we're about to fail.
+ */
+ n = nr_free_pages();
+ if (!capable(CAP_SYS_ADMIN))
+ n -= n / 32;
+ free += n;
+
+ if (free > pages)
+ return 0;
vm_unacct_memory(pages);
return -ENOMEM;
}