NVMLib  very early alpha
A library to optimally use a Hybrid RAM setup.
malloc.c File Reference
#include "malloc.h"
#include "types.h"
#include "algo.h"
#include "math.h"
#include <stdint.h>
#include <libiberty/splay-tree.h>
#include "object_maintainance.h"
#include <uv.h>
Include dependency graph for malloc.c:

Go to the source code of this file.

Macros

#define MEMOID_FIRST(m)   (get_pool_from_poolid(m.pool_id) + m.offset)
 
#define MEMOID_LAST(m)   (get_pool_from_poolid(m.pool_id) + m.offset + m.size)
 

Functions

uint64_t free_slot_size (TOID(struct pool_free_slot) slot)
 
uint64_t allot_first_free_offset_pool (uint64_t pool_id, size_t size)
 Allocates first free memory chunk of the given size in the given pool specified by pool_id. More...
 
MEMoid allot_first_free_offset (size_t size)
 Allocates the first free memory chunk of the given size. More...
 
MEMoid __memalloc (size_t size, int which_ram)
 Allocates the memory requested and returns a MEMoid. More...
 
uint64_t string_hash (const char *str)
 
MEMoidKey _memalloc (size_t size, const char *file, const char *func, const int line, int num_args,...)
 Allocates the memory requested and returns a MEMoidKey. More...
 
void * get_memobj_direct (MEMoid oid)
 The function to return the actual memptr for a given MEMoid object. More...
 
void _memfree (MEMoidKey oidkey)
 The fucntion to free the allocated memory location. More...
 
void * _key_get_first (MEMoidKey key)
 
void * _key_get_last (MEMoidKey key)
 
int addr2memoid_cmp (splay_tree_key key1, splay_tree_key key2)
 The compare function used by the splay_tree. More...
 
void addr2memoid_del (splay_tree_key key)
 
void init_splay ()
 

Variables

splay_tree addr2MemOID_read
 
splay_tree addr2MemOID_write
 

Macro Definition Documentation

◆ MEMOID_FIRST

#define MEMOID_FIRST (   m)    (get_pool_from_poolid(m.pool_id) + m.offset)

Definition at line 382 of file malloc.c.

◆ MEMOID_LAST

#define MEMOID_LAST (   m)    (get_pool_from_poolid(m.pool_id) + m.offset + m.size)

Definition at line 383 of file malloc.c.

Function Documentation

◆ __memalloc()

MEMoid __memalloc ( size_t  size,
int  which_ram 
)

Allocates the memory requested and returns a MEMoid.

Parameters
sizethe size of the object that needs to be allocated.
which_ramthe RAM in which the allocation must happen.
Returns
The MEMoid object after allocation is completed.
Note
This is an internal function. It is not exposed to other files.
See also
_memalloc() memalloc()

Definition at line 138 of file malloc.c.

Here is the call graph for this function:

◆ _key_get_first()

void* _key_get_first ( MEMoidKey  key)

Definition at line 384 of file malloc.c.

Here is the call graph for this function:

◆ _key_get_last()

void* _key_get_last ( MEMoidKey  key)

Definition at line 392 of file malloc.c.

Here is the call graph for this function:

◆ _memalloc()

MEMoidKey _memalloc ( size_t  size,
const char *  file,
const char *  func,
const int  line,
int  num_args,
  ... 
)

Allocates the memory requested and returns a MEMoidKey.

Parameters
sizethe size of the object that needs to be allocated.
filethe file where the requested object is defined.
functhe function where the requested object is defined.
linethe line number where the requested object is defined.
which_ram(optional): the RAM in which the allocation must happen.
Returns
The MEMoidkey object after allocation is completed.
See also
__memalloc() memalloc()
Attention
This function is responsible for checking if the requested object is present in NVRAM from the previous run (to ensure crash consistency).
It has to add the created objects into object_maintainance table, type_table and splay_tree.

Definition at line 202 of file malloc.c.

Here is the call graph for this function:

◆ _memfree()

void _memfree ( MEMoidKey  oidkey)

The fucntion to free the allocated memory location.

Parameters
oidkeythe MEMoidKey of the object whose memory needs to be freed.
Returns
Nothing.
Note
This function doesn't call nvm_free() or free() by itself, instead it enques the deletion task for the deletion thread to take care of it.

Definition at line 358 of file malloc.c.

Here is the call graph for this function:

◆ addr2memoid_cmp()

int addr2memoid_cmp ( splay_tree_key  key1,
splay_tree_key  key2 
)

The compare function used by the splay_tree.

Parameters
key1the splay_tree_key of one of the elements that needs to be compared.
key2the splay_tree_key of the other element that needs to be compared.
Returns
0: if both are equivalent.
the direction in which the search should continue, if the two elements are not equivalent.

Definition at line 409 of file malloc.c.

◆ addr2memoid_del()

void addr2memoid_del ( splay_tree_key  key)

Definition at line 436 of file malloc.c.

◆ allot_first_free_offset()

MEMoid allot_first_free_offset ( size_t  size)

Allocates the first free memory chunk of the given size.

Parameters
sizethe size of memory that needs to be allocated.
Returns
MEMoid object.
Attention
This function is responsible to create a new pool iff any of the previous pools are insufficient for the asked size.
See also
allot_first_free_offset_pool()

Definition at line 104 of file malloc.c.

Here is the call graph for this function:

◆ allot_first_free_offset_pool()

uint64_t allot_first_free_offset_pool ( uint64_t  pool_id,
size_t  size 
)

Allocates first free memory chunk of the given size in the given pool specified by pool_id.

Parameters
pool_idthe ID of the pool where the allocation needs to be made.
sizethe size of memory that needs to be allocated.
Returns
The offset of the memory chuck allocated. This offset is from the first address of the pool.
Note
This is an internal function. It is not exposed to other files.
See also
allot_first_free_offset()

Definition at line 48 of file malloc.c.

Here is the call graph for this function:

◆ free_slot_size()

uint64_t free_slot_size ( TOID(struct pool_free_slot slot)

Definition at line 32 of file malloc.c.

◆ get_memobj_direct()

void* get_memobj_direct ( MEMoid  oid)

The function to return the actual memptr for a given MEMoid object.

Parameters
oidthe MEMoid object.
Returns
The memory address represented by oid.

Definition at line 316 of file malloc.c.

Here is the call graph for this function:

◆ init_splay()

void init_splay ( )

Definition at line 442 of file malloc.c.

Here is the call graph for this function:

◆ string_hash()

uint64_t string_hash ( const char *  str)

Definition at line 178 of file malloc.c.

Here is the call graph for this function:

Variable Documentation

◆ addr2MemOID_read

splay_tree addr2MemOID_read

Definition at line 29 of file malloc.c.

◆ addr2MemOID_write

splay_tree addr2MemOID_write

Definition at line 30 of file malloc.c.