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.
This commit is contained in:
Augustin Cavalier 2022-03-09 19:02:31 -05:00
parent bb09a3ed07
commit 585ce471d1

View File

@ -329,6 +329,7 @@ typedef BOpenHashTable<MountHash> 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)