pike.git / src / block_allocator.c

version» Context lines:

pike.git/src/block_allocator.c:100:    blocks_used,    blocks_used,    p->prev, BA_NUM(p->prev), p->next, BA_NUM(p->next));       }   }      #ifdef BA_STATS   PMOD_EXPORT void ba_print_stats(struct block_allocator * a) {    FILE *f; -  size_t used = a->st_max * a->block_size; -  size_t malloced = a->st_max_pages * (a->block_size * a->blocks); -  size_t overhead = a->st_max_pages * sizeof(struct ba_page); -  int mall = a->st_mallinfo.uordblks; -  int moverhead = a->st_mallinfo.fordblks; -  size_t all = (size_t)sbrk(0) - (size_t)statptr; -  overhead += a->st_max_allocated * 2 * sizeof(void*); +  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 sbrek: %.1lf kb" +  " mall: %.1lf kb overhead: %.1lf kb "    " page_size: %d block_size: %d\n"; -  if (a->st_max == 0) return; +  if (s->st_max == 0) return;   #if 0    f = fopen("/dev/shm/plogs.txt", "a");    fprintf(f, fmt, -  a->st_name, +  s->st_name,    used / 1024.0, malloced / 1024.0, overhead / 1024.0,    mall / 1024.0,    moverhead / 1024.0, -  all / 1024.0, -  a->block_size * a->blocks, -  a->block_size +  s->block_size * s->blocks, +  s->block_size    );    fclose(f);   #endif    printf(fmt, -  a->st_name, +  s->st_name,    used / 1024.0, malloced / 1024.0, -  a->st_max_pages, overhead / 1024.0, +  s->st_max_pages, overhead / 1024.0,    mall / 1024.0,    moverhead / 1024.0, -  all / 1024.0, +     a->block_size * a->blocks,    a->block_size    ); -  if (a->good || a->bad || a->ugly || a->likely || a->max) { -  printf("COUNTS:\n%lu good\t %lu bad\t %lu ugly\t %lu likely\t %lu max %lu full %lu empty\n", a->good, a->bad, a->ugly, a->likely, a->max, -  a->full, a->empty); +  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);    }   }   #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;   
pike.git/src/block_allocator.c:282:    free(a->pages);    a->first_blk = NULL;    a->last_free = NULL;    a->empty = a->first = a->last = NULL;    a->htable = NULL;    a->pages = NULL;    a->empty_pages = 0;    a->allocated = 0;    a->num_pages = 0;   #ifdef BA_STATS -  a->st_max = a->st_used = 0; +  a->stats.st_max = a->stats.st_used = 0;   #endif   }      static INLINE void ba_grow(struct block_allocator * a) {    if (a->allocated) {    // try to detect 32bit overrun?    if (a->allocated >= ((ba_page_t)1 << (sizeof(ba_page_t)*8-1))) {    BA_ERROR("too many pages.\n");    }    a->allocated *= 2;