ladybird/Kernel/VM/VMObject.h
Andreas Kling dbb644f20c Kernel: Start implementing purgeable memory support
It's now possible to get purgeable memory by using mmap(MAP_PURGEABLE).
Purgeable memory has a "volatile" flag that can be set using madvise():

- madvise(..., MADV_SET_VOLATILE)
- madvise(..., MADV_SET_NONVOLATILE)

When in the "volatile" state, the kernel may take away the underlying
physical memory pages at any time, without notifying the owner.
This gives you a guilt discount when caching very large things. :^)

Setting a purgeable region to non-volatile will return whether or not
the memory has been taken away by the kernel while being volatile.
Basically, if madvise(..., MADV_SET_NONVOLATILE) returns 1, that means
the memory was purged while volatile, and whatever was in that piece
of memory needs to be reconstructed before use.
2019-12-09 19:12:38 +01:00

53 lines
1.4 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;
friend class Region;
public:
virtual ~VMObject();
virtual NonnullRefPtr<VMObject> clone() = 0;
virtual bool is_anonymous() const { return false; }
virtual bool is_purgeable() 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;
Lock m_paging_lock { "VMObject" };
private:
VMObject& operator=(const VMObject&) = delete;
VMObject& operator=(VMObject&&) = delete;
VMObject(VMObject&&) = delete;
};