Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 488 → Rev 489

/SPARTAN/trunk/generic/include/mm/frame.h
86,11 → 86,11
/*
* Buddy system operations
*/
link_t * zone_buddy_find_buddy(link_t * buddy);
link_t * zone_buddy_bisect(link_t * block);
link_t * zone_buddy_coalesce(link_t * buddy_l, link_t * buddy_r);
void zone_buddy_set_order(link_t * block, __u8 order);
__u8 zone_buddy_get_order(link_t * block);
link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * buddy);
link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block);
link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * buddy_l, link_t * buddy_r);
void zone_buddy_set_order(buddy_system_t *b, link_t * block, __u8 order);
__u8 zone_buddy_get_order(buddy_system_t *b, link_t * block);
 
__address zone_buddy_frame_alloc(int flags, __u8 order);
void zone_buddy_frame_free(__address addr);
/SPARTAN/trunk/generic/include/mm/buddy.h
34,12 → 34,13
 
#define BUDDY_SYSTEM_INNER_BLOCK 0xff
 
/** Buddy system operations to be implemented by each implementations. */
struct buddy_system_operations {
link_t *(* find_buddy)(link_t *); /**< Return pointer to left-side or right-side buddy for block passed as argument. */
link_t *(* bisect)(link_t *); /**< Bisect the block passed as argument and return pointer to the new right-side buddy. */
link_t *(* coalesce)(link_t *, link_t *); /**< Coalesce two buddies into a bigger block. */
void (*set_order)(link_t *, __u8); /**< Set order of block passed as argument. */
__u8 (*get_order)(link_t *); /**< Return order of block passed as argument. */
link_t *(* find_buddy)(buddy_system_t *, link_t *); /**< Return pointer to left-side or right-side buddy for block passed as argument. */
link_t *(* bisect)(buddy_system_t *, link_t *); /**< Bisect the block passed as argument and return pointer to the new right-side buddy. */
link_t *(* coalesce)(buddy_system_t *, link_t *, link_t *); /**< Coalesce two buddies into a bigger block. */
void (*set_order)(buddy_system_t *, link_t *, __u8); /**< Set order of block passed as argument. */
__u8 (*get_order)(buddy_system_t *, link_t *); /**< Return order of block passed as argument. */
};
 
struct buddy_system {
46,9 → 47,10
__u8 max_order;
link_t *order;
buddy_system_operations_t *op;
void *data; /**< Pointer to be used by the implementation. */
};
 
extern buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op);
extern buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op, void *data);
extern link_t *buddy_system_alloc(buddy_system_t *b, __u8 i);
extern void buddy_system_free(buddy_system_t *b, link_t *block);
 
/SPARTAN/trunk/generic/src/mm/buddy.c
40,10 → 40,11
*
* @param max_order The biggest allocable size will be 2^max_order.
* @param op Operations for new buddy system.
* @param data Pointer to be used by implentation.
*
* @return New buddy system.
*/
buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op)
buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op, void *data)
{
buddy_system_t *b;
int i;
76,6 → 77,7
b->max_order = max_order;
b->op = op;
b->data = data;
}
return b;
130,9 → 132,9
/*
* Bisect the block and set order of both of its parts to i.
*/
hlp = b->op->bisect(res);
b->op->set_order(res, i);
b->op->set_order(hlp, i);
hlp = b->op->bisect(b, res);
b->op->set_order(b, res, i);
b->op->set_order(b, hlp, i);
/*
* Return the other half to buddy system.
158,7 → 160,7
/*
* Determine block's order.
*/
i = b->op->get_order(block);
i = b->op->get_order(b, block);
 
ASSERT(i < b->max_order);
 
166,10 → 168,10
/*
* See if there is any buddy in the list of order i.
*/
buddy = b->op->find_buddy(block);
buddy = b->op->find_buddy(b, block);
if (buddy) {
 
ASSERT(b->op->get_order(buddy) == i);
ASSERT(b->op->get_order(b, buddy) == i);
/*
* Remove buddy from the list of order i.
179,18 → 181,18
/*
* Invalidate order of both block and buddy.
*/
b->op->set_order(block, BUDDY_SYSTEM_INNER_BLOCK);
b->op->set_order(buddy, BUDDY_SYSTEM_INNER_BLOCK);
b->op->set_order(b, block, BUDDY_SYSTEM_INNER_BLOCK);
b->op->set_order(b, buddy, BUDDY_SYSTEM_INNER_BLOCK);
/*
* Coalesce block and buddy into one block.
*/
hlp = b->op->coalesce(block, buddy);
hlp = b->op->coalesce(b, block, buddy);
 
/*
* Set order of the coalesced block to i + 1.
*/
b->op->set_order(hlp, i + 1);
b->op->set_order(b, hlp, i + 1);
 
/*
* Recursively add the coalesced block to the list of order i + 1.
/SPARTAN/trunk/generic/src/mm/frame.c
338,7 → 338,7
* Create buddy system for the zone
*/
for (max_order = 0; cnt >> max_order; max_order++);
z->buddy_system = buddy_system_create(max_order, &zone_buddy_system_operations);
z->buddy_system = buddy_system_create(max_order, &zone_buddy_system_operations, (void *) z);
}
return z;
543,11 → 543,13
}
 
/** Buddy system find_buddy implementation
*
* @param b Buddy system.
* @param block Block for which buddy should be found
*
* @return Buddy for given block if found
*/
link_t * zone_buddy_find_buddy(link_t * block) {
link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * block) {
frame_t * frame, * f;
zone_t * zone;
link_t * cur;
595,11 → 597,12
 
/** Buddy system bisect implementation
*
* @param b Buddy system.
* @param block Block to bisect
*
* @return right block
*/
link_t * zone_buddy_bisect(link_t * block) {
link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block) {
frame_t * frame_l, * frame_r;
frame_l = list_get_instance(block, frame_t, buddy_link);
612,12 → 615,13
 
/** Buddy system coalesce implementation
*
* @param b Buddy system.
* @param block_1 First block
* @param block_2 First block's buddy
*
* @return Coalesced block (actually block that represents lower address)
*/
link_t * zone_buddy_coalesce(link_t * block_1, link_t * block_2) {
link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * block_1, link_t * block_2) {
frame_t * frame1, * frame2;
frame1 = list_get_instance(block_1, frame_t, buddy_link);
627,10 → 631,12
}
 
/** Buddy system set_order implementation
*
* @param b Buddy system.
* @param block Buddy system block
* @param order Order to set
*/
void zone_buddy_set_order(link_t * block, __u8 order) {
void zone_buddy_set_order(buddy_system_t *b, link_t * block, __u8 order) {
frame_t * frame;
frame = list_get_instance(block, frame_t, buddy_link);
frame->buddy_order = order;
637,11 → 643,13
}
 
/** Buddy system get_order implementation
*
* @param b Buddy system.
* @param block Buddy system block
*
* @return Order of block
*/
__u8 zone_buddy_get_order(link_t * block) {
__u8 zone_buddy_get_order(buddy_system_t *b, link_t * block) {
frame_t * frame;
frame = list_get_instance(block, frame_t, buddy_link);
return frame->buddy_order;