-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmemory_pool.h
58 lines (46 loc) · 1.43 KB
/
memory_pool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <asm/ioctl.h>
#include <linux/types.h>
struct page_bundle {
struct page* stack;
unsigned long count;
};
enum memory_pool_flags {
BACKING_VM_CONTIGUOUS = (1 << 0),
};
typedef enum memory_pool_flags memory_pool_flags;
struct memory_pool_setup {
size_t pool_size;
memory_pool_flags flags;
};
struct bundle_list_head {
struct page *first;
};
struct memory_pool_ctx {
size_t pool_size;
memory_pool_flags flags;
/* start address, for contiguous pools */
unsigned long start;
/*
* One "helper" bundle to push pages into
* when full. The contents of this bundle are moved
* to the pool bundle_list
*/
struct page_bundle pool_bundle;
/*
* The bundle list contains, as the name implies,
* bundles of free pages.
* Specifically, it contains single struct page*s, whose underlying
* memory is sequentially filled with 512 addresses of further free pages.
* See also: <struct page_bundle>
*/
struct bundle_list_head bundle_list;
/* Only used for accounting purposes */
struct user_struct *user;
struct mm_struct *mm_account;
};
struct memory_pool_ctx* memory_pool_create(struct memory_pool_setup* setup);
void memory_pool_destroy(struct memory_pool_ctx* ctx);
struct page* pop_page(struct page_bundle* bundle, struct memory_pool_ctx* ctx);
void push_page(struct page* page, struct page_bundle* bundle, struct memory_pool_ctx* ctx);
unsigned free_page_bundle(struct page* bundle_page, unsigned count);