Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems /...
-
Upload
noe-nutter -
Category
Documents
-
view
215 -
download
0
Transcript of Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems /...
![Page 1: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/1.jpg)
Discussion Week 7TA: Kyle Dewey
![Page 2: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/2.jpg)
Overview
•Midterm debriefing
•Virtual memory
•Virtual Filesystems / Disk I/O
•Project #3
![Page 3: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/3.jpg)
How was the midterm?
![Page 4: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/4.jpg)
Recap
•Implemented a page table in Project #2
•Provides a mechanism for virtualizing memory
![Page 5: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/5.jpg)
Without Virtual Memory
![Page 6: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/6.jpg)
P1 Enters
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
P1P1
P1P1
Requests 2 Pages
![Page 7: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/7.jpg)
P2 Enters
FreeFree
FreeFree
FreeFree
FreeFree
P1P1
P1P1
P2P2
P2P2
FreeFree
FreeFree
P1P1
P1P1
FreeFree
FreeFree
FreeFree
FreeFree
P1P1
P1P1
Requests 2 Pages
![Page 8: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/8.jpg)
P1 Exits
FreeFree
FreeFree
FreeFree
FreeFree
P2P2
P2P2
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
P1P1
P1P1
P2P2
P2P2
FreeFree
FreeFree
P1P1
P1P1
FreeFree
FreeFree
2 Pages Freed
![Page 9: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/9.jpg)
P3 Enters
Requests 3 PagesFreeFree
FreeFree
FreeFree
FreeFree
P2P2
P2P2
FreeFree
FreeFree
FreeFree
FreeFree
???
![Page 10: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/10.jpg)
Problem
•Not enough contiguous free memory to allocate request
•Plenty of free memory in total
•This is external fragmentation
![Page 11: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/11.jpg)
VM Advantage
•Avoids external fragmentation
•Far more flexible
![Page 12: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/12.jpg)
Paging
•Way to exploit virtual memory
•Idea: use memory as a cache for the whole disk
•Virtual memory makes this caching transparent to processes
![Page 13: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/13.jpg)
Paging Details
•In an ideal world, each page has the following bits:
•Valid?
•Dirty?
•Referenced?
•NACHOS is an ideal world
![Page 14: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/14.jpg)
Valid Bit
•Project #2: does this process have access to the given page?
•Modern OS / Project #3: is this page in memory and/or does this process have access to it?
![Page 15: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/15.jpg)
Valid Bit Example
![Page 16: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/16.jpg)
What of Permissions?
•Reference to page with invalid bit set traps to OS anyway
•More accurately, it’s a “Trap to OS on Use” bit
•Still need to check if caller can access page
![Page 17: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/17.jpg)
Dirty Bit•Consider the lifetime of a page
DiskDisk
UsedUsed
FreeFree
FreeFree
FreeFree
UsedUsed
UsedUsed
UsedUsed
UsedUsedDiskDisk
Page Swapped In Page Swapped Out
![Page 18: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/18.jpg)
Swapping Out
•What if a page is read-only?
•What if a page was never modified since being swapped in?
•In these cases, we end up paging out information that is the same as what is already on disk
•Complete waste!
![Page 19: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/19.jpg)
Dirty Bit
•If a page is modified, the dirty bit is set (by hardware)
•Only write out if dirty bit is set
•Potentially cuts I/O on paging in half
![Page 20: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/20.jpg)
Referenced Bit
•If a page is used, set the referenced bit (by hardware)
•Allow software to reset the bit
•Makes certain algorithms easier to implement
![Page 21: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/21.jpg)
Question: Can kernel pages be
paged out?
![Page 22: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/22.jpg)
Project #3 Task I
•Implement paging with either FIFO with second chance or LRU
•Step-by-step implementation instructions included
![Page 23: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/23.jpg)
n Stages in Demand Paging
1. Trap to the operating system
2. Save the user registers and process state
3. Determine that the interrupt was a page fault
4. Check that the page reference was legal and determine the location of the page on the disk
5. Issue a read from the disk to a free frame:
1. Wait in a queue for this device until the read request is serviced
2. Wait for the device seek and/or latency time
• Begin the transfer of the page to a free frame
6. While waiting, allocate the CPU to some other user
7. Receive an interrupt from the disk I/O subsystem (I/O completed)
8. Save the registers and process state for the other user
9. Determine that the interrupt was from the disk
10.Correct the page table and other tables to show page is now in memory
11.Wait for the CPU to be allocated to this process again
12.Restore the user registers, process state, and new page table, and then resume the interrupted instruction
![Page 24: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/24.jpg)
Virtual Filesystems
![Page 25: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/25.jpg)
Behold!
[kyledewey@csil ~]$ df -hFilesystem Size Used Avail Use% Mounted on/dev/sda6 26G 8.9G 16G 37% /tmpfs 4.0G 1.4M 4.0G 1% /dev/shm/dev/sda1 504M 68M 411M 15% /boot/dev/sda7 26G 2.7G 22G 12% /local/dev/sda3 4.0G 137M 3.7G 4% /tmp/dev/sda2 7.9G 1011M 6.5G 14% /varodin:/local/home/faculty 268G 171G 84G 68% /cs/facultyletters:/spool/mail 268G 62G 194G 25% /cs/mailfrigga:/local/home/student 268G 252G 3.3G 99% /cs/studentfrigga:/local/home/class 268G 252G 3.3G 99% /cs/classhal1.engr.ucsb.edu:/fs.real/hal1a/home 4.5T 1006G 3.3T 24% /fs/home1offside:/local/home 547G 451G 69G 87% /cs/arch[kyledewey@csil ~]$ ls /csarch class faculty mail student[kyledewey@csil ~]$
![Page 26: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/26.jpg)
Virtual Filesystem
•Puts underlying filesystems into a single, consistent view
•Object-oriented design at its best
![Page 27: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/27.jpg)
Design Hierarchyopen(), read()...
(OS Specific)
(FS specifi
c)
![Page 28: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/28.jpg)
Advantage
•Easy to extend to multiple filesystems
•LOTS of code sharing possible (caching, file management, ...)
![Page 29: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/29.jpg)
Storing Files
•Similar problems as with physical memory
•Differences:
•Access times are MUCH slower
•Much better performance if accessing contiguous blocks
![Page 30: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/30.jpg)
F1 Written
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
F1F1
F1F1
2 Bytes Long
![Page 31: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/31.jpg)
F2 Written
FreeFree
FreeFree
FreeFree
FreeFree
P1P1
P1P1
F2F2
F2F2
FreeFree
FreeFree
F1F1
F1F1
FreeFree
FreeFree
FreeFree
FreeFree
F1F1
F1F1
2 Bytes Long
![Page 32: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/32.jpg)
F1 is Deleted
FreeFree
FreeFree
FreeFree
FreeFree
F2F2
F2F2
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
FreeFree
P1P1
P1P1
F2F2
F2F2
FreeFree
FreeFree
F1F1
F1F1
FreeFree
FreeFree
2 Bytes Freed
![Page 33: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/33.jpg)
P3 Written
3 Bytes WrittenFreeFree
FreeFree
FreeFree
FreeFree
P2P2
P2P2
FreeFree
FreeFree
FreeFree
FreeFree
???
![Page 34: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/34.jpg)
Solution
•Indirection in much the same way as virtual memory
•This is what the File Allocation Table (FAT) filesystem is named for
![Page 35: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/35.jpg)
FAT
•Separates disks into blocks
•Intuitively, blocks are to disk as pages are to memory
•The number afterward defines the number of bits used for an entry
![Page 36: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/36.jpg)
FAT
BlockBlock Next Next BlockBlock
0 ∞1 32 93 64 -15 -16 ∞7 -18 ∞9 8
Next BlockNext Block∞
3
9
6
-1
-1
∞
-1
∞
8
Intuitively Actually Stored
![Page 37: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/37.jpg)
Issues
•Fragile with respect to faults
•Worst case: entire FAT must be read for a single file
•seek() is actually O(n), where n is the number of blocks used in a file
![Page 38: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/38.jpg)
Tradeoff
•Represent some blocks directly, others indirectly
•Make the whole file metadata fit into one block
•UNIX inodes usually do this
![Page 39: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/39.jpg)
UNIX inode
![Page 40: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/40.jpg)
Advantages
•For small files, only direct blocks are needed
•seek() will be O(1)
•Still can represent large files
•seek() will be either O(1) or O(n), depending how far into the file we are seeking
![Page 41: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/41.jpg)
Relevance to NACHOS
•NACHOS has file size limitation of 4 Kb
•Need to extend to 100 Kb
•Will involve adding an indirect level on top of existing direct level
![Page 42: Discussion Week 7 TA: Kyle Dewey. Overview Midterm debriefing Virtual memory Virtual Filesystems / Disk I/O Project #3.](https://reader035.fdocuments.in/reader035/viewer/2022062803/56649c7d5503460f949324ac/html5/thumbnails/42.jpg)
Project #3 Implementation
Notes