Page MenuHomeFreeBSD
Authored By
dougm
May 31 2019, 7:38 AM
Size
1 KB
Referenced Files
None
Subscribers
None

mapper4.c

#include <sys/mman.h>
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
enum {MAX_MAPS = 16384, PAGE_SIZE = 4096 };
int main(int argc, const char *argv[])
{
int i;
int nmappings = 0;
void *mappings[MAX_MAPS];
struct timeval beg, end;
struct timezone tz = {0, 0};
if (argc >= 2)
srandom(atoi(argv[1]));
for (i = 0; i < MAX_MAPS; ++i)
mappings[i] = MAP_FAILED;
gettimeofday(&beg, &tz);
for (i = 0; i < 2048 * MAX_MAPS; ++i) {
long r = random() % MAX_MAPS;
if (mappings[r] == MAP_FAILED) {
mappings[r] = mmap(0, 3*PAGE_SIZE, PROT_WRITE, MAP_ALIGNED(14) | MAP_ANON, -1, 0);
if (mappings[r] != MAP_FAILED)
++nmappings;
} else {
munmap(mappings[r], 3*PAGE_SIZE);
mappings[r] = MAP_FAILED;
--nmappings;
}
}
gettimeofday(&end, &tz);
end.tv_sec -= beg.tv_sec;
end.tv_usec -= beg.tv_usec;
if (end.tv_usec < 0) {
end.tv_usec += 1000000;
end.tv_sec--;
}
printf("nmappings = %d, time %ld.%ld; ok?\n", nmappings,
(long)end.tv_sec, (long)end.tv_usec);
return 0;
}

File Metadata

Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1933369
Default Alt Text
mapper4.c (1 KB)

Event Timeline