From c6cfc27f43a3a84f0660dea1f082008e39aaf5fe Mon Sep 17 00:00:00 2001 From: Shuxin Yang Date: Fri, 15 Aug 2014 16:04:47 -0700 Subject: [PATCH] pass the 1st unit test --- Makefile | 3 +++ page_alloc.c | 14 ++++++++++---- page_alloc.h | 8 ++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index bbdb1f8..c6e9c92 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,10 @@ $(RBTREE_TEST) : ${RB_TREE_SRCS:%.c=%.o} ${RB_TEST_SRCS:%.cxx=%.o} $(CXX) $(CXXFLAGS) -c $< test : $(RBTREE_TEST) $(UNIT_TEST) + @echo "RB-tree unit testing" ./$(RBTREE_TEST) + @echo "" + @echo "Memory management unit testing" ./$(UNIT_TEST) clean: diff --git a/page_alloc.c b/page_alloc.c index 5b77c74..3567867 100644 --- a/page_alloc.c +++ b/page_alloc.c @@ -32,6 +32,7 @@ lm_init_page_alloc(lm_trunk_t* trunk, lj_mm_opt_t* mm_opt) { int pn = mm_opt->page_num; if (((pn > 0) && (pn > page_num)) || !pn) return 0; + page_num = pn; } int alloc_sz = sizeof(lm_alloc_t) + @@ -188,7 +189,6 @@ lm_get_status(void) { if (alloc_blk_num) { block_info_t* ai; ai = (block_info_t*)malloc(sizeof(block_info_t) * alloc_blk_num); - s->alloc_blk_info = ai; rb_iter_t iter, iter_e; int idx = 0; @@ -201,6 +201,9 @@ lm_get_status(void) { ai[idx].order = alloc_info->page_info[blk->key].order; idx++; } + + s->alloc_blk_info = ai; + s->alloc_blk_num = idx; } /* Populate free block info */ @@ -212,10 +215,9 @@ lm_get_status(void) { if (free_blk_num) { block_info_t* fi; fi = (block_info_t*)malloc(sizeof(block_info_t) * free_blk_num); - s->free_blk_info = fi; int idx = 0; - + int page_size_log2 = alloc_info->page_size_log2; for (i = 0, e = alloc_info->max_order; i < e; i++) { rb_tree_t* rbt = alloc_info->free_blks + i; @@ -226,10 +228,14 @@ lm_get_status(void) { rb_node_t* nd = rbt_iter_deref(iter); fi[idx].page_idx = nd->key; fi[idx].order = alloc_info->page_info[nd->key].order; - fi[idx].size = 1 << fi[idx].order; + fi[idx].size = (1 << fi[idx].order) << page_size_log2; + idx++; } } ASSERT(idx == free_blk_num); + + s->free_blk_info = fi; + s->free_blk_num = idx; } return s; diff --git a/page_alloc.h b/page_alloc.h index c90f243..ba07be3 100644 --- a/page_alloc.h +++ b/page_alloc.h @@ -138,12 +138,8 @@ add_block(page_idx_t block, int order) { static inline void migrade_alloc_block(page_idx_t block, int ord_was, int ord_is, size_t new_map_sz) { rb_tree_t* rbt = &alloc_info->alloc_blks; - int res = rbt_delete(rbt, block); - ASSERT(res != 0); - - rbt_insert(rbt, block, new_map_sz); - - ASSERT(alloc_info->page_info[block].order == ord_was); + int res = rbt_set_value(rbt, block, new_map_sz); + ASSERT(res != 0 && alloc_info->page_info[block].order == ord_was); alloc_info->page_info[block].order = ord_is; }