signals & sessions 4cputnam/comp420/putnam/svr4 v…  · web view14 svr4 vm architecture. sun...

34
Unix Internals 14 SVR4 VM Architecture Sun Microsystems SunOS 4.0 Virtual Memory Memory Management Architecture provide support for memory sharing shared libraries memory-mapped files traditional file access open system call kernel creates buffer kernel reads file data to buffer in-memory copy : buffer process address space A in-memory copy : buffer process address space B C. Robert Putnam Page 1 4/28/2022 document.doc 2:17 AM Process A Page Table Process B Page Table Buffer Cache Pageable Physical Memory

Upload: others

Post on 04-Aug-2020

18 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

Unix Internals14

SVR4 VM Architecture

Sun Microsystems SunOS 4.0 Virtual Memory Memory Management Architecture provide support for memory sharing shared libraries memory-mapped files

traditional file access open system call kernel creates buffer kernel reads file data to buffer in-memory copy : buffer process address space A in-memory copy : buffer process address space B

C. Robert Putnam Page 1 5/23/2023document.doc 7:32 PM

Process APage Table

Process BPage Table

Buffer Cache Pageable Physical Memory

Page 2: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

memory-mapped files open file system call map the file into an allocated memory area (page) process A attempts to access file via memory location

o page faulto kernel reads file block into memory pageo kernel update process A page table

process A accesses file via memory page process B attempts to access file via memory location

o page faulto kernel update process B page table

no additional system calls required for read/write operations kernel may

o read additional file blocks into memoryo update the page tables

shared mappingso modifications are made directly to the shared copy of the page (mapped

object)o changes made by one process are immediately seen by other processeso page (mapped object) is written back to file when page is

flushed private mappings

o modifications make private copy of page apply modifications to private page

o page (mapped object) is not written back to file when page is flushed

C. Robert Putnam Page 2 5/23/2023document.doc 7:32 PM

Process APage Table

Process BPage Table

Pageable Physical Memory

Page 3: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

process receives its private copy of a page only when it attempts to modify it; the private copy will contain all modifications made by other process prior to the time it attempts its first write to the page

read/write system call o locks inode during data transfer

atomic operation guaranteed for entire operationo changes made by one process are seen by other processes only

after issuing another read operation

memory-mapped fileso atomic operation guaranteed for single word only o file locking & synchronization is the responsibility of cooperating

processeso process sees page contents as they are at the time of access –

not at the time the mapping was created

C. Robert Putnam Page 3 5/23/2023document.doc 7:32 PM

Process APage Table

Process BPage Table

Pageable Physical Memory

X

private shared

Page 4: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

mapping a file into memoryopen file system callmmap system call paddr = mmap(addr, len, prot, flags, fd, offset) mapping : file fd byte range memory address range [offset, offset+len) [paddr, paddr+len) flags MAP_SHARED, MAP_PRIVATE, MAP_FIXED, MAP_RENAME prot PROT_READ, PROT_WRITE, PROT_EXECUTE suitable values

o offset must be page alignedo addr must be paged alignedo addr must be within the range of valid user addresseso len will be rounded up to a multiple of the page size

MAP_FIXED not set kernel provides suitable paddr value (never zero) MAP_FIXED set

o addr is suitable paddr = addro addr is not suitable mmap returns error

mmap with MAP_RENAME flago unmaps the memory address range from the current fileo maps the memory address range to another file

munmap(addr, len) o unmaps the memory address range from the current file

mprotect(addr, len, prot) changes protections on a per-page basis

VM Design Principles memory object – map: memory region backing store backing store – data object

o swap spaceo local fileso remote fileso frame buffers

common interface to memory object – abstract base classo backing store class – derived class of base class

address space (process)

C. Robert Putnam Page 4 5/23/2023document.doc 7:32 PM

swap space backing store

class

common interface

class local files backing store

class

frame buffers backing store

class

remote files backing store

class

Page 5: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

o set of mappings to different data objectso only valid addresses are those mapped to an objecto data object provides persistent backing store for the mapped pageso mapping renders data object directly addressable by the process

mappedo object is not aware of nor affected by the mapping

file system provideso name space for memory objectso mechanisms to access their data

vnode layer allows VM subsystem to interact with file system each named memory object is associated with a unique vnode single vnode may be associated with several memory objects

memory objects not associated with files (e.g., user stacks)o do not have nameso represented by anonymous objects

physical memory serves as cache for data from mapped objects page is smallest unit of memory

address space – array of pages page is a property of address space, not of the data object VM Architecture is independent of Unix –

o all machine dependencies relegated to separate hardware address translation layer (HAT) which is accessed via a well-defined interface

o Unix semantics for text regions data regions stack regions

kernel uses copy-on-write to reduceo in-memory copy operations o the number of physical copies of a page in memory

C. Robert Putnam Page 5 5/23/2023document.doc 7:32 PM

vnodeswap spacedata object

frame buffersdata object

local file Adata object

remote file C data object

local file Bdata object

remote file D data object

are provided by the layer above the VM system

o address translation

o mapping

o allocation

o pr

Page 6: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

VM Architecture Abstractions page (struct page) address space (struct as) segment (struct seg) hardware address translation (struct hat) anonymous page (struct anon)

Physical Memory

non-paged region paged region

o array of page structureso each page structure describes one logical pageo logical page -- cluster of hardware pageso page structure must contain standard cache management information

each page is mapped to a memory object each object is represented by a vnode physical page name is defined by <vnode, offset> tuple

o specifies offset of the page in the object represented by the vnode page structure stores offset and pointer to the vnode

C. Robert Putnam Page 6 5/23/2023document.doc 7:32 PM

File System

Swap Devicevnode layer swap layer

anon layerpage layer

as layer

vnode layer

physical memory

virtual address space

struct proc

Page 7: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

page structure

or

but not both

page structure maintains o reference count of processes sharing the page

using copy-on-write semanticso synchronization flags – locked, wanted, in-transito copies of the modified and referenced bit from the HAT layero low-level interface comprising routines that o find page given the vnode and offseto move page it onto and off the hash queues and free listo synchronize assess to the page

C. Robert Putnam Page 7 5/23/2023document.doc 7:32 PM

vnode pointeroffset in the vnodehash chain pointerspointers for vnode page listpointers for free list or I/O listflagsHAT related information

list of all object pages currently in physical memory

vnode

to find physical page, pages are hashedbased on the vnode and offset; each page is on one of the hash chains

list of pages waiting to be written to disk

list of free pages

Page 8: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

Virtual Address Space of Process

struct proc

struct as

proc structure as structure linked list of seg structure mappings seg structure mappings non-overlapping page-aligned address ranges

sorted by their base addresses hat structure provides low level access to pages as structure contains

o hint as to the last segment that had a page faulto synchronization flagso address space sizeso resident set

as layer operations operations performed on entire address space

o as_alloc() allocate new address space – fork() & exec()o as_free() release address space – fork() & exec()

C. Robert Putnam Page 8 5/23/2023document.doc 7:32 PM

p_as

segment listhint

as ptrprivates_opsbasesize

private data

text

data

stack

u area

as ptrprivates_opsbasesize

as ptrprivates_opsbasesize

as ptrprivates_opsbasesize

seg_u ops

seg_vn ops

struct hat

structsegvn_data

struct seg

private data

private data

private data

structsegu_data

structsegvn_data

structsegvn_data

struct segops

Page 9: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

o as_dup() duplicate address space – fork() operations performed on range of pages within address space

o as_map() map memory objects into address space – mmap()o as_unmap() unmap memory objects from address space –

munmap()o as_setprot() set protections on portions of address spaceo as_checkprot() check protections on portions of address spaceo as_fault() starting point for page fault handlingo as_faulta() used for anticipatory paging (fault ahead)

Address Mappings address space

set of memory objects which represent mappings between backing store items and process address regions

segmento memory objecto contiguous range of virtual addresses of process

mapped to a contiguous byte range in a data object with either private or shared mappings

o represented by seg structureo interface – abstract base class

generic functions to allocate segment free segment attach segment to address space unmap segment from address space

o specific segment type – derived class specific functions to

allocate segment free segment attach segment to address space unmap segment from address space

segment structure contains public, type-independent fields of the segmento base pointero size of the address range mapped by segmento pointer to as structureo pointer to seg_ops vector

set of virtual functions that definetype-independent interface of the segment class

o pointer to type-dependent data structure which holds private type-dependent data of the segment

segments of address space maintained on doubly linked list sorted by base address

seg_ops operationso dup duplicate mapping

C. Robert Putnam Page 9 5/23/2023document.doc 7:32 PM

Page 10: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

o fault & faulta handle page faults for segmento setprot & checkprot set and check proitectionso unmap unmap segment and free its resourceso swapout called by swapper to swap out segmento sync flush all pages of segment back to

underlying data object each segment has create routine

o kernel knows the names & calling syntax of all specific create routineso kernel calls the appropriate create routine to create a segment

Anonymous Pages no permanent storage allocated created when process first modifies page that has MAP_PRIVATE mapping VM system makes private copy of page

o modifications do not change underlying objecto subsequent access to page is resolved to private copy

not to the original page swap layer provides backing store for anonymous pages discarded when process terminates or unmaps the page struct anon

o represents an anonymous pageo are reference counted since anonymous pages may be shared

segment that has an anonymous page holds a reference to the pages anon structure o if mapping is private then each segment holds separate reference to

pageo if mappings are shared then segments share the same reference to

page

Anonymous Object single anonymous object in entire system represented by NULL vnode pointer source of all zero-filled pages uninitialized data and stack regions are

MAP_PRIVATE mappings to anonymous object shared memory regions are

MAP_SHARED mappings to anonymous object anonymous object does not provide backing store for its pages first modification of page mapped to anonymous object

page becomes an anonymous page

C. Robert Putnam Page 10 5/23/2023document.doc 7:32 PM

Page 11: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

Anon Structureexports a procedural interface to VM System anon_dup() duplicates references to set of anonymous pages;

increments reference count of each anon structure in the set anon_free() releases references to set of anonymous paqges;

decrementing reference count on specified anon structures; if count reaches zero then

page is discarded and anon structure is released anon_private() makes private copy of page;

associates new anon structure with page anan_zero() creates zero-filled paqe;

associates new anon structure with page anon_getpage() resolves fault to anonymous page;

reading page back from swap space if necessary

Hardware Address Translation (HAT) Layer responsible for all address translations establish & maintain mappings required by MMU

page tables & translation buffers intermediary between the kernel & the MMU accessed via procedural interface

operations on HAT layero hat_alloc() allocate hat structureo hat_free() free hat structureo hat_dup(() duplicate the translations during fork()o hat_swapin() rebuild HAT information o hat_swapout() release HAT information

operations on a range of pages of a selected processo hat_chgprot() change protectionso hat_unload() unload or invalidate the translations;

flush corresponding TLB entrieso hat_memload() load translations for single pageo hat_devload() load trqnslations to device pages

operations on all translations of a given page for all processes sharing the pageo hat_pageunload() unloads all translations for a single page;

invalidates PTE & flushes TBL entryo hat_pagesync() updates modified & reference bits in all translations

for the page, using values in its page structure HAT layer information is redundant – it may be rebuilt at any time HAT structure is machine-dependent each physical page has a linked list of mapping chunk entries, one for each

active translation to the page; struct page holds a pointer to the mapping chain

C. Robert Putnam Page 11 5/23/2023document.doc 7:32 PM

Page 12: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

Segment Drivers collection of routines & private data that implement the segment type implement all functions defined in the segment interface segment types

o seg_vn mappings to regular files & the anonymous objecto seg_map kernel internal mappings to regular fileso seg_dev mappings to character deviceso seg_kmem miscellaneous kernel mappingso seg_u mapping the u_areao seg_objs map kernel objects into user spaceo seg_kp multithreaded system mappings

free to merge adjacent segments of the same type break segment into several smaller segments may permit protections on a per-page basis

vnode segment seg_vn maps user addresses to regular files & the anonymous object anonymous object

o NULL vnode pointer o /dev/zero

initial page fault on anonymous object returns zero-filled anonymous pageo unitialized (bbs) data regiono user stack

maps text & initialized data regions to executable file additional seg_vn segments created for

o shared memoryo files mapped with the mmap system call

each vnode segment maintains a private data structure for driver informationo current protections for segment pageso maximum protections for segment pageso mapping type – shared or privateo pointer to vnode – access to all vnode operationso file offset to beginning of the segmento anonymous map pointer – modified pages of private mappingso pointer to per-page protections array

C. Robert Putnam Page 12 5/23/2023document.doc 7:32 PM

diagram page 449 goes here

Page 13: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

kernel internal mappings seg_map Unix file access methods

o demand paging of executable files -- memory subsystem & page faults

o direct access to memory mapped files – memory subsystem & page faults

o read/write system calls to open files kernel maps the required pages of the file

into its own virtual address space using seg_map driver copies data to the processes address space seg_map driver manages its own virtual address space as a

cache; hence only recently accessed mappings will be in memory

seg_map segment – only one segment in entire systemo belongs to kernelo created during system initializationo operations

segmap_getmap() map part of vnode to a virtual address segmap_release() release mapping; writing modified data back

to disk seg_map driver

o optimized version of vnode drivero provides a quick but transitory mapping of a file to the kernel

device driver mappings seg_dev maps character devices that implement an mmap interface

o frame bufferso physical memoryo kernel virtual memoryo bus memory

only supports shared mappings

non-paged kernel mappings seg_kmem portions of kernel address space

o kernel texto kernel initialized data datao kernel uninitialized (bss) regionso dynamically allocated kernel memory

mappings are non-paged address translations do not change unless kernel unmaps the data object

multthreaded mappings seg_kp

C. Robert Putnam Page 13 5/23/2023document.doc 7:32 PM

Page 14: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

seg_kp driver allocateso thread structureso kernel stacks o light-weight process structureso red zone

single write-protected page at end of a stack prevent stack overflow

Swap Layeranon layer manages anonymous pages maintains information necessary to locate page page in memory anon structure stores pointer to page structure page swapped out swap layer manages retrieval from backing store swap_xlate() manages mapping between anon structure & outswapped

pages

swap devices local disk partition remote disk file

swapctl(int cmd, void * arg); dynamically add or remove swap device cmd : SC_ADD, SC_REMOVE, SC_LIST, SC_GETNSWP arg : pointer to swapres structure

swapres structure contains pathname to swap file

o local swap partition : pathname == device special file location of swap area in file size of swap area

R : memory residentF : free

C. Robert Putnam Page 14 5/23/2023document.doc 7:32 PM

swapinfo

vnode pointeroffsetstartendfreenext

vnode pointeroffsetstartendfreenext

R F O F F R F O

struct page struct page

Page 15: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

O : outswapped

kernel creates linked list of swapinfo structures;

one swapinfo structure for each swap device allocates array of anon structures;

one array element allocated for each page on swap device creates segment;

requests reservation of sufficient swap space (segment size)

swap layer monitors total available swap space reserves required amount of swap space from total available swap space ensures reserved space will be available when required swap_alloc()

o allocates a free swap pageo associates it with an anonymous page via the anon structureo distribute load across swap devices;

allocate swap space from different devices swap_free() frees page on anon structure swap_xlate() returns the vnode & offset of swap page provided by

the anon structure

apply VOP_GETPAGE(vnode) to retrieve the selected page from swap device

segment allocates swap space on a per-page basis,

when an anonymous page is created swap space allocations are only made against a previous reservation

SVR4 position of anon structure in the anon array

equalsposition of the swap page on the swap device

swap_alloc() returns pointer to anon structure; pointer used to locate page on swap device

C. Robert Putnam Page 15 5/23/2023document.doc 7:32 PM

F FF F F F F F F F

Page 16: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

New Mappingsexec / mmap -- new regions are mapped into address space locates vnode of file being mapped invokes VOP_MAP function vnodeops vector contains

o virtual functions -- VOP_MAP, VOP_GETPAGE, VOP_PUTPAGEo actual functions executed depend on the filesystem specified by the

vnode

VOP_MAP functiono file system specific argument checkingo checks if process has another mapping for this address rangeo as_unmap() deletes pror mappingo as_map() creates map of the file into address space

allocates seg structure calls appropriate create routine to initialize the segment

mmap function ensures that o permissions never exceed those under which the file was opened

seg structure records maximum permissions that segment is allowed mprotect checks seg structure before modifying the permissions exec()

o establishes private mappings for text regions data regions stack regions

o maps text region to the executable file with

PROT_READ & PROT_EXECUTE permissions initialized data to the executable file bss data and stack to the anonymous object

o establishes additional mappings to the shared library regions as_unmap()

o frees range of address – one or more partial or full segmentso loops through segments calling segment layer routines to unmap

pageso called by munmap() function

as_free() o releases entire address spaceo loops through segments calling segment layer routines to unmap

pageso called by exit() function

C. Robert Putnam Page 16 5/23/2023document.doc 7:32 PM

Page 17: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

Anonymous Page Handling

anonymous pages -- created when process first writes to page mapped MAP_PRIVATE to file

o pages set as read-onlyo kernel traps first write & detaches its mapping to the fileo allocates backing store on the swap device

page mapped MAP_PRIVATE to anonymous object shared memory page

vnode segment implemetation segment private data structure points to anon_map structure anon_map structure points to anon reference array anon reference array

o one entry for each page of the segmento each entry is

reference to anon structure for the corresponding page NULL if that page is not yet anonymous

anon structure o locates page in physical memory or on the swapping deviceo contains reference counto reference count == 0 page & anon structure may be deleted

seg

segvn_data

anon_map

anonymous page data structures created only upon first write to a page in the segment

C. Robert Putnam Page 17 5/23/2023document.doc 7:32 PM

s_data

basesize

0

0

memory

swap disk

anon reference array

swap device anon array struct page[ ]

Page 18: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

o many vnode segments never need to create anonymous pageso creation upon demand – lazy creation

first attempt to write to privately mapped page protection fault fault handler

o recogniizes situation since mapping type MAP_PRIVATE segment protections are not read-only

o if page is first anonymous page created for the segment, the handler allocates and initializes the

the anon_map and the anon reference array

o allocates anon structure swap space is allocated since

each anon structure corresponds to unique page on swap deviceo stores reference to anon structure in

corresponding element of anon reference arrayo makes new copy of the page using newly allocated physical pageo stores pointer to page structure for new page in anon structureo call HAT layer to load new translation for write-enabled page o translates to new copy

attempt to access page swapped to backing store protection fault fault handler

o recogniizes situation since faulting page has a reference to the anon structure uses reference to anon structure to retrieve page from the swap

device

Process Creation

fork() system call allocates & initializes proc structure

C. Robert Putnam Page 18 5/23/2023document.doc 7:32 PM

hardware address translation page protectionread-only trap write attempt

Page 19: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

invokes as_dup() function – duplicates parents address spaceo invokes as_alloc() – allocate new as structure for childo traverses segment list, for each segment

invokes dup operation of segment driver to duplicate the segment allocate new seg structure -- struct seg allocate new type-independent private data structure struct

segvn_data child inherits parents values of the following struct seg

variables base address size vnode pointer offset protection

C. Robert Putnam Page 19 5/23/2023document.doc 7:32 PM

Process A

0

1

2

3

4

ref = 2

ref = 2anon_map

segvn_data

seg0

0

ref = 2

anon reference array

Process B

0

1

2

3

4

0

0

anon reference array

seg

segvn_data

anon_map

swap device anon array

Page 20: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

struct proc

struct as

child inherits seg_ops pointer & mapping type from the parent parent & child MAP_PRIVATE mappings

text data stack

parent MAP_SHARED mappings inherited as MAP_SHARED by child

as pointer initialized as appropriate for the child

MAP_PRIVATE mappings invoke hat_chgprot() to write protect all anon pages segment driver invokes anon_dup()

C. Robert Putnam Page 20 5/23/2023document.doc 7:32 PM

p_as

segment listhint

as ptrprivates_opsbasesize

private data

text

data

stack

u area

as ptrprivates_opsbasesize

as ptrprivates_opsbasesize

as ptrprivates_opsbasesize

seg_u ops

seg_vn ops

struct hat

structsegvn_data

struct seg

private data

private data

private data

structsegu_data

structsegvn_data

structsegvn_data

struct segops

Page 21: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

anon_dup() allocates new anon_map & anon reference array

clones all references in array o by copying the pointers and o incrementing the reference counts of the

associated anon structureso after all segments have been duplicated, as_dup() invokes hat_dup()

hat_dup() duplicates the hat structure and translation information

may allocate new page tables for the child; initialize new page tables by copying them from the parent

Sharing Anonymous Pages

C. Robert Putnam Page 21 5/23/2023document.doc 7:32 PM

SVR4 retains vfork() -- faster than copy-on-write -- does not even copy mappings

Process A

0

1

2

3

4

ref = 1

ref = 1

ref = 1

ref = 2anon_map

segvn_data

seg0

0

ref = 2

anon reference array

Process B

0

1

2

3

4

0

anon reference array

seg

segvn_data

anon_map

swap device anon array

Page 22: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

Page Fault Handling

trap() routine invoked by

o protection faultso validation faults

determines o fault typeo access type -- read/writeo as structure of the faulting process

invokes as_fault() as_fault()

o locates the segment containing the faulting addresso invokes the segment drivers fault operation

as layer sorts the segments in order of increasing base address maintains a pointer to the last segment that had a fault;

locality of reference principle – initiation of new search o actual fault handling depends upon the segment typeo seg_vn segment driver fault handler segvn_fault()o segvn_fault()

converts fault address to logical page number in segment uses logical page number as an index into the

anon_map per-page protections array

protection faultso triggered by production settings in the hardware translation entry

real protection faults spurious protection faults

o segvn_fault() checks the segment’s private data area real protections for the page are contained in

page entry of the per-page protection array if not NULL segment protection structure if page entry is NULL

if access is to be denied, segvn_fault() notifies the process by sending a SIGSEGV signal

spurious protection faults hardware has deliberately disabled protection in the

hardware address translation for the page in order to implement copy-on-write sharing or reference-bit simulation

C. Robert Putnam Page 22 5/23/2023document.doc 7:32 PM

Page 23: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

segvn_fault() actions – based on the state of the page

anon_map entry exists invokes anon_getpage() anon_getpage() obtains anonymous page

o find page in memory -- anon structure points to page

o read page from swap device

anon_map entry does not exist but segment is mapped to a file

invokes VOP_GETPAGE operation on vnode VOP_GETPAGE

o searches hash queues – finds page in memoryo reads page in from disk

anon_map entry does not exist and segment is mapped to the anonymous object

invoke anon_zero() to return a zero-filled age

special cases – VOP_GETPAGE & anon_getpage() page on free list reclaim page from list page invalid wrt reference-bit simulation turn on valid

bit page in transit wait for I/O completion text pages still remaining in memory from previous

activities search hash queues based on <vnode, offset> values

segvn_fault() has pointer to page in memory check for copy-on-write

o write access attempted on private mappingand

o segment or per-page protections permit writes, ando page has no anon structure – private mapping to a file

oro anon structure has more than one reference – copy-on-write sharing

of anonymous pageso fault handler calls o anon_private() to make private copy of the pageo hat_memload() to load the new translation for the page

into the hardware translation structures

C. Robert Putnam Page 23 5/23/2023document.doc 7:32 PM

Page 24: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

Shared Memory

process o allocates a shared memory regiono attaches to the memory region

other process may attach to the memory region each process may attach the region to a different address process may attach region to multiple locations in address space memory region remains in existence until it is explicitly removed

even if no processes are attached to it shared memory region

o represented by vnode segment mapped MAP_SHARED to anonymous object

o all modifications are applied to the single shared copy of the datao immediately available to all processeso first writing attempt to page

page converted to anonymous page anonymous page backed up on swap device

C. Robert Putnam Page 24 5/23/2023document.doc 7:32 PM

Process A

ref = 1

ref = 1

anon_mapsegvn_data

seg

0

0

ref = 1

anon reference array

swap device anon array

Process B

shared memory IPC structure

ref_cnt = 4base

Process C

segseg

segvn_datasegvn_data

Page 25: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

IPC reference created when shared memory region is first allocated released when shared memory region is explicitly deleted

shmctl() system call with IPC_RMID command option anon_map holds references to individual anonymous pages reference count == 0

o all processes have detached the shared memory region from their address spaces

o region has been deletedo kernel releases

a. all anonymous pages b. anon reference array c. anon_map

C. Robert Putnam Page 25 5/23/2023document.doc 7:32 PM

Page 26: Signals & Sessions 4cputnam/Comp420/Putnam/SVR4 V…  · Web view14 SVR4 VM Architecture. Sun Microsystems . SunOS 4.0 Virtual Memory . Memory Management Architecture . provide support

Free Page Pool

C. Robert Putnam Page 26 5/23/2023document.doc 7:32 PM