CSE 120 Principles of Operating Systems

Similar documents
CSE 120 Principles of Operating Systems

CS 318 Principles of Operating Systems

Motivation: I/O is Important. CS 537 Lecture 12 File System Interface. File systems

CSE 451: Operating Systems Winter Module 15 File Systems

Operating Systems. Operating Systems Professor Sina Meraji U of T

CSE 153 Design of Operating Systems

CSE 153 Design of Operating Systems Fall 2018

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

CSE 451: Operating Systems Winter Lecture 12 Secondary Storage. Steve Gribble 323B Sieg Hall.

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

CSE 153 Design of Operating Systems

STORAGE SYSTEMS. Operating Systems 2015 Spring by Euiseong Seo

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

CSE 451: Operating Systems Winter Secondary Storage. Steve Gribble. Secondary storage

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

File Systems Overview. Jin-Soo Kim ( Computer Systems Laboratory Sungkyunkwan University

CSE 451: Operating Systems Spring Module 12 Secondary Storage

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

File System Internals. Jo, Heeseung

CSC369 Lecture 9. Larry Zhang, November 16, 2015

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

Computer Systems Laboratory Sungkyunkwan University

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

CS 153 Design of Operating Systems

File Systems. Chapter 11, 13 OSPP

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

CS 4284 Systems Capstone

STORING DATA: DISK AND FILES

CS3600 SYSTEMS AND NETWORKS

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 18: Naming, Directories, and File Caching

Disks, Memories & Buffer Management

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 18: Naming, Directories, and File Caching

File Systems. File system interface (logical view) File system implementation (physical view)

UNIX File Systems. How UNIX Organizes and Accesses Files on Disk

Disk Scheduling COMPSCI 386

Operating Systems. Lecture File system implementation. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

EECS 482 Introduction to Operating Systems

CSE 120 Principles of Operating Systems

FFS: The Fast File System -and- The Magical World of SSDs

CS 111. Operating Systems Peter Reiher

File system internals Tanenbaum, Chapter 4. COMP3231 Operating Systems

File Systems. ECE 650 Systems Programming & Engineering Duke University, Spring 2018

Workloads. CS 537 Lecture 16 File Systems Internals. Goals. Allocation Strategies. Michael Swift

ECE 650 Systems Programming & Engineering. Spring 2018

Lecture S3: File system data layout, naming

File Systems. What do we need to know?

Motivation. Operating Systems. File Systems. Outline. Files: The User s Point of View. File System Concepts. Solution? Files!

Disks and Files. Storage Structures Introduction Chapter 8 (3 rd edition) Why Not Store Everything in Main Memory?

Operating Systems. File Systems. Thomas Ropars.

CSCI-GA Database Systems Lecture 8: Physical Schema: Storage

Virtual Memory. Reading. Sections 5.4, 5.5, 5.6, 5.8, 5.10 (2) Lecture notes from MKP and S. Yalamanchili

FILE SYSTEMS. Jo, Heeseung

L9: Storage Manager Physical Data Organization

Introduction to OS. File Management. MOS Ch. 4. Mahmoud El-Gayyar. Mahmoud El-Gayyar / Introduction to OS 1

FILE SYSTEMS. CS124 Operating Systems Winter , Lecture 23

File Systems: FFS and LFS

File Layout and Directories

File Systems: Consistency Issues

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

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

File System Implementation

File System Implementation. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

ECE 598 Advanced Operating Systems Lecture 14

Storing Data: Disks and Files

Storing Data: Disks and Files

Chapter 11: File System Implementation. Objectives

File system internals Tanenbaum, Chapter 4. COMP3231 Operating Systems

CSE380 - Operating Systems

Last Class: Memory management. Per-process Replacement

Filesystem. Disclaimer: some slides are adopted from book authors slides with permission 1

Main Points. File layout Directory layout

To understand this, let's build a layered model from the bottom up. Layers include: device driver filesystem file

ECE331: Hardware Organization and Design

Computer Systems CSE 410 Autumn Disks and File Systems

What is a file system

Main Points. File systems. Storage hardware characteristics. File system usage patterns. Useful abstractions on top of physical devices

Storing Data: Disks and Files

Lecture 16: Storage Devices

Hard Disk Drives (HDDs)

SCSI overview. SCSI domain consists of devices and an SDS

File System Internals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CSE 120 Principles of Operating Systems

EECS 482 Introduction to Operating Systems

CSE 333 Lecture 9 - storage

Storing Data: Disks and Files

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

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

CPSC 421 Database Management Systems. Lecture 11: Storage and File Organization

Chapter 11: Implementing File Systems

L7: Performance. Frans Kaashoek Spring 2013

Arvind Krishnamurthy Spring Implementing file system abstraction on top of raw disks

Block Device Scheduling. Don Porter CSE 506

Block Device Scheduling

COMP 530: Operating Systems File Systems: Fundamentals

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

File Systems. Kartik Gopalan. Chapter 4 From Tanenbaum s Modern Operating System

Typical File Extensions File Structure

Locality and The Fast File System. Dongkun Shin, SKKU

Local File Stores. Job of a File Store. Physical Disk Layout CIS657

Chapter 12: File System Implementation

Transcription:

CSE 120 Principles of Operating Systems Fall 2016 Lecture 12: File Systems Geoffrey M. Voelker

File Systems First we ll discuss properties of physical disks Structure Performance Scheduling Then we ll discuss how we build file systems on them Files Directories Sharing Protection File System Layouts File Buffer Cache Read Ahead November 13, 2016 CSE 120 Lecture 12 File Systems 2

Disks and the OS Disks are messy physical devices: Errors, bad blocks, missed seeks, etc. The job of the OS is to hide this mess from higher level software Low-level device control (initiate a disk read, etc.) Higher-level abstractions (files, databases, etc.) The OS may provide different levels of disk access to different clients Physical disk (surface, cylinder, sector) Logical disk (disk block #) Logical file (file block, record, or byte #) November 13, 2016 CSE 120 Lecture 12 File Systems 3

Physical Disk Structure Disk components Platters Surfaces Tracks Arm Track Sector Surface Sectors Cylinders Arm Heads Heads Platter Cylinder November 13, 2016 CSE 120 Lecture 12 File Systems 4

Disk Interaction Specifying disk requests requires a lot of info: Cylinder #, surface #, track #, sector #, transfer size Older disks required the OS to specify all of this The OS needed to know all disk parameters Modern disks are more complicated Not all sectors are the same size, sectors are remapped, etc. Current disks provide a higher-level interface (SCSI) The disk exports its data as a logical array of blocks [0 N]» Disk maps logical blocks to cylinder/surface/track/sector Only need to specify the logical block # to read/write But now the disk parameters are hidden from the OS November 13, 2016 CSE 120 Lecture 12 File Systems 5

Modern Disk Specifications Seagate Enterprise Performance 3.5" (server) capacity: 600 GB rotational speed: 15,000 RPM sequential read performance: 233 MB/s (outer) 160 MB/s (inner) seek time (average): 2.0 ms Seagate Barracuda 3.5" (workstation) capacity: 3000 GB rotational speed: 7,200 RPM sequential read performance: 210 MB/s - 156 MB/s (inner) seek time (average): 8.5 ms Seagate Savvio 2.5" (smaller form factor) capacity: 2000 GB rotational speed: 7,200 RPM sequential read performance: 135 MB/s (outer) -? MB/s (inner) seek time (average): 11 ms November 13, 2016 CSE 120 Lecture 12 File Systems 6

Disk Performance Disk request performance depends upon three steps Seek moving the disk arm to the correct cylinder» Depends on how fast disk arm can move (increasing very slowly) Rotation waiting for the sector to rotate under the head» Depends on rotation rate of disk (increasing, but slowly) Transfer transferring data from surface into disk controller electronics, sending it back to the host» Depends on density (increasing quickly) When the OS uses the disk, it tries to minimize the cost of all of these steps Particularly seeks and rotation November 13, 2016 CSE 120 Lecture 12 File Systems 7

Solid State Disks SSDs are a relatively new storage technology Memory that does not require power to remember state No physical moving parts faster than hard disks No seek and no rotation overhead But more expensive, not as much capacity Generally speaking, file systems have remained unchanged when using SSDs Some optimizations no longer necessary (e.g., layout policies, disk head scheduling), but basically leave FS code as is Initially, SSDs have the same disk interface (SATA) Increasingly, SSDs used directly over the I/O bus (PCIe)» Much higher performance November 13, 2016 CSE 120 Lecture 12 File Systems 8

Non-Volatile Memory (NVM) (On the horizon ) Under development are new technologies that provide non-volatile memory Phase change (PCM), spin-torque transfer (STTM), resistive Performance close to DRAM But persistent Byte-addressable SSD is in units of a page Unlike SSDs, NVM will have a dramatic effect on both operating systems and applications November 13, 2016 CSE 120 Lecture 12 File Systems 9

Disk Scheduling Because seeks are so expensive (milliseconds!), the OS tries to schedule disk requests that are queued waiting for the disk Many algorithms for doing so In general, unless there are request queues, disk scheduling does not have much impact Important for servers, less so for PCs Modern disks often do the disk scheduling themselves Disks know their layout better than OS, can optimize better Ignores, undoes any scheduling done by OS November 13, 2016 CSE 120 Lecture 12 File Systems 10

File Systems File systems Implement an abstraction (files) for secondary storage Organize files logically (directories) Permit sharing of data between processes, people, and machines Protect data from unwanted access (security) November 13, 2016 CSE 120 Lecture 12 File Systems 11

Files A file is data with some properties Contents, size, owner, last read/write time, protection, etc. A file can also have a type Understood by the file system» Block, character, device, portal, link, etc. Understood by other parts of the OS or runtime libraries» Executable, dll, source, object, text, etc. A file s type can be encoded in its name or contents Windows encodes type in name».com,.exe,.bat,.dll,.jpg, etc. Unix encodes type in contents» Magic numbers, initial characters (e.g., #! for shell scripts) November 13, 2016 CSE 120 Lecture 12 File Systems 12

Basic File Operations Unix creat(name) open(name, how) read(fd, buf, len) write(fd, buf, len) sync(fd) seek(fd, pos) close(fd) unlink(name) Windows CreateFile(name, CREATE) CreateFile(name, OPEN) ReadFile(handle, ) WriteFile(handle, ) FlushFileBuffers(handle, ) SetFilePointer(handle, ) CloseHandle(handle, ) DeleteFile(name) CopyFile(name) MoveFile(name) November 13, 2016 CSE 120 Lecture 12 File Systems 13

File Access Methods Some file systems provide different access methods that specify different ways for accessing data in a file Sequential access read bytes one at a time, in order Direct access random access given block/byte number Record access file is array of fixed- or variable-length records, read/written sequentially or randomly by record # Indexed access file system contains an index to a particular field of each record in a file, reads specify a value for that field and the system finds the record via the index (DBs) What file access method does Unix, Windows provide? Older systems provide the more complicated methods November 13, 2016 CSE 120 Lecture 12 File Systems 14

Directories Directories serve two purposes For users, they provide a structured way to organize files For the file system, they provide a convenient naming interface that allows the implementation to separate logical file organization from physical file placement on the disk Most file systems support multi-level directories Naming hierarchies (/, /usr, /usr/local/, ) Most file systems support the notion of a current directory Relative names specified with respect to current directory Absolute names start from the root of directory tree November 13, 2016 CSE 120 Lecture 12 File Systems 15

Directory Internals A directory is a list of entries <name, location> Name is just the name of the file or directory Location depends upon how file is represented on disk List is usually unordered (effectively random) Entries usually sorted by program that reads directory Directories typically stored in files Only need to manage one kind of secondary storage unit November 13, 2016 CSE 120 Lecture 12 File Systems 16

Basic Directory Operations Unix Directories implemented in files Use file ops to create dirs C runtime library provides a higher-level abstraction for reading directories opendir(name) readdir(dir) seekdir(dir) closedir(dir) Windows Explicit dir operations CreateDirectory(name) RemoveDirectory(name) Very different method for reading directory entries FindFirstFile(pattern) FindNextFile() November 13, 2016 CSE 120 Lecture 12 File Systems 17

Path Name Translation (v1) Let s say you want to open /one/two/three What does the file system do? Open directory / (well known, can always find) Search for the entry one, get location of one (in dir entry) Open directory one, search for two, get location of two Open directory two, search for three, get location of three Open file three Systems spend a lot of time walking directory paths This is why open is separate from read/write OS will cache prefix lookups for performance» /a/b, /a/bb, /a/bbb, etc., all share /a prefix November 13, 2016 CSE 120 Lecture 12 File Systems 18

File Sharing File sharing has been around since timesharing Easy to do on a single machine PCs, workstations, and networks get us there (mostly) File sharing is important for getting work done Basis for communication and synchronization Two key issues when sharing files Semantics of concurrent access» What happens when one process reads while another writes?» What happens when two processes open a file for writing?» What are we going to use to coordinate? Protection November 13, 2016 CSE 120 Lecture 12 File Systems 19

Protection File systems implement a protection system Who can access a file How they can access it More generally Objects are what, subjects are who, actions are how A protection system dictates whether a given action performed by a given subject on a given object should be allowed You can read and/or write your files, but others cannot You can read /etc/motd, but you cannot write it November 13, 2016 CSE 120 Lecture 12 File Systems 20

Representing Protection Access Control Lists (ACL) For each object, maintain a list of subjects and their permitted actions Capabilities For each subject, maintain a list of objects and their permitted actions Subjects Objects /one /two /three Alice rw - rw Bob w - r Charlie w r rw Capability ACL November 13, 2016 CSE 120 Lecture 12 File Systems 21

Root & Administrator The user root is special on Unix It bypasses all protection checks in the kernel Administrator is the equivalent on Windows Always running as root can be dangerous A mistake (or exploit) can harm the system» rm will always remove a file This is why you create a user account on Unix even if you have root access» You only run as root when you need to modify the system If you have Administrator privileges on Windows, then you are effectively always running as root (unfortunately) November 13, 2016 CSE 120 Lecture 12 File Systems 22

setuid OSes provide a mechanism to enable you to run programs with the privileges of other users Unix: setuid, setgid (specified on executable files) Windows: runas, CreateProcessAsUser (on process creation) Another form of protected control transfer Normally a process runs with your user privileges By running a setuid program, the process runs with the privileges of the user or group associated with the file November 13, 2016 CSE 120 Lecture 12 File Systems 23

ACLs and Capabilities Approaches differ only in how the table is represented What approach does Unix use in the FS? Capabilities are easier to transfer They are like keys, can handoff, does not depend on subject In practice, ACLs are easier to manage Object-centric, easy to grant, revoke To revoke capabilities, have to keep track of all subjects that have the capability a challenging problem ACLs have a problem when objects are heavily shared The ACLs become very large Use groups (e.g., Unix) November 13, 2016 CSE 120 Lecture 12 File Systems 24

File System Layout How do file systems use the disk to store files? File systems define a block size (e.g., 4KB) Disk space is allocated in granularity of blocks A Master Block determines location of root directory Always at a well-known disk location Often replicated across disk for reliability A free map determines which blocks are free, allocated Usually a bitmap, one bit per block on the disk Also stored on disk, cached in memory for performance Remaining disk blocks used to store files (and dirs) There are many ways to do this November 13, 2016 CSE 120 Lecture 12 File Systems 25

Disk Layout Strategies Files span multiple disk blocks How do you find all of the blocks for a file? 1. Contiguous allocation» Like memory» Fast, simplifies directory access» Inflexible, causes fragmentation, needs compaction 2. Linked structure» Each block points to the next, directory points to the first» Good for sequential access, bad for all others 3. Indexed structure (indirection, hierarchy)» An index block contains pointers to many other blocks» Handles random better, still good for sequential» May need multiple index blocks (linked together) November 13, 2016 CSE 120 Lecture 12 File Systems 26

Unix Inodes Unix inodes implement an indexed structure for files Also store metadata info (protection, timestamps, length, ref count ) Each inode contains 15 block pointers First 12 are direct blocks (e.g., 4 KB blocks) Then single, double, and triple indirect (Metadata) 0 1 12 13 14 (1) (2) (3) November 13, 2016 CSE 120 Lecture 12 File Systems 27

Unix Inodes and Path Search Unix inodes are not directories Inodes describe where on the disk the blocks for a file are placed Directories are files, so inodes also describe where the blocks for directories are placed on the disk Directory entries map file names to inodes (v2) To open /one, use Master Block to find inode for / on disk Open /, look for entry for one This entry gives the disk block number for the inode for one Read the inode for one into memory The inode says where first data block is on disk Read that block into memory to access the data in the file November 13, 2016 CSE 120 Lecture 12 File Systems 28

File Buffer Cache Applications exhibit significant locality for reading and writing files Idea: Cache file blocks in memory to capture locality Issues Called the file buffer cache Cache is system wide, used and shared by all processes Reading from the cache makes a disk perform like memory Even a small cache can be very effective The file buffer cache competes with VM (tradeoff here) Like VM, it has limited size Need replacement algorithms again (LRU usually used) November 13, 2016 CSE 120 Lecture 12 File Systems 29

Caching Writes On a write, some applications assume that data makes it through the buffer cache and onto the disk As a result, writes are often slow even with caching OSes typically do write back caching Maintain a queue of uncommitted blocks Periodically flush the queue to disk (30 second threshold) If blocks changed many times in 30 secs, only need one I/O If blocks deleted before 30 secs (e.g., /tmp), no I/Os needed Unreliable, but practical On a crash, all writes within last 30 secs are lost Modern OSes do this by default; too slow otherwise System calls (Unix: fsync) enable apps to force data to disk November 13, 2016 CSE 120 Lecture 12 File Systems 30

Read Ahead Many file systems implement read ahead FS predicts that the process will request next block FS goes ahead and requests it from the disk This can happen while the process is computing on previous block» Overlap I/O with execution When the process requests block, it will be in cache Compliments the disk cache, which also is doing read ahead For sequentially accessed files can be a big win Unless blocks for the file are scattered across the disk File systems try to prevent that, though (during allocation) November 13, 2016 CSE 120 Lecture 12 File Systems 31

Summary Files Operations, access methods Directories Operations, using directories to do path searches Sharing Protection ACLs vs. capabilities File System Layouts Unix inodes File Buffer Cache Strategies for handling writes Read Ahead November 13, 2016 CSE 120 Lecture 12 File Systems 32

Next time Read Chapters 11.8, 12.7 November 13, 2016 CSE 120 Lecture 12 File Systems 33