Changeset 085d973 in mainline for generic/src/mm/buddy.c


Ignore:
Timestamp:
2006-02-08T12:34:05Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5e3757d
Parents:
eb1b8b6
Message:

Cleanup o frame allocator.
Removed early_malloc & initial heap.
Will break ia64, ppc & sparc.
Added e820 table print.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • generic/src/mm/buddy.c

    reb1b8b6 r085d973  
    2929#include <mm/buddy.h>
    3030#include <mm/frame.h>
    31 #include <mm/heap.h>
    3231#include <arch/types.h>
    3332#include <typedefs.h>
     
    3635#include <print.h>
    3736
     37/** Return size needed for the buddy configuration data */
     38size_t buddy_conf_size(int max_order)
     39{
     40        return sizeof(buddy_system_t) + (max_order + 1) * sizeof(link_t);
     41}
     42
     43
    3844/** Create buddy system
    3945 *
    4046 * Allocate memory for and initialize new buddy system.
    4147 *
     48 * @param b Preallocated buddy system control data
    4249 * @param max_order The biggest allocable size will be 2^max_order.
    4350 * @param op Operations for new buddy system.
     
    4653 * @return New buddy system.
    4754 */
    48 buddy_system_t *buddy_system_create(__u8 max_order, buddy_system_operations_t *op, void *data)
    49 {
    50         buddy_system_t *b;
     55void buddy_system_create(buddy_system_t *b,
     56                         __u8 max_order,
     57                         buddy_system_operations_t *op,
     58                         void *data)
     59{
    5160        int i;
    5261
     
    6170
    6271        /*
    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;
    8682}
    8783
     
    113109        return false;
    114110       
     111}
     112
     113/** Allocate PARTICULAR block from buddy system
     114 *
     115 * @ return Block of data or NULL if no such block was found
     116 */
     117link_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        }
    115147}
    116148
     
    138170                return res;
    139171        }
    140        
    141172        /*
    142173         * If order i is already the maximal order,
     
    168199       
    169200        /*
    170          * Return the other half to buddy system.
    171          * PROBLEM!!!! WILL FIND OTHER PART AS BUDDY AND LINK TOGETHER
     201         * Return the other half to buddy system. Mark the first part
     202         * full, so that it won't coalsce again.
    172203         */
    173204        b->op->mark_busy(b, res);
Note: See TracChangeset for help on using the changeset viewer.