usermode/library/pmalloc/src/pdlmalloc.c File Reference

A simple persistent memory allocator based on Doug Lea's malloc. More...

#include <sys/types.h>
#include <stdio.h>
#include "genalloc.h"
#include "pdlmalloc.h"
#include <sys/param.h>
#include <mnemosyne.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <pcm.h>

Go to the source code of this file.

Classes

struct  malloc_chunk
struct  malloc_bin

Defines

#define SBRK_UNIT   8192
#define MAX_PREALLOCS   5
#define __STD_C   0
#define _BEGIN_EXTERNS_
#define _END_EXTERNS_
#define _ARG_(x)   ()
#define Void_t   char
#define NIL(type)   ((type)0)
#define DLMALLOC_PHEAP_BASE   0xc00000000
#define DLMALLOC_PHEAP_SIZE   (1024*1024*1024)
#define malloc_getpagesize   SBRK_UNIT
#define SIZE_SZ   (sizeof(size_t))
#define MALLOC_MIN_OVERHEAD   (SIZE_SZ + SIZE_SZ)
#define MALLOC_ALIGN_MASK   (MALLOC_MIN_OVERHEAD - 1)
#define MINSIZE   (sizeof(struct malloc_chunk) + SIZE_SZ)
#define request2size(req)
#define aligned_OK(m)   (((size_t)((m)) & (MALLOC_ALIGN_MASK)) == 0)
#define exact_fit(ptr, req)   ((unsigned)((ptr)->size - (req)) < MINSIZE)
#define INUSE   0x1
#define inuse(p)   ((p)->size & INUSE)
#define set_inuse(p)   ((p)->size |= INUSE)
#define clear_inuse(p)   ((p)->size &= ~INUSE)
#define next_chunk(p)   ((mchunkptr)( ((char*)(p)) + ((p)->size & ~INUSE) ))
#define prev_chunk(p)   ((mchunkptr)( ((char*)(p)) - ( *((size_t*)((char*)(p) - SIZE_SZ)) & ~INUSE)))
#define set_size(P, Sz)
#define chunk2mem(p)   ((Void_t*)((char*)(p) + SIZE_SZ))
#define mem2chunk(mem)   ((mchunkptr)((char*)(mem) - SIZE_SZ))
#define clean_head(b)   (&((b)->chd))
#define first_clean(b)   ((b)->chd.fd)
#define last_clean(b)   ((b)->chd.bk)
#define dirty_head(b)   (&((b)->dhd))
#define first_dirty(b)   ((b)->dhd.fd)
#define last_dirty(b)   ((b)->dhd.bk)
#define NBINS   128
#define LASTBIN   (&(av[NBINS-1]))
#define FIRSTBIN   (&(av[2]))
#define MAX_SMALLBIN_OFFSET   18
#define MAX_SMALLBIN_SIZE   144
#define IAV(i)   {{ 0, &(av[i].dhd), &(av[i].dhd) }, { 0, &(av[i].chd), &(av[i].chd) }}
#define findbin(Sizefb, Bfb)
#define reset_maxClean
#define unlink(Qul)
#define dirtylink(Qdl)
#define cleanlink(Qcl)
#define consolidate(Qc)
#define clear_last_remainder
#define return_chunk(Prc)

Typedefs

typedef malloc_chunkmchunkptr
typedef malloc_binmbinptr

Functions

 __attribute__ ((section("PERSISTENT")))
TM_CALLABLE Void_t * PDL_MALLOC (size_t bytes)
TM_CALLABLE void PDL_FREE (Void_t *mem)
TM_CALLABLE Void_t * PDL_REALLOC (Void_t *mem, size_t bytes)
TM_CALLABLE Void_t * PDL_MEMALIGN (size_t alignment, size_t bytes)
size_t PDL_OBJSIZE (void *mem)
TM_CALLABLE Void_t * PDL_VALLOC (size_t bytes)
TM_CALLABLE Void_t * PDL_CALLOC (size_t n, size_t elem_size)
TM_CALLABLE void PDL_CFREE (Void_t *mem)
TM_CALLABLE size_t PDL_GET_USABLE_SIZE (Void_t *mem)
TM_CALLABLE void PDL_MALLOC_STATS ()


Detailed Description

A simple persistent memory allocator based on Doug Lea's malloc.

Definition in file pdlmalloc.c.


Define Documentation

#define cleanlink ( Qcl   ) 

Value:

{                                                                                                                                                         \
  mchunkptr Pcl = (Qcl);                                                                                                          \
  mbinptr Bcl;                                                                                                                            \
  mchunkptr Hcl, Fcl;                                                                                                             \
                                                                                                                                                          \
  findbin(Qcl->size, Bcl);                                                                                                        \
  Hcl  = clean_head(Bcl);                                                                                                         \
  Fcl  = Hcl->fd;                                                                                                                         \
  if (Hcl == Fcl && Bcl > maxClean) maxClean = Bcl;                                                       \
                                                                                                                                                          \
  Pcl->bk = Hcl;  Pcl->fd = Fcl;  Fcl->bk = Hcl->fd = Pcl;                                        \
}                                                                                                                                                         \

#define clear_last_remainder

Value:

{                                                                                                                                                         \
  if (last_remainder != 0)                                                                                                        \
  {                                                                                                                                                       \
    cleanlink(last_remainder);                                                                                            \
    last_remainder = 0;                                                                                                           \
  }                                                                                                                                                       \
}                                                                                                                                                         \

#define consolidate ( Qc   ) 

Value:

{                                                                                                                                                         \
  for (;;)                                                                                                                                        \
  {                                                                                                                                                       \
    mchunkptr Pc = prev_chunk(Qc);                                                                                        \
    if (!inuse(Pc))                                                                                                                       \
    {                                                                                                                                             \
      unlink(Pc);                                                                                                                         \
      set_size(Pc, Pc->size + (Qc)->size);                                                                        \
      (Qc) = Pc;                                                                                                                          \
    }                                                                                                                                             \
    else break;                                                                                                                           \
  }                                                                                                                                                       \
  for (;;)                                                                                                                                        \
  {                                                                                                                                                       \
    mchunkptr Nc = next_chunk(Qc);                                                                                        \
    if (!inuse(Nc))                                                                                                                       \
    {                                                                                                                                             \
      unlink(Nc);                                                                                                                         \
      set_size((Qc), (Qc)->size + Nc->size);                                                              \
    }                                                                                                                                             \
    else break;                                                                                                                           \
  }                                                                                                                                                       \
}                                                                                                                                                         \

#define dirtylink ( Qdl   ) 

Value:

{                                                                                                                                                         \
  mchunkptr Pdl = (Qdl);                                                                                                          \
  mbinptr   Bndl;                                                                                                                         \
  mchunkptr Hdl, Fdl;                                                                                                             \
                                                                                                                                                          \
  findbin(Pdl->size, Bndl);                                                                                                       \
  Hdl  = dirty_head(Bndl);                                                                                                        \
  Fdl  = Hdl->fd;                                                                                                                         \
                                                                                                                                                          \
  Pdl->bk = Hdl;  Pdl->fd = Fdl;  Fdl->bk = Hdl->fd = Pdl;                                        \
}                                                                                                                                                         \

#define findbin ( Sizefb,
Bfb   ) 

Value:

{                                                                                                                                                         \
  size_t Sfb = (Sizefb);                                                                                                          \
  if (Sfb < MAX_SMALLBIN_SIZE)                                                                                            \
    (Bfb) = (av + (Sfb >> 3));                                                                                            \
  else                                                                                                                                            \
  {                                                                                                                                                       \
    /* Offset wrt small bins */                                                                                           \
    size_t Ifb = MAX_SMALLBIN_OFFSET;                                                                             \
    Sfb >>= 3;                                                                                                                            \
        /* find power of 2 */                                                                                                     \
    while (Sfb >= (MINSIZE * 2)) { Ifb += 4; Sfb >>= 1; }                                         \
        /* adjust for quadrant */                                                                                                 \
    Ifb += (Sfb - MINSIZE) >> 2;                                                          \
    (Bfb) = av + Ifb;                                                                                                             \
  }                                                                                                                                                       \
}                                                                                                                                                         \

#define request2size ( req   ) 

Value:

(((long)(req) <= 0) ?  MINSIZE : \
    (((req) + MALLOC_MIN_OVERHEAD + MALLOC_ALIGN_MASK) \
      & ~(MALLOC_ALIGN_MASK)))

Definition at line 372 of file pdlmalloc.c.

Referenced by PDL_MALLOC(), PDL_MEMALIGN(), and PDL_REALLOC().

#define reset_maxClean

Value:

{                                                                                                                                                         \
  while (maxClean > FIRSTBIN && clean_head(maxClean)==last_clean(maxClean))       \
    --maxClean;                                                                                                                           \
}                                                                                                                                                         \

#define return_chunk ( Prc   ) 

Value:

{                                                                                                                                                         \
  (Prc)->fd = returned_list;                                                                                              \
  returned_list = (Prc);                                                                                                          \
}                                                                                                                                                         \

#define set_size ( P,
Sz   ) 

Value:

{                                                                                                                                                         \
  size_t Sss = (Sz);                                                                                                              \
  (P)->size = *((size_t*)((char*)(P) + Sss - SIZE_SZ)) = Sss;                             \
}                                                                                                                                                         \

Definition at line 412 of file pdlmalloc.c.

Referenced by PDL_MALLOC(), PDL_MEMALIGN(), and PDL_REALLOC().

#define unlink ( Qul   ) 

Value:

{                                                                                                                                                         \
  mchunkptr Bul = (Qul)->bk;                                                                                              \
  mchunkptr Ful = (Qul)->fd;                                                                                              \
  Ful->bk = Bul;  Bul->fd = Ful;                                                                                          \
}                                                                                                                                                         \


Generated on Sat Apr 23 11:43:36 2011 for Mnemosyne by  doxygen 1.4.7