Rev 430 | Rev 490 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 430 | Rev 489 | ||
---|---|---|---|
Line 38... | Line 38... | ||
38 | * |
38 | * |
39 | * Allocate memory for and initialize new buddy system. |
39 | * Allocate memory for and initialize new buddy system. |
40 | * |
40 | * |
41 | * @param max_order The biggest allocable size will be 2^max_order. |
41 | * @param max_order The biggest allocable size will be 2^max_order. |
42 | * @param op Operations for new buddy system. |
42 | * @param op Operations for new buddy system. |
- | 43 | * @param data Pointer to be used by implentation. |
|
43 | * |
44 | * |
44 | * @return New buddy system. |
45 | * @return New buddy system. |
45 | */ |
46 | */ |
46 | buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op) |
47 | buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op, void *data) |
47 | { |
48 | { |
48 | buddy_system_t *b; |
49 | buddy_system_t *b; |
49 | int i; |
50 | int i; |
50 | 51 | ||
51 | ASSERT(max_order < BUDDY_SYSTEM_INNER_BLOCK); |
52 | ASSERT(max_order < BUDDY_SYSTEM_INNER_BLOCK); |
Line 74... | Line 75... | ||
74 | for (i = 0; i < max_order; i++) |
75 | for (i = 0; i < max_order; i++) |
75 | list_initialize(&b->order[i]); |
76 | list_initialize(&b->order[i]); |
76 | 77 | ||
77 | b->max_order = max_order; |
78 | b->max_order = max_order; |
78 | b->op = op; |
79 | b->op = op; |
- | 80 | b->data = data; |
|
79 | } |
81 | } |
80 | 82 | ||
81 | return b; |
83 | return b; |
82 | } |
84 | } |
83 | 85 | ||
Line 128... | Line 130... | ||
128 | res = hlp; |
130 | res = hlp; |
129 | 131 | ||
130 | /* |
132 | /* |
131 | * Bisect the block and set order of both of its parts to i. |
133 | * Bisect the block and set order of both of its parts to i. |
132 | */ |
134 | */ |
133 | hlp = b->op->bisect(res); |
135 | hlp = b->op->bisect(b, res); |
134 | b->op->set_order(res, i); |
136 | b->op->set_order(b, res, i); |
135 | b->op->set_order(hlp, i); |
137 | b->op->set_order(b, hlp, i); |
136 | 138 | ||
137 | /* |
139 | /* |
138 | * Return the other half to buddy system. |
140 | * Return the other half to buddy system. |
139 | */ |
141 | */ |
140 | buddy_system_free(b, hlp); |
142 | buddy_system_free(b, hlp); |
Line 156... | Line 158... | ||
156 | __u8 i; |
158 | __u8 i; |
157 | 159 | ||
158 | /* |
160 | /* |
159 | * Determine block's order. |
161 | * Determine block's order. |
160 | */ |
162 | */ |
161 | i = b->op->get_order(block); |
163 | i = b->op->get_order(b, block); |
162 | 164 | ||
163 | ASSERT(i < b->max_order); |
165 | ASSERT(i < b->max_order); |
164 | 166 | ||
165 | if (i != b->max_order - 1) { |
167 | if (i != b->max_order - 1) { |
166 | /* |
168 | /* |
167 | * See if there is any buddy in the list of order i. |
169 | * See if there is any buddy in the list of order i. |
168 | */ |
170 | */ |
169 | buddy = b->op->find_buddy(block); |
171 | buddy = b->op->find_buddy(b, block); |
170 | if (buddy) { |
172 | if (buddy) { |
171 | 173 | ||
172 | ASSERT(b->op->get_order(buddy) == i); |
174 | ASSERT(b->op->get_order(b, buddy) == i); |
173 | 175 | ||
174 | /* |
176 | /* |
175 | * Remove buddy from the list of order i. |
177 | * Remove buddy from the list of order i. |
176 | */ |
178 | */ |
177 | list_remove(buddy); |
179 | list_remove(buddy); |
178 | 180 | ||
179 | /* |
181 | /* |
180 | * Invalidate order of both block and buddy. |
182 | * Invalidate order of both block and buddy. |
181 | */ |
183 | */ |
182 | b->op->set_order(block, BUDDY_SYSTEM_INNER_BLOCK); |
184 | b->op->set_order(b, block, BUDDY_SYSTEM_INNER_BLOCK); |
183 | b->op->set_order(buddy, BUDDY_SYSTEM_INNER_BLOCK); |
185 | b->op->set_order(b, buddy, BUDDY_SYSTEM_INNER_BLOCK); |
184 | 186 | ||
185 | /* |
187 | /* |
186 | * Coalesce block and buddy into one block. |
188 | * Coalesce block and buddy into one block. |
187 | */ |
189 | */ |
188 | hlp = b->op->coalesce(block, buddy); |
190 | hlp = b->op->coalesce(b, block, buddy); |
189 | 191 | ||
190 | /* |
192 | /* |
191 | * Set order of the coalesced block to i + 1. |
193 | * Set order of the coalesced block to i + 1. |
192 | */ |
194 | */ |
193 | b->op->set_order(hlp, i + 1); |
195 | b->op->set_order(b, hlp, i + 1); |
194 | 196 | ||
195 | /* |
197 | /* |
196 | * Recursively add the coalesced block to the list of order i + 1. |
198 | * Recursively add the coalesced block to the list of order i + 1. |
197 | */ |
199 | */ |
198 | buddy_system_free(b, hlp); |
200 | buddy_system_free(b, hlp); |