Files
hakmem/archive/tools/analyze_overhead.c

37 lines
1.4 KiB
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
int main() {
printf("=== HAKMEM Tiny Pool Memory Overhead Analysis ===\n\n");
// 1M allocations of 16B
const int num_allocs = 1000000;
const int alloc_size = 16;
const int slab_size = 65536; // 64KB
const int blocks_per_slab = slab_size / alloc_size; // 4096
printf("Data:\n");
printf(" Total allocations: %d\n", num_allocs);
printf(" Allocation size: %d bytes\n", alloc_size);
printf(" Actual data: %d MB\n\n", num_allocs * alloc_size / 1024 / 1024);
printf("Slab overhead:\n");
printf(" Slab size: %d KB\n", slab_size / 1024);
printf(" Blocks per slab: %d\n", blocks_per_slab);
printf(" Slabs needed: %d\n", (num_allocs + blocks_per_slab - 1) / blocks_per_slab);
printf(" Total slab memory: %d MB\n",
((num_allocs + blocks_per_slab - 1) / blocks_per_slab) * slab_size / 1024 / 1024);
printf("\nTLS Magazine overhead:\n");
printf(" Magazine capacity: 2048 items\n");
printf(" Size classes: 8\n");
printf(" Pointer size: 8 bytes\n");
printf(" Per-thread overhead: %d KB\n", 2048 * 8 * 8 / 1024);
printf("\nBitmap overhead per slab:\n");
printf(" Bitmap size: %d bytes (1 bit per block)\n", blocks_per_slab / 8);
printf(" Summary bitmap: ~%d bytes\n", (blocks_per_slab / 8) / 64);
return 0;
}