#include #include #include #include #include #include #include #include #include struct what { char *p; size_t s; long pagesize; }; void * run(void *v) { struct what *w = v; char *ep; char *p = w->p; printf("mapped 0x%jx\n", (intmax_t)w->s); for (ep = p + w->s; p < ep; p += w->pagesize) *p = 1; } int main(int argc, char * argv[]) { long pagesize = sysconf(_SC_PAGE_SIZE); size_t s, o; char *p, *ep; pthread_t t; struct what w[100]; int e; for (o = 1; o != 0; o <<= 1) { s = o; } for (o = 0; s; s >>= 1) { for (; (p = mmap(NULL, s, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0)) != MAP_FAILED; o++) { if (o == 100) abort(); w[o].p = p; w[o].s = s; w[o].pagesize = pagesize; if ((e = pthread_create(&t, NULL, run, &w[o])) != 0) { errno = e; warn("pthread_create"); } } } sleep(100000); return 0; }