Changeset 085d973 in mainline for generic/src/mm/buddy.c
- Timestamp:
- 2006-02-08T12:34:05Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5e3757d
- Parents:
- eb1b8b6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/src/mm/buddy.c
reb1b8b6 r085d973 29 29 #include <mm/buddy.h> 30 30 #include <mm/frame.h> 31 #include <mm/heap.h>32 31 #include <arch/types.h> 33 32 #include <typedefs.h> … … 36 35 #include <print.h> 37 36 37 /** Return size needed for the buddy configuration data */ 38 size_t buddy_conf_size(int max_order) 39 { 40 return sizeof(buddy_system_t) + (max_order + 1) * sizeof(link_t); 41 } 42 43 38 44 /** Create buddy system 39 45 * 40 46 * Allocate memory for and initialize new buddy system. 41 47 * 48 * @param b Preallocated buddy system control data 42 49 * @param max_order The biggest allocable size will be 2^max_order. 43 50 * @param op Operations for new buddy system. … … 46 53 * @return New buddy system. 47 54 */ 48 buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op, void *data) 49 { 50 buddy_system_t *b; 55 void buddy_system_create(buddy_system_t *b, 56 __u8 max_order, 57 buddy_system_operations_t *op, 58 void *data) 59 { 51 60 int i; 52 61 … … 61 70 62 71 /* 63 * Allocate memory for structure describing the whole buddy system. 64 */ 65 b = (buddy_system_t *) early_malloc(sizeof(buddy_system_t)); 66 67 if (b) { 68 /* 69 * Allocate memory for all orders this buddy system will work with. 70 */ 71 b->order = (link_t *) early_malloc((max_order + 1) * sizeof(link_t)); 72 if (!b->order) { 73 early_free(b); 74 return NULL; 75 } 76 77 for (i = 0; i <= max_order; i++) 78 list_initialize(&b->order[i]); 79 80 b->max_order = max_order; 81 b->op = op; 82 b->data = data; 83 } 84 85 return b; 72 * Use memory after our own structure 73 */ 74 b->order = (link_t *) (&b[1]); 75 76 for (i = 0; i <= max_order; i++) 77 list_initialize(&b->order[i]); 78 79 b->max_order = max_order; 80 b->op = op; 81 b->data = data; 86 82 } 87 83 … … 113 109 return false; 114 110 111 } 112 113 /** Allocate PARTICULAR block from buddy system 114 * 115 * @ return Block of data or NULL if no such block was found 116 */ 117 link_t *buddy_system_alloc_block(buddy_system_t *b, link_t *block) 118 { 119 link_t *left,*right, *tmp; 120 __u8 order; 121 122 left = b->op->find_block(b, block, BUDDY_SYSTEM_INNER_BLOCK); 123 ASSERT(left); 124 list_remove(left); 125 while (1) { 126 if (! b->op->get_order(b,left)) { 127 b->op->mark_busy(b, left); 128 return left; 129 } 130 131 order = b->op->get_order(b, left); 132 133 right = b->op->bisect(b, left); 134 b->op->set_order(b, left, order-1); 135 b->op->set_order(b, right, order-1); 136 137 tmp = b->op->find_block(b, block, BUDDY_SYSTEM_INNER_BLOCK); 138 139 if (tmp == right) { 140 right = left; 141 left = tmp; 142 } 143 b->op->mark_busy(b, left); 144 buddy_system_free(b, right); 145 b->op->mark_available(b, left); 146 } 115 147 } 116 148 … … 138 170 return res; 139 171 } 140 141 172 /* 142 173 * If order i is already the maximal order, … … 168 199 169 200 /* 170 * Return the other half to buddy system. 171 * PROBLEM!!!! WILL FIND OTHER PART AS BUDDY AND LINK TOGETHER201 * Return the other half to buddy system. Mark the first part 202 * full, so that it won't coalsce again. 172 203 */ 173 204 b->op->mark_busy(b, res);
Note:
See TracChangeset
for help on using the changeset viewer.