NVMLib  very early alpha
A library to optimally use a Hybrid RAM setup.
malloc.h File Reference
#include "globals.h"
#include "pool.h"
#include <stdint.h>
#include <libiberty/splay-tree.h>
#include <stdarg.h>
Include dependency graph for malloc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MEMoid_st
 The struct that stores the memptr for the object. More...
 
struct  addr2memoid_key
 The structure used in spaly_tree which used for getting MEMoid from the memory address. More...
 

Macros

#define __FILENAME__   (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
 
#define NUMARGS(...)   (sizeof((int[]){0, ##__VA_ARGS__})/sizeof(int)-1)
 
#define memalloc(size, ...)   _memalloc(size, __FILENAME__, __func__, __LINE__, NUMARGS(__VA_ARGS__), ##__VA_ARGS__)
 The user API for requesting allocation of object. More...
 
#define KEY_FIRST(key)   (_key_get_first(key))
 
#define KEY_LAST(key)   (_key_get_last(key))
 
#define memfree(o)   _memfree((o).oidkey)
 The user API to free the memory space allocated. More...
 

Typedefs

typedef struct MEMoid_st MEMoid
 The struct that stores the memptr for the object. More...
 
typedef uint64_t MEMoidKey
 The key of the HashTable that contains <MEMoidKey, MEMoid>. More...
 
typedef struct addr2memoid_key addr2memoid_key
 The structure used in spaly_tree which used for getting MEMoid from the memory address. More...
 

Enumerations

enum  splay_comp { cmp_node, cmp_addr }
 

Functions

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...
 
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 obj)
 The function to return the actual memptr for a given MEMoid object. More...
 
void * _key_get_last (MEMoidKey key)
 
void * _key_get_first (MEMoidKey key)
 
void _memfree (MEMoidKey oidkey)
 The fucntion to free the allocated memory location. More...
 
void init_splay ()
 

Variables

splay_tree addr2MemOID_read
 
splay_tree addr2MemOID_write
 
static const MEMoid MEMOID_NULL = { 0, 0, 0 }
 Just a dummy obj. More...
 

Macro Definition Documentation

◆ __FILENAME__

#define __FILENAME__   (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)

Definition at line 56 of file malloc.h.

◆ KEY_FIRST

#define KEY_FIRST (   key)    (_key_get_first(key))

Definition at line 89 of file malloc.h.

◆ KEY_LAST

#define KEY_LAST (   key)    (_key_get_last(key))

Definition at line 90 of file malloc.h.

◆ memalloc

#define memalloc (   size,
  ... 
)    _memalloc(size, __FILENAME__, __func__, __LINE__, NUMARGS(__VA_ARGS__), ##__VA_ARGS__)

The user API for requesting allocation of object.

Example

LIB_TOID(int) array = LIB_TOID(int)memalloc(10 * sizeof(int)); // allocated an integer array of size 10.
Parameters
sizethe size of memory that needs to be allocated.
which_ram(optional): the RAM in which the user wants to place the object
Returns
MEMoidKey that the user needs to typecast into LIB_TOID.
Note
The API interface and functionality is almost exactly similar to that of malloc().
See also
_memalloc() __memalloc()

Definition at line 79 of file malloc.h.

◆ memfree

#define memfree (   o)    _memfree((o).oidkey)

The user API to free the memory space allocated.

Example

memfree(array); // freed the array that had bee allocated
Parameters
LIB_TOIDobject: the object that was return by memalloc() during allocation.
Note
The API interface and functionality is almost exactly similar to that of free().
See also
_memfree() nvm_free()

Definition at line 109 of file malloc.h.

◆ NUMARGS

#define NUMARGS (   ...)    (sizeof((int[]){0, ##__VA_ARGS__})/sizeof(int)-1)

Definition at line 57 of file malloc.h.

Typedef Documentation

◆ addr2memoid_key

The structure used in spaly_tree which used for getting MEMoid from the memory address.

◆ MEMoid

typedef struct MEMoid_st MEMoid

The struct that stores the memptr for the object.

◆ MEMoidKey

The key of the HashTable that contains <MEMoidKey, MEMoid>.

This is the library level representation of pointer to the object.

Definition at line 49 of file malloc.h.

Enumeration Type Documentation

◆ splay_comp

enum splay_comp
Enumerator
cmp_node 
cmp_addr 

Definition at line 110 of file malloc.h.

Function Documentation

◆ _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:

◆ 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:

◆ 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:

Variable Documentation

◆ addr2MemOID_read

splay_tree addr2MemOID_read

Definition at line 25 of file malloc.h.

◆ addr2MemOID_write

splay_tree addr2MemOID_write

Definition at line 26 of file malloc.h.

◆ MEMOID_NULL

const MEMoid MEMOID_NULL = { 0, 0, 0 }
static

Just a dummy obj.

Definition at line 52 of file malloc.h.

LIB_TOID
#define LIB_TOID(t)
The MACRO used by user while allocating memory.
Definition: types.h:43
memalloc
#define memalloc(size,...)
The user API for requesting allocation of object.
Definition: malloc.h:78
memfree
#define memfree(o)
The user API to free the memory space allocated.
Definition: malloc.h:108