From cf8b3687f4dc9db3b99bdd345651f7d0c4c5d367 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 9 Sep 2007 17:36:13 +0000 Subject: [PATCH] * The page cache hash table size was fixed to 1024 slots, but even when freshly booted, it would already contain > 20000 pages. The size is now initialized to half of the available pages. Ideally it would grow/shrink dynamically, though. * Changed the hash function to yield a better distribution. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22211 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/vm/vm_cache.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/system/kernel/vm/vm_cache.cpp b/src/system/kernel/vm/vm_cache.cpp index a9e67adfef..ad6b8c40d9 100644 --- a/src/system/kernel/vm/vm_cache.cpp +++ b/src/system/kernel/vm/vm_cache.cpp @@ -34,9 +34,6 @@ #endif -/* hash table of pages keyed by cache they're in and offset */ -#define PAGE_TABLE_SIZE 1024 /* TODO: make this dynamic */ - static hash_table *sPageCacheTable; static spinlock sPageCacheTableLock; @@ -73,7 +70,8 @@ page_hash_func(void *_p, const void *_key, uint32 range) vm_page *page = (vm_page *)_p; const struct page_lookup_key *key = (page_lookup_key *)_key; -#define HASH(offset, ref) ((offset) ^ ((uint32)(ref) >> 4)) + #define HASH(offset, ref) ((offset) + ((uint32)(ref) >> 6) * 997) + // sizeof(vm_cache) >= 64, hence (uint32)(ref) >> 6 is still unique if (page) return HASH(page->cache_offset, page->cache) % range; @@ -107,8 +105,9 @@ acquire_unreferenced_cache_pseudo_ref(vm_cache* cache) status_t vm_cache_init(kernel_args *args) { - sPageCacheTable = hash_init(PAGE_TABLE_SIZE, offsetof(vm_page, hash_next), - &page_compare_func, &page_hash_func); + // TODO: The table should grow/shrink dynamically. + sPageCacheTable = hash_init(vm_page_num_pages() / 2, + offsetof(vm_page, hash_next), &page_compare_func, &page_hash_func); if (sPageCacheTable == NULL) panic("vm_cache_init: no memory\n");