Commit | Line | Data |
---|---|---|
644bf7b5 NG |
1 | /* |
2 | * xvmalloc memory allocator | |
3 | * | |
1130ebba | 4 | * Copyright (C) 2008, 2009, 2010 Nitin Gupta |
644bf7b5 NG |
5 | * |
6 | * This code is released using a dual license strategy: BSD/GPL | |
7 | * You can choose the licence that better fits your requirements. | |
8 | * | |
9 | * Released under the terms of 3-clause BSD License | |
10 | * Released under the terms of GNU General Public License Version 2.0 | |
11 | */ | |
12 | ||
13 | #ifndef _XV_MALLOC_INT_H_ | |
14 | #define _XV_MALLOC_INT_H_ | |
15 | ||
16 | #include <linux/kernel.h> | |
17 | #include <linux/types.h> | |
18 | ||
19 | /* User configurable params */ | |
20 | ||
21 | /* Must be power of two */ | |
22 | #define XV_ALIGN_SHIFT 2 | |
23 | #define XV_ALIGN (1 << XV_ALIGN_SHIFT) | |
24 | #define XV_ALIGN_MASK (XV_ALIGN - 1) | |
25 | ||
26 | /* This must be greater than sizeof(link_free) */ | |
27 | #define XV_MIN_ALLOC_SIZE 32 | |
28 | #define XV_MAX_ALLOC_SIZE (PAGE_SIZE - XV_ALIGN) | |
29 | ||
30 | /* Free lists are separated by FL_DELTA bytes */ | |
31 | #define FL_DELTA_SHIFT 3 | |
32 | #define FL_DELTA (1 << FL_DELTA_SHIFT) | |
33 | #define FL_DELTA_MASK (FL_DELTA - 1) | |
34 | #define NUM_FREE_LISTS ((XV_MAX_ALLOC_SIZE - XV_MIN_ALLOC_SIZE) \ | |
35 | / FL_DELTA + 1) | |
36 | ||
37 | #define MAX_FLI DIV_ROUND_UP(NUM_FREE_LISTS, BITS_PER_LONG) | |
38 | ||
39 | /* End of user params */ | |
40 | ||
41 | enum blockflags { | |
42 | BLOCK_FREE, | |
43 | PREV_FREE, | |
44 | __NR_BLOCKFLAGS, | |
45 | }; | |
46 | ||
47 | #define FLAGS_MASK XV_ALIGN_MASK | |
48 | #define PREV_MASK (~FLAGS_MASK) | |
49 | ||
50 | struct freelist_entry { | |
51 | struct page *page; | |
52 | u16 offset; | |
53 | u16 pad; | |
54 | }; | |
55 | ||
56 | struct link_free { | |
57 | struct page *prev_page; | |
58 | struct page *next_page; | |
59 | u16 prev_offset; | |
60 | u16 next_offset; | |
61 | }; | |
62 | ||
63 | struct block_header { | |
64 | union { | |
ef4ffb7a | 65 | /* This common header must be XV_ALIGN bytes */ |
644bf7b5 NG |
66 | u8 common[XV_ALIGN]; |
67 | struct { | |
68 | u16 size; | |
69 | u16 prev; | |
70 | }; | |
71 | }; | |
72 | struct link_free link; | |
73 | }; | |
74 | ||
75 | struct xv_pool { | |
76 | ulong flbitmap; | |
77 | ulong slbitmap[MAX_FLI]; | |
78 | spinlock_t lock; | |
79 | ||
80 | struct freelist_entry freelist[NUM_FREE_LISTS]; | |
81 | ||
82 | /* stats */ | |
83 | u64 total_pages; | |
84 | }; | |
85 | ||
86 | #endif |