SimGrid  3.16
Versatile Simulation of Distributed Systems
mmprivate.h File Reference
#include <xbt/base.h>
#include <xbt/misc.h>
#include "src/internal_config.h"
#include "xbt/xbt_os_thread.h"
#include "xbt/mmalloc.h"
#include "xbt/ex.h"
#include "xbt/dynar.h"
#include "xbt/swag.h"
#include <pthread.h>
#include <stdint.h>

Classes

struct  list
 
struct  mstats
 
struct  malloc_info
 
struct  mdesc
 Descriptor of a mmalloc area. More...
 

Macros

#define CHAR_BIT   8
 
#define MMALLOC_MAGIC   "mmalloc" /* Mapped file magic number */
 
#define MMALLOC_MAGIC_SIZE   8 /* Size of magic number buf */
 
#define MMALLOC_VERSION   2 /* Current mmalloc version */
 
#define INT_BIT   (CHAR_BIT * sizeof(int))
 
#define BLOCKLOG   (INT_BIT > 16 ? 12 : 9)
 
#define BLOCKSIZE   ((unsigned int) 1 << BLOCKLOG)
 
#define BLOCKIFY(SIZE)   (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE)
 
#define SMALLEST_POSSIBLE_MALLOC   (16*sizeof(struct list))
 
#define MAX_FRAGMENT_PER_BLOCK   (BLOCKSIZE / SMALLEST_POSSIBLE_MALLOC)
 
#define ADDR2UINT(addr)   ((uintptr_t) ((char*) (addr) - (char*) NULL))
 
#define RESIDUAL(addr, bsize)   ((uintptr_t) (ADDR2UINT (addr) % (bsize)))
 
#define HEAP   (INT_BIT > 16 ? 4194304 : 65536)
 
#define FINAL_FREE_BLOCKS   8
 
#define MALLOC_SEARCH_START   mdp -> heapindex
 
#define BLOCK(A)   (((char*) (A) - (char*) mdp -> heapbase) / BLOCKSIZE + 1)
 
#define ADDRESS(B)   ((void*) (((ADDR2UINT(B)) - 1) * BLOCKSIZE + (char*) mdp -> heapbase))
 
#define MMALLOC_TYPE_HEAPINFO   (-2)
 
#define MMALLOC_TYPE_FREE   (-1)
 
#define MMALLOC_TYPE_UNFRAGMENTED   0
 
#define MMALLOC_DEVZERO   (1 << 0) /* Have mapped to /dev/zero */
 
#define MMALLOC_ANONYMOUS   (1 << 1) /* Use anonymous mapping */
 
#define MMALLOC_INITIALIZED   (1 << 2) /* Initialized mmalloc */
 
#define LOCK(mdp)   pthread_mutex_lock(&mdp->mutex)
 Thread-safety (if the mutex is already created) More...
 
#define UNLOCK(mdp)   pthread_mutex_unlock(&mdp->mutex)
 

Functions

void__mmalloc_remap_core (xbt_mheap_t mdp)
 
voidmmorecore (struct mdesc *mdp, ssize_t size)
 Add memoty to this heap. More...
 
static void mmalloc_paranoia (struct mdesc *mdp)
 
static int mmalloc_get_increment (malloc_info *heapinfo)
 
void mmcheck (xbt_mheap_t heap)
 
int malloc_use_mmalloc (void)
 
int mmalloc_exec_using_mm (int argc, const char **argv)
 
void mmalloc_ensure_using_mm (int argc, const char **argv)
 
size_t mmalloc_get_bytes_used_remote (size_t heaplimit, const malloc_info *heapinfo)
 

Variables

struct mdesc__mmalloc_default_mdp
 

Macro Definition Documentation

◆ CHAR_BIT

#define CHAR_BIT   8

◆ MMALLOC_MAGIC

#define MMALLOC_MAGIC   "mmalloc" /* Mapped file magic number */

◆ MMALLOC_MAGIC_SIZE

#define MMALLOC_MAGIC_SIZE   8 /* Size of magic number buf */

◆ MMALLOC_VERSION

#define MMALLOC_VERSION   2 /* Current mmalloc version */

◆ INT_BIT

#define INT_BIT   (CHAR_BIT * sizeof(int))

◆ BLOCKLOG

#define BLOCKLOG   (INT_BIT > 16 ? 12 : 9)

◆ BLOCKSIZE

#define BLOCKSIZE   ((unsigned int) 1 << BLOCKLOG)

◆ BLOCKIFY

#define BLOCKIFY (   SIZE)    (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE)

◆ SMALLEST_POSSIBLE_MALLOC

#define SMALLEST_POSSIBLE_MALLOC   (16*sizeof(struct list))

◆ MAX_FRAGMENT_PER_BLOCK

#define MAX_FRAGMENT_PER_BLOCK   (BLOCKSIZE / SMALLEST_POSSIBLE_MALLOC)

◆ ADDR2UINT

#define ADDR2UINT (   addr)    ((uintptr_t) ((char*) (addr) - (char*) NULL))

◆ RESIDUAL

#define RESIDUAL (   addr,
  bsize 
)    ((uintptr_t) (ADDR2UINT (addr) % (bsize)))

◆ HEAP

#define HEAP   (INT_BIT > 16 ? 4194304 : 65536)

◆ FINAL_FREE_BLOCKS

#define FINAL_FREE_BLOCKS   8

◆ MALLOC_SEARCH_START

#define MALLOC_SEARCH_START   mdp -> heapindex

◆ BLOCK

#define BLOCK (   A)    (((char*) (A) - (char*) mdp -> heapbase) / BLOCKSIZE + 1)

◆ ADDRESS

#define ADDRESS (   B)    ((void*) (((ADDR2UINT(B)) - 1) * BLOCKSIZE + (char*) mdp -> heapbase))

◆ MMALLOC_TYPE_HEAPINFO

#define MMALLOC_TYPE_HEAPINFO   (-2)

◆ MMALLOC_TYPE_FREE

#define MMALLOC_TYPE_FREE   (-1)

◆ MMALLOC_TYPE_UNFRAGMENTED

#define MMALLOC_TYPE_UNFRAGMENTED   0

◆ MMALLOC_DEVZERO

#define MMALLOC_DEVZERO   (1 << 0) /* Have mapped to /dev/zero */

◆ MMALLOC_ANONYMOUS

#define MMALLOC_ANONYMOUS   (1 << 1) /* Use anonymous mapping */

◆ MMALLOC_INITIALIZED

#define MMALLOC_INITIALIZED   (1 << 2) /* Initialized mmalloc */

◆ LOCK

#define LOCK (   mdp)    pthread_mutex_lock(&mdp->mutex)

Thread-safety (if the mutex is already created)

This is mandatory in the case where the user runs a parallel simulation in a model-checking enabled tree. Without this protection, our malloc implementation will not like multi-threading AT ALL.

◆ UNLOCK

#define UNLOCK (   mdp)    pthread_mutex_unlock(&mdp->mutex)

Function Documentation

◆ __mmalloc_remap_core()

void* __mmalloc_remap_core ( xbt_mheap_t  mdp)

◆ mmorecore()

void* mmorecore ( struct mdesc mdp,
ssize_t  size 
)

Add memoty to this heap.

Get core for the memory region specified by MDP, using SIZE as the amount to either add to or subtract from the existing region. Works like sbrk(), but using mmap().

It never returns NULL. Instead, it dies verbosely on errors.

Parameters
mdpThe heap
sizeBytes to allocate for this heap (or <0 to free memory from this heap)

◆ mmalloc_paranoia()

static void mmalloc_paranoia ( struct mdesc mdp)
inlinestatic

◆ mmalloc_get_increment()

static int mmalloc_get_increment ( malloc_info heapinfo)
inlinestatic

◆ mmcheck()

void mmcheck ( xbt_mheap_t  heap)

◆ malloc_use_mmalloc()

int malloc_use_mmalloc ( void  )

◆ mmalloc_exec_using_mm()

int mmalloc_exec_using_mm ( int  argc,
const char **  argv 
)

◆ mmalloc_ensure_using_mm()

void mmalloc_ensure_using_mm ( int  argc,
const char **  argv 
)

◆ mmalloc_get_bytes_used_remote()

size_t mmalloc_get_bytes_used_remote ( size_t  heaplimit,
const malloc_info heapinfo 
)

Variable Documentation

◆ __mmalloc_default_mdp

struct mdesc* __mmalloc_default_mdp