|
| 1 | +The Driller lib |
| 2 | +--------------- |
| 3 | + |
| 4 | +The set of files in this tarball implement a way for a group of |
| 5 | +cooperating processes to directly access memory segments of one |
| 6 | +another. This can form the basis of a message passing system that |
| 7 | +avoids costly data copy, as is demonstrated with mmpi ("mini-MPI), a |
| 8 | +very simple API loosely inspired from MPI (it only has send, recv and |
| 9 | +barrier primitives). |
| 10 | + |
| 11 | +The name "driller" comes from the idea that we could drill holes in |
| 12 | +the closed container that forms the memory of a regular process. |
| 13 | + |
| 14 | +The code has been designed for Linux and tested on 2.6 only, though |
| 15 | +it might be portable to some Unix variants. It has small portions of |
| 16 | +architecture specific code, but has been tested on x86 and x64, and |
| 17 | +it should not be difficult to port to other architectures. |
| 18 | + |
| 19 | +How to test it |
| 20 | +-------------- |
| 21 | + |
| 22 | + - run "make" to build all library files and tests, or |
| 23 | + "make DEBUG_FLAGS=-DDEBUG" for more verbose output during tests |
| 24 | + - run "./test_driller.sh" for a basic sanity test |
| 25 | + - run "./test_mmpi.sh" for a performance test with mmpi |
| 26 | + |
| 27 | +How it works |
| 28 | +------------ |
| 29 | + |
| 30 | +The code uses the following tricks to achieve its goals: |
| 31 | + |
| 32 | + - under Linux, a process can examine the layout of its own memory |
| 33 | + space by reading /proc/self/maps (on Linux 2.6, the stack and heap |
| 34 | + are clearly identified) |
| 35 | + |
| 36 | + - an existing memory segment can be atomically replaced by a call to |
| 37 | + mmap at the same address; thus, we can copy an existing segment to a |
| 38 | + file, and then map this file over the original segment, which gives |
| 39 | + us the same data, except it is now in a file |
| 40 | + |
| 41 | + - unix sockets can be used to pass file descriptors from one process |
| 42 | + to another; for example one created with the trick above, so another |
| 43 | + process can map the same segment in its own memory space |
| 44 | + |
| 45 | + - under Linux, memory is usually allocated by calling malloc (in the |
| 46 | + C library) or mmap, both of which can be intercepted (using malloc |
| 47 | + hooks and symbol overloading); this means that these memory segments |
| 48 | + can be memory-mapped files if we want them to |
| 49 | + |
| 50 | +These tricks make it possible for a process to simply replace most of |
| 51 | +its memory segments by memory-mapped files. The file descriptors for |
| 52 | +al replaced regions can then be passed to cooperating process, which, |
| 53 | +after an mmap(), can directly access the same memory. When the first |
| 54 | +process modifies or destroys its mapping, this is notified to other |
| 55 | +processes, which will drop any reference to the file and eventually |
| 56 | +free associated ressources. |
| 57 | + |
| 58 | +The code implementing these mechanisms is split in three parts: |
| 59 | + - fdproxy.c: this implements file descriptor passing; one of the |
| 60 | + participants forks a server process that will forward file |
| 61 | + descriptors to any client |
| 62 | + - driller.c: this replaces the memory segments of a process with |
| 63 | + memory-mapped files, and tracks calls to mmap or brk, which modify |
| 64 | + the process memory layout |
| 65 | + - map_cache.c: this provides a cache structure for memory segments |
| 66 | + that a process can have remapped from another process |
| 67 | + |
| 68 | +Since the glibc implementation of malloc cannot be forced to use our |
| 69 | +overloaded version of mmap, an alternate allocator had to be used, and |
| 70 | +Doug Lea's malloc in dlmalloc.c is a convenient substitute. |
| 71 | + |
| 72 | +The file mmpi.c implements a very simple message passing API that uses |
| 73 | +the files above and requires at most one buffer copy to transfer a |
| 74 | +message. Of course, the cost of a few system calls cannot always be |
| 75 | +avoided, but in favorable cases, it can be spread over many messages. |
| 76 | + |
| 77 | +Licensing |
| 78 | +--------- |
| 79 | + |
| 80 | +The files dlmalloc.c and dlmalloc.h are released by Doug Lea to the |
| 81 | +public domain. |
| 82 | + |
| 83 | +All other files were written by Jean-Marc Saffroy and are released as |
| 84 | +free software, distributed under the terms of the GNU General Public |
| 85 | +License version 2. |
| 86 | + |
| 87 | +Contact |
| 88 | +------- |
| 89 | + |
| 90 | +Jean-Marc Saffroy < [email protected]> |
| 91 | + |
| 92 | +Acknowledgements |
| 93 | +---------------- |
| 94 | + |
| 95 | +Thanks to Ga�l Roualland for testing and debugging this code on IA32. |
0 commit comments