Understanding Operating System Memory Management in CS 345

undefined
 
 
W
e
l
c
o
m
e
 
t
o
C
S
 
3
4
5
 
O
p
e
r
a
t
i
n
g
 
S
y
s
t
e
m
s
 
 
M
e
m
o
r
y
 
M
a
n
a
g
e
m
e
n
t
,
 
C
h
 
7
 
(
1
8
)
T
i
p
 
#
1
9
:
 
B
e
f
o
r
e
 
C
 
S
t
a
r
t
s
 
What happens when your computer boots up?
Execution starts at the reset vector.
Assembler code configures and initializes the CPU core, putting it into a clean state to avoid Lock Step exceptions when
saving state later.
MMU configured for RAM access, rest of the flash, and on-chip peripherals. Reconfiguring the TLB entries describing flash
often requires to code to be copied to and executed from RAM.
Watchdog configured to prevent timeout during initialization.
ECC RAM and caches initialized.
Variables initialized for C by copying the init values from flash to RAM.
If RAM code is needed (e.g. for flash programming functions), after copying the data cache has to be cleaned, write buffer
synchronized and instruction cache invalidated, to force it re-reading the updated code.
Call stack, C stack, small data pointer etc… have to be set up.
Then finally main() can be called.
In main(), initialization continues…
Setup interrupts and exception handling mechanisms.
Self Test Control Unit, Fault Collection and Control Unit initialized.
CPU run modes initialized, peripheral clocks enabled, and configured.
PLL set up, timing adjusted for the high clock.
Then all peripherals and subsystems have to be initialized.
Virtual Memory (18)
2
P
a
g
i
n
g
 
How is a program started?
Start a process with no pages in memory (pure demand paging).
Place in memory on a page fault.
At what point in a program’s execution can a page fault occur?
instruction fetch
operand fetch
operand store (any memory reference)
What is the worse case of page faulting?
VLIW or CISC instruction: Add C,A,B (C = A + B)
Instruction and all operands on different pages
4 possible page faults   )-: slooooow :-(
Virtual Memory (18)
3
S
i
m
p
l
e
 
P
a
g
i
n
g
Virtual Memory (18)
4
P
a
g
e
 
T
a
b
l
e
 
P
t
r
+
F
r
a
m
e
 
#
 
|
 
O
f
f
s
e
t
 
M
a
i
n
 
M
e
m
o
r
y
 
Use page number as an index into the page table, which then contains the
physical frame holding that page.
Typical Flag bits: Present, Accessed, Modified, various protection-related
bits.
 
Logical Address
 
Physical Address
P
a
g
i
n
g
 
H
a
r
d
w
a
r
e
 
How large are page tables?
4G address space with 4K pages requires 4M entries (2
32
 / 2
12
 = 2
22
)
8 byte page table entry 

Virtual Memory (18)
5
 
Solutions?
Put page tables in VM space.
Most systems use multilevel page tables
Top level page table validates entire address space.
Second level page table only used if that part for part of address space.
Second level tables can 
 
also be used for shared libraries.
M
u
l
t
i
-
l
e
v
e
l
 
S
i
m
p
l
e
 
P
a
g
i
n
g
 
Use page number as an index into the page table, which then contains
the physical frame holding that page
Virtual Memory (18)
 
Logical Address
 
Physical Address
6
undefined
 
Simple Paging Exercise
 
logical address
 
physical address
 
page table
 
Consider a simple (1 level) byte addressable paging system with the following
parameters: 2
24
 bytes of physical memory; page/frame size of 2
11
 bytes; 2
9
 pages of
logical address space.
 
a.
How many bits are in a logical address?
b.
How many bytes in a frame?
c.
How many bits in the physical address specify the frame #?
d.
What is the size of the logical address space?
e.
How many bits in each page table entry?  (Include valid, dirty, and pin bits.)
f.
 
What is the size of a page table?
undefined
Simple Paging Exercise
logical address
physical address
page table
 
9 bits    |   11 bits
 
13 bits            |   11 bits
 
vdp|   13 bits
 
2
9
 pages + 2
11
 bytes/page = 20 bits
 
2
11
 = 2048 bytes
 
24 - 11 = 13 bits
 
2
9+11
 = 1,048,576 bytes
 
24 - 11 + 3 = 16 bits
 
2
9
 × 2
 = 1024 bytes
Consider a simple (1 level) byte addressable paging system with the following
parameters: 2
24
 bytes of physical memory; page/frame size of 2
11
 bytes; 2
9
 pages of
logical address space.
a.
How many bits are in a logical address?
b.
How many bytes in a frame?
c.
How many bits in the physical address specify the frame #?
d.
What is the size of the logical address space?
e.
How many bits in each page table entry?  (Include valid, dirty, and pin bits.)
f.
 
What is the size of a page table?
M
e
m
o
r
y
 
R
e
f
e
r
e
n
c
e
s
Virtual Memory (18)
9
undefined
10
10
C
P
U
M
M
U
M
M
-
1
M
-
2
M
a
i
n
M
e
m
o
r
y
S
e
c
o
n
d
a
r
y
S
t
o
r
a
g
e
0
1
2
P
a
g
e
 
T
a
b
l
e
T
L
B
 
R
e
p
l
a
c
e
m
e
n
t
 
A
l
g
o
r
i
t
h
m
s
 
Random (RAND)
choose any page to replace at random
Belady’s Optimal Algorithm
best but unrealizable – used for comparison
First-In, First-Out (FIFO)
for the dogs, forget ‘em
Least Frequently Used (LFU)
strictly a straw-man for stack algorithms
Least Recently Used (LRU)
discard pages we have probably lost interest in
Clock – Not Recently Used (NRU)
efficient software LRU
 
Virtual Memory (18)
 
11
11
undefined
Be Safe
Slide Note
Embed
Share

This content delves into the intricate processes that occur when a computer boots up, the concept of virtual memory, demand paging, page faults, and simple paging in operating systems memory management. It discusses the initialization steps, paging mechanisms, and hardware considerations involved in managing memory efficiently to optimize system performance.


Uploaded on Aug 14, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Welcome to CS 345 Operating Systems Memory Management, Ch 7 (18)

  2. Tip #19: Before C Starts 2 Virtual Memory (18) What happens when your computer boots up? Execution starts at the reset vector. Assembler code configures and initializes the CPU core, putting it into a clean state to avoid Lock Step exceptions when saving state later. MMU configured for RAM access, rest of the flash, and on-chip peripherals. Reconfiguring the TLB entries describing flash often requires to code to be copied to and executed from RAM. Watchdog configured to prevent timeout during initialization. ECC RAM and caches initialized. Variables initialized for C by copying the init values from flash to RAM. If RAM code is needed (e.g. for flash programming functions), after copying the data cache has to be cleaned, write buffer synchronized and instruction cache invalidated, to force it re-reading the updated code. Call stack, C stack, small data pointer etc have to be set up. Then finally main() can be called. In main(), initialization continues Setup interrupts and exception handling mechanisms. Self Test Control Unit, Fault Collection and Control Unit initialized. CPU run modes initialized, peripheral clocks enabled, and configured. PLL set up, timing adjusted for the high clock. Then all peripherals and subsystems have to be initialized.

  3. Paging 3 Virtual Memory (18) How is a program started? Start a process with no pages in memory (pure demand paging). Place in memory on a page fault. At what point in a program s execution can a page fault occur? instruction fetch operand fetch operand store (any memory reference) What is the worse case of page faulting? VLIW or CISC instruction: Add C,A,B (C = A + B) Instruction and all operands on different pages 4 possible page faults )-: slooooow :-(

  4. Simple Paging 4 Virtual Memory (18) Use page number as an index into the page table, which then contains the physical frame holding that page. Typical Flag bits: Present, Accessed, Modified, various protection-related bits. Logical Address Page # Offset Main Memory + Frane # | Flags Frame # | Offset Physical Address Page Table Ptr

  5. Paging Hardware 5 Virtual Memory (18) How large are page tables? 4G address space with 4K pages requires 4M entries (232 / 212 = 222) 8 byte page table entry 4M entries = 32M memory Solutions? Put page tables in VM space. Most systems use multilevel page tables Top level page table validates entire address space. Second level page table only used if that part for part of address space. Second level tables can also be used for shared libraries.

  6. Multi-level Simple Paging 6 Virtual Memory (18) Use page number as an index into the page table, which then contains the physical frame holding that page Logical Address Physical Address

  7. Simple Paging Exercise Consider a simple (1 level) byte addressable paging system with the following parameters: 224 bytes of physical memory; page/frame size of 211 bytes; 29 pages of logical address space. page table logical address physical address ... a. How many bits are in a logical address? b. How many bytes in a frame? c. How many bits in the physical address specify the frame #? d. What is the size of the logical address space? e. How many bits in each page table entry? (Include valid, dirty, and pin bits.) f. What is the size of a page table?

  8. Simple Paging Exercise Consider a simple (1 level) byte addressable paging system with the following parameters: 224 bytes of physical memory; page/frame size of 211 bytes; 29 pages of logical address space. page table logical address 9 bits | 11 bits physical address 13 bits | 11 bits vdp| 13 bits ... 29pages + 211bytes/page = 20 bits a. How many bits are in a logical address? 211 = 2048 bytes b. How many bytes in a frame? 24 - 11 = 13 bits c. How many bits in the physical address specify the frame #? d. What is the size of the logical address space? 29+11 = 1,048,576 bytes e. How many bits in each page table entry? (Include valid, dirty, and pin bits.) 24 - 11 + 3 = 16 bits 29 2 = 1024 bytes f. What is the size of a page table?

  9. Memory References 9 Virtual Memory (18) Check TLB for resolved address. If found, append offset and return physical address. If TLB miss, index into page table. If hit, append offset and return physical address. If page table miss (page fault), either find free frame or unload a frame, read referenced page into frame (if in secondary memory), update page table and TLB, append offset and return physical address.

  10. 10 Segmentation Fault 3a. Page Hit M M-1 M-2 0 1 2 Page Table Main Memory 3b. Invalid Page Request 1. Virtual Address CPU TLB 12345678 Secondary Storage MMU

  11. Replacement Algorithms 11 Virtual Memory (18) Random (RAND) choose any page to replace at random Belady s Optimal Algorithm best but unrealizable used for comparison First-In, First-Out (FIFO) for the dogs, forget em Least Frequently Used (LFU) strictly a straw-man for stack algorithms Least Recently Used (LRU) discard pages we have probably lost interest in Clock Not Recently Used (NRU) efficient software LRU

  12. Be Safe

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#