1
#ifndef KR_MALLOC_H /* K&R malloc */
12
#define ALIGNMENT (1 << LOG_ALIGN)
14
#define KR_CTX_SHMEM 101
15
#define KR_CTX_LOCALMEM 102
19
unsigned valid1; /* Token to check if is not overwritten */
20
union header *ptr; /* next block if on free list */
21
int shmid; /* next block's shared memory id */
22
long shmoffset; /* next block's shmem offset */
23
size_t shmsize; /* next block's shared memory segment size */
24
size_t size; /* size of this block*/
25
unsigned valid2; /* Another token acting as a guard */
27
char align[ALIGNMENT]; /* Align to ALIGNMENT byte boundary */
30
typedef union header Header;
32
typedef struct malloc_context {
33
size_t usize; /* unit size in bytes */
34
size_t nalloc; /* No. of units of length ALIGNMENT */
35
size_t max_nalloc; /* Maximum no. of units that can get */
36
void * (*alloc_fptr)(); /* function pointer to memory alloc routine */
37
size_t total; /* Amount request from system in units */
38
long nchunk; /* No. of chunks of system memory */
39
long inuse; /* Amount in use in units */
40
long maxuse; /* Maximum value of inuse */
41
long nfrags; /* No. of fragments divided into */
42
long nmcalls; /* No. of calls to _armci_alloc() */
43
long nfcalls; /* No. of calls to memfree */
44
int ctx_type; /* context id.
45
-1 represents ctx_local context.
46
otherwise, it is ctx_shmem context. */
47
int shmid; /* first free block's (i.e.freep) shmem id */
48
long shmoffset; /* first free block's shmem offset */
49
size_t shmsize; /* first free block's shmem total size */
50
Header base; /* empty list to get started */
51
Header *freep; /* start of free list */
52
Header *usedp; /* start of used list */
55
/* Memory required to store the shmem context in shared memory. This shmem
56
context shuld be stored in shared memory and is stored in the first shared
57
memory segment created (i.e.armci_krmalloc_init_ctxshmem) */
58
#define SHMEM_CTX_MEM (sizeof(context_t)+sizeof(void*))
59
#define SHMEM_CTX_BYTES ((SHMEM_CTX_MEM + sizeof(Header) - 1)>>LOG_ALIGN) + 1;
61
extern void kr_malloc_init(size_t usize, /* unit size in bytes */
64
void * (*alloc_fptr)(), /* memory alloc routine */
69
Returns data aligned on a quad boundary. Even if the request
70
size is zero it returns a non-zero pointer.
72
extern char *kr_malloc(size_t size, context_t *ctx);
75
Frees memory allocated by kr_malloc(). Ignores NULL pointers
76
but must not be called twice for the same pointer or called
77
with non-memalloc'ed pointers
79
extern void kr_free(char *ptr, context_t *ctx);
82
Print to standard output the usage statistics ... a wrapper
83
for kr_malloc_stats();
85
extern void kr_malloc_print_stats(context_t *ctx);
87
extern void kr_malloc_verify(context_t *ctx);