Stress-testing mmap on OpenBSD
mmap(2)maps a file to a range of memory and gives the calling process a
void*to manipulate the contents of the file. If no file descriptor is given, it creates an “anonymous” memory range. In both cases, the memory range can be used for inter-process communication. As an additional feature, the caller can specify how child processes see the memory. If
MAP_INHERITis set, the children see the same as the parent. If additionally (or more precisely OR-ally)
MAP_PRIVATEis set, modifications (i.e. writes) by the parent are invisible to the children. If
MAP_SHAREis set, the children see the bytes written by the parent. The
minherit(2)syscall allows setting these bits for arbitrary pages.
Now, what would be the most stressing situation for the kernel? Overlapping memory ranges with different copy/share policies for several generations of processes. This program does exactly that. It subdivides the same piece of memory recursively, and each child sets another inheritance policy on top of the set ones of the stack of parents.
stress.mmap [-f file] [-m size] [-r level] [-n num]
-f <file> use <file> to mmap on -m <size> size of mmaped area in bytes -r <level> the number of recursions -n <num> number of byteblocks to touch in each incarnation
TODO: let each child
mmapthe same file to another location, with different policies…