mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 05:55:13 +00:00
Kernel: Break retain cycle between Inode and VMObject.
There's no need for an Inode to keep its corresponding VMObject alive. Obviously there are huge benefits to keeping a filesystem cache, but leaking everything is hardly the right strategy. :^)
This commit is contained in:
parent
e1be5a468d
commit
d4ba155711
Notes:
sideshowbarker
2024-07-19 15:49:22 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d4ba1557110
4 changed files with 9 additions and 9 deletions
|
@ -148,7 +148,7 @@ void FS::sync()
|
|||
}
|
||||
}
|
||||
|
||||
void Inode::set_vmo(RetainPtr<VMObject>&& vmo)
|
||||
void Inode::set_vmo(VMObject& vmo)
|
||||
{
|
||||
m_vmo = move(vmo);
|
||||
m_vmo = vmo.make_weak_ptr();
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <AK/Function.h>
|
||||
#include <AK/kstdio.h>
|
||||
#include <AK/Lock.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
|
||||
static const dword mepoch = 476763780;
|
||||
|
||||
|
@ -103,7 +104,7 @@ public:
|
|||
|
||||
void will_be_destroyed();
|
||||
|
||||
void set_vmo(RetainPtr<VMObject>&&);
|
||||
void set_vmo(VMObject&);
|
||||
VMObject* vmo() { return m_vmo.ptr(); }
|
||||
const VMObject* vmo() const { return m_vmo.ptr(); }
|
||||
|
||||
|
@ -118,7 +119,7 @@ protected:
|
|||
private:
|
||||
FS& m_fs;
|
||||
unsigned m_index { 0 };
|
||||
RetainPtr<VMObject> m_vmo;
|
||||
WeakPtr<VMObject> m_vmo;
|
||||
bool m_metadata_dirty { false };
|
||||
};
|
||||
|
||||
|
|
|
@ -667,7 +667,7 @@ RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode)
|
|||
if (inode->vmo())
|
||||
return static_cast<VMObject*>(inode->vmo());
|
||||
auto vmo = adopt(*new VMObject(move(inode)));
|
||||
vmo->inode()->set_vmo(vmo.ptr());
|
||||
vmo->inode()->set_vmo(*vmo);
|
||||
return vmo;
|
||||
}
|
||||
|
||||
|
@ -732,10 +732,8 @@ VMObject::VMObject(RetainPtr<Inode>&& inode)
|
|||
|
||||
VMObject::~VMObject()
|
||||
{
|
||||
if (m_inode) {
|
||||
if (m_inode)
|
||||
ASSERT(m_inode->vmo() == this);
|
||||
m_inode->set_vmo(nullptr);
|
||||
}
|
||||
MM.unregister_vmo(*this);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <AK/HashTable.h>
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/Weakable.h>
|
||||
#include <Kernel/VirtualFileSystem.h>
|
||||
|
||||
#define PAGE_ROUND_UP(x) ((((dword)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1)))
|
||||
|
@ -77,7 +78,7 @@ private:
|
|||
HashMap<unsigned, RetainPtr<PhysicalPage>> m_physical_pages;
|
||||
};
|
||||
|
||||
class VMObject : public Retainable<VMObject> {
|
||||
class VMObject : public Retainable<VMObject>, public Weakable<VMObject> {
|
||||
friend class MemoryManager;
|
||||
public:
|
||||
static RetainPtr<VMObject> create_file_backed(RetainPtr<Inode>&&);
|
||||
|
|
Loading…
Add table
Reference in a new issue