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

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

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

File System Performance (and Abstractions) Kevin Webb Swarthmore College April 5, 2018

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

Lecture S3: File system data layout, naming

COMP 530: Operating Systems File Systems: Fundamentals

CS 111. Operating Systems Peter Reiher

Operating Systems. Operating Systems Professor Sina Meraji U of T

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

CS 4284 Systems Capstone

File Systems. CS 4410 Operating Systems. [R. Agarwal, L. Alvisi, A. Bracy, M. George, E. Sirer, R. Van Renesse]

File Systems: Fundamentals

ECE 650 Systems Programming & Engineering. Spring 2018

CS 550 Operating Systems Spring File System

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

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

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

File Systems: Fundamentals

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

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

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

SCSI overview. SCSI domain consists of devices and an SDS

CS 31: Intro to Systems Storage and Memory. Kevin Webb Swarthmore College March 17, 2015

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

Hard Disk Organization. Vocabulary

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

[537] Fast File System. Tyler Harter

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

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

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

Operating Systems. File Systems. Thomas Ropars.

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

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

1 / 23. CS 137: File Systems. General Filesystem Design

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

CSC369 Lecture 9. Larry Zhang, November 16, 2015

CS370 Operating Systems

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

I/O and file systems. Dealing with device heterogeneity

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

Main Points. File layout Directory layout

CS370 Operating Systems

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

Lab 4 File System. CS140 February 27, Slides adapted from previous quarters

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

1 / 22. CS 135: File Systems. General Filesystem Design

ECE 598 Advanced Operating Systems Lecture 14

File Systems Part 1. Operating Systems In Depth XIV 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

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

FCFS: On-Disk Design Revision: 1.8

Da-Wei Chang CSIE.NCKU. Professor Hao-Ren Ke, National Chiao Tung University Professor Hsung-Pin Chang, National Chung Hsing University

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

Page Replacement. (and other virtual memory policies) Kevin Webb Swarthmore College March 27, 2018

csci 3411: Operating Systems

CS 318 Principles of Operating Systems

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

CS 31: Intro to Systems Operating Systems Overview. Kevin Webb Swarthmore College November 8, 2018

Introduction. Secondary Storage. File concept. File attributes

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

Typical File Extensions File Structure

File Systems. CS170 Fall 2018

CS 537 Fall 2017 Review Session

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

CSE 120 Principles of Operating Systems

CS3600 SYSTEMS AND NETWORKS

File Systems Management and Examples

Storing Data: Disks and Files. Storing and Retrieving Data. Why Not Store Everything in Main Memory? Database Management Systems need to:

File System: Interface and Implmentation

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

FILE SYSTEMS. Tanzir Ahmed CSCE 313 Fall 2018

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

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

Disk Scheduling COMPSCI 386

Storing and Retrieving Data. Storing Data: Disks and Files. Solution 1: Techniques for making disks faster. Disks. Why Not Store Everything in Tapes?

Storing Data: Disks and Files. Storing and Retrieving Data. Why Not Store Everything in Main Memory? Chapter 7

Principles of Data Management. Lecture #2 (Storing Data: Disks and Files)

Table 12.2 Information Elements of a File Directory

Storing and Retrieving Data. Storing Data: Disks and Files. Solution 1: Techniques for making disks faster. Disks. Why Not Store Everything in Tapes?

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

Lecture 21: Reliable, High Performance Storage. CSC 469H1F Fall 2006 Angela Demke Brown

Network File System (NFS)

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

Disks, Memories & Buffer Management

Network File System (NFS)

22 File Structure, Disk Scheduling

FILE SYSTEMS. CS124 Operating Systems Winter , Lecture 23

File System Implementation. Sunu Wibirama

EECE.4810/EECE.5730: Operating Systems Spring 2017

CS 318 Principles of Operating Systems

File Systems: FFS and LFS

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

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

ECE 598 Advanced Operating Systems Lecture 18

CSE506: Operating Systems CSE 506: Operating Systems

Operating Systems. Week 9 Recitation: Exam 2 Preview Review of Exam 2, Spring Paul Krzyzanowski. Rutgers University.

EECS 482 Introduction to Operating Systems

Operating System Concepts Ch. 11: File System Implementation

Final Exam Preparation Questions

CS 31: Intro to Systems Caching. Kevin Webb Swarthmore College March 24, 2015

Transcription:

File System Structure Kevin Webb Swarthmore College March 29, 2018

Today s Goals Characterizing disks and storage media File system: adding order and structure to storage FS abstractions (files, directories, paths) and their implementation with data structures (inodes, block pointers, directory entries)

Motivation for File Systems Long-term storage is needed for user data: text, graphics, images, audio, video user programs system programs (including OS kernel) and data Persistent: remains forever Large: unlimited size Sharing: controlled access Security: protecting information

Using Disks for Storage Why disks: persistent, random access, cheap

Source: http://www.mkomo.com/cost-per-gigabyte

Source: https://www.backblaze.com/blog/hard-drive-cost-per-gigabyte/

Using Disks for Storage Why disks: persistent, random access, cheap Biggest hurdle to OS: disks are slow

Disk Geometry Disk components Platters Surfaces Tracks Sectors Cylinders Arm Heads

Disk Geometry disk r/w head(s) disk arm sector platters track cylinder Moving parts: spinning platters, disk actuator arm seek time: moving the arm to the desired track rotational latency: turning the platter so that the desired data is under the head

Implications of moving parts https://www.youtube.com/watch?v=tdacjrsceq4 Disks have a MUCH higher failure rate than most other components PSA: back up your data!

Should the OS take these disk parameters into account when using a disk? Why or why not? Disk components Platters Surfaces Tracks Sectors Cylinders Arm Heads A. Yes B. No C. It depends (on?)

Disk Interaction In the old days: specifying disk requests required a lot of info: Cylinder #, head #, sector # (CHS) Disks did not have controller hardware built-in Very early OSes needed to know this info to make requests, but didn t attempt to optimize data storage for it. ~mid 80 s: fast file system emerged, which took disk geometry into account. Paper: A Fast File System for Unix Example disk in paper is 150 MB

Disk Interaction Problem: storage increased rapidly, only 10 bits available for cylinder Maximum size disk that could be represented: approx. 500 MB Solution : put a hardware controller on the disk Controller lies to the OS about how many sectors and heads are available Controller translates request from OS to actual >10-bit cylinder number More problems: disk complexity increases, new types of disk (SSD) For history, see: http://jdebp.eu/fga/os2-disc-and-volume-size-limits.html

Modern Disk Interaction Very simple block number interface: disk is divided into N abstract blocks (traditionally 512 B, today often 4 KB) read(block #) write(block #, data) Trust the disk controller. Convert block number to the right place in disk geometry. For some disks (SSDs), this may not even be the same location every time! Significant research happening now in new types of storage.

Storage Abstraction for File System Block 0 Block 1 Block 2 Abstraction: Illusion of an array of blocks. Spinning Disk SSD Block n-1

Storage Abstraction for File System Block 0 Block 1 Block 2 Can I have block 5? Here s block 5! Block 5 Abstraction: Illusion of an array of blocks. Spinning Disk SSD Block n-1

File Systems Disk reality to the OS: here s a bunch of blocks, go crazy! File System: Add order and structure to the blocks. Abstractions: files, directories, and others Control how data is stored and retrieved. Translate high-level abstractions into low-level block requests. There are LOTS of ways to build file systems. We re going to mainly focus on traditional structure.

Data vs. Metadata Data: the files, directories, and other stuff you re for the user. Metadata: information you re storing about your data. Example for entire FS: What type of FS is it? How large is it? Example for one file: Where are the file s blocks located on disk? Data: for the user or programs Metadata: for the system to make the file system work Both data and metadata stored together on disk!

File System Metadata Information about the FS as a whole. FS Metadata For most file systems, use the first few blocks to store global metadata. Includes: Type of file system. Block size. First block: superblock Possibly replicated, for redundancy. Of the remaining blocks, which are free/in use. (% full) FS Metadata

FS Abstraction: Hierarchical Name Space - Tree Root / home usr var soni kwebb fontes Query path TODO CS45 Paths: /home/kwebb/todo /home/soni Retrieve file info/data

What is a file? To the FS, a collection of attributes: Type Times: creation, accessed, modified Sizes: current size, maximum size Structure: where is the content stored on disk? Access control (permissions) Others?

Should the name be an attribute of a file? Why / why not? A. Yes B. No

FS Abstraction: Hierarchical Name Space - Tree Root / home usr var soni kwebb fontes Kevin-TODO TODO CS45 The same file can appear in multiple locations. (hard linking) Not used commonly.

What is a file? To the FS, a collection of attributes: Type? Times: creation, accessed, modified Sizes: current size, maximum size Structure: where is the content stored on disk? Access control (permissions) Others?

Regarding file types A. The OS distinguishes between file types. B. The user distinguishes between file types. C. Both the OS and users distinguish between file types. D. Nobody distinguishes between file types, files are all just files.

File Type To a human: Is this a music file? text file? video? pdf? To distinguish name the file with a suffix add special magic number in beginning of file (e.g., Java: 0xCAFEBABE) OS does NOT care what your files are. You ask for bytes, it delivers them. To the OS: How should I interpret these bytes? regular file? directory? device? FIFO (named pipe)?

File Metadata Information about files. Everything we know about a file encapsulated in inode structure. Each file has an inode. Typically about 2-5% of blocks reserved for inodes. FS Metadata File Metadata Every file needs an inode. It includes: Type of file (to the OS). File size. Most recent modification time. Number of times file is hard linked. Block(s) it s stored in on disk. Many more NOT the name of the file. (it might be linked from multiple directories)

File Metadata Information about files. Everything we know about a file encapsulated in inode structure. Each file has an inode. Typically about 2-5% of blocks reserved for inodes. inodes are a file system resource! FS Metadata File Metadata Includes:Type of file (to the OS). File size. Most recent modification time. Number of times file is hard linked. Block(s) it s stored in on disk. Many more NOT the name of the file. (it might be linked from multiple directories)

Data Blocks Rest of disk: data blocks Stores file contents. How do we find the data on disk? In file metadata (inode): Block(s) file is stored in on disk. Once we ve found the metadata for a file, it will tell us which blocks the data is in. FS Metadata File Metadata Data Blocks

Data Blocks In the inode structure for a file, there is a collection of block pointers. inode Type: reg file Size: X bytes Last modified: data/time Block pointers: FS Metadata File Metadata Data Blocks Block map

Data Blocks In the inode structure for a file, there is a collection of block pointers. inode Type: reg file Size: X bytes Last modified: data/time Block pointers: 6 FS Metadata File Metadata Data Blocks

Data Blocks In the inode structure for a file, there is a collection of block pointers. inode Type: reg file Size: X bytes Last modified: data/time Block pointers: 6 14 FS Metadata File Metadata Data Blocks 8 11

Suppose a block is 1 KB (2 10 bytes). How many block pointers does an inode need to support a maximum file size of 16 GB (2 34 bytes)? A: 2 10 pointers B: 2 16 pointers C: 2 24 pointers D: 2 34 pointers E: Some other number of pointers Block size: 1 KB?

Survey: Most of my files are A. Tiny (< 1 KB) B. Small (1 KB 1 MB) C. Medium (1 MB 100 MB) D. Large (100 MB 1 GB) E. Huge (> 1GB)

Suppose a block is 1 KB (2 10 bytes). How many block pointers does an inode need to support a maximum file size of 16 GB (2 34 bytes)? We need 2 24 block pointers. If a pointer is 4 bytes, that s 4 * 2 24 = 64 MB Per inode (per file)!? Block size: 1 KB

Don t discuss yet!

Problem: FS doesn t know in advance how big a file is going to be, so we need a lot of block pointers in case it s big. Having lots of pointers makes our inodes large (e.g., 64 MB). Result: If we want to store a small file (e.g., 1 KB) it ends up using a lot of disk space. What can we do about this?

Stop looking ahead through the slides for answers. Yes, that means YOU!

Recall: Multi-Level Page Tables Virtual Address 1st-level Page d 2nd-level Page p Offset i Insight: VAS is typically sparsely populated. Idea: every process gets a page directory (1 st -level table) V R M Frame Points to (base) frame containing 2nd-level page table V R M Frame concat Only allocate 2 nd -level tables when the process is using that VAS region! Level of Indirection Physical Address

Block Map (Traditional Unix FS) inode contains total 13 pointers (52 bytes per inode!) 10 direct: references 10 data blocks 1 singly-indirect: references n data blocks 1 doubly-indirect: references n 2 data blocks 1 triply-indirect: references n 3 data blocks Same max file size: 16 GB. inode is now WAY smaller: 52 byte block map vs. 64 MB For data block of 1024 bytes Assuming pointer requires 4 bytes, n = 256 Max file size: (10 + 256 + 256 2 + 256 3 ) * 1024 = 16 GB Storage space for file metadata (inode s block map) now scales with file size. This all sounds great! Is it free?

Block Pointers Data Blocks Direct pointers Block Map Triple Indirect Block Ptrs to Double Indirect Blocks Double Indirect Block Ptrs to Single Indirect Blocks Single Indirect Block Ptrs to Data blocks Direct: 10 x 1KB = 10KB Single Indirect: 256 x 1KB = 256KB Double Indirect: 256 x 256 x 1KB = 64MB Triple Indirect: 256 x 256 x 256 x 1KB = 16GB

Suppose we want to store a 100 KB file. How many bytes of metadata will we need for our block map? Direct pointers Data Blocks Block Map Triple Indirect Block Ptrs to Double Indirect Blocks Double Indirect Block Ptrs to Single Indirect Blocks Single Indirect Block Ptrs to Data blocks Block size: 1 KB (2 10 ) Pointer size: 4 bytes 2 8 = 256 pointers per block

File Metadata (inode) Summary Information about files. Everything we know about a file encapsulated in inode structure. Each file has an inode. Typically about 2-5% of blocks reserved for inodes. FS Metadata File Metadata Every file needs an inode. It includes: Type of file (to the OS). File size. Most recent modification time. Number of times file is hard linked. Block(s) it s stored in on disk. (block map) Many more NOT the name of the file. (it might be linked from multiple directories)

What s in a name? Root / So far, missing: file path (name) -> inode home usr var soni kwebb fontes Query path TODO CS45 Paths: /home/kwebb/todo /home/soni Retrieve file info/data

Directories A directory is a file. That is, just like a regular file, it has an inode, with attributes and a block map. What s different/special about a directory? The OS interprets the data of a directory differently. Rather than ignoring the data and just handing to users (regular files) Directory contains a collection of mappings: name -> inode number

Directory Data Blocks Direct pointers Block Map Triple Indirect Block Ptrs to Double Indirect Blocks Double Indirect Block Ptrs to Single Indirect Blocks Single Indirect Block Ptrs to Data blocks Name inode number (inumber) soni 7245 kwebb 10355 fontes 16873

Data Blocks Rest of disk: data blocks Stores user file and directory content. Once we ve found the metadata for a file, it will tell us which blocks the data is in. If the data is a directory, it will refer to other file metadata. FS Metadata File Metadata Data Blocks

Directory Lookup Example Inode 0 (root) Inode 22 Inode 15 Inode 88 File metadata bin 37 boot 12 local 25 home 22 usr 67 meeden 62 newhall 44 adanner 21 kwebb 15 TODO 88 CS31 92 CS45 46 TODO file data Data Given pathname: /home/kwebb/todo 1. Inode 0 block map points to data block(s) of root directory 2. Look up home in root directory to get inode 22 3. Inode 22 block map points to data block(s) of home directory 4. Look up kwebb in home directory to get inode 15

The Big Picture 0 1 File System Metadata Directory 2 3 File Metadata Regular file 4 Block Map 2 7 32... cat inodes Data Blocks 4 16 dog fish contents of dog

Summary Modern disk interface let s OS read/write numbered blocks. File system s goal is to add nice user abstractions on top of blocks. We focused on two main file types (to the OS): Regular file: user data, OS doesn t care what it contains Directory: maps names to inodes in the file system