MACHINEINDEPENDENT VIRTUAL MEMORY MANAGEMENT FOR PAGED UNIPROCESSOR AND

  • Slides: 29
Download presentation
MACHINE-INDEPENDENT VIRTUAL MEMORY MANAGEMENT FOR PAGED UNIPROCESSOR AND MULTIPROCESSOR ARCHITECTURES R. Rashid, A. Tevanian,

MACHINE-INDEPENDENT VIRTUAL MEMORY MANAGEMENT FOR PAGED UNIPROCESSOR AND MULTIPROCESSOR ARCHITECTURES R. Rashid, A. Tevanian, M. Young, D. Golub, R. Baron, D. Black, W. Bolosky and J. Chew CMU

Paper overview n n n Presents the Mach virtual memory system Three most important

Paper overview n n n Presents the Mach virtual memory system Three most important issues: ¨ External pagers to support mapped files ¨ Concept of inheritance ¨ Copy on write Shortened version of Avadis Tevanian’s dissertation

General Objectives n To be as portable as the UNIX virtual memory system while

General Objectives n To be as portable as the UNIX virtual memory system while supporting more functionality: ¨ Mapped files ¨ Threads through page inheritance n To support multiprocessing, distributed systems and large address spaces

VM and I/O Buffering (I) n Current situation: Process in main memory System calls

VM and I/O Buffering (I) n Current situation: Process in main memory System calls I/O Virtual Memory buffer Swap area Disk Drive

VM and I/O Buffering (II) n In a VM system, we have ¨ Implicit

VM and I/O Buffering (II) n In a VM system, we have ¨ Implicit transfers of data between main memory and swap area (page faults, etc. ) ¨ Implicit transfers of information between the disk drive and the system I/O buffer ¨ Explicit transfers of information between the I/O buffer and the process address space

VM and I/O Buffering (III) n n n I/O buffering greatly reduces number of

VM and I/O Buffering (III) n n n I/O buffering greatly reduces number of disk accesses Each I/O request must still be serviced by the OS: ¨ Two context switches per I/O request A better solution consists of mapping files in the process virtual address space

Mapped files (I) Process in main memory Usual VM Pager “External” Pager Swap area

Mapped files (I) Process in main memory Usual VM Pager “External” Pager Swap area Disk Driv e

Mapped files (II) n n When a process opens a file, the whole file

Mapped files (II) n n When a process opens a file, the whole file is mapped into the process virtual address space ¨ No data transfer takes place File blocks are brought in memory on demand File contents are accessed using regular program instructions (or library functions) Shared files are in shared memory segments

Mach implementation Process virtual address space Usual VM Pager Swap area “External” Pager File

Mach implementation Process virtual address space Usual VM Pager Swap area “External” Pager File Syste m

Comments n n n Solution requires very large address spaces Most programs will continue

Comments n n n Solution requires very large address spaces Most programs will continue to access files through calls to read() and write() ¨ Function calls instead of system calls Two major problems ¨ Harder to know the exact size of a file ¨ Much harder to emulate the UNIX consistency model in a distributed file system n How can we have atomic writes?

Threads n n Also known as lightweight processes Share the address space of their

Threads n n Also known as lightweight processes Share the address space of their parent Can be ¨ Kernel-supported ¨ Implemented at user level Kernel-supported threads are essential in multiprocessor architectures

Mach VM user interface n Consistent on all machines supporting Mach: including the features

Mach VM user interface n Consistent on all machines supporting Mach: including the features that cannot be efficiently implemented on a specific hardware n Full support for multiprocessing: thread support, efficient data sharing mechanisms, etc. . n Modular paging: external pagers are allowed to implement file mapping or recoverable virtual memory (for transaction management).

VM IMPLEMENTATION n n n Main implementation problem was hardware incompatibilities BSD VM implementation

VM IMPLEMENTATION n n n Main implementation problem was hardware incompatibilities BSD VM implementation was tailored to VAX hardware (and its lack of a page-referenced bit) Mach designers wanted a design that would be architecture neutral ¨ Many competing microprocessor architectures were then available

Data structures n n Resident page table: keeps track of Mach pages residing in

Data structures n n Resident page table: keeps track of Mach pages residing in main memory Memory object: a unit of backing storage such as a disk file or a swap area Address map: a doubly linked list of map entries each of which maps a range of virtual addresses to a region of a memory object P-map: the memory-mapping data structure used by the hardware

The address map First Current Last VM From To Object Offset Protection Inheritance Previous

The address map First Current Last VM From To Object Offset Protection Inheritance Previous Next could map code segment (inheritance = share) VM From To Object Offset Protection Inheritance Previous Next could map stack segment (inheritance = copy)

Protection n One protection field per range of pages Combination of read, write and

Protection n One protection field per range of pages Combination of read, write and execute permissions Comprises ¨ The current protection of pages in the range, ¨ Their maximum protection n Current protection cannot include permissions that are not included in the maximum protection (!!!) Cannot grant more rights than a given maximum

Inheritance (I) n n After a regular UNIX fork() ¨ code segment is shared

Inheritance (I) n n After a regular UNIX fork() ¨ code segment is shared between parent and child ¨ child inherits a copy of data segment of parent Mach inheritance attribute specifies if pages in a given range of addresses are to be shared, copied or ignored

Inheritance (II) n n Pages of a mapped file are always shared between parent

Inheritance (II) n n Pages of a mapped file are always shared between parent and child to preserve file sharing semantics Pages in the data segment can either be ¨ copied to maintain UNIX fork() semantics ¨ shared if we want to create a thread instead of a regular UNIX process

Lazy evaluation n n Mach VM system postpones execution of tasks whenever possible Approach

Lazy evaluation n n Mach VM system postpones execution of tasks whenever possible Approach is based on the belief that task is likely to become unnecessary ¨ copying whole data segment of parent process in a fork() that is very likely to be followed by an exec() ¨ Mach uses copy-on-write

Copy on write (I) n Already present in Accent n Best solution for efficient

Copy on write (I) n Already present in Accent n Best solution for efficient implementation of UNIX fork() n When Mach is told to copy a range of pages, it lets processes share the same copy of each page but traps write accesses n Only pages that are modified are copied

Copy on write (II) Process A and B share a range of pages X

Copy on write (II) Process A and B share a range of pages X COW creates new co Process B tries to modify shared page

Copy-on-write (III) n Uses shadow objects to keep track of which pages were modified

Copy-on-write (III) n Uses shadow objects to keep track of which pages were modified after a copy-on-write fault ¨ Only contain pointers to modified pages n Shadow objects can themselves be shadowed by future copy-on-write faults ¨ Creates shadow chains That’s all you need to know.

Page replacement policy (I) Global pool of pages FIFO Expelled pages Reclaimed pages Global

Page replacement policy (I) Global pool of pages FIFO Expelled pages Reclaimed pages Global Queue Disk

Page replacement policy (II) n n Similar to that of VAX VMS ¨ Requires

Page replacement policy (II) n n Similar to that of VAX VMS ¨ Requires little hardware support Major change is global FIFO pool replacing resident sets of all programs ¨ Much easier to tune ¨ Does not support real-time processes ¨ Can use external pagers

Locks and deadlocks n n Mach VM algorithms rely on locks to achieve exclusive

Locks and deadlocks n n Mach VM algorithms rely on locks to achieve exclusive access to kernel data structures ¨ Price to pay for a parallel kernel To prevent deadlocks, all algorithms gain locks using the same linear ordering ¨ Well known deadlock prevention technique

Miscellanea n Total size of the machine-dependent part of Mach VM implementation is about

Miscellanea n Total size of the machine-dependent part of Mach VM implementation is about 16 Kbytes. n Copy-on-write is used to implement efficient message passing : ¨ Messages are shared by sender and receiver until either of them modifies the data. n Shared libraries are supported through the mapped file interface

Problem with inverted page table n n IBM RT had a single inverted page

Problem with inverted page table n n IBM RT had a single inverted page table for its whole memory ¨ One page table entry per page frame ¨ A page frame could not belong to two processes at the same time Cannot implement shared pages in an efficient fashion ¨ Mach still offers the feature

FINAL COMMENTS n n Paper is hard to read but covers a lot of

FINAL COMMENTS n n Paper is hard to read but covers a lot of ground You should at least understand ¨ mapped files ¨ external pagers and memory objects ¨ the concept of inheritance ¨ copy-on-write ¨ the Mach page replacement policy

More about Mach n n Mach provides UNIX emulation through either ¨ a UNIX

More about Mach n n Mach provides UNIX emulation through either ¨ a UNIX emulator in the kernel ¨ a UNIX emulation server in user space Even tried to emulate UNIX through a set of specific servers, all in user space ¨ GNU’s HURD