CS162 Operating Systems and Systems Programming Lecture 17. Disk Management and File Systems. Page 1

Similar documents
CS162 Operating Systems and Systems Programming Lecture 17. Disk Management and File Systems. Review: Want Standard Interfaces to Devices

Operating Systems (1DT020 & 1TT802) Lecture 11. File system Interface (cont d), Disk Management, File System Implementation.

Page 1. CS194-3/CS16x Introduction to Systems. Lecture 14. I/O, Disks, Filesystems. Goals for Today. I/O Systems Hardware Access Device Drivers

CS162 Operating Systems and Systems Programming Lecture 18. File Systems, Naming, and Directories

CS162 Operating Systems and Systems Programming Lecture 17. Disk Management and File Systems

Page 1. Quiz 13.1: Synchronization" Quiz 13.1: Synchronization" CS162 Operating Systems and Systems Programming Lecture 13. Disk/SSDs, File Systems"

CS162 Operating Systems and Systems Programming Lecture 18. File Systems, Naming, and Directories

CS162 Operating Systems and Systems Programming Lecture 17. Disk Management and File Systems

I/O Performance" CS162 C o Operating Systems and Response" 300" Time (ms)" User" I/O" Systems Programming Thread" lle device" 200" Lecture 13 Queue"

CS162 Operating Systems and Systems Programming Lecture 14 File Systems (Part 2)"

Quiz 12.1: I/O" Quiz 13.1: Synchronization" Quiz 12.1: I/O" Page 1. CS162 Operating Systems and Systems Programming Lecture 13

Operating Systems (1DT020 & 1TT802) Lecture 12. File System Implementation (continued) I/O systems. Léon Mugwaneza

CS162 Operating Systems and Systems Programming Lecture 19. File Systems continued Distributed Systems. Review: A Little Queuing Theory: Some Results

Page 1. Review: Storage Performance" SSD Firmware Challenges" SSD Issues" CS162 Operating Systems and Systems Programming Lecture 14

we are here Page 1 Recall: How do we Hide I/O Latency? I/O & Storage Layers Recall: C Low level I/O

Lecture S3: File system data layout, naming

Page 1. Recap: File System Goals" Recap: Linked Allocation"

Disk Management and File Systems. Dr. Yingwu Zhu

Page 1. CS162 Operating Systems and Systems Programming Lecture 16. File Systems, Naming, Directories, and Caching"

we are here I/O & Storage Layers Recall: C Low level I/O Recall: C Low Level Operations CS162 Operating Systems and Systems Programming Lecture 18

Page 1. CS194-3/CS16x Introduction to Systems. Lecture 15. Filesystems

Page 1. CS162 Operating Systems and Systems Programming Lecture 13. File Systems, Naming, Directories, and Caching"

CS162 Operating Systems and Systems Programming Lecture 16. I/O Systems. Page 1

Disk Scheduling COMPSCI 386

EECS 482 Introduction to Operating Systems

Operating Systems. Operating Systems Professor Sina Meraji U of T

CS162 Operating Systems and Systems Programming Lecture 16. Page Allocation and Replacement (con t) I/O Systems

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

COS 318: Operating Systems. Storage Devices. Vivek Pai Computer Science Department Princeton University

CSCI-GA Operating Systems. I/O : Disk Scheduling and RAID. Hubertus Franke

Ref: Chap 12. Secondary Storage and I/O Systems. Applied Operating System Concepts 12.1

The Berkeley File System. The Original File System. Background. Why is the bandwidth low?

CS152 Computer Architecture and Engineering Lecture 19: I/O Systems

19 File Structure, Disk Scheduling

u Covered: l Management of CPU & concurrency l Management of main memory & virtual memory u Currently --- Management of I/O devices

COS 318: Operating Systems. Storage Devices. Jaswinder Pal Singh Computer Science Department Princeton University

Introduction Disks RAID Tertiary storage. Mass Storage. CMSC 420, York College. November 21, 2006

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

CSC369 Lecture 9. Larry Zhang, November 16, 2015

Page 1. CS162 Operating Systems and Systems Programming Lecture 15. Kernel/User, I/O, Disks"

COMP 530: Operating Systems File Systems: Fundamentals

The Requirements of I/O. In a Picture. OS Basics: I/O. CS162 Operating Systems and Systems Programming Lecture 16. General I/O. So far in this course:

I/O & Storage. Jin-Soo Kim ( Computer Systems Laboratory Sungkyunkwan University

Page 1. Goals for Today" TLB organization" CS162 Operating Systems and Systems Programming Lecture 11. Page Allocation and Replacement"

COS 318: Operating Systems. Storage Devices. Kai Li Computer Science Department Princeton University

CS162 Operating Systems and Systems Programming Lecture 12. Address Translation. Page 1

Outlook. File-System Interface Allocation-Methods Free Space Management

Chapter 11: File System Implementation. Objectives

File Layout and Directories

File Systems. CS170 Fall 2018

File. File System Implementation. Operations. Permissions and Data Layout. Storing and Accessing File Data. Opening a File

CPS104 Computer Organization and Programming Lecture 18: Input-Output. Outline of Today s Lecture. The Big Picture: Where are We Now?

Hard Disk Drives. Nima Honarmand (Based on slides by Prof. Andrea Arpaci-Dusseau)

CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement"

CS510 Operating System Foundations. Jonathan Walpole

22 File Structure, Disk Scheduling

Input/Output. Today. Next. Principles of I/O hardware & software I/O software layers Disks. Protection & Security

CSE 120: Principles of Operating Systems. Lecture 10. File Systems. November 6, Prof. Joe Pasquale

File Systems. Before We Begin. So Far, We Have Considered. Motivation for File Systems. CSE 120: Principles of Operating Systems.

CSE 451: Operating Systems Spring Module 12 Secondary Storage. Steve Gribble

OPERATING SYSTEMS CS3502 Spring Input/Output System Chapter 9

OPERATING SYSTEMS CS3502 Spring Input/Output System Chapter 9

Principles of Operating Systems CS 446/646

Lecture 16: Storage Devices

CS420: Operating Systems. Mass Storage Structure

3/3/2014! Anthony D. Joseph!!CS162! UCB Spring 2014!

I/O Handling. ECE 650 Systems Programming & Engineering Duke University, Spring Based on Operating Systems Concepts, Silberschatz Chapter 13

CSE 451: Operating Systems Spring Module 12 Secondary Storage

CSE 120: Principles of Operating Systems. Lecture 10. File Systems. February 22, Prof. Joe Pasquale

Today: Secondary Storage! Typical Disk Parameters!

csci 3411: Operating Systems

File. File System Implementation. File Metadata. File System Implementation. Direct Memory Access Cont. Hardware background: Direct Memory Access

Operating Systems. File Systems. Thomas Ropars.

Disc Allocation and Disc Arm Scheduling?

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

I/O, Disks, and RAID Yi Shi Fall Xi an Jiaotong University

File Systems: Fundamentals

Operating Systems Design Exam 2 Review: Spring 2011

CSE 120. Overview. July 27, Day 8 Input/Output. Instructor: Neil Rhodes. Hardware. Hardware. Hardware

Filesystems Lecture 10. Credit: some slides by John Kubiatowicz and Anthony D. Joseph

SCSI overview. SCSI domain consists of devices and an SDS

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

CS 416: Opera-ng Systems Design March 23, 2012

File Systems: Fundamentals

File System Structure. Kevin Webb Swarthmore College March 29, 2018

Mass-Storage Structure

Hard Disk Drives (HDDs) Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 10: Mass-Storage Systems. Operating System Concepts 9 th Edition

Midterm II December 4 th, 2006 CS162: Operating Systems and Systems Programming

CS 537 Fall 2017 Review Session

V. Mass Storage Systems

Chapter 12: Mass-Storage Systems. Operating System Concepts 8 th Edition,

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2002

CS510 Operating System Foundations. Jonathan Walpole

Secondary storage. CS 537 Lecture 11 Secondary Storage. Disk trends. Another trip down memory lane

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

CS 318 Principles of Operating Systems

Hard Disk Drives (HDDs)

I/O and file systems. Dealing with device heterogeneity

FFS. CS380L: Mike Dahlin. October 9, Overview of file systems trends, future. Phase 1: Basic file systems (e.g.

Transcription:

CS162 Operating Systems and Systems Programming Lecture 17 Disk Management and File Systems April 2, 2008 Prof. Anthony D. Joseph http://inst.eecs.berkeley.edu/~cs162 Review: Want Standard Interfaces to Devices Block Devices: e.g. disk drives, tape drives, Cdrom Access blocks of data Commands include open(), read(), write(), seek() Raw I/O or file-system access Memory-mapped file access possible Character Devices: e.g. keyboards, mice, serial ports, some USB devices Single characters at a time Commands include get(), put() Libraries layered on top allow line editing Network Devices: e.g. Ethernet, Wireless, Bluetooth Different enough from block/character to have own interface Unix and Windows include socket interface» Separates network protocol from network operation» Includes select() functionality Usage: pipes, FIFOs, streams, queues, mailboxes Lec 17.2 Review: How Does User Deal with Timing? Blocking Interface: Wait When request data (e.g. read() system call), put process to sleep until data is ready When write data (e.g. write() system call), put process to sleep until device is ready for data Non-blocking Interface: Don t Wait Returns quickly from read or write request with count of bytes successfully transferred Read may return nothing, write may write nothing Asynchronous Interface: Tell Me Later When request data, take pointer to user s buffer, return immediately; later kernel fills buffer and notifies user When send data, take pointer to user s buffer, return immediately; later kernel takes data and notifies user Lec 17.3 Goals for Today Disk Performance Hardware performance parameters File Systems Structure, Naming, Directories Note: Some slides and/or pictures in the following are adapted from slides 2005 Silberschatz, Galvin, and Gagne. Many slides generated from my lecture notes by Kubiatowicz. Lec 17.4 Page 1

Hard Disk Drives Properties of a Hard Magnetic Disk Platters Sector Western Digital Drive http://www.storagereview.com/guide/ Read/Write Head Side View IBM/Hitachi Microdrive Lec 17.5 Track Properties Independently addressable element: sector» OS always transfers groups of sectors together blocks A disk can access directly any given block of information it contains (random access). Can access any file either sequentially or randomly. A disk can be rewritten in place: it is possible to read/modify/write a block from the disk Typical numbers (depending on the disk size): 500 to more than 20,000 tracks per surface 32 to 800 sectors per track» A sector is the smallest unit that can be read or written Zoned bit recording Constant bit density: more sectors on outer tracks Speed varies with track location Lec 17.6 User Thread Queue [OS Paths] Disk I/O Performance Controller Disk Response Time = Queue+Disk Service Time Throughput (Utilization) (% total BW) Performance of disk drive/file system Metrics: Response Time, Throughput Contributing factors to latency:» Software paths (can be loosely modeled by a queue)» Hardware controller» Physical disk media Queuing behavior: Can lead to big increases of latency as utilization approaches 100% 300 200 100 0 Response Time (ms) 0% Lec 17.7 100% Magnetic Disk Characteristic Cylinder: all the tracks under the head at a given point on all surfaceshead Read/write data is a three-stage process: Seek time: position the head/arm over the proper track (into proper cylinder) Rotational latency: wait for the desired sector to rotate under the read/write head Transfer time: transfer a block of bits (sector) under the read-write head Disk Latency = Queueing Time + Controller time + Seek Time + Rotation Time + Xfer Time Request Software Queue (Device Driver) Hardware Controller Highest Bandwidth: Transfer large group of blocks sequentially from one track Media Time (Seek+Rot+Xfer) Track Sector Cylinder Platter Result Lec 17.8 Page 2

Typical Numbers of a Magnetic Disk Average seek time as reported by the industry: Typically in the range of 8 ms to 12 ms Due to locality of disk reference may only be 25% to 33% of the advertised number Rotational Latency: Most disks rotate at 3,600 to 7200 RPM (Up to 15,000RPM or more) Approximately 16 ms to 8 ms per revolution, respectively An average latency to the desired information is halfway around the disk: 8 ms at 3600 RPM, 4 ms at 7200 RPM Transfer Time is a function of: Transfer size (usually a sector): 512B 1KB per sector Rotation speed: 3600 RPM to 15000 RPM Recording density: bits per inch on a track Diameter: ranges from 1 in to 5.25 in Typical values: 2 to 50 MB per second Controller time depends on controller hardware Cost drops by factor of two per year (since 1991) Disk Performance Examples Assumptions: Ignoring queuing and controller times for now Avg seek time of 5ms, 7200RPM Time for one rotation: 8ms Transfer rate of 4MByte/s, sector size of 1 KByte Read sector from random place on disk: Seek (5ms) + Rot. Delay (4ms) + Transfer (0.25ms) Approx 10ms to fetch/put data: 100 KByte/sec Read sector from random place in same cylinder: Rot. Delay (4ms) + Transfer (0.25ms) Approx 5ms to fetch/put data: 200 KByte/sec Read next sector on same track: Transfer (0.25ms): 4 MByte/sec Key to using disk effectively (esp. for filesystems) is to minimize seek and rotational delays Lec 17.9 Lec 17.10 Administrivia Disk Tradeoffs Group problems? Don t wait. Talk to TA/talk to me Let s get things fixed! Project #3 design doc due next Monday (4/7) at 11:59pm Midterm #2 is in two weeks (Wed 4/16) 6-7:30pm in 10 Evans All material from projects 1-3, lectures #9 (2/25) to #19 (4/9)» OS History, Services, and Structure; CPU Scheduling; Kernel and Address Spaces; Address Translation, Caching and TLBs; Demand Paging; I/O Systems; Filesystems, Disk Management, Naming, and Directories; Distributed Systems Survey Lec 17.11 How do manufacturers choose disk sector sizes? Need 100-1000 bits between each sector to allow system to measure how fast disk is spinning and to tolerate small (thermal) changes in track length What if sector was 1 byte? Space efficiency only 1% of disk has useful space Time efficiency each seek takes 10 ms, transfer rate of 50 100 Bytes/sec What if sector was 1 KByte? Space efficiency only 90% of disk has useful space Time efficiency transfer rate of 100 KByte/sec What if sector was 1 MByte? Space efficiency almost all of disk has useful space Time efficiency transfer rate of 4 MByte/sec Lec 17.12 Page 3

Disk Scheduling Disk can do only one request at a time; What order do you choose to do queued requests? User Requests 2,3 2,1 3,10 7,2 5,2 2,2 FIFO Order Fair among requesters, but order of arrival may be to random spots on the disk Very long seeks SSTF: Shortest seek time first Pick the request that s closest on the disk Although called SSTF, today must include rotational delay in calculation, since rotation can be as long as seek Con: SSTF good at reducing seeks, but may lead to starvation SCAN: Implements an Elevator Algorithm: take the closest request in the direction of travel No starvation, but retains flavor of SSTF C-SCAN: Circular-Scan: only goes in one direction Skips any requests on the way back Fairer than SCAN, not biased towards pages in middle Head 3 2 1 4 Lec 17.13 Disk Head Building a File System File System: Layer of OS that transforms block interface of disks (or other block devices) into Files, Directories, etc. File System Components Disk Management: collecting disk blocks into files Naming: Interface to find files by name, not by blocks Protection: Layers to keep data secure Reliability/Durability: Keeping of files durable despite crashes, media failures, attacks, etc User vs. System View of a File User s view:» Durable Data Structures System s view (system call interface):» Collection of Bytes (UNIX)» Doesn t matter to system what kind of data structures you want to store on disk! System s view (inside OS):» Collection of blocks (a block is a logical transfer unit, while a sector is the physical transfer unit)» Block size sector size; in UNIX, block size is 4KB Lec 17.14 Translating from User to System View File System What happens if user says: give me bytes 2 12? Fetch block corresponding to those bytes Return just the correct portion of the block What about: write bytes 2 12? Fetch block Modify portion Write out Block Everything inside File System is in whole size blocks For example, getc(), putc() buffers something like 4096 bytes, even if interface is one byte at a time From now on, file is a collection of blocks Lec 17.15 Disk Management Policies Basic entities on a disk: File: user-visible group of blocks arranged sequentially in logical space Directory: user-visible index mapping names to files (next lecture) Access disk as linear array of sectors. Two Options: Identify sectors as vectors [cylinder, surface, sector]. Sort in cylinder-major order. Not used much anymore. Logical Block Addressing (LBA). Every sector has integer address from zero up to max number of sectors. Controller translates from address physical position» First case: OS/BIOS must deal with bad sectors» Second case: hardware shields OS from structure of disk Need way to track free disk blocks Link free blocks together too slow today Use bitmap to represent free space on disk Need way to structure files: File Header Track which blocks belong at which offsets within the logical file structure Optimize placement of files disk blocks to match access and usage patterns Lec 17.16 Page 4

Designing the File System: Access Patterns How do users access files? Need to know type of access patterns user is likely to throw at system Sequential Access: bytes read in order ( give me the next X bytes, then give me next, etc ) Almost all file access are of this flavor Random Access: read/write element out of middle of array ( give me bytes i j ) Less frequent, but still important. For example, virtual memory backing file: page of memory stored in file Want this to be fast don t want to have to read all bytes to get to the middle of the file Content-based Access: ( find me 100 bytes starting with JOSEPH ) Example: employee records once you find the bytes, increase my salary by a factor of 2 Many systems don t provide this; instead, databases are built on top of disk access to index content (requires efficient random access) Lec 17.17 Designing the File System: Usage Patterns Most files are small (for example,.login,.c files) A few files are big nachos, core files, etc.; the nachos executable is as big as all of your.class files combined However, most files are small.class s,.o s,.c s, etc. Large files use up most of the disk space and bandwidth to/from disk May seem contradictory, but a few enormous files are equivalent to an immense # of small files Although we will use these observations, beware usage patterns: Good idea to look at usage patterns: beat competitors by optimizing for frequent patterns Except: changes in performance or cost can alter usage patterns. Maybe UNIX has lots of small files because big files are really inefficient? Digression, danger of predicting future: In 1950 s, marketing study by IBM said total worldwide need for computers was 7! Company (that you haven t heard of) called GenRad invented oscilloscope; thought there was no market, so sold patent to Tektronix (bet you have heard of them!) Lec 17.18 BREAK How to organize files on disk Goals: Maximize sequential performance Easy random access to file Easy management of file (growth, truncation, etc) First Technique: Continuous Allocation Use continuous range of blocks in logical block space» Analogous to base+bounds in virtual memory» User says in advance how big file will be (disadvantage) Search bit-map for space using best fit/first fit» What if not enough contiguous space for new file? File Header Contains:» First block/lba in file» File size (# of blocks) Pros: Fast Sequential Access, Easy Random access Cons: External Fragmentation/Hard to grow files» Free holes get smaller and smaller» Could compact space, but that would be really expensive Continuous Allocation used by IBM 360 Result of allocation and management cost: People would create a big file, put their file in the middle Lec 17.20 Page 5

Linked List Allocation Second Technique: Linked List Approach Each block, pointer to next on disk Linked Allocation: File-Allocation Table (FAT) File Header Pros: Can grow files dynamically, Free list same as file Cons: Bad Sequential Access (seek between each block), Unreliable (lose block, lose rest of file) Serious Con: Bad random access!!!! Technique originally from Alto (First PC, built at Xerox)» No attempt to allocate contiguous blocks Null Lec 17.21 MSDOS links pages together to create a file Links not in pages, but in the File Allocation Table (FAT)» FAT contains an entry for each block on the disk» FAT Entries corresponding to blocks of file linked together Access properties:» Sequential access expensive unless FAT cached in memory» Random access expensive always, but really expensive if FAT not cached in memory Lec 17.22 Indexed Allocation Multilevel Indexed Files (UNIX 4.1) Multilevel Indexed Files: Like multilevel address translation (from UNIX 4.1 BSD) Key idea: efficient for small files, but still allow big files Third Technique: Indexed Files (Nachos, VMS) System Allocates file header block to hold array of pointers big enough to point to all blocks» User pre-declares max file size; Pros: Can easily grow up to space allocated for index Random access is fast Cons: Clumsy to grow file bigger than table size Still lots of seeks: blocks may be spread over disk Lec 17.23 File hdr contains 13 pointers Fixed size table, pointers not all equivalent This header is called an inode in UNIX File Header format: First 10 pointers are to data blocks Ptr 11 points to indirect block containing 256 block ptrs Pointer 12 points to doubly indirect block containing 256 indirect block ptrs for total of 64K blocks Pointer 13 points to a triply indirect block (16M blocks) Lec 17.24 Page 6

Multilevel Indexed Files (UNIX 4.1): Discussion Basic technique places an upper limit on file size that is approximately 16Gbytes Designers thought this was bigger than anything anyone would need. Much bigger than a disk at the time Fallacy: today, EOS producing 2TB of data per day Pointers get filled in dynamically: need to allocate indirect block only when file grows > 10 blocks On small files, no indirection needed Lec 17.25 Example of Multilevel Indexed Files Sample file in multilevel indexed format: How many accesses for block #23? (assume file header accessed on open)?» Two: One for indirect block, one for data How about block #5?» One: One for data Block #340?» Three: double indirect block, indirect block, and data UNIX 4.1 Pros and cons Pros: Simple (more or less) Files can easily expand (up to a point) Small files particularly cheap and easy Cons: Lots of seeks Very large files must read many indirect blocks (four I/Os per block!) Lec 17.26 Summary Disk Performance: Queuing time + Controller + Seek + Rotational + Transfer Rotational latency: on average ½ rotation Transfer time: spec of disk depends on rotation speed and bit storage density File System: Transforms blocks into Files and Directories Optimize for access and usage patterns Maximize sequential access, allow efficient random access File (and directory) defined by header Called inode with index called inumber Multilevel Indexed Scheme Inode contains file info, direct pointers to blocks, indirect blocks, doubly indirect, etc.. Lec 17.27 Page 7