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_INHERIT is set, the children see the same as the parent. If additionally (or more precisely OR-ally) MAP_PRIVATE is set, modifications (i.e. writes) by the parent are invisible to the children. If MAP_SHARE is 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.

Usage: 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 mmap the same file to another location, with different policies…

Mon, 23 Jan 2006
[/projects] permanent link