Skip to content

Commit

Permalink
Move abstract base implementation into allocator.c (vmware#519)
Browse files Browse the repository at this point in the history
Co-authored-by: Jon Howell <[email protected]>
  • Loading branch information
jonhnet and Jon Howell authored Jan 6, 2023
1 parent d45335e commit 77e2883
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ PLATFORM_IO_SYS = $(OBJDIR)/$(SRCDIR)/$(PLATFORM_DIR)/laio.o
UTIL_SYS = $(OBJDIR)/$(SRCDIR)/util.o $(PLATFORM_SYS)

CLOCKCACHE_SYS = $(OBJDIR)/$(SRCDIR)/clockcache.o \
$(OBJDIR)/$(SRCDIR)/allocator.o \
$(OBJDIR)/$(SRCDIR)/rc_allocator.o \
$(OBJDIR)/$(SRCDIR)/task.o \
$(UTIL_SYS) \
Expand Down
27 changes: 27 additions & 0 deletions src/allocator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2018-2021 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0

/*
* allocator.c --
*
* This file implements the abstract base behavior shared by allocators.
*/

#include "allocator.h"
#include "poison.h"

void
allocator_config_init(allocator_config *allocator_cfg,
io_config *io_cfg,
uint64 capacity)
{
ZERO_CONTENTS(allocator_cfg);

allocator_cfg->io_cfg = io_cfg;
allocator_cfg->capacity = capacity;

allocator_cfg->page_capacity = capacity / io_cfg->page_size;
allocator_cfg->extent_capacity = capacity / io_cfg->extent_size;
uint64 log_extent_size = 63 - __builtin_clzll(io_cfg->extent_size);
allocator_cfg->extent_mask = ~((1ULL << log_extent_size) - 1);
}
17 changes: 2 additions & 15 deletions src/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,10 @@ typedef struct allocator_config {
* Initialize allocator config values
*-----------------------------------------------------------------------------
*/
// TODO(robj): maybe someday add allocator.c
static inline void
void
allocator_config_init(allocator_config *allocator_cfg,
io_config *io_cfg,
uint64 capacity)
{
ZERO_CONTENTS(allocator_cfg);

allocator_cfg->io_cfg = io_cfg;
allocator_cfg->capacity = capacity;

allocator_cfg->page_capacity = capacity / io_cfg->page_size;
allocator_cfg->extent_capacity = capacity / io_cfg->extent_size;
uint64 log_extent_size = 63 - __builtin_clzll(io_cfg->extent_size);
allocator_cfg->extent_mask = ~((1ULL << log_extent_size) - 1);
}

uint64 capacity);

static inline uint64
allocator_config_extent_base_addr(allocator_config *allocator_cfg, uint64 addr)
Expand Down

0 comments on commit 77e2883

Please sign in to comment.