Sharing the same VM address space between Kernel and UserSpace
PeterJeremy at optushome.com.au
Tue Nov 15 08:00:28 GMT 2005
On Mon, 2005-Nov-14 13:39:19 -0700, John Giacomoni wrote:
>I am in need of a way to share memory between kernel space and possibly
>multiple different user-space processes for an extended period of time.
>This memory would need to be a single unpageable region.
Does the region have to have the same address in both kernel and user
space? Based on some of your later comments, I suspect you only need
the same address is all userland processes.
If this is true, then I think all you need to do is malloc(9) the
space, vm_map_wire(9) it and arrange for all userland processes to
mmap(2) it at the same address - by having them pass MAP_FIXED.
(The malloc() and vm_map_wire() are only needed once because the
memory will remain wired until the kernel releases it).
Avoiding other mappings isn't that difficult, though it's not totally
trivial. You need to avoid KVA, stack, text, heap, shared libraries,
SysV SHM and other random mmap()'s. If this is a fairly custom
application, you can get a fairly good idea of what other mappings
exist and just ensure that you pick an unused address and mmap it
fairly early. If you need to allocate a very large region (getting
towards the GB region) or this is part of a library that is supposed
to be linked into arbitrary applications then things may be more
More information about the freebsd-hackers