SimGrid
3.18
Versatile Simulation of Distributed Systems
|
#include <xbt/base.h>
#include <xbt/misc.h>
#include "swag.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 <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) |
void * | mmorecore (struct mdesc *mdp, ssize_t size) |
Add memoty to this heap. More... | |
static int | mmalloc_get_increment (malloc_info *heapinfo) |
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 |
#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 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 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)
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.
#define UNLOCK | ( | mdp | ) | pthread_mutex_unlock(&mdp->mutex) |
void* __mmalloc_remap_core | ( | xbt_mheap_t | mdp | ) |
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.
mdp | The heap |
size | Bytes to allocate for this heap (or <0 to free memory from this heap) |
|
inlinestatic |
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 | ||
) |
struct mdesc* __mmalloc_default_mdp |