From 585ce471d194a3ce6736842d71dec85b2a9e6d22 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 9 Mar 2022 19:02:31 -0500 Subject: [PATCH] kernel/vfs: Create an object_cache for vnodes. In addition to being slightly more efficient, this also allows one to see precisely how many vnodes are currently "alive" across all mounts via the "slabs" KDL command. --- src/system/kernel/fs/vfs.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index aa01f89b6a..88663b34d8 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -329,6 +329,7 @@ typedef BOpenHashTable MountTable; object_cache* sPathNameCache; +object_cache* sVnodeCache; object_cache* sFileDescriptorCache; #define VNODE_HASH_TABLE_SIZE 1024 @@ -950,7 +951,7 @@ create_new_vnode_and_lock(dev_t mountID, ino_t vnodeID, struct vnode*& _vnode, { FUNCTION(("create_new_vnode_and_lock()\n")); - struct vnode* vnode = (struct vnode*)malloc(sizeof(struct vnode)); + struct vnode* vnode = (struct vnode*)object_cache_alloc(sVnodeCache, 0); if (vnode == NULL) return B_NO_MEMORY; @@ -1055,7 +1056,7 @@ free_vnode(struct vnode* vnode, bool reenter) remove_vnode_from_mount_list(vnode, vnode->mount); - free(vnode); + object_cache_free(sVnodeCache, vnode, 0); } @@ -5379,6 +5380,11 @@ vfs_init(kernel_args* args) if (sPathNameCache == NULL) panic("vfs_init: error creating path name object_cache\n"); + sVnodeCache = create_object_cache("vfs vnodes", + sizeof(struct vnode), 8, NULL, NULL, NULL); + if (sVnodeCache == NULL) + panic("vfs_init: error creating vnode object_cache\n"); + sFileDescriptorCache = create_object_cache("vfs fds", sizeof(file_descriptor), 8, NULL, NULL, NULL); if (sFileDescriptorCache == NULL)