mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
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.
This commit is contained in:
parent
7248c34e35
commit
dbb644f20c
13 changed files with 196 additions and 9 deletions
|
@ -56,4 +56,11 @@ int shm_unlink(const char* name)
|
|||
int rc = syscall(SC_shm_unlink, name);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int madvise(void* address, size_t size, int advice)
|
||||
{
|
||||
int rc = syscall(SC_madvise, address, size, advice);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define MAP_ANONYMOUS 0x20
|
||||
#define MAP_ANON MAP_ANONYMOUS
|
||||
#define MAP_STACK 0x40
|
||||
#define MAP_PURGEABLE 0x80
|
||||
|
||||
#define PROT_READ 0x1
|
||||
#define PROT_WRITE 0x2
|
||||
|
@ -17,6 +18,9 @@
|
|||
|
||||
#define MAP_FAILED ((void*)-1)
|
||||
|
||||
#define MADV_SET_VOLATILE 0x100
|
||||
#define MADV_SET_NONVOLATILE 0x200
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
void* mmap(void* addr, size_t, int prot, int flags, int fd, off_t);
|
||||
|
@ -26,5 +30,6 @@ int mprotect(void*, size_t, int prot);
|
|||
int set_mmap_name(void*, size_t, const char*);
|
||||
int shm_open(const char* name, int flags, mode_t);
|
||||
int shm_unlink(const char* name);
|
||||
int madvise(void*, size_t, int advice);
|
||||
|
||||
__END_DECLS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue