Changeset 2810636 in mainline


Ignore:
Timestamp:
2006-04-09T16:29:26Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
33472fa
Parents:
7f7859b9
Message:

Switch B+tree node allocation from malloc() to a dedicated slab - btree_node_slab.

Location:
generic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • generic/include/adt/btree.h

    r7f7859b9 r2810636  
    7777};
    7878
     79extern void btree_init(void);
     80
    7981extern void btree_create(btree_t *t);
    8082extern void btree_destroy(btree_t *t);
  • generic/src/adt/btree.c

    r7f7859b9 r2810636  
    2929/*
    3030 * This B-tree has the following properties:
    31  * - it is a ballanced 2-3-4-5 tree (i.e. BTREE_M = 5)
     31 * - it is a ballanced 3-4-5 tree (i.e. BTREE_M = 5)
    3232 * - values (i.e. pointers to values) are stored only in leaves
    3333 * - leaves are linked in a list
     
    7575#define MEDIAN_HIGH(n)          ((n)->key[MEDIAN_HIGH_INDEX((n))]);
    7676
     77static slab_cache_t *btree_node_slab;
     78
     79/** Initialize B-trees. */
     80void btree_init(void)
     81{
     82        btree_node_slab = slab_cache_create("btree_node_slab", sizeof(btree_node_t), 0, NULL, NULL, SLAB_CACHE_MAGDEFERRED);
     83}
     84
    7785/** Create empty B-tree.
    7886 *
     
    8290{
    8391        list_initialize(&t->leaf_head);
    84         t->root = (btree_node_t *) malloc(sizeof(btree_node_t), 0);
     92        t->root = (btree_node_t *) slab_alloc(btree_node_slab, 0);
    8593        node_initialize(t->root);
    8694        list_append(&t->root->leaf_link, &t->leaf_head);
     
    9199{
    92100        ASSERT(!t->root->keys);
    93         free(t->root);
     101        slab_free(btree_node_slab, t->root);
    94102}
    95103
     
    162170                         * We split the root node. Create new root.
    163171                         */
    164                         t->root = (btree_node_t *) malloc(sizeof(btree_node_t), 0);
     172                        t->root = (btree_node_t *) slab_alloc(btree_node_slab, 0);
    165173                        node->parent = t->root;
    166174                        rnode->parent = t->root;
     
    215223                        t->root = node->subtree[0];
    216224                        t->root->parent = NULL;
    217                         free(node);
     225                        slab_free(btree_node_slab, node);
    218226                } else {
    219227                        /*
     
    270278                idx = find_key_by_subtree(parent, rnode, true);
    271279                ASSERT((int) idx != -1);
    272                 free(rnode);
     280                slab_free(btree_node_slab, rnode);
    273281                _btree_remove(t, parent->key[idx], parent);
    274282        }
     
    563571         * Allocate and initialize new right sibling.
    564572         */
    565         rnode = (btree_node_t *) malloc(sizeof(btree_node_t), 0);
     573        rnode = (btree_node_t *) slab_alloc(btree_node_slab, 0);
    566574        node_initialize(rnode);
    567575        rnode->parent = node->parent;
  • generic/src/main/main.c

    r7f7859b9 r2810636  
    5858#include <ipc/ipc.h>
    5959#include <macros.h>
     60#include <adt/btree.h>
    6061
    6162#ifdef CONFIG_SMP
     
    169170        frame_init();           /* Initialize at least 1 memory segment big enough for slab to work */
    170171        slab_cache_init();
     172        btree_init();
    171173        as_init();
    172174        page_init();
Note: See TracChangeset for help on using the changeset viewer.