Midterm Review II
CS-202 Computer Systems
Today’s focus
2
File system recap: inode
3
Pages (page table) vs. blocks in file system
4
| Page | Block |
Purpose | Fixed size chunks in DRAM | Fixed size chunk on disk |
Manager | OS memory management | File system (inodes, bitmaps etc.) |
Size | 4 KB, also (2MB, 1GB) | 512 bytes to 4 KB (depends on FS and storage device) |
Access mech. | CPU via load/stores | File IO operations (read/write) |
Permission granularity | Pages (PTE) | File-level and directory-level permissions |
Peeking inside a partition (storage block)
5
Data blocks
B
S
i
d
I
I
I
I
0
7
I
D
D
D
D
D
D
D
8
15
D
D
D
D
D
D
D
D
16
23
D
D
D
D
D
D
D
D
24
31
D
D
D
D
D
D
D
D
32
39
D
63
D
D
D
D
D
D
D
40
47
D
D
D
D
D
D
D
D
48
55
D
D
D
D
D
D
D
D
56
Data blocks
Data blocks
Data blocks
Data blocks
Data blocks
Data blocks
Inodes
Free lists
Inode table information
6
S
I
I
I
I
I
I
I
I
inode blocks
Data blocks
Inode array / inode table
Inode
Inode number
Permissions
File size
Timestamps
…
Block pointer
Block pointers stores data block information
Data structure for multi-level indexing
7
File metadata
Inode
Direct pointer to blocks
Indirect
pointers
inode
├─ Direct Pointer → Block (data)
├─ Direct Pointer → Block (data)
├─ Single-indirect pointer → [Pointer Block] → Blocks (data)
├─ Double-indirect pointer → [Pointer Block] → [Pointer Block] → Blocks (data)
└─ Triple-indirect pointer → [Pointer Block] → [Pointer Block] → [Pointer Block] → Blocks (data)
File allocation approach: Multi-level indexing
8
S
I
I
I
I
I
I
I
I
inode blocks
Remaining blocks
Inode array
File metadata
Inode
…
…
…
…
…
…
…
…
Data blocks
Indirect block
Double indirect block
Triple indirect block
12 x 4 KB = 48 KB
1K x 4 KB = 4 MB
1K x 1K x 4 KB = 4 GB
1K x 1K x 1K x 4 KB = 4 TB
Today’s focus
9
File operation: Reading from a file
10
File operation: Writing to a file
(assuming file already exists)
11
File operation: Writing to a file
Might need to allocate new blocks:
12
Exercise: output of the program
13
Exercise: which inode blocks read/written
14
Inode blocks
Exercise: which data blocks read/written
15
Data blocks
Today’s focus
16
Simplified journaling example
Goal: Write 10 to block 0 and 5 to block 1 atomically
This does not work! Must not crash between 1 and 2 unit time
17
Time | Block 0 | Block 1 | Extra | Extra | Extra |
0 | 12 | 3 | 0 | 0 | 0 |
1 | 10 | 3 | 0 | 0 | 0 |
2 | 10 | 5 | 0 | 0 | 0 |
Simplified journaling example
Goal: Write 10 to block 0 and 5 to block 1 atomically
18
Time | Block 0 | Block 1 | Block 0’ | Block 1’ | Valid |
0 | 12 | 3 | 0 | 0 | 0 |
1 | 12 | 3 | 10 | 0 | 0 |
2 | 12 | 3 | 10 | 5 | 0 |
3 | 12 | 3 | 10 | 5 | 1 |
4 | 10 | 3 | 10 | 5 | 1 |
5 | 10 | 5 | 10 | 5 | 1 |
6 | 10 | 5 | 10 | 5 | 0 |
Extra blocks: journal
Journal commit block
Writes to journal: Journal transaction
Simplified journaling example
Goal: Write 10 to block 0 and 5 to block 1 atomically
19
Time | Block 0 | Block 1 | Block 0’ | Block 1’ | Valid |
0 | 12 | 3 | 0 | 0 | 0 |
1 | 12 | 3 | 10 | 0 | 0 |
2 | 12 | 3 | 10 | 5 | 0 |
3 | 12 | 3 | 10 | 5 | 1 |
4 | 10 | 3 | 10 | 5 | 1 |
5 | 10 | 5 | 10 | 5 | 1 |
6 | 10 | 5 | 10 | 5 | 0 |
Today’s focus
20
Canonical device
21
Status
CMD
DTA
Device registers
Device internals
Microcontroller (CPU + RAM)
Storage (ROM/flash)
Special purpose chips
Controller
// 1. spin while (STATUS == BUSY) ;� // 2. Write data to DTA register�*dtaRegister = DATA;� // 3. Write command to CMD register�*cmdRegister = COMMAND; // 4. spin�while (STATUS == BUSY) ; |
Polling-based CPU-device communication
Three points to minimize CPU spinning
22
// 1. spin while (STATUS == BUSY) ;�// 2. Write data to DTA register�*dtaRegister = DATA;�// 3. Write command to CMD register�*cmdRegister = COMMAND; // 4. spin�while (STATUS == BUSY) ; |
B
A
C
A
CPU
Disk
1
2
4
3
Time →
Device protocol at a high level
Interrupts to the rescue!
23
B
A
C
A
CPU
Disk
B
C
A
CPU
Disk
3
B
2
A
B
A
A
1
4
1
2
4
3
Time →
Time →
Transferring data to/from controller
24
B
C
A
CPU
Disk
3
B
2
A
B
A
A
1
4
Today’s focus
25
Multi-level feedback queue (MLFQ)
Goal: Supporting general purpose scheduling
Challenge: The scheduler must support both long running background threads (batch processing) and low latency foreground threads (interactive processes)
(not a lot of CPU is required but used frequently)
26
Multi-level feedback queue (MLFQ)
27
Multi-level feedback queue (MLFQ)
28
Decreasing priority
Time slice
Multi-level feedback queue (MLFQ)
Rule 1: if priority (A) > priority (B) then A runs
Rule 2: if priority (A) == priority (B) then A, B run in RR
29
Decreasing priority
Time slice
MLFQ changing priority of jobs
Rule 3: Jobs start at top priority
Rule 4: If a job A uses up total time slice, the scheduler lowers A’s priority
→ MLFQ approximates SJF
30
Handling starved tasks
Starvation
31
0
100
150
200
50
L3
L2
L1
Handling starved tasks
Starvation
Rule 5: Periodically moves all threads to the topmost queue (priority boosting)
32
0
100
150
200
50
L3
L2
L1
0
100
150
200
50
L3
L2
L1
boost
boost
boost
MLFQ: All basic rules
Set of rules adjusts priorities dynamically
Rule 1: if priority (A) > priority (B) then A runs
Rule 2: if priority (A) == priority (B) then A, B run in RR
Rule 3: Threads start at top priority
Rule 4: If a thread A uses up total time slice, the scheduler lowers A’s priority
Rule 5: Periodically moves all threads to the topmost queue (priority boosting)
33
Decreasing priority
Time slice
MLFQ question
34
Tick per time slice
Decreasing priority
L1 L2 L3
1
2
4
Thread ID | Arrival time | Length |
0 | 0 | 7 |
1 | 0 | 3 |
2 | 3 | 6 |
3 | 3 | 0.99 + IO for 4 + 5 |
MLFQ question
35
Tick per time slice
Decreasing priority
L1 L2 L3
1
2
4
Thread ID | Arrival time | Length |
0 | 0 | 7 |
1 | 0 | 3 |
2 | 3 | 6 |
3 | 3 | 0.99 + IO for 4 + 5 |
0
20
30
40
10
L3
L2
L1
boost
boost
MLFQ question
Q. When does thread 3 resumes execution after being blocked?
Q. How does priority boosting after 10 ticks affect the execution order?
Q. How does MLFQ balances short threads vs. long-running threads?
Q. If a thread repeatedly performs IO and avoids long CPU bursts, how does MLFQ treats it against CPU-bound jobs?
36
Thread ID | Arrival time | Length |
0 | 0 | 7 |
1 | 0 | 3 |
2 | 3 | 6 |
3 | 3 | 0.99 + IO for 4 + 5 |
0
20
30
40
10
L3
L2
L1
boost
boost