Motr  M0
alloc.c File Reference
#include "lib/trace.h"
#include "be/alloc.h"
#include "be/alloc_internal.h"
#include "be/seg_internal.h"
#include "be/tx.h"
#include "be/op.h"
#include "lib/memory.h"
#include "lib/errno.h"
#include "lib/misc.h"
#include "motr/magic.h"
#include "be/domain.h"
Include dependency graph for alloc.c:

Go to the source code of this file.

Macros

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_BE
 
#define P_ACS(acs)   (acs)->bcs_nr, (acs)->bcs_size
 

Enumerations

enum  { BE_ALLOC_HEADER_SHIFT = 3, BE_ALLOC_ZONE_SIZE_SHIFT = 3 }
 

Functions

 M0_BE_LIST_DESCR_DEFINE (chunks_all, "list of all chunks in m0_be_allocator", static, struct be_alloc_chunk, bac_linkage, bac_magic, M0_BE_ALLOC_ALL_LINK_MAGIC, M0_BE_ALLOC_ALL_MAGIC)
 
 M0_BE_LIST_DEFINE (chunks_all, static, struct be_alloc_chunk)
 
static const char * be_alloc_zone_name (enum m0_be_alloc_zone_type type)
 
static void be_allocator_call_stat_init (struct m0_be_allocator_call_stat *cstat)
 
static void be_allocator_call_stats_init (struct m0_be_allocator_call_stats *cs)
 
static void be_allocator_stats_init (struct m0_be_allocator_stats *stats, struct m0_be_allocator_header *h)
 
static void be_allocator_call_stat_update (struct m0_be_allocator_call_stat *cstat, unsigned long nr, m0_bcount_t size)
 
static void be_allocator_call_stats_update (struct m0_be_allocator_call_stats *cs, m0_bcount_t size, bool alloc, bool failed)
 
static void be_allocator_call_stats_print (struct m0_be_allocator_call_stats *cs, const char *descr)
 
static void be_allocator_stats_print (struct m0_be_allocator_stats *stats)
 
static void be_allocator_stats_update (struct m0_be_allocator_stats *stats, m0_bcount_t size, bool alloc, bool failed)
 
static void be_allocator_stats_capture (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct m0_be_tx *tx)
 
static void be_alloc_chunk_capture (struct m0_be_allocator *a, struct m0_be_tx *tx, struct be_alloc_chunk *c)
 
static void be_alloc_free_flag_capture (const struct m0_be_allocator *a, struct m0_be_tx *tx, struct be_alloc_chunk *c)
 
static void be_alloc_size_capture (const struct m0_be_allocator *a, struct m0_be_tx *tx, struct be_alloc_chunk *c)
 
static bool be_alloc_mem_is_in (const struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, const void *ptr, m0_bcount_t size)
 
static bool be_alloc_chunk_is_in (const struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, const struct be_alloc_chunk *c)
 
static bool be_alloc_chunk_is_not_overlapping (const struct be_alloc_chunk *a, const struct be_alloc_chunk *b)
 
static bool be_alloc_chunk_invariant (struct m0_be_allocator *a, const struct be_alloc_chunk *c)
 
static void be_alloc_chunk_init (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct m0_be_tx *tx, struct be_alloc_chunk *c, m0_bcount_t size, bool free)
 
static void be_alloc_chunk_del_fini (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct m0_be_tx *tx, struct be_alloc_chunk *c)
 
static struct be_alloc_chunkbe_alloc_chunk_addr (void *ptr)
 
static struct be_alloc_chunkbe_alloc_chunk_prev (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct be_alloc_chunk *c)
 
static struct be_alloc_chunkbe_alloc_chunk_next (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct be_alloc_chunk *c)
 
static void be_alloc_chunk_mark_free (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct m0_be_tx *tx, struct be_alloc_chunk *c)
 
static uintptr_t be_alloc_chunk_after (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct be_alloc_chunk *c)
 
static struct be_alloc_chunkbe_alloc_chunk_add_after (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct m0_be_tx *tx, struct be_alloc_chunk *c, uintptr_t offset, m0_bcount_t size_total, bool free)
 
static void be_alloc_chunk_resize (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct m0_be_tx *tx, struct be_alloc_chunk *c, m0_bcount_t new_size)
 
static struct be_alloc_chunkbe_alloc_chunk_tryadd_free_after (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct m0_be_tx *tx, struct be_alloc_chunk *c, uintptr_t offset, m0_bcount_t size_total)
 
static struct be_alloc_chunkbe_alloc_chunk_split (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct m0_be_tx *tx, struct be_alloc_chunk *c, uintptr_t start_new, m0_bcount_t size)
 
static struct be_alloc_chunkbe_alloc_chunk_trysplit (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct m0_be_tx *tx, struct be_alloc_chunk *c, m0_bcount_t size, unsigned shift)
 
static bool be_alloc_chunk_trymerge (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct m0_be_tx *tx, struct be_alloc_chunk *x, struct be_alloc_chunk *y)
 
M0_INTERNAL int m0_be_allocator_init (struct m0_be_allocator *a, struct m0_be_seg *seg)
 
M0_INTERNAL void m0_be_allocator_fini (struct m0_be_allocator *a)
 
M0_INTERNAL bool m0_be_allocator__invariant (struct m0_be_allocator *a)
 
static int be_allocator_header_create (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct m0_be_tx *tx, uintptr_t offset, m0_bcount_t size)
 
static void be_allocator_header_destroy (struct m0_be_allocator *a, enum m0_be_alloc_zone_type ztype, struct m0_be_tx *tx)
 
M0_INTERNAL int m0_be_allocator_create (struct m0_be_allocator *a, struct m0_be_tx *tx, uint32_t *zone_percent, uint32_t zones_nr)
 
M0_INTERNAL void m0_be_allocator_destroy (struct m0_be_allocator *a, struct m0_be_tx *tx)
 
M0_INTERNAL void m0_be_allocator_credit (struct m0_be_allocator *a, enum m0_be_allocator_op optype, m0_bcount_t size, unsigned shift, struct m0_be_tx_credit *accum)
 
M0_INTERNAL void m0_be_alloc_aligned (struct m0_be_allocator *a, struct m0_be_tx *tx, struct m0_be_op *op, void **ptr, m0_bcount_t size, unsigned shift, uint64_t zonemask)
 
M0_INTERNAL void m0_be_alloc (struct m0_be_allocator *a, struct m0_be_tx *tx, struct m0_be_op *op, void **ptr, m0_bcount_t size)
 
M0_INTERNAL void m0_be_free_aligned (struct m0_be_allocator *a, struct m0_be_tx *tx, struct m0_be_op *op, void *ptr)
 
M0_INTERNAL void m0_be_free (struct m0_be_allocator *a, struct m0_be_tx *tx, struct m0_be_op *op, void *ptr)
 
M0_INTERNAL void m0_be_alloc_stats (struct m0_be_allocator *a, struct m0_be_allocator_stats *out)
 
M0_INTERNAL void m0_be_alloc_stats_credit (struct m0_be_allocator *a, struct m0_be_tx_credit *accum)
 
M0_INTERNAL void m0_be_alloc_stats_capture (struct m0_be_allocator *a, struct m0_be_tx *tx)
 

Macro Definition Documentation

◆ M0_TRACE_SUBSYSTEM

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_BE

Definition at line 23 of file alloc.c.

◆ P_ACS

#define P_ACS (   acs)    (acs)->bcs_nr, (acs)->bcs_size

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
BE_ALLOC_HEADER_SHIFT 

Alignment for m0_be_allocator_header inside segment.

BE_ALLOC_ZONE_SIZE_SHIFT 

Alignment for zone's size.

Definition at line 210 of file alloc.c.

Function Documentation

◆ be_alloc_chunk_add_after()

static struct be_alloc_chunk* be_alloc_chunk_add_after ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct m0_be_tx tx,
struct be_alloc_chunk c,
uintptr_t  offset,
m0_bcount_t  size_total,
bool  free 
)
static

try to add a chunk after the c

Definition at line 540 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_addr()

static struct be_alloc_chunk* be_alloc_chunk_addr ( void *  ptr)
static

Definition at line 472 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_after()

static uintptr_t be_alloc_chunk_after ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct be_alloc_chunk c 
)
static

Definition at line 526 of file alloc.c.

Here is the caller graph for this function:

◆ be_alloc_chunk_capture()

static void be_alloc_chunk_capture ( struct m0_be_allocator a,
struct m0_be_tx tx,
struct be_alloc_chunk c 
)
static

Definition at line 352 of file alloc.c.

Here is the caller graph for this function:

◆ be_alloc_chunk_del_fini()

static void be_alloc_chunk_del_fini ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct m0_be_tx tx,
struct be_alloc_chunk c 
)
static

Definition at line 456 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_init()

static void be_alloc_chunk_init ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct m0_be_tx tx,
struct be_alloc_chunk c,
m0_bcount_t  size,
bool  free 
)
static

Definition at line 433 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_invariant()

static bool be_alloc_chunk_invariant ( struct m0_be_allocator a,
const struct be_alloc_chunk c 
)
static

Definition at line 406 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_is_in()

static bool be_alloc_chunk_is_in ( const struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
const struct be_alloc_chunk c 
)
static

Definition at line 386 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_is_not_overlapping()

static bool be_alloc_chunk_is_not_overlapping ( const struct be_alloc_chunk a,
const struct be_alloc_chunk b 
)
static

Definition at line 393 of file alloc.c.

Here is the caller graph for this function:

◆ be_alloc_chunk_mark_free()

static void be_alloc_chunk_mark_free ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct m0_be_tx tx,
struct be_alloc_chunk c 
)
static

Definition at line 507 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_next()

static struct be_alloc_chunk* be_alloc_chunk_next ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct be_alloc_chunk c 
)
static

Definition at line 493 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_prev()

static struct be_alloc_chunk* be_alloc_chunk_prev ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct be_alloc_chunk c 
)
static

Definition at line 478 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_resize()

static void be_alloc_chunk_resize ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct m0_be_tx tx,
struct be_alloc_chunk c,
m0_bcount_t  new_size 
)
static

Definition at line 574 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_split()

static struct be_alloc_chunk* be_alloc_chunk_split ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct m0_be_tx tx,
struct be_alloc_chunk c,
uintptr_t  start_new,
m0_bcount_t  size 
)
static

Definition at line 614 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_tryadd_free_after()

static struct be_alloc_chunk* be_alloc_chunk_tryadd_free_after ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct m0_be_tx tx,
struct be_alloc_chunk c,
uintptr_t  offset,
m0_bcount_t  size_total 
)
static

Definition at line 593 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_trymerge()

static bool be_alloc_chunk_trymerge ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct m0_be_tx tx,
struct be_alloc_chunk x,
struct be_alloc_chunk y 
)
static

Definition at line 693 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_chunk_trysplit()

static struct be_alloc_chunk* be_alloc_chunk_trysplit ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct m0_be_tx tx,
struct be_alloc_chunk c,
m0_bcount_t  size,
unsigned  shift 
)
static

Definition at line 664 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_free_flag_capture()

static void be_alloc_free_flag_capture ( const struct m0_be_allocator a,
struct m0_be_tx tx,
struct be_alloc_chunk c 
)
static

Definition at line 360 of file alloc.c.

Here is the caller graph for this function:

◆ be_alloc_mem_is_in()

static bool be_alloc_mem_is_in ( const struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
const void *  ptr,
m0_bcount_t  size 
)
static

Definition at line 376 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_alloc_size_capture()

static void be_alloc_size_capture ( const struct m0_be_allocator a,
struct m0_be_tx tx,
struct be_alloc_chunk c 
)
static

Definition at line 368 of file alloc.c.

Here is the caller graph for this function:

◆ be_alloc_zone_name()

static const char* be_alloc_zone_name ( enum m0_be_alloc_zone_type  type)
static

Definition at line 222 of file alloc.c.

Here is the caller graph for this function:

◆ be_allocator_call_stat_init()

static void be_allocator_call_stat_init ( struct m0_be_allocator_call_stat cstat)
static

Definition at line 235 of file alloc.c.

Here is the caller graph for this function:

◆ be_allocator_call_stat_update()

static void be_allocator_call_stat_update ( struct m0_be_allocator_call_stat cstat,
unsigned long  nr,
m0_bcount_t  size 
)
static

Definition at line 268 of file alloc.c.

Here is the caller graph for this function:

◆ be_allocator_call_stats_init()

static void be_allocator_call_stats_init ( struct m0_be_allocator_call_stats cs)
static

Definition at line 243 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_allocator_call_stats_print()

static void be_allocator_call_stats_print ( struct m0_be_allocator_call_stats cs,
const char *  descr 
)
static

Definition at line 294 of file alloc.c.

Here is the caller graph for this function:

◆ be_allocator_call_stats_update()

static void be_allocator_call_stats_update ( struct m0_be_allocator_call_stats cs,
m0_bcount_t  size,
bool  alloc,
bool  failed 
)
static

Definition at line 277 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_allocator_header_create()

static int be_allocator_header_create ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct m0_be_tx tx,
uintptr_t  offset,
m0_bcount_t  size 
)
static

Definition at line 768 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_allocator_header_destroy()

static void be_allocator_header_destroy ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct m0_be_tx tx 
)
static

Definition at line 800 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_allocator_stats_capture()

static void be_allocator_stats_capture ( struct m0_be_allocator a,
enum m0_be_alloc_zone_type  ztype,
struct m0_be_tx tx 
)
static

Definition at line 342 of file alloc.c.

Here is the caller graph for this function:

◆ be_allocator_stats_init()

static void be_allocator_stats_init ( struct m0_be_allocator_stats stats,
struct m0_be_allocator_header h 
)
static

Definition at line 250 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_allocator_stats_print()

static void be_allocator_stats_print ( struct m0_be_allocator_stats stats)
static

Definition at line 305 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ be_allocator_stats_update()

static void be_allocator_stats_update ( struct m0_be_allocator_stats stats,
m0_bcount_t  size,
bool  alloc,
bool  failed 
)
static

Definition at line 318 of file alloc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ M0_BE_LIST_DEFINE()

M0_BE_LIST_DEFINE ( chunks_all  ,
static  ,
struct be_alloc_chunk   
)

◆ M0_BE_LIST_DESCR_DEFINE()

M0_BE_LIST_DESCR_DEFINE ( chunks_all  ,
"list of all chunks in m0_be_allocator ,
static  ,
struct be_alloc_chunk  ,
bac_linkage  ,
bac_magic  ,
M0_BE_ALLOC_ALL_LINK_MAGIC  ,
M0_BE_ALLOC_ALL_MAGIC   
)