Operating Systems ECE344

Download Report

Transcript Operating Systems ECE344

Operating Systems
ECE344
Lab assignment 3: Memory management
Ding Yuan
Overview
• The most challenging problem for any OS
• You need to implement all (yes, I mean ALL) the memory
management features we discussed
–
–
–
–
–
Page table (possibly two-level)
TLB management
Handling TLB miss
Copy-on-write
Demand paging
• Load the pages from disk on demand
• Swapout when RAM is full
– Smart page replacement
Ding Yuan, ECE344 Operating System
2
MIPS TLB Management
• Software managed TLB
– OS handles TLB fault
• How?
vm_fault(int faulttype, vaddr_t faultaddress)
• Difference with x86 (hw. managed TLB)
– Do you need to worry about “page fault”?
– When you design your two-level page-table, do you
still need to use only physical addr. in master PT?
– Do you still need to store the addr. of master PT in a
register on every context switch?
Ding Yuan, ECE344 Operating System
3
Challenges
• All the challenges you faced in lab 2 will come back
– E.g., debugging user/kernel mode transition,
synchronization, memory leak, etc.
• In addition:
Last-minute hacking without a clear
design in mind will guarantee you a
– Non-trivial designs
wild goose chase
• Coremap data structure
• Page table data structure
• Replacement policy
– Debugging memory-related bugs is hard
• TLB look-up is out of your control
Ding Yuan, ECE344 Operating System
4
A few hints
• You only need to implement invalidation-based
TLB on context switches
• Implementing swap requires access to filesystem
struct vnode* swap_file;
vfs_open("lhd0raw:", O_RDWR, &swap_file);
// You can also use a regular filename
VOP_WRITE(swap_file, uio);
VOP_READ(swap_file, uio);
Ding Yuan, ECE344 Operating System
5
Advices
• Start early!
• Read code
– Understand how dumbvm works will take you a loooooong way
• Explicitly assert all your assumptions
– Debugging MM is frustrating
– The most frustrating bugs are the ones with long propagation
– Stop the errors early!
• Be careful with kprintf!
• No deadline extensions!
– The prof. is a mean person…
• Don’t drink too much coffee 
Ding Yuan, ECE344 Operating System
6