From 2f37cef1e414c296b7ee3ea2a1dc19554838d2d2 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 18 Nov 2024 13:27:31 -0500 Subject: [PATCH] kernel/fs: Use DoublyLinkedList for the unused vnodes list. Avoids needing a nonstandard "offsetof", and inlines more methods. No behavioral change intended. Also rename "next" to "hash_next" for clarity, and remove an unused "next" field from LockWaiter. --- src/system/kernel/fs/Vnode.h | 5 ++--- src/system/kernel/fs/unused_vnodes.h | 10 ++++++---- src/system/kernel/fs/vfs.cpp | 11 +++-------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/system/kernel/fs/Vnode.h b/src/system/kernel/fs/Vnode.h index 6efe921a5c..c223e01a29 100644 --- a/src/system/kernel/fs/Vnode.h +++ b/src/system/kernel/fs/Vnode.h @@ -24,14 +24,14 @@ typedef struct vnode Vnode; struct vnode : fs_vnode, DoublyLinkedListLinkImpl { - struct vnode* next; + struct vnode* hash_next; VMCache* cache; struct fs_mount* mount; struct vnode* covered_by; struct vnode* covers; struct advisory_locking* advisory_locking; struct file_descriptor* mandatory_locked_by; - list_link unused_link; + DoublyLinkedListLink unused_link; ino_t id; dev_t device; int32 ref_count; @@ -83,7 +83,6 @@ private: static const uint32 kBucketCount = 32; struct LockWaiter : DoublyLinkedListLinkImpl { - LockWaiter* next; Thread* thread; struct vnode* vnode; }; diff --git a/src/system/kernel/fs/unused_vnodes.h b/src/system/kernel/fs/unused_vnodes.h index 5f5bb490b6..e15860700b 100644 --- a/src/system/kernel/fs/unused_vnodes.h +++ b/src/system/kernel/fs/unused_vnodes.h @@ -29,7 +29,9 @@ const static uint32 kMaxUnusedVnodes = 8192; Innermost lock. Must not be held when acquiring any other lock. */ static mutex sUnusedVnodesLock = MUTEX_INITIALIZER("unused vnodes"); -static list sUnusedVnodeList; +typedef DoublyLinkedList > + UnusedVnodeList; +static UnusedVnodeList sUnusedVnodeList; static uint32 sUnusedVnodes = 0; static const int32 kMaxHotVnodes = 1024; @@ -56,7 +58,7 @@ flush_hot_vnodes_locked() if (vnode->IsHot()) { if (vnode->IsUnused()) { - list_add_item(&sUnusedVnodeList, vnode); + sUnusedVnodeList.Add(vnode); sUnusedVnodes++; } vnode->SetHot(false); @@ -146,7 +148,7 @@ vnode_used(Vnode* vnode) if (!vnode->IsHot()) { MutexLocker unusedLocker(sUnusedVnodesLock); - list_remove_item(&sUnusedVnodeList, vnode); + sUnusedVnodeList.Remove(vnode); sUnusedVnodes--; } } @@ -174,7 +176,7 @@ vnode_to_be_freed(Vnode* vnode) } } else if (vnode->IsUnused()) { MutexLocker unusedLocker(sUnusedVnodesLock); - list_remove_item(&sUnusedVnodeList, vnode); + sUnusedVnodeList.Remove(vnode); sUnusedVnodes--; } diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index 5728620f13..55719b8aa5 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -291,7 +291,7 @@ struct VnodeHash { ValueType*& GetLink(ValueType* value) const { - return value->next; + return value->hash_next; } }; @@ -1319,8 +1319,7 @@ free_unused_vnodes(int32 level) // get the first node MutexLocker unusedVnodesLocker(sUnusedVnodesLock); - struct vnode* vnode = (struct vnode*)list_get_first_item( - &sUnusedVnodeList); + struct vnode* vnode = sUnusedVnodeList.First(); unusedVnodesLocker.Unlock(); if (vnode == NULL) @@ -1336,7 +1335,7 @@ free_unused_vnodes(int32 level) // has been touched in the meantime, i.e. it is no longer the least // recently used unused vnode and we rather don't free it. unusedVnodesLocker.Lock(); - if (vnode != list_get_first_item(&sUnusedVnodeList)) + if (vnode != sUnusedVnodeList.First()) continue; unusedVnodesLocker.Unlock(); @@ -5262,10 +5261,6 @@ vfs_init(kernel_args* args) if (sVnodeTable == NULL || sVnodeTable->Init(VNODE_HASH_TABLE_SIZE) != B_OK) panic("vfs_init: error creating vnode hash table\n"); - struct vnode dummy_vnode; - list_init_etc(&sUnusedVnodeList, offset_of_member(dummy_vnode, unused_link)); - - struct fs_mount dummyMount; sMountsTable = new(std::nothrow) MountTable(); if (sMountsTable == NULL || sMountsTable->Init(MOUNTS_HASH_TABLE_SIZE) != B_OK)