1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:57:44 +00:00

Kernel: Cache Custody objects (weakly) to avoid expensive reconstruction

This patch adds a (spinlock-protected) custody cache. It's a simple
intrusive list containing all currently live custody objects.

This allows us to re-use existing custodies instead of creating them
again and again.

This gives a pretty decent performance improvement on "find /" :^)
This commit is contained in:
Andreas Kling 2021-08-15 19:02:48 +02:00
parent a412fd2ed8
commit d6d7d11590
2 changed files with 52 additions and 8 deletions

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/IntrusiveList.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/String.h>
@ -18,9 +19,11 @@ namespace Kernel {
// FIXME: Custody needs some locking.
class Custody : public RefCounted<Custody> {
class Custody : public RefCountedBase {
MAKE_SLAB_ALLOCATED(Custody)
public:
bool unref() const;
static KResultOr<NonnullRefPtr<Custody>> try_create(Custody* parent, StringView name, Inode&, int mount_flags);
~Custody();
@ -43,6 +46,11 @@ private:
NonnullOwnPtr<KString> m_name;
NonnullRefPtr<Inode> m_inode;
int m_mount_flags { 0 };
mutable IntrusiveListNode<Custody> m_all_custodies_list_node;
public:
using AllCustodiesList = IntrusiveList<Custody, RawPtr<Custody>, &Custody::m_all_custodies_list_node>;
};
}