CS 4284 Systems Capstone Disks & File Systems Godmar Back.

Slides:



Advertisements
Similar presentations
Disks Disk Hardware (1) Disk parameters for the original IBM PC floppy disk and a Western Digital WD hard disk.
Advertisements

CSCC69: Operating Systems
Buffer management.
Segmentation and Paging Considerations
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
1 File Systems Chapter Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems.
Lecture 17 I/O Optimization. Disk Organization Tracks: concentric rings around disk surface Sectors: arc of track, minimum unit of transfer Cylinder:
Recap of Feb 25: Physical Storage Media Issues are speed, cost, reliability Media types: –Primary storage (volatile): Cache, Main Memory –Secondary or.
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
Disks.
OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.
12.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 12: Mass-Storage Systems.
Disk and I/O Management
File System. NET+OS 6 File System Architecture Design Goals File System Layer Design Storage Services Layer Design RAM Services Layer Design Flash Services.
CS 346 – Chapter 10 Mass storage –Advantages? –Disk features –Disk scheduling –Disk formatting –Managing swap space –RAID.
Disk Structure Disk drives are addressed as large one- dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer.
I/O Management and Disk Structure Introduction to Operating Systems: Module 14.
CS 3204 Operating Systems Godmar Back Lecture 20.
CS 4284 Systems Capstone Project 4 Hints.
CS 3204 Operating Systems Godmar Back Lecture 22.
Chapter 21 Virtual Memoey: Policies Chien-Chung Shen CIS, UD
Lecture 3 Page 1 CS 111 Online Disk Drives An especially important and complex form of I/O device Still the primary method of providing stable storage.
CS 3204 Operating Systems Godmar Back Lecture 21.
Processes and Virtual Memory
1.  Disk Structure Disk Structure  Disk Scheduling Disk Scheduling  FCFS FCFS  SSTF SSTF  SCAN SCAN  C-SCAN C-SCAN  C-LOOK C-LOOK  Selecting a.
Chapter 14: Mass-Storage Systems Disk Structure. Disk Scheduling. RAID.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 7 – Buffer Management.
Disk Systems Operating Systems 1 Computer Science Dept Va Tech August 2007 ©2007 Back What Disks Look Like Hitachi Deskstar T7K500 SATA.
CS 3204 Operating Systems Godmar Back Lecture 18.
1 Chapter 11 I/O Management and Disk Scheduling Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and.
Chapter 10: Mass-Storage Systems
Jonathan Walpole Computer Science Portland State University
Module 11: File Structure
ECE232: Hardware Organization and Design
Pintos Project 4 Hints.
CS161 – Design and Architecture of Computer
Chapter 11: File System Implementation
Disks and RAID.
Operating Systems Disk Scheduling A. Frank - P. Weisberg.
CS703 - Advanced Operating Systems
Operating System I/O System Monday, August 11, 2008.
Swapping Segmented paging allows us to have non-contiguous allocations
Disk Scheduling Algorithms
DISK SCHEDULING FCFS SSTF SCAN/ELEVATOR C-SCAN C-LOOK.
Chapter 14 Based on the slides supporting the text
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
CS Introduction to Operating Systems
Chapter 9: Virtual-Memory Management
Disk Scheduling The operating system is responsible for using hardware efficiently — for the disk drives, this means having a fast access time and disk.
CS 4284 Systems Capstone Disks & File Systems Godmar Back.
CS 3204 Operating Systems Lecture 22 Godmar Back.
Overview Continuation from Monday (File system implementation)
CS3204: Operating Systems Project 4 Help Session
Secondary Storage Management Brian Bershad
Persistence: hard disk drive
Chapter 11 I/O Management and Disk Scheduling
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Contents Memory types & memory hierarchy Virtual memory (VM)
CS 3410, Spring 2014 Computer Science Cornell University
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Secondary Storage Management Hank Levy
CSE451 File System Introduction and Disk Drivers Autumn 2002
Update : about 8~16% are writes
Disk Scheduling The operating system is responsible for using hardware efficiently — for the disk drives, this means having a fast access time and disk.
CS 3204 Operating Systems Lecture 30 Godmar Back.
COMP755 Advanced Operating Systems
Page Cache and Page Writeback
Operating Systems Disk Scheduling A. Frank - P. Weisberg.
Presentation transcript:

CS 4284 Systems Capstone Disks & File Systems Godmar Back

Disks & Filesystems

Disk Schematics Source: Micro House PC Hardware Library Volume I: Hard Drives CS 4284 Spring 2013 9/19/2018

Tracks, Sectors, Cylinders CS 4284 Spring 2013 9/19/2018

Hard Disk Example 2008 Seagate Barracuda 7200.11 See here for 2012 Drive CS 4284 Spring 2013 9/19/2018

What’s important about disks from OS perspective Disks are big & slow - compared to RAM Access to disk requires Seek (move arm to track + time to settle) – to cross all tracks anywhere from 20-50ms, on average takes 1/3. Rotational delay (wait for sector to appear under track) 7,200rpm is 8.3ms per rotation, on average takes ½: 4.15ms rot delay Transfer time (fast: 512 bytes at 960 Mbit/s is about 4.26s) Seek+Rot Delay dominates Random Access is expensive and unlikely to get better Consequence: avoid seeks seek to short distances amortize seeks by doing bulk transfers CS 4284 Spring 2013 9/19/2018

Disk Scheduling Can use priority scheme (sometimes done) (absent priorities:) goal is to reduce average access time by sending requests to disk controller in certain order Or, more commonly, have disk controller itself reorder requests SSTF: shortest seek time first Like SJF in CPU scheduling, guarantees minimum avg seek time, but can lead to starvation SCAN: “elevator algorithm” Process requests with increasing track numbers until highest reached, then decreasing etc. – repeat Variations: LOOK – don’t go all the way to the top without passengers C-SCAN: - only take passengers when going up CS 4284 Spring 2013 9/19/2018

Accessing Disks Sector is the unit of atomic access Writes to sectors should always complete, even if power fails Consequence of sector granularity: Writing a single byte requires read-modify-write void set_byte(off_t off, char b) { char buffer[512]; block_read(disk, off/DISK_SECTOR_SIZE, buffer); buffer[off % DISK_SECTOR_SIZE] = b; block_write(disk, off/DISK_SECTOR_SIZE, buffer); } CS 4284 Spring 2013 9/19/2018

Disks & Filesystems Buffer Cache CS 4284 Spring 2013 9/19/2018

Disk Caching – Buffer Cache How much memory should be dedicated for it? In older systems (& Pintos), set aside a portion of physical memory In newer systems, integrated into virtual memory system: e.g., page cache in Linux How should eviction be handled? How should prefetching be done? How should concurrent access be mediated (multiple processes may be attempting to write/read to same sector)? How is consistency guaranteed? (All accesses must go through buffer cache!) What write-back strategy should be used? CS 4284 Spring 2013 9/19/2018

Buffer Cache in Pintos Cache Block Descriptor block_sector_id, if in use dirty bit valid bit # of readers # of writers # of pending read/write requests lock to protect above variables signaling variables to signal availability changes usage information for eviction policy data (pointer or embedded) desc 512 bytes desc 512 bytes desc 512 bytes desc 512 bytes 64 desc 512 bytes desc 512 bytes desc 512 bytes CS 4284 Spring 2013 9/19/2018

A Buffer Cache Interface // cache.h struct cache_block; // opaque type // reserve a block in buffer cache dedicated to hold this sector // possibly evicting some other unused buffer // either grant exclusive or shared access struct cache_block * cache_get_block (disk_sector_t sector, bool exclusive); // release access to cache block void cache_put_block(struct cache_block *b); // read cache block from disk, returns pointer to data void *cache_read_block(struct cache_block *b); // fill cache block with zeros, returns pointer to data void *cache_zero_block(struct cache_block *b); // mark cache block dirty (must be written back) void cache_mark_block_dirty(struct cache_block *b); // not shown: initialization, readahead, shutdown CS 4284 Spring 2013 9/19/2018

Block State Perspective ALLOCATED to disk block k VALID + DIRTY? Block State Perspective cache_get_block (k, SHARED) cache_get_block (k, EXCL) cache_put_block() EXCLUSIVE + VALID + DIRTY? SHARED + VALID + DIRTY? eviction cache_read_block()/cache_zero_block() + cache_mark_block_dirty()? SHARED access to disk block k readers > 0 EXCLUSIVE access to disk block k writers == 1 FREE cache_get_block (k, EXCL) cache_get_block (k, SHARED) Not subject to eviction; kernel code holds pointer ALLOCATED to disk block k INVALID cache_get_block(k) (only when miss) Subject to eviction CS 4284 Spring 2013 9/19/2018

Buffer Cache Rationale class BufferPool { // (2) Buffer Passing public: virtual void* getblock(int block) = 0; virtual void dirtyblock(int block) = 0; virtual int blocksize() = 0; }; Compare to buffer pool assignment in CS2606 CS3214 Differences: Do not combine allocating a buffer (a resource management decision) with loading the data into the buffer from file (which is not always necessary) Provide a way for buffer user to say they’re done with the buffer Provide a way to share buffer between multiple users More efficient interface (opaque type instead of block idx saves lookup, constant size buffers) CS 4284 Spring 2013 9/19/2018

Buffer Cache Sizing Simple approach Set aside part of physical memory for buffer cache/use rest for virtual memory pages as page cache – evict buffer/page from same pool Disadvantage: can’t use idle memory of other pool - usually use unified cache subject to shared eviction policy Windows allows user to limit buffer cache size (“Adjust for best performance of programs”) Problem: Bad prediction of buffer cache accesses can result in poor VM performance (and vice versa) Specifically, don’t want large sequential file accesses to evict program pages CS 4284 Spring 2013 9/19/2018

Buffer Cache Replacement Similar to VM Page Replacement, differences: Can do exact LRU (because client must call cache_get_block()!) But LRU hurts when long sequential accesses – should use MRU (most recently used) instead. Example reference string: ABCDABCDABCD, can cache 3 blocks: LRU causes 12 misses, 0 hits, 9 evictions How many misses/hits/evictions would there be with (most-recently-used) MRU? Also: not all blocks are equally important, benefit from some hits more than from others CS 4284 Spring 2013 9/19/2018

Buffer Cache Writeback Strategies Write-Through: Good for floppy drive, USB stick Poor performance – every write causes disk access (Delayed) Write-Back: Makes individual writes faster – just copy & set bit Absorbs multiple writes Allows write-back in batches Problem: what if system crashes before you’ve written data back? Trade-off: performance in no-fault case vs. damage control in fault case If crash occurs, order of write-back can matter CS 4284 Spring 2013 9/19/2018

Writeback Strategies (2) Must write-back on eviction (naturally) Periodically (every 30 seconds or so) When user demands: fsync(2) writes back all modified data belonging to one file – database implementations use this sync(1) writes back entire cache Some systems guarantee write-back on file close But not all, since many files are used in open/write/close/open/read/close/delete sequence Some systems (databases) bypass OS buffer cache (O_SYNC flag) CS 4284 Spring 2013 9/19/2018

Buffer Cache Prefetching b = cache_get_block(n, _); cache_read_block(b); cache_readahead(next(n)); Would like to bring next block to be accessed into cache before it’s accessed Exploit “Spatial locality” Must be done in parallel use daemon thread and producer/consumer pattern Note: next(n) not always equal to n+1 although we try for it – via clustering to minimize seek times Don’t initiate read_ahead if next(n) is unknown or would require another disk access to find out queue q; cache_readahead(sector s) { q.lock(); q.add(request(s)); signal qcond; q.unlock(); } cache_readahead_daemon() { while (true) { q.lock(); while (q.empty()) qcond.wait(); s = q.pop(); read sector(s); CS 4284 Spring 2013 9/19/2018