2 * alloc.c - specialized allocator for internal objects
4 * Copyright (C) 2006 Linus Torvalds
6 * The standard malloc/free wastes too much space for objects, partly because
7 * it maintains all the allocation infrastructure (which isn't needed, since
8 * we never free an object descriptor anyway), but even more because it ends
9 * up with maximal alignment because it doesn't know what the object alignment
10 * for the new allocation is.
21 #define DEFINE_ALLOCATOR(name) \
22 static unsigned int name##_allocs; \
23 struct name *alloc_##name##_node(void) \
26 static struct name *block; \
30 block = xcalloc(BLOCKING, sizeof(struct name)); \
37 DEFINE_ALLOCATOR(blob)
38 DEFINE_ALLOCATOR(tree)
39 DEFINE_ALLOCATOR(commit)
42 #define REPORT(name) \
43 fprintf(stderr, "%10s: %8u (%zu kB)\n", #name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)
45 void alloc_report(void)