Skip to contentSkip to conversation

shrink hash sizes on small machines, take 2

PATCH Gerald Schaefer 1 participant 2 messages May 18, 2004 – May 22, 2004 1 message not in the archive

lore
Share & tools
lore
#0 lore raw
Quoted 20 lines · Matt Mackall

Base hash sizes on available memory rather than total memory. An additional 50% above current used memory is considered reserved for the purposes of hash sizing to compensate for the hashes themselves and the remainder of kernel and userspace initialization.

Index: tiny/fs/dcache.c
===================================================================

fs/dcache.c +1 -0
@@ -28,6 +28,7 @@
 #include <asm/uaccess.h>
 #include <linux/security.h>
 #include <linux/seqlock.h>
+#include <linux/swap.h>
 
 #define DCACHE_PARANOIA 1
 /* #define DCACHE_DEBUG 1 */
@@ -1619,13 +1620,21 @@
 
 void __init vfs_caches_init(unsigned long mempages)

fs/dcache.c line 1629

Quoted 10 lines
fs/dcache.c +7 -2
 {
-	names_cachep = kmem_cache_create("names_cache", 
-			PATH_MAX, 0, 
+	unsigned long reserve;
+
+	/* Base hash sizes on available memory, with a reserve equal to
+           150% of current kernel size */
+
+	reserve = (mempages - nr_free_pages()) * 3/2;
+	mempages -= reserve;

This calculation doesn't sound right. The value of mempages is set to num_physpages from the calling function start_kernel(), which also includes pages from a potential "mem=" kernel parameter (which we use for reserving memory to load DCSS segments on z/VM).

Whenever the amount of reserved pages goes above some limit (for whatever reason, not only with "mem="), this calculation results in a negative value for mempages, respectively a very large value due to "unsigned long".

I am not on the mailing list, so please put me on cc if you answer.

--
Gerald

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 4 lines · you

num_physpages should represent the memory available to the kernel for normal use and should not reflect any other reserved memory. Otherwise it'll unduly influence the hash sizes both with and without this patch.

This is a very good point, Arnd and I have been looking at our "mem=" hack and it does look a little bit fishy...
There are possibly more things affected in the s390 kernel with "mem=" parameter, not only num_physpages (max_low_pfn, etc.), so we will have to take a closer look and see what Martin thinks about it.

fs/dcache.c 2004-05-18 12:37:42.000000000 -0500 line 1631

Quoted 13 lines

Index: mm/fs/dcache.c
===================================================================

fs/dcache.c 2004-05-18 12:37:42.000000000 -0500 renamed from fs/dcache.c 2004-05-18 12:29:28.000000000 -0500 +1 -1
@@ -1625,7 +1625,7 @@
      /* 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",

This patch is o.k. for us, in our case (with "mem=") it would more or less restore the previous situation (without the calculation, but still with a potential memory problem on our side)

--
Gerald