mirror of
https://github.com/RGBCube/serenity
synced 2025-05-29 20:35: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
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/Function.h>
|
||||||
#include <AK/kstdio.h>
|
#include <AK/kstdio.h>
|
||||||
#include <AK/Lock.h>
|
#include <AK/Lock.h>
|
||||||
|
#include <AK/WeakPtr.h>
|
||||||
|
|
||||||
static const dword mepoch = 476763780;
|
static const dword mepoch = 476763780;
|
||||||
|
|
||||||
|
@ -103,7 +104,7 @@ public:
|
||||||
|
|
||||||
void will_be_destroyed();
|
void will_be_destroyed();
|
||||||
|
|
||||||
void set_vmo(RetainPtr<VMObject>&&);
|
void set_vmo(VMObject&);
|
||||||
VMObject* vmo() { return m_vmo.ptr(); }
|
VMObject* vmo() { return m_vmo.ptr(); }
|
||||||
const VMObject* vmo() const { return m_vmo.ptr(); }
|
const VMObject* vmo() const { return m_vmo.ptr(); }
|
||||||
|
|
||||||
|
@ -118,7 +119,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
FS& m_fs;
|
FS& m_fs;
|
||||||
unsigned m_index { 0 };
|
unsigned m_index { 0 };
|
||||||
RetainPtr<VMObject> m_vmo;
|
WeakPtr<VMObject> m_vmo;
|
||||||
bool m_metadata_dirty { false };
|
bool m_metadata_dirty { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -667,7 +667,7 @@ RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode)
|
||||||
if (inode->vmo())
|
if (inode->vmo())
|
||||||
return static_cast<VMObject*>(inode->vmo());
|
return static_cast<VMObject*>(inode->vmo());
|
||||||
auto vmo = adopt(*new VMObject(move(inode)));
|
auto vmo = adopt(*new VMObject(move(inode)));
|
||||||
vmo->inode()->set_vmo(vmo.ptr());
|
vmo->inode()->set_vmo(*vmo);
|
||||||
return vmo;
|
return vmo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,10 +732,8 @@ VMObject::VMObject(RetainPtr<Inode>&& inode)
|
||||||
|
|
||||||
VMObject::~VMObject()
|
VMObject::~VMObject()
|
||||||
{
|
{
|
||||||
if (m_inode) {
|
if (m_inode)
|
||||||
ASSERT(m_inode->vmo() == this);
|
ASSERT(m_inode->vmo() == this);
|
||||||
m_inode->set_vmo(nullptr);
|
|
||||||
}
|
|
||||||
MM.unregister_vmo(*this);
|
MM.unregister_vmo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <AK/HashTable.h>
|
#include <AK/HashTable.h>
|
||||||
#include <AK/AKString.h>
|
#include <AK/AKString.h>
|
||||||
#include <AK/Badge.h>
|
#include <AK/Badge.h>
|
||||||
|
#include <AK/Weakable.h>
|
||||||
#include <Kernel/VirtualFileSystem.h>
|
#include <Kernel/VirtualFileSystem.h>
|
||||||
|
|
||||||
#define PAGE_ROUND_UP(x) ((((dword)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1)))
|
#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;
|
HashMap<unsigned, RetainPtr<PhysicalPage>> m_physical_pages;
|
||||||
};
|
};
|
||||||
|
|
||||||
class VMObject : public Retainable<VMObject> {
|
class VMObject : public Retainable<VMObject>, public Weakable<VMObject> {
|
||||||
friend class MemoryManager;
|
friend class MemoryManager;
|
||||||
public:
|
public:
|
||||||
static RetainPtr<VMObject> create_file_backed(RetainPtr<Inode>&&);
|
static RetainPtr<VMObject> create_file_backed(RetainPtr<Inode>&&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue