Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Generalization of constraints on page allocation and implementation/use
[palacios.git] / linux_module / buddy.h
1 /* Copyright (c) 2007, Sandia National Laboratories */
2
3 #ifndef _LWK_BUDDY_H
4 #define _LWK_BUDDY_H
5
6 #include <linux/list.h>
7 #include <linux/rbtree.h>
8
9
10
11 struct buddy_memzone {
12     unsigned long    max_order;    /** max size of memory pool = 2^max_order */
13     unsigned long    min_order;    /** minimum allocatable block size */
14
15
16     struct list_head *avail;       /** one free list for each block size,
17                                     * indexed by block order:
18                                     *   avail[i] = free list of 2^i blocks
19                                     */
20
21     spinlock_t lock;               /** For now we will lock all zone operations...
22                                     *   Hopefully this does not cause a performance issue 
23                                     */
24
25     unsigned int node_id;         /** The NUMA node this zone allocates from 
26                                    */
27
28     
29     unsigned long num_pools;
30     struct rb_root mempools;
31 };
32
33 /**
34  * This structure stores the state of a buddy system memory allocator object.
35  */
36 struct buddy_mempool {
37     struct buddy_memzone * zone; 
38
39     unsigned long    base_addr;    /** physical base address of the memory pool */
40
41
42     unsigned long    pool_order;   /** Size of this memory pool = 2^pool_order */
43
44     unsigned long    num_blocks;   /** number of bits in tag_bits */
45     unsigned long    *tag_bits;    /** one bit for each 2^min_order block
46                                     *   0 = block is allocated
47                                     *   1 = block is available
48                                     */
49
50     unsigned long num_free_blocks;
51     
52     void             *user_metadata; // whatever the user wants
53
54     struct rb_node tree_node;
55 };
56
57
58 /**
59  * Each free block has one of these structures at its head. The link member
60  * provides linkage for the mp->avail[order] free list, where order is the
61  * size of the free block.
62  */
63 struct block {
64     struct buddy_mempool * mp;
65     struct list_head link;
66     unsigned long order;
67 };
68
69
70 extern struct buddy_memzone *
71 buddy_init(unsigned long pool_order,
72            unsigned long min_order,
73            unsigned int node_id);
74
75 extern void 
76 buddy_deinit(struct buddy_memzone * zone,
77              int (*free_callback)(void *user_metadata));
78
79 /* Add pool at given physical address */
80 extern int 
81 buddy_add_pool(struct buddy_memzone * zone, 
82                unsigned long base_addr, 
83                unsigned long pool_order,
84                void          *user_metadata);
85                           
86
87 /* Remove pool based at given physical address */
88 extern int
89 buddy_remove_pool(struct buddy_memzone * zone, 
90                   unsigned long base_addr, 
91                   unsigned char force,
92                   void          **user_metadata);
93
94
95
96 /* Allocate pages, returns physical address */
97 extern uintptr_t 
98 buddy_alloc(struct buddy_memzone * zone,
99             unsigned long order,
100             int (*filter_func)(void *paddr, void *filter_state),
101             void *filter_state);
102
103
104 /* Free a physical address */
105 extern int
106 buddy_free(struct buddy_memzone * zone,
107            uintptr_t  addr,
108            unsigned long order);
109
110
111 extern void
112 buddy_dump_memzone(struct buddy_memzone * zone);
113
114 #endif