Index: sys/kern/subr_blist.c =================================================================== --- sys/kern/subr_blist.c +++ sys/kern/subr_blist.c @@ -121,7 +121,7 @@ #define free(a,b) free(a) #define ummin(a,b) ((a) < (b) ? (a) : (b)) -#include +#include "../sys/blist.h" void panic(const char *ctl, ...); @@ -1042,23 +1042,76 @@ main(int ac, char **av) { int size = BLIST_META_RADIX * BLIST_BMAP_RADIX; + int histAlloc, histSize, evCount, nEvents; int i; blist_t bl; struct sbuf *s; + histAlloc = 0; + nEvents = 0; for (i = 1; i < ac; ++i) { const char *ptr = av[i]; if (*ptr != '-') { size = strtol(ptr, NULL, 0); continue; } - ptr += 2; - fprintf(stderr, "Bad option: %s\n", ptr - 2); - exit(1); + switch (*++ptr) { + case 'r': + srandom(strtol(av[++i], NULL, 0)); + break; + case 'h': + histAlloc = strtol(av[++i], NULL, 0); + break; + case 'n': + nEvents = strtol(av[++i], NULL, 0); + break; + default: + fprintf(stderr, "Bad option: %s. \n" + "Usage: -r " + "-h -n \n", + ptr); + exit(1); + } } bl = blist_create(size, M_WAITOK); blist_free(bl, 0, size); + /* + * Initialize with nEvents random allocation and free events. + * Maintain a history of active allocations so that one can + * be selected randomly for freeing. On average, there are + * histAlloc/2 outstanding allocations after startup, if + * memory is big enough. + */ + struct { + daddr_t addr; + long long size; + } *history; + history = malloc(histAlloc * sizeof(history[0]), 0, 0); + histSize = 0; + for (evCount = 0; evCount < nEvents; ++evCount) { + long r = random(); + int ev = r % histAlloc; + if (ev >= histSize) { + r /= histAlloc; + long long hsize = 1 + r % BLIST_MAX_ALLOC; + history[histSize].size = hsize; + history[histSize].addr = blist_alloc(bl, hsize); + if (history[histSize].addr != SWAPBLK_NONE) + ++histSize; + else { + blist_fill(bl, 0, size); + blist_free(bl, 0, size); + histSize = 0; + } + } + else { + blist_free(bl, history[ev].addr, history[ev].size); + history[ev] = history[--histSize]; + } + } + free(history, 0); + for (;;) { char buf[1024]; long long da = 0;