From 58c1607e031275af22d4a3e82781f860b96f44d6 Mon Sep 17 00:00:00 2001 From: Stephen McKay Date: Tue, 20 Jan 2009 04:21:21 +0000 Subject: [PATCH] Add a limit on namecache entries. In normal operation, the number of cache entries is roughly equal to the number of active vnodes. However, when most of the recently accessed vnodes have many hard links, the number of cache entries can be 32000 times as large, exhausting kernel memory and provoking a panic in kmem_malloc(). MFC after: 2 weeks --- sys/kern/vfs_cache.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 977b8cf78300..e79a568cd427 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -489,6 +489,12 @@ cache_enter(dvp, vp, cnp) if (!doingcache) return; + /* + * Avoid blowout in namecache entries. + */ + if (numcache >= desiredvnodes * 2) + return; + if (cnp->cn_nameptr[0] == '.') { if (cnp->cn_namelen == 1) { return;