1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:17:36 +00:00

Kernel: Return an already destructed PhysicalPage to the allocators

By making sure the PhysicalPage instance is fully destructed the
allocators will have a chance to reclaim the PhysicalPageEntry for
free-list purposes. Just pass them the physical address of the page
that was freed, which is enough to lookup the PhysicalPageEntry later.
This commit is contained in:
Tom 2021-07-07 20:28:51 -06:00 committed by Andreas Kling
parent 87dc4c3d2c
commit c1006a3689
6 changed files with 32 additions and 28 deletions

View file

@ -28,11 +28,8 @@ public:
void unref()
{
if (m_ref_count.fetch_sub(1, AK::memory_order_acq_rel) == 1) {
if (m_may_return_to_freelist)
return_to_freelist();
this->~PhysicalPage(); // delete in place
}
if (m_ref_count.fetch_sub(1, AK::memory_order_acq_rel) == 1)
free_this();
}
static NonnullRefPtr<PhysicalPage> create(PhysicalAddress, bool supervisor, bool may_return_to_freelist = true);
@ -46,7 +43,7 @@ private:
PhysicalPage(bool supervisor, bool may_return_to_freelist = true);
~PhysicalPage() = default;
void return_to_freelist() const;
void free_this();
Atomic<u32> m_ref_count { 1 };
bool m_may_return_to_freelist { true };