Skip to content

Commit

Permalink
(#538) Unit-test to exercise mini_allocator. Minor cleanup of module.
Browse files Browse the repository at this point in the history
This commit does some minor cleanup of the mini-allocator module.
Some interfaces are slightly changed to streamline init / deinit
interfaces. A new unit-test is added to exercise core interfaces
of this page allocation system, and to exercise / test the print
methods for keyed and unkeyed page allocation schemes.

Extend print methods to also print page_addr and extent_addr as
page_num and extent_num, where applicable.
  • Loading branch information
gapisback committed Feb 1, 2023
1 parent 1f09113 commit a307bd8
Show file tree
Hide file tree
Showing 7 changed files with 666 additions and 70 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ $(BINDIR)/$(UNITDIR)/platform_apis_test: $(UTIL_SYS) \
$(COMMON_UNIT_TESTOBJ) \
$(PLATFORM_SYS)

$(BINDIR)/$(UNITDIR)/mini_allocator_test: $(COMMON_TESTOBJ) \
$(OBJDIR)/$(FUNCTIONAL_TESTSDIR)/test_async.o \
$(LIBDIR)/libsplinterdb.so

########################################
# Convenience mini unit-test targets
unit/util_test: $(BINDIR)/$(UNITDIR)/util_test
Expand Down
17 changes: 17 additions & 0 deletions src/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,23 @@ allocator_print_allocated(allocator *al)
return al->ops->print_allocated(al);
}

// Return the address of the extent holding page at address 'addr'
static inline uint64
allocator_extent_base_addr(allocator *al, uint64 addr)
{
allocator_config *allocator_cfg = allocator_get_config(al);
return allocator_config_extent_base_addr(allocator_cfg, addr);
}

// Returns the address of the page next to input 'page_addr'
static inline uint64
allocator_next_page_addr(allocator *al, uint64 page_addr)
{
allocator_config *allocator_cfg = allocator_get_config(al);
return (page_addr + allocator_cfg->io_cfg->page_size);
}


static inline bool
allocator_page_valid(allocator *al, uint64 addr)
{
Expand Down
7 changes: 5 additions & 2 deletions src/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,11 @@ btree_truncate_index(const btree_config *cfg, // IN
*-----------------------------------------------------------------------------
* btree_alloc --
*
* Allocates a node from the preallocator. Will refill it if there are no
* more nodes available for the given height.
* Allocates a new page from the mini-allocator for a new BTree node.
* from the (previously setup) mini-allocator. Will refill the mini-
* allocator's cache of pre-allocated extents if there are no more nodes
* (pages) available from the already-allocated extent for the given
* height.
*-----------------------------------------------------------------------------
*/
bool
Expand Down
Loading

0 comments on commit a307bd8

Please sign in to comment.