📄 duality.ps.ps
字号:
(5)SH10 SS 7200 29093 MT(is known to the kernel at system initialization)225 W( time)226 W29623 XM(, in a)226 W/Times-Italic SF32523 XM(pager_create)SH/Times-Roman SF38331 XM(call. This)702 W( call is similar in form to)226 W/Times-Italic SF7200 30470 MT(pager_init)SH/Times-Roman SF(; however, it cannot be made on the memory object port itself, but on a port provided by the default pager.)SH8200 32949 MT(Since these kernel-created objects have no initial memory, the default pager may not have data to)149 W( provide in)148 W7200 34326 MT(response to a request. In this case, it must perform a)4 W/Times-Italic SF28522 XM(pager_data_unavailable)SH/Times-Roman SF38609 XM(call to indicate that)4 W( the page should be)5 W8 SS 11365 35358 MT(6)SH10 SS 7200 35703 MT(zero-filled)SH11765 XM(.)SH12 /Times-Bold AF7200 39387 MT(4. Using Memory Objects)SH10 /Times-Roman AF8200 40764 MT(This section briefly describes two sample data managers)84 W( and their applications. The first is a filesystem with a)83 W7200 42141 MT(read/copy-on-write interface, which uses the minimal subset of the memory management interface. The second)78 W( is)79 W7200 43518 MT(an excerpt from the operation of a consistent network shared memory service.)SH11 /Times-Bold AF7200 47135 MT(4.1. A Minimal Filesystem)SH10 /Times-Roman AF8200 48512 MT(An example of a service which minimally uses the Mach external interface is a filesystem server which provides)46 W7200 49889 MT(read-whole-file/write-whole-file functionality. Although it is simple, this style of interface has been used in)63 W( actual)64 W7200 51266 MT(servers [12, 19] and should be considered a serious example.)SH8200 53745 MT(An application might use this filesystem as follows:)SH10800 50 7200 66656 UL6 SS 8000 67995 MT(4)SH8 SS 8300 68304 MT(The same mechanism is used for)SH/Times-Italic SF18960 XM(shadow objects)SH/Times-Roman SF24070 XM(that contain changes to copy-on-write data.)SH6 SS 8000 69843 MT(5)SH8 SS 8300 70152 MT(The default pager will be described in more detail in a later section.)SH6 SS 8000 71691 MT(6)SH8 SS 8300 72000 MT(When shadowing, the data is instead copied from the original.)SHES%%Page: 9 10BS0 SI10 /Times-Roman AF30350 4286 MT(9)SH9 /Courier AF9360 7762 MT(char *file_data;)SH9360 8710 MT(int i, file_size;)SH9360 9658 MT(extern float rand\050\051;)SH( /*)1620 W( random in [0,1\051 */)SH9360 11554 MT(/* Read the file -- ignore errors */)SH9360 12502 MT(fs_read_file\050"filename", &file_data, file_size\051;)SH9360 14398 MT(/* Randomly change contents */)SH9360 15346 MT(for \050i = 0; i < file_size; i++\051)SH11520 16294 MT(file_data[\050int\051\050file_size*rand\050\051\051]++;)SH9360 18190 MT(/* Write back some results -- ignore errors */)SH9360 19138 MT(fs_write_file\050"filename", file_data, file_size/2\051;)SH9360 21034 MT(/* Throw away working copy */)SH9360 21982 MT(vm_deallocate\050task_self\050\051, file_data, file_size\051;)SH10 /Times-Roman AF7200 23392 MT(Note that the)213 W/Times-Italic SF13255 XM(fs_read_file)SH/Times-Roman SF18496 XM(call returns new virtual memory as a result. This memory is copy-on-write in)213 W( the)212 W7200 24769 MT(application's address space; other applications will consistently see)188 W( the original file contents while the random)189 W7200 26146 MT(changes are being made. The application must explicitly store back its changes.)SH8200 28625 MT(To process the)182 W/Times-Italic SF14828 XM(fs_read_file)SH/Times-Roman SF20038 XM(request, the filesystem server)182 W( creates a memory object and maps it into)181 W/Times-Bold SF50791 XM(its own)181 W/Times-Roman SF7200 30002 MT(address space. It then returns that memory region)74 W( through the IPC mechanism so that it will be mapped copy-on-)75 W8 SS 20919 31034 MT(7)SH10 SS 7200 31379 MT(write in the client's address space.)SH9 /Courier AF9360 32665 MT(return_t fs_read_file\050name, data, size\051)SH11520 33613 MT(string_t name;)SH11520 34561 MT(char **data;)SH11520 35509 MT(int *size;)SH9360 36457 MT({)SH11520 37405 MT(port_t new_object;)2160 W11520 39301 MT(/* Allocate a memory object \050a port\051, */)SH11520 40249 MT(/* and accept request */)SH11520 41197 MT(port_allocate\050task_self\050\051, &new_object\051;)SH11520 42145 MT(port_enable\050task_self\050\051, new_object\051;)SH11520 44041 MT(/* Perform file lookup, find current file size,*/)SH11520 44989 MT(/* record association of file to new_object */)SH11520 45937 MT(...)SH11520 47833 MT(/* Map the memory object into our address space*/)SH11520 48781 MT(vm_allocate_with_pager\050task_self\050\051, data, *size,)SH26640 49729 MT(TRUE, new_object, 0\051;)SH11520 51625 MT(return\050success\051;)SH9360 52573 MT(})SH10 /Times-Roman AF7200 53983 MT(When the)95 W/Times-Italic SF11500 XM(vm_allocate_with_pager)SH/Times-Roman SF21789 XM(call is performed, the kernel will issue)95 W( a)96 W/Times-Italic SF38798 XM(pager_init)SH/Times-Roman SF43311 XM(call. The)442 W( filesystem must)96 W7200 55360 MT(receive this message at some time, and should record the pager request port contained therein.)SH8200 57839 MT(When the application)53 W( first uses a page of the data, it generates a page fault. To fill that fault, the kernel issues a)52 W/Times-Italic SF7200 59216 MT(pager_data_request)SH/Times-Roman SF15601 XM(for that page. To fulfill this request, the data)96 W( manager responds with a)97 W/Times-Italic SF45334 XM(pager_data_provided)SH/Times-Roman SF7200 60593 MT(call.)SH10800 50 7200 69428 UL6 SS 8000 70767 MT(7)SH8 SS 8300 71076 MT(If the client were)64 W( to map the memory object into its address space using)63 W/Times-Italic SF32325 XM(vm_allocate_with_pager)SH/Times-Roman SF(, the client would not see a copy-on-write)63 W7200 72000 MT(version of the data, but would have read/write access to the memory object.)SHES%%Page: 10 11BS0 SI10 /Times-Roman AF30100 4286 MT(10)SH9 /Courier AF9360 7762 MT(void pager_data_request\050memory_object, pager_request,)SH13680 8710 MT(offset, size, access\051)SH11520 9658 MT(port_t memory_object;)SH11520 10606 MT(port_t pager_request;)SH11520 11554 MT(vm_offset_t offset;)SH11520 12502 MT(vm_size_t size;)SH11520 13450 MT(vm_prot_t access;)SH9360 14398 MT({)SH11520 15346 MT(char *data;)SH11520 17242 MT(/* Allocate disk buffer */)SH11520 18190 MT(vm_allocate\050task_self\050\051, &data, size\051;)SH11520 20086 MT(/* Lookup memory_object; find actual disk data*/)SH11520 21034 MT(disk_read\050disk_address\050memory_object, offset\051,)SH26640 21982 MT(data, size\051;)SH11520 23878 MT(/* Return the data with no locking */)SH11520 24826 MT(pager_data_provided\050pager_request, offset, data,)SH26640 25774 MT(size, VM_PROT_NONE\051;)SH11520 27670 MT(/* Deallocate disk buffer */)SH11520 28618 MT(vm_deallocate\050task_self\050\051, data, size\051;)SH9360 29566 MT(})SH10 /Times-Roman AF8200 32045 MT(The filesystem will never receive any)131 W/Times-Italic SF24260 XM(pager_data_write)SH/Times-Roman SF31807 XM(or)SH/Times-Italic SF33020 XM(pager_data_unlock)SH/Times-Roman SF41177 XM(requests. After)510 W( the application)130 W7200 33422 MT(deallocates its memory copy)52 W( of the file, the filesystem will receive a port death message for the pager request port.)53 W7200 34799 MT(It can then release its data structures and resources for this file.)SH9 /Courier AF9360 36085 MT(void port_death\050request_port\051)SH11520 37033 MT(port_t request_port;)SH9360 37981 MT({)SH11520 38929 MT(port_t memory_object;)SH11520 39877 MT(char *data;)SH11520 40825 MT(int size;)SH11520 42721 MT(/* Find the associated memory object */)SH11520 43669 MT(lookup_by_request_port\050request_port,)SH19080 44617 MT(&memory_object, &data, &size\051;)SH11520 46513 MT(/* Release resources */)SH11520 47461 MT(port_deallocate\050task_self\050\051, memory_object\051;)SH11520 48409 MT(vm_deallocate\050task_self\050\051, data, size\051;)SH9360 49357 MT(})SH11 /Times-Bold AF7200 52974 MT(4.2. Consistent Network Shared Memory Excerpt)SH10 /Times-Roman AF8200 54351 MT(In this subsection)99 W( we describe how the memory management interface might be used to implement a region of)98 W7200 55728 MT(shared memory between two clients on different hosts.)SH8200 58207 MT(In order to use the shared memory region, a client must first contact a data manager which provides)173 W( shared)174 W7200 59584 MT(memory service. In our example, the first client has made a request for a shared memory region not in use by any)57 W7200 60961 MT(other client. The shared)87 W( memory server creates a memory object \050)88 W/Times-Italic SF(i.e.)SH/Times-Roman SF(, allocates a port\051 to refer to this region and)88 W7200 62338 MT(returns that memory object, X, to the first client.)SH8 SS 51135 64472 MT(8)SH10 SS 8200 64817 MT(The second)81 W( client, running on a different host, later makes a request for the same shared memory region)80 W51535 XM(. The)410 W7200 66194 MT(shared memory server finds the memory object, X, and returns it to the second client.)SH10800 50 7200 70352 UL6 SS 8000 71691 MT(8)SH8 SS 8300 72000 MT(How it specifies that region \050e.g., by name or by use of another capability\051 is not important to the example.)SHES%%Page: 11 12BS0 SI10 /Times-Roman AF30100 4286 MT(11)SH8200 7886 MT(Each client maps the memory object X into its address space, using)123 W/Times-Italic SF36868 XM(vm_allocate_with_pager)SH/Times-Roman SF(. As)498 W( each kernel)124 W7200 9263 MT(processes that call, it makes a)56 W/Times-Italic SF19617 XM(pager_init)SH/Times-Roman SF24090 XM(call to the memory object X. The shared memory)56 W( server records each use)55 W7200 10640 MT(of X, and the pager request and name ports for those uses. Note that the Mach kernel does not await a reply from)63 W7200 12017 MT(the shared memory server, but does perform the)39 W/Times-Italic SF26924 XM(pager_init)SH/Times-Roman SF31380 XM(call before allowing the)39 W/Times-Italic SF41256 XM(vm_allocate_with_pager)SH/Times-Roman SF51489 XM(call to)39 W7200 13394 MT(complete. Also)346 W( note that while there)48 W( is only one memory object port \050X\051, there are distinct request and name ports)49 W7200 14771 MT(for each kernel.)39 W( In)326 W( this example, the shared memory server may be located on either of the clients' hosts, or on yet)38 W7200 16148 MT(another host.)SH8200 18627 MT(In the second frame, each)26 W( client takes a read fault on the same page of the shared memory region. The same page)27 W7200 20004 MT(may be mapped to different)21 W( addresses in the two clients. Each kernel makes a)20 W/Times-Italic SF38997 XM(pager_data_request)SH/Times-Roman SF47322 XM(on X, specifying)20 W7200 21381 MT(its own pager request port for X.)158 W( The shared memory server replies using the)159 W/Times-Italic SF40441 XM(pager_data_provided)SH/Times-Roman SF49516 XM(call on the)159 W7200 22758 MT(appropriate request port. Since the request only requires read access, the)27 W( shared memory server applies a write lock)26 W8 SS 18102 23790 MT(9)SH10 SS 7200 24135 MT(on the data as it is returned)21 W18502 XM(. The)290 W( shared memory server must also record all of the uses \050i.e. pager request ports\051 of)20 W7200 25512 MT(this page.)SH8200 27991 MT(In the final frame, one client attempts to write)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -