3 Memory Management (E Next - In)
3 Memory Management (E Next - In)
Chapter 3
https://E-next.in
Memory
• Paraphrase of Parkinson’s Law, ‘‘Programs
expand to fill the memory available to hold
them.’’
• Average home computer nowadays has
10,000 times more memory than the IBM
7094, the largest computer in the world in the
early 1960s
https://E-next.in
No Memory Abstraction
https://E-next.in
Swapping (1)
https://E-next.in
Memory Management with Linked Lists
• First fit
• Next fit
• Best fit
• Worst fit
• Quick fit
https://E-next.in
Virtual Memory
• There is a need to run programs that are too
large to fit in memory
• Solution adopted in the 1960s, split programs
into little pieces, called overlays
– Kept on the disk, swapped in and out of memory
• Virtual memory : each program has its own
address space, broken up into chunks called
pages
https://E-next.in
Paging (1)
Figure 3-8. The position and function of the MMU. Here the
MMU is shown as being a part of the CPU chip because
it commonly is nowadays. However, logically it
could be a separate chip and was years ago.
https://E-next.in
Paging (2)
https://E-next.in
Structure of a Page Table Entry
https://E-next.in
Speeding Up Paging
Major issues faced:
1. The mapping from virtual address to physical
address must be fast.
2. If the virtual address space is large, the page
table will be large.
https://E-next.in
Translation Lookaside Buffers
https://E-next.in
Multilevel
Page Tables
https://E-next.in
Inverted Page Tables
https://E-next.in
Not Recently Used Algorithm
• At page fault, system inspects pages
• Categories of pages based on the current
values of their R and M bits:
Class 0: not referenced, not modified.
Class 1: not referenced, modified.
Class 2: referenced, not modified.
Class 3: referenced, modified.
https://E-next.in
Second-Chance Algorithm
https://E-next.in
Clock Page Replacement Algorithm
https://E-next.in
Simulating LRU in Software
Figure 3-18. The working set is the set of pages used by the k
most recent memory references. The function w(k, t) is the
size of the working set at time t.
https://E-next.in
Working Set Algorithm (2)
https://E-next.in
WSClock Algorithm (1)
https://E-next.in
Local versus Global Allocation Policies (1)
https://E-next.in
Separate Instruction and Data Spaces
https://E-next.in
Page Fault Handling (1)
1. The hardware traps to kernel, saving program
counter on stack.
2. Assembly code routine started to save
general registers and other volatile info
3. system discovers page fault has occurred,
tries to discover which virtual page needed
4. Once virtual address caused fault is known,
system checks to see if address valid and the
protection consistent with access
https://E-next.in
Page Fault Handling (2)
5. If frame selected dirty, page is scheduled for
transfer to disk, context switch takes place,
suspending faulting process
6. As soon as frame clean, operating system
looks up disk address where needed page is,
schedules disk operation to bring it in.
7. When disk interrupt indicates page has
arrived, tables updated to reflect position,
and frame marked as being in normal state.
https://E-next.in
Page Fault Handling (3)
8. Faulting instruction backed up to state it had
when it began and program counter is reset
9. Faulting process is scheduled, operating
system returns to routine that called it.
10. Routine reloads registers and other state
information, returns to user space to
continue execution
https://E-next.in
Instruction Backup
https://E-next.in
Backing Store
https://E-next.in
Separation of Policy and Mechanism (2)
https://E-next.in
Segmentation (1)
Examples of tables generated by compiler:
1. The source text being saved for the printed listing
2. The symbol table, names and attributes of
variables.
3. The table containing integer and floating-point
constants used.
4. The parse tree, syntactic analysis of the program.
5. The stack used for procedure calls within compiler.
https://E-next.in
Segmentation (2)
https://E-next.in
Segmentation with Paging: MULTICS (4)
https://E-next.in
Segmentation with Paging:
The Intel x86 (2)
Chapter 3
https://E-next.in