mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 17:55:08 +00:00

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.
32 lines
948 B
C++
32 lines
948 B
C++
#pragma once
|
|
|
|
#include <Kernel/VM/AnonymousVMObject.h>
|
|
|
|
class PurgeableVMObject final : public AnonymousVMObject {
|
|
public:
|
|
virtual ~PurgeableVMObject() override;
|
|
|
|
static NonnullRefPtr<PurgeableVMObject> create_with_size(size_t);
|
|
virtual NonnullRefPtr<VMObject> clone() override;
|
|
|
|
int purge();
|
|
|
|
bool was_purged() const { return m_was_purged; }
|
|
void set_was_purged(bool b) { m_was_purged = b; }
|
|
|
|
bool is_volatile() const { return m_volatile; }
|
|
void set_volatile(bool b) { m_volatile = b; }
|
|
|
|
private:
|
|
explicit PurgeableVMObject(size_t);
|
|
explicit PurgeableVMObject(const PurgeableVMObject&);
|
|
|
|
PurgeableVMObject& operator=(const PurgeableVMObject&) = delete;
|
|
PurgeableVMObject& operator=(PurgeableVMObject&&) = delete;
|
|
PurgeableVMObject(PurgeableVMObject&&) = delete;
|
|
|
|
virtual bool is_purgeable() const override { return true; }
|
|
|
|
bool m_was_purged { false };
|
|
bool m_volatile { false };
|
|
};
|