Commit 227d8064 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] VFS cache sizing fix for small machines

From: Matt Mackall <mpm@selenic.com>

Doing the algebra:

c = (a - b) * 3/2
a' = a - c = a - 3/2(a - b) = (2a - 3a + 3b)/2 = (3b - a)/2
a' >= 0
3b - a >= 0
3b >= a
b >= a/3
nr_free_pages() >= mempages/3

We can indeed get into trouble if we try to load a large kernel on a very
small box (ie kernel reserves more than 2/3 of usable memory).  Surprisingly I
haven't hit this, but here's a fix.
parent c0b5943f
......@@ -1635,7 +1635,7 @@ void __init vfs_caches_init(unsigned long mempages)
/* Base hash sizes on available memory, with a reserve equal to
150% of current kernel size */
reserve = (mempages - nr_free_pages()) * 3/2;
reserve = min((mempages - nr_free_pages()) * 3/2, mempages - 1);
mempages -= reserve;
names_cachep = kmem_cache_create("names_cache",
......
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