/* * bloat - waste memory. * * This test allocates memory a page at a time and keeps going until * it runs out. It gets the memory directly with sbrk to avoid malloc- * related overheads, which as long as OS/161 has a dumb userlevel * malloc is important for performance. */ #include #include #include #include #include #include #include #include /* OS/161 doesn't currently have a way to get this from the kernel. */ #define PAGE_SIZE 4096 /* the memory we've gotten */ static void *firstpage; static void *lastpage; /* number of page allocations per cycle */ static unsigned allocs; /* number of pages to touch every cycle */ static unsigned touchpages; /* when touching pages, the extent to which we favor the middle of the range */ static unsigned bias; static void moremem(void) { static unsigned totalpages; void *ptr; unsigned i; for (i=0; i= numpages) { mnum = numpages; } moffset = numpages / 2 - mnum / 2; assert(bias >= 1); span = (mnum + bias - 1) / bias; do { val = 0; for (i=0; i= mnum); return moffset + val; } static void touchmem(void) { unsigned i, num; num = (((uintptr_t)lastpage - (uintptr_t)firstpage) / PAGE_SIZE) + 1; if (num % 256 == 0) { warnx("%u pages", num); } for (i=0; i