serenity/Kernel/VM/VMObject.h
Andreas Kling a96d76fd90 Kernel: Put all VMObjects in an InlineLinkedList instead of a HashTable
Using a HashTable to track "all instances of Foo" is only useful if we
actually need to look up entries by some kind of index. And since they
are HashTable (not HashMap), the pointer *is* the index.

Since we have the pointer, we can just use it directly. Duh.
This increase sizeof(VMObject) by two pointers, but removes a global
table that had an entry for every VMObject, where the cost was higher.
It also avoids all the general hash tabling business when creating or
destroying VMObjects. Generally we should do more of this. :^)
2019-08-08 11:11:22 +02:00

52 lines
1.3 KiB
C++

#pragma once
#include <AK/FixedArray.h>
#include <AK/InlineLinkedList.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/Weakable.h>
#include <Kernel/Lock.h>
class Inode;
class PhysicalPage;
class VMObject : public RefCounted<VMObject>
, public Weakable<VMObject>
, public InlineLinkedListNode<VMObject> {
friend class MemoryManager;
public:
virtual ~VMObject();
virtual NonnullRefPtr<VMObject> clone() = 0;
virtual bool is_anonymous() const { return false; }
virtual bool is_inode() const { return false; }
size_t page_count() const { return m_physical_pages.size(); }
const FixedArray<RefPtr<PhysicalPage>>& physical_pages() const { return m_physical_pages; }
FixedArray<RefPtr<PhysicalPage>>& physical_pages() { return m_physical_pages; }
size_t size() const { return m_physical_pages.size() * PAGE_SIZE; }
// For InlineLinkedListNode
VMObject* m_next { nullptr };
VMObject* m_prev { nullptr };
protected:
explicit VMObject(size_t);
explicit VMObject(const VMObject&);
template<typename Callback>
void for_each_region(Callback);
FixedArray<RefPtr<PhysicalPage>> m_physical_pages;
private:
VMObject& operator=(const VMObject&) = delete;
VMObject& operator=(VMObject&&) = delete;
VMObject(VMObject&&) = delete;
Lock m_paging_lock { "VMObject" };
};