pike.git / src / block_allocator.c

version» Context lines:

pike.git/src/block_allocator.c:90: Inside #if defined(BA_STATS)
     #ifdef BA_STATS   PMOD_EXPORT void ba_print_stats(struct block_allocator * a) {    FILE *f;    struct block_alloc_stats * s = &a->stats;    size_t used = s->st_max * a->block_size;    size_t malloced = s->st_max_pages * (a->block_size * a->blocks);    size_t overhead = s->st_max_pages * sizeof(struct ba_page);    int mall = s->st_mallinfo.uordblks;    int moverhead = s->st_mallinfo.fordblks; -  overhead += s->st_max_allocated * 2 * sizeof(void*); +     const char * fmt = "%s: max used %.1lf kb in %.1lf kb (#%lld) pages"    " (overhead %.2lf kb)"    " mall: %.1lf kb overhead: %.1lf kb "    " page_size: %d block_size: %d\n"; -  +  overhead += s->st_max_allocated * 2 * sizeof(void*);    if (s->st_max == 0) return;   #if 0    f = fopen("/dev/shm/plogs.txt", "a");    fprintf(f, fmt,    s->st_name,    used / 1024.0, malloced / 1024.0, overhead / 1024.0,    mall / 1024.0,    moverhead / 1024.0,    s->block_size * s->blocks,    s->block_size
pike.git/src/block_allocator.c:117: Inside #if defined(BA_STATS)
  #endif    printf(fmt,    s->st_name,    used / 1024.0, malloced / 1024.0,    s->st_max_pages, overhead / 1024.0,    mall / 1024.0,    moverhead / 1024.0,    a->block_size * a->blocks,    a->block_size    ); -  if (s->good || s->bad || s->ugly || s->likely || s->max) { -  printf("COUNTS:\n%lu good\t %lu bad\t %lu ugly\t %lu likely\t %lu max %lu full %lu empty\n", s->good, s->bad, s->ugly, s->likely, s->max, -  s->full, s->empty); +  printf("free COUNTS: "); +  PRCOUNT(free_fast1); +  PRCOUNT(free_fast2); +  PRCOUNT(find_linear); +  PRCOUNT(find_hash); +  PRCOUNT(free_empty); +  PRCOUNT(free_full); +  printf("\n");   } - } +    #endif      //#define BA_ALIGNMENT 8      PMOD_EXPORT INLINE void ba_init(struct block_allocator * a,    uint32_t block_size, ba_page_t blocks) {    uint32_t page_size;      #ifdef BA_ALIGNMENT    if (block_size & (BA_ALIGNMENT - 1))
pike.git/src/block_allocator.c:168:       a->magnitude = (uint16_t)ctz32(page_size);    a->block_size = block_size;    a->num_pages = 0;    a->empty_pages = 0;    a->max_empty_pages = BA_MAX_EMPTY;       // we start with management structures for 16 pages    a->allocated = BA_ALLOC_INITIAL;    a->pages = (ba_page*)malloc(BA_ALLOC_INITIAL * sizeof(ba_page)); +  if (!a->pages) Pike_error("nomem");    memset(a->pages, 0, BA_ALLOC_INITIAL * sizeof(ba_page));   }      static INLINE void ba_free_page(struct block_allocator * a, ba_page p) {    p->first = BA_BLOCKN(a, p, 0);    p->used = 0;    if (a->blueprint) {    //xmemset(p+1, a->blueprint, a->block_size, a->blocks);    size_t len = (a->blocks - 1) * a->block_size, clen = a->block_size;    p++;
pike.git/src/block_allocator.c:306:    MIX(t);       return (ba_page_t) t;   }      static INLINE void ba_htable_grow(struct block_allocator * a) {    ba_page_t n, old;    old = a->allocated;    a->allocated *= 2;    a->pages = (ba_page*)realloc(a->pages, a->allocated * sizeof(ba_page)); +  if (!a->pages) Pike_error("nomem");    memset(a->pages+old, 0, old * sizeof(ba_page));    for (n = 0; n < old; n++) {    ba_page * b = a->pages + n;       while (*b) {    ba_page_t h = hash1(a, BA_LASTBLOCK(a, *b)) & BA_HASH_MASK(a);    if (h != n) {    ba_page p = *b;    *b = p->hchain;    p->hchain = a->pages[h];
pike.git/src/block_allocator.c:343:    ba_page t = p;    if (a->pages[n]) {    while (t->hchain) t = t->hchain;    t->hchain = a->pages[n];    }    a->pages[n] = p;    }    }       a->pages = (ba_page*)realloc(a->pages, a->allocated * sizeof(ba_page)); +  if (!a->pages) Pike_error("nomem");   }      #ifdef BA_DEBUG   PMOD_EXPORT void ba_print_htable(const struct block_allocator * a) {    unsigned int i;       for (i = 0; i < a->allocated; i++) {    ba_page p = a->pages[i];    ba_page_t hval;    if (!p) {
pike.git/src/block_allocator.c:604:    if (likely(!p)) {    ba_find_page(a, ptr);    p = a->last_free;    ((ba_block_header)ptr)->next = p->first;    p->first = (ba_block_header)ptr;    p->used--;    }       // page was full    if (unlikely(!ptr->next)) { -  +  INC(free_full);    if (a->first) {    p->prev = a->last;    a->last->next = p;    a->last = p;    p->first = ptr;    } else {    p->prev = p->next = NULL;    a->first = a->last = p;    a->first_blk = ptr;    }    } else if (!p->used) { -  +  INC(free_empty);    if (a->empty_pages == a->max_empty_pages) {    ba_remove_page(a, p);    return;    }    if (p->next) p->next->prev = p->prev;    else a->last = p->prev;    if (p->prev) {    p->prev->next = p->next;    p->prev = NULL;    }
pike.git/src/block_allocator.c:642:      ATTRIBUTE((always_inline))   PMOD_EXPORT INLINE void ba_find_page(struct block_allocator * a,    const void * ptr) {    ba_page p;   #ifdef BA_DEBUG    ba_check_allocator(a, "ba_low_free", __FILE__, __LINE__);   #endif   #ifdef BA_HASH_THLD    if (a->num_pages <= BA_HASH_THLD) { +  INC(find_linear);    PAGE_LOOP(a, {    if (BA_CHECK_PTR(a, p, ptr)) {    a->last_free = p;    return;    }    });    } else {   #endif -  +  INC(find_hash);    p = ba_htable_lookup(a, ptr);    if (p) {    a->last_free = p;    return;    }   #ifdef BA_HASH_THLD    }   #endif   #ifdef BA_DEBUG    fprintf(stderr, "magnitude: %u\n", a->magnitude);