1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 20:27:35 +00:00

Kernel: Turns global Custody and Inode tables into InlineLinkedLists

Yet more of this same thing. Each one of these patches has a small but
noticeable impact on the steady-state kmalloc numbers. :^)
This commit is contained in:
Andreas Kling 2019-08-08 11:08:27 +02:00
parent 07425580a8
commit 318068fe1b
5 changed files with 34 additions and 21 deletions

View file

@ -4,18 +4,18 @@
#include <Kernel/FileSystem/Inode.h> #include <Kernel/FileSystem/Inode.h>
#include <Kernel/Lock.h> #include <Kernel/Lock.h>
static Lockable<HashTable<Custody*>>& all_custodies() static Lockable<InlineLinkedList<Custody>>& all_custodies()
{ {
static Lockable<HashTable<Custody*>>* table; static Lockable<InlineLinkedList<Custody>>* list;
if (!table) if (!list)
table = new Lockable<HashTable<Custody*>>; list = new Lockable<InlineLinkedList<Custody>>;
return *table; return *list;
} }
Custody* Custody::get_if_cached(Custody* parent, const String& name) Custody* Custody::get_if_cached(Custody* parent, const String& name)
{ {
LOCKER(all_custodies().lock()); LOCKER(all_custodies().lock());
for (auto& custody : all_custodies().resource()) { for (auto* custody = all_custodies().resource().head(); custody; custody = custody->next()) {
if (custody->is_deleted()) if (custody->is_deleted())
continue; continue;
if (custody->is_mounted_on()) if (custody->is_mounted_on())
@ -47,7 +47,7 @@ Custody::Custody(Custody* parent, const String& name, Inode& inode)
, m_inode(inode) , m_inode(inode)
{ {
LOCKER(all_custodies().lock()); LOCKER(all_custodies().lock());
all_custodies().resource().set(this); all_custodies().resource().append(this);
} }
Custody::~Custody() Custody::~Custody()

View file

@ -2,15 +2,17 @@
#include <AK/AKString.h> #include <AK/AKString.h>
#include <AK/Badge.h> #include <AK/Badge.h>
#include <AK/RefPtr.h> #include <AK/InlineLinkedList.h>
#include <AK/RefCounted.h> #include <AK/RefCounted.h>
#include <AK/RefPtr.h>
class Inode; class Inode;
class VFS; class VFS;
// FIXME: Custody needs some locking. // FIXME: Custody needs some locking.
class Custody : public RefCounted<Custody> { class Custody : public RefCounted<Custody>
, public InlineLinkedListNode<Custody> {
public: public:
static Custody* get_if_cached(Custody* parent, const String& name); static Custody* get_if_cached(Custody* parent, const String& name);
static NonnullRefPtr<Custody> get_or_create(Custody* parent, const String& name, Inode&); static NonnullRefPtr<Custody> get_or_create(Custody* parent, const String& name, Inode&);
@ -35,6 +37,10 @@ public:
void did_mount_on(Badge<VFS>); void did_mount_on(Badge<VFS>);
void did_rename(Badge<VFS>, const String& name); void did_rename(Badge<VFS>, const String& name);
// For InlineLinkedListNode.
Custody* m_next { nullptr };
Custody* m_prev { nullptr };
private: private:
Custody(Custody* parent, const String& name, Inode&); Custody(Custody* parent, const String& name, Inode&);

View file

@ -5,12 +5,12 @@
#include <Kernel/Net/LocalSocket.h> #include <Kernel/Net/LocalSocket.h>
#include <Kernel/VM/InodeVMObject.h> #include <Kernel/VM/InodeVMObject.h>
HashTable<Inode*>& all_inodes() InlineLinkedList<Inode>& all_inodes()
{ {
static HashTable<Inode*>* s_inode_set; static InlineLinkedList<Inode>* list;
if (!s_inode_set) if (!list)
s_inode_set = new HashTable<Inode*>(); list = new InlineLinkedList<Inode>;
return *s_inode_set; return *list;
} }
void Inode::sync() void Inode::sync()
@ -18,7 +18,7 @@ void Inode::sync()
NonnullRefPtrVector<Inode, 32> inodes; NonnullRefPtrVector<Inode, 32> inodes;
{ {
InterruptDisabler disabler; InterruptDisabler disabler;
for (auto* inode : all_inodes()) { for (auto* inode = all_inodes().head(); inode; inode = inode->next()) {
if (inode->is_metadata_dirty()) if (inode->is_metadata_dirty())
inodes.append(*inode); inodes.append(*inode);
} }
@ -63,7 +63,7 @@ Inode::Inode(FS& fs, unsigned index)
: m_fs(fs) : m_fs(fs)
, m_index(index) , m_index(index)
{ {
all_inodes().set(this); all_inodes().append(this);
} }
Inode::~Inode() Inode::~Inode()

View file

@ -2,6 +2,7 @@
#include <AK/AKString.h> #include <AK/AKString.h>
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/InlineLinkedList.h>
#include <AK/RefCounted.h> #include <AK/RefCounted.h>
#include <AK/WeakPtr.h> #include <AK/WeakPtr.h>
#include <Kernel/FileSystem/FileSystem.h> #include <Kernel/FileSystem/FileSystem.h>
@ -15,7 +16,9 @@ class InodeVMObject;
class InodeWatcher; class InodeWatcher;
class LocalSocket; class LocalSocket;
class Inode : public RefCounted<Inode>, public Weakable<Inode> { class Inode : public RefCounted<Inode>
, public Weakable<Inode>
, public InlineLinkedListNode<Inode> {
friend class VFS; friend class VFS;
friend class FS; friend class FS;
@ -77,6 +80,10 @@ public:
void register_watcher(Badge<InodeWatcher>, InodeWatcher&); void register_watcher(Badge<InodeWatcher>, InodeWatcher&);
void unregister_watcher(Badge<InodeWatcher>, InodeWatcher&); void unregister_watcher(Badge<InodeWatcher>, InodeWatcher&);
// For InlineLinkedListNode.
Inode* m_next { nullptr };
Inode* m_prev { nullptr };
protected: protected:
Inode(FS& fs, unsigned index); Inode(FS& fs, unsigned index);
void set_metadata_dirty(bool); void set_metadata_dirty(bool);

View file

@ -593,11 +593,11 @@ Optional<KBuffer> procfs$all(InodeIdentifier)
Optional<KBuffer> procfs$inodes(InodeIdentifier) Optional<KBuffer> procfs$inodes(InodeIdentifier)
{ {
extern HashTable<Inode*>& all_inodes(); extern InlineLinkedList<Inode>& all_inodes();
KBufferBuilder builder; KBufferBuilder builder;
for (auto it : all_inodes()) { InterruptDisabler disabler;
RefPtr<Inode> inode = *it; for (auto* inode = all_inodes().head(); inode; inode = inode->next()) {
builder.appendf("Inode{K%x} %02u:%08u (%u)\n", inode.ptr(), inode->fsid(), inode->index(), inode->ref_count()); builder.appendf("Inode{K%x} %02u:%08u (%u)\n", inode, inode->fsid(), inode->index(), inode->ref_count());
} }
return builder.build(); return builder.build();
} }