🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.mach
Article #1103

Re: Efficient copying from task to task

#1103
From: Alex Goykhman
Date: Fri, 17 May 1991 18:50
90 lines
3758 bytes
In article <1991May17.074526.19128@sics.se> roland@sics.se (Roland Karlsson) writes:
>
>I have two tasks with the same virtual memory layout.  Now I want to
>(very efficiently) copy a block from one task to another task.  The
>block shall be at the same addresses in both tasks.  The block do not
>have to start or end at page boundaries.  The block can consist of any
>number of integers.  It can be just some bytes or several megabytes.
>This copying is made very frequently during execution of several one
>thread tasks (=processes).

    How about vm_copy(target_task, source_address, count, dest_address) ?

    Vm_copy can only transfer whole pages, though.

>
>Proposal one:
>------------
>The solution in UNIX was to map the memory, to a file, with mmap.  All
>UNIX processes can then map other processes memory to another address.
>Then can an ordinary block copy be used.
>
>    File:
>    -------------
>    | 0 | 1 | 2 |
>    -------------
>
>    Map for process 0:   Map for process 1:   Map for process 2:
>    -------------        -------------        -------------
>    | 0 | 1 | 2 |        | 1 | 2 | 0 |        | 2 | 0 | 1 |
>    -------------        -------------        -------------
>    x                    x                    x
>
>I have tried to use vm_map to implement this behavior, but in without
>success.  Every time I use vm_map (with the memory_object
>MEMORY_OBJECT_NULL) to the same offset in the memory object it looks
>like I get a new piece of memory, not an alias for the same.  Can it
>be done???  Someone said the magical word "external pager" but I do
>not know how to use it.

    Speaking of mmap, MEMORY_OBJECT_NULL is same as:

   #define  MAP_ANON         0x0002  /* allocated from memory, swap space */

    Since there is no underlying memory object (file), the vm_map()'s behavior
    with MEMORY_OBJECT_NULL is quite understandable
>
>Proposal two:
>------------

...
>
>Refinement one to proposal two:
>-------------------------------
>It would be very nice if I could use a "copy on write" technique to
>copy the integral pages from one task to another task.  How can that
>be made???

    For that, the source task must be the parent of a destination task.
    I.e., the source tasks issues a

        vm_map (..,MEMORY_OBJECT_NULL,..., VM_INHERIT_COPY),

    fills the region with data, and task_create() the dest. task
    The latter would get a "snapshot" of the region.  Trouble is, you'd
    need to issue task_create() every time you want to copy a block.

    Perhaps, what you need is to substitute VM_INHERIT_COPY for VM_INHERIT_SHARE,
    so the tasks can share the region in some ordered fashion.

>
>Refinement two to proposal two:
>-------------------------------
...
>
>Proposal three:
>--------------
>Something completely different.  But what???

    Sending data via MACH messages is another possibility.
>
>
>--
>Roland Karlsson
>SICS, PO Box 1263, S-164 28 KISTA, SWEDEN	Internet: roland@sics.se
>Tel: +46 8 752 15 40	Ttx: 812 61 54 SICS S	Fax: +46 8 751 72 30


Alex Goykhman                    speaking for myself  
Chelmsford System Software Lab   mit-eddie!apollo!goykhman_a
Hewlett-Packard, Company         goykhman_a@apollo.hp.com
Technical Details
Message-ID: <519f0047.20b6d@apollo.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!apollo!goykhman_a

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!apollo!goykhman_a
From: goykhman_a@apollo.HP.COM (Alex Goykhman)
Newsgroups: comp.os.mach
Subject: Re: Efficient copying from task to task
Message-ID: <519f0047.20b6d@apollo.HP.COM>
Date: 17 May 91 18:50 GMT
Sender: root@apollo.HP.COM
Reply-To: goykhman_a@apollo.HP.COM (Alex Goykhman)
Organization: Hewlett-Packard Apollo Division - Chelmsford, MA
Lines: 90