Sharing the same VM address space between Kernel and UserSpace

Kamal R. Prasad kamalp at
Tue Nov 15 04:25:46 GMT 2005

On 15-Nov-05, at 3:58 AM, John Giacomoni wrote:

> On Nov 14, 2005, at 1:57 PM, Scott Long wrote:
>> 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.
>>> I am using the vm routines as cribbed from mmap, however I'd like  
>>> the
>>> address spaces to be viewed as the same regardless of which  
>>> process I'm
>>> in to avoid swizzling pointers as I'm storing data structures in the
>>> shared memory region.
>>> I imagine I'd need to find a way to expose part of the kernel  
>>> address
>>> space to user space to accomplish this.
>>> Is there a way to do this?
>>> thanks
>>> John G
>> If you get this working then it'll be very useful for the syspage  
>> support that was talked about recently.
>> The kernel can access addresses in the user space so long as they
>> are wired and won't cause a fault.  Thus I imagine that you
>> only need to allocate the memory, wire it, mark it with the  
>> appropriate
>> page permissions, and reserve a user address range for it in the
>> process map.  I'd look at the process exec path in the kernel for
>> places to hook in.  The only other trick then is how to let the user
>> process know the address for this magic region.  An easy way would be
>> to store it in a sysctl that can be read at runtime.  A harder way  
>> would
>> be to have the kernel dummy up an elf segment in the image activator
>> code that the dynamic linker could read and put into a global  
>> variable
>> for the program to access.
>> Scott
> Which thread/list was the syspage support discussed?
> (I did a quick search in my freebsd-hackers mailbox and didn't find  
> it)
> As for my problem I'm not sure that the kernel being able to access  
> userpages
> is quite what is needed.  The first reason is that if there are two  
> processes
> trying to map the same region it would be problematic if one of  
> them had
> allocated something in the same area of the heap as the shared  
> memory region

Typically, the address range for heap is different from that of  
shared memory segment. Im not sure of freebsd -but for AIX what Im  
saying is true. So, unless you have allocated another shared memory  
object, MAP_FIXED should suffice to get the same address across user  

> resides. This suggests that to avoid swizzling the region needs to  
> be in an
> address region where the user-space processes will never allocate  
> in (kernel).
> The other reason is that the kernel code needs to be able to  
> function using
> the shared memory without a user-space process being attached at  
> all times.
> So the question is, is it possible to mark wired kernel pages as  
> being accessible
> to a user-space process without triggering a context switch?
How about you bring in a kernel process to access the mmap'ed file/ 


> John G
> --
> John.Giacomoni at
> University of Colorado at Boulder
> Department of Computer Science
> Engineering Center, ECCR 1B05
> 430 UCB
> Boulder, CO 80303-0430
> _______________________________________________
> freebsd-hackers at mailing list
> To unsubscribe, send any mail to "freebsd-hackers- 
> unsubscribe at"

Kamal R. Prasad
UNIX systems consultant
kamalp at

More information about the freebsd-hackers mailing list