From dd9aad47f87b7043d3c0bf3fed80a25fdf188a23 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 13 Nov 2024 22:47:11 -0500 Subject: kernel: vfs: Recycle vnodes before allocating This commit makes changes to how vnodes are allocated and released. When we want to allocate a new vnode, we check if there is something we can recycle before calling dynalloc(). Instead of calling dynfree() on a vnode, enter it into the vnode cache. Signed-off-by: Ian Moffett --- sys/kern/vfs_subr.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index cbcf7c5..062d182 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -39,11 +39,16 @@ mountlist_t g_mountlist; int vfs_alloc_vnode(struct vnode **res, int type) { - struct vnode *vp = dynalloc(sizeof(struct vnode)); + struct vnode *vp = vfs_recycle_vnode(); - if (vp == NULL) { + /* + * If there are no vnodes to be recycled, attempt + * to allocate a new one. + */ + if (vp == NULL) + vp = dynalloc(sizeof(struct vnode)); + if (vp == NULL) return -ENOMEM; - } memset(vp, 0, sizeof(*vp)); vp->type = type; @@ -97,8 +102,9 @@ vfs_name_mount(struct mount *mp, const char *name) } /* - * Release a vnode and its resources from - * memory. + * Release the resources associated with a vnode and + * mark the vnode to *possibly* be deallocated unless + * recycled. */ int vfs_release_vnode(struct vnode *vp) @@ -130,7 +136,7 @@ vfs_release_vnode(struct vnode *vp) if (status != 0) return status; - dynfree(vp); + vfs_vcache_enter(vp); return status; } -- cgit v1.2.3