Chapter 3
MEMORY MANAGEMENT
[email protected]
1
Cleaning Policy
• Need for a background process, paging daemon
– periodically inspects state of memory
• When too few frames are free
– selects pages to evict using a replacement algorithm
2
Implementation Issues
Operating System Involvement with Paging
Four times when OS involved with paging
1. Process creation
determine program size
create page table
2. Process execution
MMU reset for new process
TLB flushed
3. Page fault time
determine virtual address causing fault
swap target page out, needed page in
4. Process termination time
release page table, pages
3
Page Fault Handling (1)
1. The hardware traps to the kernel, saving the program
counter on the stack.
2. An assembly code routine is started to save the
general registers and other volatile information.
3. The operating system discovers that a page fault has
occurred, and tries to discover which virtual page is
needed.
4. Once the virtual address that caused the fault is
known, the system checks to see if this address valid
and the protection consistent with the access
4
Page Fault Handling (2)
5. If the page frame selected is dirty, the page is scheduled
for transfer to the disk, and a context switch takes place.
6. When page frame is clean, operating system looks up the
disk address where the needed page is, schedules a disk
operation to bring it in.
7. When disk interrupt indicates page has arrived, page
tables updated to reflect position, frame marked as being
in normal state.
5
Page Fault Handling (3)
8. Faulting instruction backed up to state it had when
it began and program counter reset to point to that
instruction.
9. Faulting process scheduled, operating system
returns to the (assembly language) routine that
called it.
10. This routine reloads registers and other state
information and returns to user space to continue
execution, as if no fault had occurred.
6
Backing Store
(a) Paging to static swap area
(b) Backing up pages dynamically
7
Separation of Policy and Mechanism
Page fault handling with an external pager
8
Segmentation (1)
• One-dimensional address space with growing tables
• One table may bump into another 9
Segmentation (2)
Allows each table to grow or shrink, independently
10