summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-11-13 22:47:11 -0500
committerIan Moffett <ian@osmora.org>2024-11-13 22:47:11 -0500
commitdd9aad47f87b7043d3c0bf3fed80a25fdf188a23 (patch)
tree7181649ee67cf4075b9bfa7660aa46846b6f008e /sys/kern
parentfa8c57777ca97b94c2cf9b17fcb6941668255320 (diff)
kernel: vfs: Recycle vnodes before allocatingexpt
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 <ian@osmora.org>
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/vfs_subr.c18
1 files 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;
}