Arax -8d09c51940345c86062e8ef2427c705ae66e5926
A Runtime Framework for Decoupling Applications from Heterogeneous Accelerators
Loading...
Searching...
No Matches
alloc.c File Reference
#include "arch/alloc.h"
#include "utils/timer.h"
#include <string.h>
#include <malloc.h>
+ Include dependency graph for dlmalloc/alloc.c:

Go to the source code of this file.

Data Structures

struct  arch_alloc_inner_s
 

Macros

#define MALLOC_INSPECT_ALL   1
 
#define ONLY_MSPACES   1
 
#define USE_SPIN_LOCKS   1
 
#define MSPACES   1
 
#define HAVE_MMAP   1
 
#define BIT_ALLOCATOR_BLOCK   (4096ul)
 
#define BIT_ALLOCATOR_BLOCK_MASK   (BIT_ALLOCATOR_BLOCK - 1)
 
#define BITS_PER_PAGE   (BIT_ALLOCATOR_BLOCK * 8ul)
 

Functions

int arch_alloc_init_once (arch_alloc_s *_alloc, size_t size)
 
void arch_alloc_init_always (arch_alloc_s *alloc)
 
void * arch_alloc_allocate (arch_alloc_s *_alloc, size_t size)
 
void _arch_alloc_free (arch_alloc_s *_alloc, void *mem)
 
void arch_alloc_exit (arch_alloc_s *_alloc)
 
static void _arch_alloc_mspace_mallinfo (mspace *mspace, arch_alloc_stats_s *stats)
 
arch_alloc_stats_s arch_alloc_stats (arch_alloc_s *_alloc)
 
void arch_alloc_inspect (arch_alloc_s *_alloc, void(*inspector)(void *start, void *end, size_t size, void *arg), void *arg)
 
void * arax_mmap (size_t s)
 
void * arax_ummap (void *a, size_t s)
 
arch_alloc_sarch_alloc_create_sub_alloc (arch_alloc_s *parent)
 
utils_bitmap_sarch_alloc_get_bitmap ()
 

Variables

static struct arch_alloc_inner_sglobal_alloc
 

Macro Definition Documentation

◆ BIT_ALLOCATOR_BLOCK

#define BIT_ALLOCATOR_BLOCK   (4096ul)

Definition at line 20 of file dlmalloc/alloc.c.

Referenced by arax_mmap(), arax_ummap(), and arch_alloc_init_once().

◆ BIT_ALLOCATOR_BLOCK_MASK

#define BIT_ALLOCATOR_BLOCK_MASK   (BIT_ALLOCATOR_BLOCK - 1)

Definition at line 21 of file dlmalloc/alloc.c.

Referenced by arax_mmap(), and arch_alloc_init_once().

◆ BITS_PER_PAGE

#define BITS_PER_PAGE   (BIT_ALLOCATOR_BLOCK * 8ul)

Definition at line 22 of file dlmalloc/alloc.c.

Referenced by arch_alloc_init_once().

◆ HAVE_MMAP

#define HAVE_MMAP   1

Definition at line 9 of file dlmalloc/alloc.c.

Referenced by sys_alloc(), and sys_trim().

◆ MALLOC_INSPECT_ALL

#define MALLOC_INSPECT_ALL   1

Definition at line 4 of file dlmalloc/alloc.c.

◆ MSPACES

#define MSPACES   1

Definition at line 8 of file dlmalloc/alloc.c.

◆ ONLY_MSPACES

#define ONLY_MSPACES   1

Definition at line 6 of file dlmalloc/alloc.c.

◆ USE_SPIN_LOCKS

#define USE_SPIN_LOCKS   1

Definition at line 7 of file dlmalloc/alloc.c.

Function Documentation

◆ _arch_alloc_free()

void _arch_alloc_free ( arch_alloc_s * _alloc,
void * mem )

Definition at line 83 of file dlmalloc/alloc.c.

◆ _arch_alloc_mspace_mallinfo()

static void _arch_alloc_mspace_mallinfo ( mspace * mspace,
arch_alloc_stats_s * stats )
static

Definition at line 109 of file dlmalloc/alloc.c.

References mallinfo::arena, arch_alloc_stats_s::total_bytes, mallinfo::uordblks, and arch_alloc_stats_s::used_bytes.

Referenced by arch_alloc_stats().

+ Here is the caller graph for this function:

◆ arax_mmap()

void * arax_mmap ( size_t s)

Allocate enough pages(4096 bytes) to hold s bytes.

Parameters
sNumber of bytes requested (has to be multiple of BIT_ALLOCATOR_BLOCK)
Returns
Page alligned pointer to memory

Definition at line 143 of file dlmalloc/alloc.c.

◆ arax_ummap()

void * arax_ummap ( void * a,
size_t s )

Release the pages starting from a and ending after bytes

Parameters
aPointer returned from a call of arax_mmap().
sNumber of bytes to be freed (has to be multiple of BIT_ALLOCATOR_BLOCK)
Returns
NULL on success

Definition at line 154 of file dlmalloc/alloc.c.

◆ arch_alloc_allocate()

void * arch_alloc_allocate ( arch_alloc_s * alloc,
size_t size )

Allocate contiguous memory from the alloc arch_alloc_s instance.

Parameters
allocAn initialized arch_alloc_s instance.
sizeThe size of the allocation.
Returns
Pointer to the beginning of size usable bytes, or NULL on failure.

Definition at line 62 of file dlmalloc/alloc.c.

Referenced by arch_alloc_create_sub_alloc().

+ Here is the caller graph for this function:

◆ arch_alloc_create_sub_alloc()

arch_alloc_s * arch_alloc_create_sub_alloc ( arch_alloc_s * parent)

Create a sub-allocator.

This allocator user the same global bitmap for requesting bulk allocations, but maintains separate metadata from the 'global' allocator.

Use arch_alloc_free(), arch_alloc_allocate() to alloc/free memory.

Returned allocator should be eventually released by calling arch_alloc_exit()

Parameters
parentallocator
Returns
New arch_alloc_s instance.

Definition at line 163 of file dlmalloc/alloc.c.

◆ arch_alloc_exit()

void arch_alloc_exit ( arch_alloc_s * alloc)

Release any resources claimed by the alloc arch_alloc_s instance.

Note
The shared memory segment (shm in arch_alloc_init) must be freed by the user.

Definition at line 102 of file dlmalloc/alloc.c.

◆ arch_alloc_get_bitmap()

utils_bitmap_s * arch_alloc_get_bitmap ( )

Definition at line 172 of file dlmalloc/alloc.c.

◆ arch_alloc_init_always()

void arch_alloc_init_always ( arch_alloc_s * alloc)

Perform necessary initialization for every arax application.

Note
This has to be called on new processes, that have not called arch_alloc_init_once
Parameters
alloc

Definition at line 57 of file dlmalloc/alloc.c.

◆ arch_alloc_init_once()

int arch_alloc_init_once ( arch_alloc_s * alloc,
size_t size )

Initialize a arch_alloc_s instance on a mapped shared memory segment.

Note
This only has to be called by the first process, to initialize global state
Parameters
allocPointer to be filled with initialized instance.
sizeThe size of the shared memory segment in bytes.
Returns
0 on success.

Definition at line 27 of file dlmalloc/alloc.c.

◆ arch_alloc_inspect()

void arch_alloc_inspect ( arch_alloc_s * _alloc,
void(* inspector )(void *start, void *end, size_t size, void *arg),
void * arg )

Definition at line 135 of file dlmalloc/alloc.c.

◆ arch_alloc_stats()

arch_alloc_stats_s arch_alloc_stats ( arch_alloc_s * _alloc)

Definition at line 117 of file dlmalloc/alloc.c.

Variable Documentation

◆ global_alloc

struct arch_alloc_inner_s* global_alloc
static