copy-on-write anonymous memory?

Kostik Belousov kostikbel at gmail.com
Thu May 15 11:18:56 UTC 2008


On Thu, May 15, 2008 at 01:20:32PM +0300, Teemu Rinta-aho wrote:
> Hi all,
> 
> is it possible to create a memory object that represents
> anonymous memory pages *and* is copy-on-write?
> 
> I have this code in a kernel module:
> 
>     object = vm_object_allocate(OBJT_DEFAULT, 1);
> 
>     result = vm_map_find(vmmap_proc,
>                          object,
>                          0,
>                          &addr,
>                          len,
>                          TRUE,
>                          VM_PROT_ALL,
>                          VM_PROT_ALL,
>                          MAP_COPY_ON_WRITE);
> 
> Then I pass the addr to the user space, but when
> I write to the addr, I see no shadow objects created,
> i.e. the changes are written to the original memory
> pages no matter if I have the map entry set as
> copy-on-write or not... I am assuming a write fault would
> create a new page and hang it to a shadow object thus
> leaving the original memory untouched.
> 
> I'd appreciate any kind of help here.

I cannot get a complete handle on your problem without full code, but
I guess that you have only one reference to the backing object through
the vm map entry. If this is the case, then the shadow copying actually
does not make sense since no other users of the object need it.

Look at the vm_object_shadow(), check at the start of the function.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20080515/26d0fc41/attachment.pgp


More information about the freebsd-hackers mailing list