#include "nedmalloc.h"#include "malloc.c.h"

Go to the source code of this file.
Classes | |
| struct | threadcacheblk_t |
| struct | threadcache_t |
| struct | nedpool_t |
Defines | |
| #define | MSPACES 1 |
| #define | ONLY_MSPACES 1 |
| #define | USE_LOCKS 1 |
| #define | FOOTERS 1 |
| #define | DEBUG 0 |
| #define | DEFAULT_GRANULARITY (1*1024*1024) |
| #define | MAXTHREADSINPOOL 16 |
| #define | THREADCACHEMAXCACHES 256 |
| #define | THREADCACHEMAX 8192 |
| #define | THREADCACHEMAXBINS (13-4) |
| #define | THREADCACHEMAXFREESPACE (512*1024) |
| #define | TLSVAR pthread_key_t |
| #define | TLSALLOC(k) pthread_key_create(k, 0) |
| #define | TLSFREE(k) pthread_key_delete(k) |
| #define | TLSGET(k) pthread_getspecific(k) |
| #define | TLSSET(k, a) pthread_setspecific(k, a) |
| #define | GETMSPACE(m, p, tc, ms, s, action) |
Typedefs | |
| typedef struct threadcacheblk_t | threadcacheblk |
| typedef struct threadcache_t | threadcache |
Functions | |
| size_t | nedblksize (void *mem) THROWSPEC |
| void | nedsetvalue (void *v) THROWSPEC |
| void * | nedmalloc (size_t size) THROWSPEC |
| void * | nedcalloc (size_t no, size_t size) THROWSPEC |
| void * | nedrealloc (void *mem, size_t size) THROWSPEC |
| void | nedfree (void *mem) THROWSPEC |
| void * | nedmemalign (size_t alignment, size_t bytes) THROWSPEC |
| struct mallinfo | nedmallinfo (void) |
| int | nedmallopt (int parno, int value) THROWSPEC |
| int | nedmalloc_trim (size_t pad) THROWSPEC |
| void | nedmalloc_stats () |
| size_t | nedmalloc_footprint () |
| void ** | nedindependent_calloc (size_t elemsno, size_t elemsize, void **chunks) THROWSPEC |
| void ** | nedindependent_comalloc (size_t elems, size_t *sizes, void **chunks) THROWSPEC |
| static FORCEINLINE unsigned int | size2binidx (size_t _size) THROWSPEC |
| static NOINLINE void | RemoveCacheEntries (nedpool *p, threadcache *tc, unsigned int age) THROWSPEC |
| static void | DestroyCaches (nedpool *p) THROWSPEC |
| static NOINLINE threadcache * | AllocCache (nedpool *p) THROWSPEC |
| static void * | threadcache_malloc (nedpool *p, threadcache *tc, size_t *size) THROWSPEC |
| static NOINLINE void | ReleaseFreeInCache (nedpool *p, threadcache *tc, int mymspace) THROWSPEC |
| static void | threadcache_free (nedpool *p, threadcache *tc, int mymspace, void *mem, size_t size) THROWSPEC |
| static NOINLINE int | InitPool (nedpool *p, size_t capacity, int threads) THROWSPEC |
| static NOINLINE mstate | FindMSpace (nedpool *p, threadcache *tc, int *lastUsed, size_t size) THROWSPEC |
| nedpool * | nedcreatepool (size_t capacity, int threads) THROWSPEC |
| void | neddestroypool (nedpool *p) THROWSPEC |
| void | nedpsetvalue (nedpool *p, void *v) THROWSPEC |
| void * | nedgetvalue (nedpool **p, void *mem) THROWSPEC |
| void | neddisablethreadcache (nedpool *p) THROWSPEC |
| static FORCEINLINE mstate | GetMSpace (nedpool *p, threadcache *tc, int mymspace, size_t size) THROWSPEC |
| static FORCEINLINE void | GetThreadCache (nedpool **p, threadcache **tc, int *mymspace, size_t *size) THROWSPEC |
| void * | nedpmalloc (nedpool *p, size_t size) THROWSPEC |
| void * | nedpcalloc (nedpool *p, size_t no, size_t size) THROWSPEC |
| void * | nedprealloc (nedpool *p, void *mem, size_t size) THROWSPEC |
| void | nedpfree (nedpool *p, void *mem) THROWSPEC |
| void * | nedpmemalign (nedpool *p, size_t alignment, size_t bytes) THROWSPEC |
| struct mallinfo | nedpmallinfo (nedpool *p) THROWSPEC |
| int | nedpmallopt (nedpool *p, int parno, int value) THROWSPEC |
| int | nedpmalloc_trim (nedpool *p, size_t pad) THROWSPEC |
| void | nedpmalloc_stats (nedpool *p) THROWSPEC |
| size_t | nedpmalloc_footprint (nedpool *p) THROWSPEC |
| void ** | nedpindependent_calloc (nedpool *p, size_t elemsno, size_t elemsize, void **chunks) THROWSPEC |
| void ** | nedpindependent_comalloc (nedpool *p, size_t elems, size_t *sizes, void **chunks) THROWSPEC |
Variables | |
| static nedpool | syspool |
| #define DEBUG 0 |
Definition at line 50 of file nedmalloc.c.
| #define DEFAULT_GRANULARITY (1*1024*1024) |
| #define FOOTERS 1 |
Definition at line 45 of file nedmalloc.c.
| #define GETMSPACE | ( | m, | |||
| p, | |||||
| tc, | |||||
| ms, | |||||
| s, | |||||
| action | ) |
Value:
do \ { \ mstate m = GetMSpace((p),(tc),(ms),(s)); \ action; \ RELEASE_LOCK(&m->mutex); \ } while (0)
Definition at line 711 of file nedmalloc.c.
Referenced by nedpcalloc(), nedpindependent_calloc(), nedpindependent_comalloc(), nedpmalloc(), and nedpmemalign().
| #define MAXTHREADSINPOOL 16 |
| #define MSPACES 1 |
Definition at line 40 of file nedmalloc.c.
| #define ONLY_MSPACES 1 |
Definition at line 41 of file nedmalloc.c.
| #define THREADCACHEMAX 8192 |
Definition at line 78 of file nedmalloc.c.
Referenced by nedblksize(), nedpcalloc(), nedpfree(), nedpmalloc(), nedprealloc(), threadcache_free(), and threadcache_malloc().
| #define THREADCACHEMAXBINS (13-4) |
Definition at line 85 of file nedmalloc.c.
Referenced by RemoveCacheEntries(), threadcache_free(), and threadcache_malloc().
| #define THREADCACHEMAXCACHES 256 |
| #define THREADCACHEMAXFREESPACE (512*1024) |
Definition at line 89 of file nedmalloc.c.
Referenced by ReleaseFreeInCache(), and threadcache_free().
| #define TLSALLOC | ( | k | ) | pthread_key_create(k, 0) |
| #define TLSFREE | ( | k | ) | pthread_key_delete(k) |
| #define TLSGET | ( | k | ) | pthread_getspecific(k) |
Definition at line 113 of file nedmalloc.c.
Referenced by GetThreadCache(), and neddisablethreadcache().
| #define TLSSET | ( | k, | |||
| a | ) | pthread_setspecific(k, a) |
Definition at line 114 of file nedmalloc.c.
Referenced by AllocCache(), FindMSpace(), GetThreadCache(), and neddisablethreadcache().
| #define TLSVAR pthread_key_t |
Definition at line 110 of file nedmalloc.c.
| #define USE_LOCKS 1 |
Definition at line 43 of file nedmalloc.c.
| typedef struct threadcache_t threadcache |
| typedef struct threadcacheblk_t threadcacheblk |
Definition at line 168 of file nedmalloc.c.
| static NOINLINE threadcache* AllocCache | ( | nedpool * | p | ) | [static] |
Definition at line 346 of file nedmalloc.c.
References threadcache_t::mymspace, THREADCACHEMAXCACHES, threadcache_t::threadid, and TLSSET.
Referenced by GetThreadCache().
| static void DestroyCaches | ( | nedpool * | p | ) | [static] |
Definition at line 324 of file nedmalloc.c.
References assert, threadcache_t::freeInCache, threadcache_t::frees, threadcache_t::mymspace, RemoveCacheEntries(), THREADCACHEMAXCACHES, and threadcache_t::threadid.
Referenced by InitPool(), and neddestroypool().
| static NOINLINE mstate FindMSpace | ( | nedpool * | p, | |
| threadcache * | tc, | |||
| int * | lastUsed, | |||
| size_t | size | |||
| ) | [static] |
| static FORCEINLINE mstate GetMSpace | ( | nedpool * | p, | |
| threadcache * | tc, | |||
| int | mymspace, | |||
| size_t | size | |||
| ) | [static] |
| static FORCEINLINE void GetThreadCache | ( | nedpool ** | p, | |
| threadcache ** | tc, | |||
| int * | mymspace, | |||
| size_t * | size | |||
| ) | [static] |
Definition at line 727 of file nedmalloc.c.
References AllocCache(), assert, InitPool(), nedpool_t::threads, TLSGET, and TLSSET.
Referenced by nedpcalloc(), nedpfree(), nedpindependent_calloc(), nedpindependent_comalloc(), nedpmalloc(), nedpmemalign(), and nedprealloc().
| static NOINLINE int InitPool | ( | nedpool * | p, | |
| size_t | capacity, | |||
| int | threads | |||
| ) | [static] |
Definition at line 545 of file nedmalloc.c.
References ACQUIRE_MALLOC_GLOBAL_LOCK, DestroyCaches(), ensure_initialization, INITIAL_LOCK, MAXTHREADSINPOOL, RELEASE_MALLOC_GLOBAL_LOCK, TLSALLOC, and TLSFREE.
Referenced by GetThreadCache(), nedcreatepool(), neddisablethreadcache(), nedpmallinfo(), nedpmalloc_footprint(), nedpmalloc_stats(), nedpmalloc_trim(), and nedpsetvalue().
| size_t nedblksize | ( | void * | mem | ) |
Definition at line 134 of file nedmalloc.c.
References assert, chunksize, cinuse, mem2chunk, overhead_for, and THREADCACHEMAX.
Referenced by nedpfree(), nedprealloc(), RemoveCacheEntries(), and threadcache_malloc().
| void* nedcalloc | ( | size_t | no, | |
| size_t | size | |||
| ) |
| nedpool* nedcreatepool | ( | size_t | capacity, | |
| int | threads | |||
| ) |
| void neddestroypool | ( | nedpool * | p | ) |
| void neddisablethreadcache | ( | nedpool * | p | ) |
Definition at line 680 of file nedmalloc.c.
References assert, threadcache_t::freeInCache, threadcache_t::frees, InitPool(), threadcache_t::mallocs, threadcache_t::mymspace, RemoveCacheEntries(), threadcache_t::successes, threadcache_t::threadid, nedpool_t::threads, TLSGET, and TLSSET.
| void nedfree | ( | void * | mem | ) |
| void* nedgetvalue | ( | nedpool ** | p, | |
| void * | mem | |||
| ) |
Definition at line 659 of file nedmalloc.c.
References chunk2mem, cinuse, malloc_state::extp, FENCEPOST_HEAD, fm, malloc_chunk::head, is_aligned, is_mmapped, mem2chunk, next_chunk, next_pinuse, ok_address, ok_magic, pinuse, prev_chunk, and nedpool_t::uservalue.
| void** nedindependent_calloc | ( | size_t | elemsno, | |
| size_t | elemsize, | |||
| void ** | chunks | |||
| ) |
| void** nedindependent_comalloc | ( | size_t | elems, | |
| size_t * | sizes, | |||
| void ** | chunks | |||
| ) |
| struct mallinfo nedmallinfo | ( | void | ) | [read] |
| void* nedmalloc | ( | size_t | size | ) |
| size_t nedmalloc_footprint | ( | void | ) |
| void nedmalloc_stats | ( | void | ) |
| int nedmalloc_trim | ( | size_t | pad | ) |
| int nedmallopt | ( | int | parno, | |
| int | value | |||
| ) |
| void* nedmemalign | ( | size_t | alignment, | |
| size_t | bytes | |||
| ) |
| void* nedpcalloc | ( | nedpool * | p, | |
| size_t | no, | |||
| size_t | size | |||
| ) |
Definition at line 790 of file nedmalloc.c.
References GETMSPACE, GetThreadCache(), threadcache_malloc(), and THREADCACHEMAX.
Referenced by nedcalloc(), and nedcreatepool().
| void nedpfree | ( | nedpool * | p, | |
| void * | mem | |||
| ) |
Definition at line 840 of file nedmalloc.c.
References assert, CHUNK_OVERHEAD, GetThreadCache(), nedblksize(), threadcache_free(), and THREADCACHEMAX.
Referenced by nedcreatepool(), neddestroypool(), and nedfree().
| void** nedpindependent_calloc | ( | nedpool * | p, | |
| size_t | elemsno, | |||
| size_t | elemsize, | |||
| void ** | chunks | |||
| ) |
Definition at line 923 of file nedmalloc.c.
References GETMSPACE, and GetThreadCache().
Referenced by nedindependent_calloc().
| void** nedpindependent_comalloc | ( | nedpool * | p, | |
| size_t | elems, | |||
| size_t * | sizes, | |||
| void ** | chunks | |||
| ) |
Definition at line 933 of file nedmalloc.c.
References GETMSPACE, and GetThreadCache().
Referenced by nedindependent_comalloc().
Definition at line 870 of file nedmalloc.c.
References mallinfo::arena, mallinfo::fordblks, mallinfo::hblkhd, InitPool(), mallinfo::keepcost, mallinfo::ordblks, nedpool_t::threads, mallinfo::uordblks, and mallinfo::usmblks.
Referenced by nedmallinfo().
| void* nedpmalloc | ( | nedpool * | p, | |
| size_t | size | |||
| ) |
Definition at line 771 of file nedmalloc.c.
References GETMSPACE, GetThreadCache(), threadcache_malloc(), and THREADCACHEMAX.
Referenced by nedmalloc(), and nedprealloc().
| size_t nedpmalloc_footprint | ( | nedpool * | p | ) |
Definition at line 912 of file nedmalloc.c.
References InitPool(), and nedpool_t::threads.
Referenced by nedmalloc_footprint().
| void nedpmalloc_stats | ( | nedpool * | p | ) |
Definition at line 903 of file nedmalloc.c.
References InitPool(), and nedpool_t::threads.
Referenced by nedmalloc_stats().
| int nedpmalloc_trim | ( | nedpool * | p, | |
| size_t | pad | |||
| ) |
Definition at line 893 of file nedmalloc.c.
References InitPool(), and nedpool_t::threads.
Referenced by nedmalloc_trim().
| int nedpmallopt | ( | nedpool * | p, | |
| int | parno, | |||
| int | value | |||
| ) |
| void* nedpmemalign | ( | nedpool * | p, | |
| size_t | alignment, | |||
| size_t | bytes | |||
| ) |
Definition at line 857 of file nedmalloc.c.
References GETMSPACE, and GetThreadCache().
Referenced by nedmemalign().
| void* nedprealloc | ( | nedpool * | p, | |
| void * | mem, | |||
| size_t | size | |||
| ) |
Definition at line 811 of file nedmalloc.c.
References assert, GetThreadCache(), nedblksize(), nedpmalloc(), threadcache_free(), threadcache_malloc(), and THREADCACHEMAX.
Referenced by nedrealloc().
| void nedpsetvalue | ( | nedpool * | p, | |
| void * | v | |||
| ) |
Definition at line 654 of file nedmalloc.c.
References InitPool(), and nedpool_t::threads.
Referenced by nedsetvalue().
| void* nedrealloc | ( | void * | mem, | |
| size_t | size | |||
| ) |
| void nedsetvalue | ( | void * | v | ) |
| static NOINLINE void ReleaseFreeInCache | ( | nedpool * | p, | |
| threadcache * | tc, | |||
| int | mymspace | |||
| ) | [static] |
Definition at line 461 of file nedmalloc.c.
References RemoveCacheEntries(), and THREADCACHEMAXFREESPACE.
Referenced by threadcache_free().
| static NOINLINE void RemoveCacheEntries | ( | nedpool * | p, | |
| threadcache * | tc, | |||
| unsigned int | age | |||
| ) | [static] |
Definition at line 286 of file nedmalloc.c.
References assert, threadcacheblk_t::lastUsed, nedblksize(), threadcacheblk_t::next, threadcacheblk_t::prev, threadcacheblk_t::size, and THREADCACHEMAXBINS.
Referenced by DestroyCaches(), neddisablethreadcache(), and ReleaseFreeInCache().
| static FORCEINLINE unsigned int size2binidx | ( | size_t | _size | ) | [static] |
Definition at line 202 of file nedmalloc.c.
Referenced by threadcache_free(), and threadcache_malloc().
| static void threadcache_free | ( | nedpool * | p, | |
| threadcache * | tc, | |||
| int | mymspace, | |||
| void * | mem, | |||
| size_t | size | |||
| ) | [static] |
Definition at line 473 of file nedmalloc.c.
References assert, CHUNK_OVERHEAD, fm, threadcacheblk_t::lastUsed, mem2chunk, threadcacheblk_t::next, ok_magic, threadcacheblk_t::prev, ReleaseFreeInCache(), threadcacheblk_t::size, size2binidx(), THREADCACHEMAX, THREADCACHEMAXBINS, THREADCACHEMAXFREESPACE, and USAGE_ERROR_ACTION.
Referenced by nedpfree(), and nedprealloc().
| static void* threadcache_malloc | ( | nedpool * | p, | |
| threadcache * | tc, | |||
| size_t * | size | |||
| ) | [static] |
Definition at line 375 of file nedmalloc.c.
References assert, CHUNK_OVERHEAD, nedblksize(), threadcacheblk_t::next, threadcacheblk_t::prev, threadcacheblk_t::size, size2binidx(), THREADCACHEMAX, and THREADCACHEMAXBINS.
Referenced by nedpcalloc(), nedpmalloc(), and nedprealloc().
Definition at line 200 of file nedmalloc.c.
1.5.6