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/Lock.h>
static Lockable<HashTable<Custody*>>& all_custodies()
static Lockable<InlineLinkedList<Custody>>& all_custodies()
{
static Lockable<HashTable<Custody*>>* table;
if (!table)
table = new Lockable<HashTable<Custody*>>;
return *table;
static Lockable<InlineLinkedList<Custody>>* list;
if (!list)
list = new Lockable<InlineLinkedList<Custody>>;
return *list;
}
Custody* Custody::get_if_cached(Custody* parent, const String& name)
{
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())
continue;
if (custody->is_mounted_on())
@ -47,7 +47,7 @@ Custody::Custody(Custody* parent, const String& name, Inode& inode)
, m_inode(inode)
{
LOCKER(all_custodies().lock());
all_custodies().resource().set(this);
all_custodies().resource().append(this);
}
Custody::~Custody()

View file

@ -2,15 +2,17 @@
#include <AK/AKString.h>
#include <AK/Badge.h>
#include <AK/RefPtr.h>
#include <AK/InlineLinkedList.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
class Inode;
class VFS;
// FIXME: Custody needs some locking.
class Custody : public RefCounted<Custody> {
class Custody : public RefCounted<Custody>
, public InlineLinkedListNode<Custody> {
public:
static Custody* get_if_cached(Custody* parent, const String& name);
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_rename(Badge<VFS>, const String& name);
// For InlineLinkedListNode.
Custody* m_next { nullptr };
Custody* m_prev { nullptr };
private:
Custody(Custody* parent, const String& name, Inode&);

View file

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

View file

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

View file

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