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

[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.
parent a9b9b3c5
......@@ -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;
/*
......@@ -339,6 +340,18 @@ int cap_vm_enough_memory(long pages)
if (!capable(CAP_SYS_ADMIN))
free -= free / 32;
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);
......
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