CSCI 350 Ch. 13 File & Directory Implementations. Mark Redekopp Michael Shindler & Ramesh Govindan

Similar documents
Main Points. File layout Directory layout

CS 4284 Systems Capstone

FILE SYSTEMS. CS124 Operating Systems Winter , Lecture 23

Main Points. File layout Directory layout

File Systems. Chapter 11, 13 OSPP

File Systems. CS170 Fall 2018

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

File Systems: Fundamentals

Lecture S3: File system data layout, naming

File Systems: Fundamentals

FILE SYSTEM IMPLEMENTATION. Sunu Wibirama

File system internals Tanenbaum, Chapter 4. COMP3231 Operating Systems

COMP 530: Operating Systems File Systems: Fundamentals

Chapter 11: File System Implementation. Objectives

File System Implementation. Sunu Wibirama

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

Operating Systems. Operating Systems Professor Sina Meraji U of T

CS370 Operating Systems

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

Long-term Information Storage Must store large amounts of data Information stored must survive the termination of the process using it Multiple proces

CHAPTER 11: IMPLEMENTING FILE SYSTEMS (COMPACT) By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

File System Implementation

Operating System Concepts Ch. 11: File System Implementation

Chapter 12: File System Implementation

Operating Systems. File Systems. Thomas Ropars.

File System Internals. Jo, Heeseung

ECE 598 Advanced Operating Systems Lecture 14

FILE SYSTEMS, PART 2. CS124 Operating Systems Fall , Lecture 24

ECE 598 Advanced Operating Systems Lecture 18

File system internals Tanenbaum, Chapter 4. COMP3231 Operating Systems

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

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

22 File Structure, Disk Scheduling

File System: Interface and Implmentation

Computer Systems Laboratory Sungkyunkwan University

Lecture 24: Filesystems: FAT, FFS, NTFS

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

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 System Internals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

CS 537 Fall 2017 Review Session

Chapter 8: Filesystem Implementation

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

Chapter 11: Implementing File Systems

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

File System (FS) Highlights

CS3600 SYSTEMS AND NETWORKS

BTREE FILE SYSTEM (BTRFS)

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

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

TCSS 422: OPERATING SYSTEMS

Windows File System. File allocation table (FAT) NTFS - New Technology File System. used in Windows 95, and MS-DOS

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

Indexing. Jan Chomicki University at Buffalo. Jan Chomicki () Indexing 1 / 25

ICS Principles of Operating Systems

ECE 650 Systems Programming & Engineering. Spring 2018

Operating Systems Design Exam 2 Review: Fall 2010

Chapter 12: File System Implementation

File Management By : Kaushik Vaghani

OPERATING SYSTEM. Chapter 12: File System Implementation

TDDB68 Concurrent Programming and Operating Systems. Lecture: File systems

Chapter 11: File System Implementation

CS370 Operating Systems

Lecture 19: File System Implementation. Mythili Vutukuru IIT Bombay

Chapter 11: Implementing File Systems

Frequently asked questions from the previous class survey

Chapter 12: File System Implementation

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

Example Implementations of File Systems

[537] Fast File System. Tyler Harter

Typical File Extensions File Structure

Thanks for the feedback! Chapter 8: Filesystem Implementation. File system operations. Acyclic-Graph Directories. General Graph Directory

Lecture 18: Reliable Storage

NTFS Recoverability. CS 537 Lecture 17 NTFS internals. NTFS On-Disk Structure

csci 3411: Operating Systems

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

V. File System. SGG9: chapter 11. Files, directories, sharing FS layers, partitions, allocations, free space. TDIU11: Operating Systems

Principles of Operating Systems

Chapter 10: File System Implementation

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

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

Chapter 11: Implementing File-Systems

File Systems. What do we need to know?

CS5460: Operating Systems Lecture 20: File System Reliability

Recall: So What About a Real File System? Meet the inode: Recall: Unix File System (2/2) Recall: Unix File System (1/2)

EECS 482 Introduction to Operating Systems

I/O and file systems. Dealing with device heterogeneity

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

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

File System Implementation

COMP091 Operating Systems 1. File Systems

Disk Scheduling COMPSCI 386

Advanced File Systems. CS 140 Feb. 25, 2015 Ali Jose Mashtizadeh

File Layout and Directories

Segmentation with Paging. Review. Segmentation with Page (MULTICS) Segmentation with Page (MULTICS) Segmentation with Page (MULTICS)

Chapter 11: Implementing File

CS720 - Operating Systems

CS 318 Principles of Operating Systems

Chapter 11: Implementing File Systems. Operating System Concepts 9 9h Edition

File Systems Management and Examples

Transcription:

1 CSCI 35 Ch. 13 File & Directory Implementations Mark Redekopp Michael Shindler & Ramesh Govindan

2 Introduction File systems primarily map filenames to the disk blocks that contain the file data File system can also impact Performance (Seek times for poorly placed blocks) Flexibility (Various access patterns) Sequential, random, many reads/few writes, frequent writes, etc. Consistency/persistence Reliability

3 Illusions Provided by File System Physical Storage Device Physical block/sector #'s Read/write sectors No protection/access rights for sectors Possibly inconsistent structure or corrupted data OS Abstraction File names + directory hierarchy Read/write bytes File protection / access rights Reliable and robust recovery

4 Analogous to VM Maintain directories and filenames which map to physical disk blocks Keep track of free resources (disk blocks vs. physical memory frames) Usually some kind of bitmap to track free disk blocks Locality heuristics (Look for these in coming slides) Keep related files physically close on disk (i.e. files in a directory) Keep blocks of a file close (Defragmenting) Use a log structure (sequential writes)

DIRECTORIES 5

cs356 home cs35 6 Directory Representation Map filenames to file numbers File number: Unique ID that can be used to lookup physical disk location of a file Directory info can be stored in a normal file (i.e. directories are files that contain mappings of filenames to file numbers) Maintain metadata indicating a file is a directory Usually you are not allowed to write these files but the OS provides special system calls to make/remove directories Only the OS writes the directory files. When would the OS write to a directory file? Each process maintains the "current working directory" Root directory has a predefined ("well-known") file number (e.g. 1) 2 /home 24 prg.py 8 cs35 71 cs356 1344 f1.txt 143 doc.txt 817 test.c 1568 f2.txt 32 readme 1199 PINTOS Directory-related system calls: bool chdir(const char* dir); bool mkdir(const char* dir); bool readdir(int fd, char* name) Returns next filename entry in the directory file indicated by fd bool isdir(int fd); Returns true if the file indicated by fd is a directory

cs356 home cs35 7 Directory Read Issues Problems 2 /home 24 A: Opening a file can require many reads to follow the path (e.g. /home/cs35/f1.txt) B: Finding a file in a directory file prg.py 8 cs35 71 cs356 1344 f1.txt 143 doc.txt 817 test.c 1568 Directory can have 1's of files Linear search may be very slow f2.txt 32 Solutions readme 1199 A: Caching of recent directory files (often locality in subsequent directory accesses) B: Use more efficient data structures to store the filename to file number information

8 Linear Directory File Layout Simplest Approach Linear List Do we really need to store the next file offset? File Offset: k. 45 Record Def: k'.. 67 foffset name file # k k' k'' k'' p1.cpp 132 k''' notes.md 821 k''' todo.doc 695

9 Linear Directory File Layout Simplest Approach Linear List Do we really need to store the next file offset? Yes, we may delete files Then, we may create new ones Requires linear, O(n), search to find an entry in a directory File Offset: k k' k'' k. 45 File Offset: k. 45 Record Def: k'.. 67 k'.. 67 foffset name file # k'' p1.cpp 132 k''' p1.cpp 132 k''' notes.md 821 k''' k k' k'' k''' File Offset: k. 45 k'.. 67 k''' p1.cpp 132 todo.doc 695-1 todo.doc 695 k k' k'' k''' new.txt 38 k'' todo.doc 695

1 Tree Directory File Layout Use a more efficient directory file structure Could use a balanced binary search tree The "pointers" (arrows) in the diagram would be file offsets to where the child entry starts Jumping to a new offset is likely a different disk block Recall the penalty for nonsequential reads from disk For larger directories walking the tree would be expensive Often a B+ Tree is used key value "list.doc" 143 "f1.txt" 822 "max.doc" 34 "a1.cpp" 1536 "hi.txt" 739 "readme" 621 "Interesting" technical look: http://lwn.net/21/222/a/dp-ext2.php3

REVIEW OF B-TREES FROM CS14 11

12 Definition B-trees have d to 2d keys and (d+1) to (2d+1) child pointers 2-3 Tree is a B-tree (d=1) where Non-leaf nodes have 1 value & 2 children or 2 values and 3 children All leaves are at the same level Following the line of reasoning All leaves at the same level with internal nodes having at least 2 children implies a full tree FULL A full tree with n nodes implies Height that is bounded by log 2 (n) 1 a 2 Node 4 a 3 Node 2 4 a valid 2-3 tree 2 4 3 5

13 2-3 Search Trees Similar properties as a BST 2-3 Search Tree If a 2 Node with value, m Left subtree nodes are < node value Right subtree nodes are > node value If a 3 Node with value, l and r Left subtree nodes are < l Middle subtree > l and < r Right subtree nodes are > r 2-3 Trees are almost always used as search trees, so from now on if we say 2-3 tree we mean 2-3 search tree < m a 2 Node m > m m = "median" or "middle" < l a 3 Node l > l && < r l = left r = right r > r

14 2-3 Insertion Algorithm Key: Since all leaves must be at the same level ("leaves always have their feet on the ground"), insertion causes the tree to "grow upward" To insert a value, 1. walk the tree to a leaf using your search approach 2a. If the leaf is a 2-node (i.e.1 value), add the new value to that node 2b. Else break the 3-node into two 2-nodes with the smallest value as the left, biggest as the right, and median value promoted to the parent with smallest and biggest node added as children of the parent Repeat step 2(a or b) for the parent Insert 6, 2, 1, 3, 25, 5, 8 Key: Any time a node accumulates 3 values, split it into single valued nodes (i.e. 2-nodes) and promote the median Empty Add 6 Add 2 Add 1 Add 3 2 2 6 2 6 1 2 6 1 6 1 3 6

15 2-3 Insertion Algorithm Key: Since all leaves must be at the same level ("leaves always have their feet on the ground"), insertion causes the tree to "grow upward" To insert a value, 1. walk the tree to a leaf using your search approach 2a. If the leaf is a 2-node (i.e.1 value), add the new value to that node 2b. Else break the 3-node into two 2-nodes with the smallest value as the left, biggest as the right, and median value promoted to the parent with smallest and biggest node added as children of the parent Repeat step 2(a or b) for the parent Insert 6, 2, 1, 3, 25, 5, 8 Key: Any time a node accumulates 3 values, split it into single valued nodes (i.e. 2-nodes) and promote the median Add 25 Add 5 2 2 3 2 3 1 3 6 25 1 25 6 1 25 5 6

BACK TO DIRECTORIES 16

17 Tree Directory File Layout Use a more efficient directory file structure Often a B+ Tree is used Each node holds an array whose size would likely be matched to the disk block size Filename (string) is hashed to an integer Integer is used as a key to the B+ Tree All keys live in the leaf nodes (keys are repeated in root/child nodes for indexing) Leaf nodes of B+ tree store the file offset of where in the directory file that particular file's info/entry is located "Interesting" technical look: http://lwn.net/21/222/a/dp-ext2.php3

18 Allowing for growth FILE IMPLEMENTATION

19 Overview FAT FFS NTFS ZFS Index structure Linked List Fixed, asymmetric tree Index structure granularity Dynamic tree Block Block Extent Block Dynamic, COW tree Free space management Locality heuristics FAT array Bitmap Bitmap in file Space map (logstructured) Defragmentation Block groups (reserve space) Best-fit / defragmentati on Write anywhere (block groups)

2 MICROSOFT FAT (FAT-32) FILE SYSTEM

21 FAT-32 An array of entries (1 per available block on the volume) Stored in some well-known area/sectors on the disk Array entries specify both file structure and free-map If FAT[i] is NULL (), then block i on the disk is available If FAT[i] is non-null and for all j, FAT[j]!= i, then block i is the starting point of a file and FAT[i] is the next block in the file A special value (usually all 1's = -1 = x?fffffff) will be used to indicate the of the chain (last block of a file) Sectors 4 8 12 16 4 5 6 7 8 9 1 11 12 13 14 15 FAT f1.txt f1.txt f2.txt f1.txt f2.txt f1.txt -1 11 14 5 7 8-1 f2.txt

22 How do you grow a file? FAT-32 Use simple approaches like next fit (next free block starting from the last block of the file) If we add to f1.txt block 1 would be selected Recall sequential access is fastest for disks. What performance issues are likely to arise? How can they be mitigated? How do you know where a file starts? Recall that is what directories are for though the previous slide provides the method Sectors 4 8 12 16 4 5 6 7 8 9 1 11 12 13 14 15 FAT f1.txt f1.txt f2.txt f1.txt f2.txt f1.txt -1 11 14 5 7 8-1 f2.txt Next fit

23 Other FAT-32 issues FAT-32 Limited metadata and access control No support for hard links File size (stored in metadata) is limited to 32-bits limiting file size to? Each FAT-32 entry uses 28-bits for the next block pointer, limiting the FAT to entries If each disk block corresponds to 4KB then the max volume size is? Note: Block size can be chosen. Is bigger better? Still used in many simple devices Flash-based USB drive, camera storage devices, etc. FAT approach is mimicked in some file formats (.doc) 1 document is made of many objects and the objects are tracked using a FAT like system Sectors 4 8 12 16 4 5 6 7 8 9 1 11 12 13 14 15 FAT f1.txt f1.txt f2.txt f1.txt f2.txt f1.txt -1 11 14 5 7 8-1 f2.txt

UNIX FFS (FAST FILE SYSTEM) 24

25 Inode = (index node?) 1 inode = 1 file inodes inode contains file metadata and location of the files data blocks Number of inodes often set when drive is formatted Inodes may be stored in an array at some well-known location on the disk Directories map filenames to file numbers which is simply the inode number (index in the inode array) If "f1.txt" has file number 2 then f1.txt's inode is at index 2 in the inode array 4 8 12 16 4 8 12 1 2 3 4 5 6 7 8 N-2 N-1 prg.py,8 cs35,15 inode f1.txt inode home,9 prg.py data

26 inode's File to Block Mapping Rather than using a linked list like FAT-32, FFS uses a multilevel index Really a fixed-depth, asymmetric tree The leaves of the tree are the data blocks of the file The root is the inode Internal nodes provide indirection to support ever-larger file sizes Internal nodes are usually whole sectors or blocks that store many pointers

27 Inode Multi-level Tree Index Inode File Metadata Inode array 1 2 3 4 5 6 7 8 N-2 N-1 (f1.txt). Indirect Ptr. Dbl. Ind. Ptr. Trip. Ind. Ptr IP IP DIP DIP IP IP IP IP f1.txt's inode 4 8 12 16 4 8 12 Inode array f1.txt data block f1.txt data block Ind. Block f1.txt data block

28 Pintos Base Filesys Implementation Uses an "extent" based approach where a file's size is fixed at creation time and must occupy a contiguous range of disk blocks Inode is used but simply stores the file's size and has one "direct" pointer to the starting block of the file Inode occupies an entire sector, thus that sector's number becomes the "inode"/file number In the illustration, the root-dir would have entries {f1.txt,2} and {f2.txt,12} f1.txt's inode at sector 2 would indicate the file's size and "point to" sector 5 4 8 12 16 f1.txt f2's inode Freemap Rootdir f1's inode f1.txt f1.txt f1.txt f2.txt f2.txt Pintos inodes occupy an entire sector

29 Pintos Base Implementation You will add code to enable extensible files using an asymmetric tree that provides at least doublyindirect blocks You may continue to use an entire sector per inode thus allowing the sector number to be the file number and easily access the inode Inode File Metadata. Indirect Ptr. Dbl. Ind. Ptr. IP IP

3 Locality Heuristics Disk is broken into groups of contiguous tracks called a block group Block group has a partition of the inode array and bitmap Attempt to place files of a directory in the block group where the directory's inode is located Subdirectories can be located in different block groups to avoid filling it

31 More About Block Groups Within a block group, first-fit algorithm is used Attempts to fill holes thus leaving greater contiguous free space at the end of the block group To increase ability to support sequential allocation, some amount of the disk is reserved (i.e. disk is "full" even if block groups have an average of 1% free space remaining) Want to ensure each block group has free space so large files might be split across a block group Good reference for FFS: http://pages.cs.wisc.edu/~remzi/classes/537/fall28/ Notes/file-ffs.txt

32 Opening and Reading a File List the sequence for finding and opening /tmp/f1.txt Use the well-known inode index for root directory, / Use the inode to go to the block where the file for "/" is stored Read through the data (possibly spanning multiple blocks) to find the mappint of 'tmp' to its file (inode) number Go back to the inode array and possibly read a new sector/block to get the inode Use the inode for tmp to go to the block where the file for "tmp" is stored Read through the data to find the file (inode) number associated with "f1.txt" Go back to the inode array to read the inode for "f1.txt" Use the inode for "f1.txt" to start reading through its direct blocks If "f1.txt" is large enough to require use of an indirect block, read the indirect block to obtain the subsequent direct pointers and then continue to read the blocks indicated by those direct pointers And so on for double or triply indirect blocks

33 Opening and Reading a File Reading a file may require many "random" accesses to walk the directory and file index structures OS:PP 2 nd Ed. Fig. 13.25 Read of /foo/bar/baz in the FFS file system

NTFS 34

35 MFT Records Uses an extent-based (variable size, contiguous ranges) approach Allocates by unit of clusters (multiple sectors) usually starts at 4KB Master File Table (MFT) Entries are 1KB Each entry contains A header (hard link count, in use, dir/file, size of MFT entry) Some number of attributes Attributes hold file metadata (name, std. info) or data Attributes can be resident (in the current extent) or non-resident (pointers to other extents) Usually 1/8 of disk set aside for MFT growth http://www.kes.talktalk.net/ntfs/ Header Offset to 1 st Attribute Std. Info Attribute (x1) Indicates size Filename Attribute (x3) Inidcates size Data (Non-Resident) Attribute (x8) End of Attribute (xffffffff) Data Extent Data Extent

36 Resident Data Attributes A small file's data (smaller than 1KB) can be contained in a "data" attribute entirely in the MFT record Header Offset to 1 st Attribute Std. Info Attribute (x1) Filename Attribute (x3) Data (Resident) Attribute (x8)

37 Entry with Large Number of Attributes If there are too many attributes or an attribute is too large to fit in the MFT entry, an extension record can be created using another MFT entry This may occur if the file is fragmented over many extents First entry acts as the file number/index Header Offset to 1 st Attribute Std. Info Attribute [Resident] (x1) Attribute List (x2) Filename Attribute (x3) Data (Non-Resident) Attribute Header Offset to 1 st Attribute Std. Info Attribute [Resident] (x1) Data (Non-Resident) Attribute

38 Non-resident Attribute Lists (Very Large Files) Even attribute lists can be non-resident Header Offset to 1 st Attribute Std. Info Attribute [Non-Resident] (x1) Attribute List (x2) Filename Attribute (x3) Data (Non-Resident) Attribute Attribute Extent Header Offset to 1 st Attribute Std. Info Attribute [Resident] (x1) Data (Non-Resident) Attribute

39 Comparison FFS (Linux ext2, ext3) Block-based Can be susceptible to long seek times Fixed-depth (asymmetric) index tree Limits file size Data never stored in inode entry Block groups using first-fit Internal Fragmentation NTFS (Linux ext4, Apple HFS) Extent-based Allows better sequential access Variable-depth index structure Arbitrary file size Small files in MFT entry itself Best-fit algorithm (API allows estimated file size to be communicated) External Fragmentation

4 ZFS, Btrfs COPY-ON-WRITE FILE SYSTEMS

41 Motivation Small writes are expensive Random access (data block, indirect node, i-node) Especially to RAID (if one block on a disk changes, need to update parity block) but sequential writes are faster Block caches (data from files maintained in RAM by the OS) filter reads Prevalence of flash Need to even wearing Greater disk space Allows versioning

42 Basic Idea Don't update blocks in place, simply write them all sequentially to a new location Data block, indirect block, i-node, directory, freespace bitmap, etc Make everything mobile Main issue: inodes need to be mobile rather than at fixed locations Solution: Store inode array itself in a file

43 Copy-On-Write Idea Suppose we need to add a block to a file whose old size fit in direct blocks but now needs to start using indirect pointers Inode File Metadata. Indirect Ptr. Dbl. Ind. Ptr.

44 Copy-On-Write Idea Suppose we need to add a block to a file whose old size fit in direct blocks but now needs to start using indirect pointers Inode File Metadata We would allocate and update The actual data block The indirect block The inode indirect ptr.. Indirect Ptr. Dbl. Ind. Ptr. The freespace bitmap The writes would like be nonsequential (spread) over the disk OS:PP 2 nd Ed. Fig. 13.19

45 Copy-On-Write Idea Instead, COW file systems would sequentially write new versions of the following blocks Data block Indirect block I-node Inode File Metadata Freespace bitmap. Indirect Ptr. Dbl. Ind. Ptr. OS:PP 2 nd Ed. Fig. 13.19

46 Updates Lead to Re-Writes If we already had an indirect block of pointers and wanted to add a new data block, would the inode need to change? Inode File Metadata IP IP. Indirect Ptr. Dbl. Ind. Ptr.

47 Updates Lead to Re-Writes No, but in COW we don't update in place instead making a new indirect block And since the indirect block location is different the inode we need to be updated Since the inode would need to be updated we'd simply write a new version of it sequentially with the other updated blocks Inode File Metadata. Indirect Ptr. Dbl. Ind. Ptr. IP IP And since the inode got updated, our directory entry would have to change, so we'd rewrite the directory file And since the directory file changed OS:PP 2 nd Ed. Fig. 13.19

48 Chain of Updates In COW, we would re-write all the updated blocks sequentially Since blocks are moving, may need to update inode and directory entries If the file is deep in the directory path, all parent directories would likely need to be updated We would move all the way to the root node of the file system Many random sectors may need to be updated when adding a new block In COW, we make al updates in new, sequential blocks (which may require updating more blocks), but might be as fast or faster as the random writes. 4 8 f1 data Freemap Rootdir f1 data f1 ind. block f1's inode f1 data 4 8 f1 data Freemap Rootdir f1 data f1 ind. block f1's inode f1 data 12 16 new f1 data 12 16 new f1 data Freemap Rootdir f1's f1 ind. inode block

49 Implementation In FFS the inode array would need to be in fixed (well-known) locations so that they could be found when needed In COW, inodes change and thus need to be mobile We could place them in a file (files are extensible) But how do we know where that file is? We could have a small "circular" buffer of "root inode" slots with only one (the latest) in use at a time Each update moves the root inode on OS:PP 2 nd Ed. Fig. 13.2 OS:PP 2 nd Ed. Fig. 13.21

5 ZFS Implementation Sun's ZFS implements COW concepts Uberblock array is like the root inode array slots (rotates entries on updates) and stores a pointer to the current "root Dnode" which is essentially the inode for the file containing all the other inodes Dnodes are like i-nodes Variable depth tree of block pointers Initial Dnode has room for 3 block pointers Support small files with data in the Dnode itself (i.e. tree depth=) Like MFT entry of NTFS File containing all the inodes ("dnodes") OS:PP 2 nd Ed. Fig. 13.23 Actual files are variable depth trees of indirect block pointers with a certain max depth (6 levels ZFS)

51 ZFS Example and Block Sizes Figure to the right shows an update of a file that uses 1 level of indirection Files can specify block size ranging from 512 bytes to 128KB But block pointers are large 128- byte structures (not just 4-bytes like in Pintos) as they hold checksums and other info, snapshots, etc. Large blocks Larger file sizes w/ same size index tree Potentially less free-space tracking overhead But it seems like a lot of work OS:PP 2 nd Ed. Fig. 13.22

52 Performance Enhancements Recall: Sequential writes are fast Writes can be buffered in memory allowing writes to the same file which cause multiple updates of the indirect pointers and dnodes to be coalesced In the figure if we did two writes, EACH write may require re-writing the indirect block, inode, etc. But if we buffer these updates in memory and coalesce the writes we would only need to write the indirect block and inode once (amortizing the cost over the 2 data blocks written) Inode File Metadata. Indirect Ptr. Dbl. Ind. Ptr. IP IP 1 st Write 2 nd Write After a short interval the writes are performed on disk

53 COW Benefits Versioning! Notice old version of file and directory structure are still present Consistency Transactional approach (all data maintained until atomic switch of uberblock) Power failure or crash still presents a consistent (old or new) view of the FS Even wearing Many updates to one file will now result in many rewrites to different locations OS:PP 2 nd Ed. Fig. 13.22

54 ZFS Locality (Free-Space) Management Bitmaps for large drives can still consume vast amounts of space 32 TB drive with 4KB pages = 1GB of bitmap space ZFS uses a similar notion of FFS block groups Maintains free-space: Per block group Partitions the free-space data structure (bitmap or extent tree) to make lookups faster As extents (contiguous ranges) Large, sequential free extents can be stored compactly rather than 1 bit per block Stores extents in an AVL tree indexed on size Using log-based updates Frees are simply logged (in memory) and then the free-space tree is updated only when a new allocation need be performed 143 1258 Bitmap for a large contiguous set of free blocks Start: 143 Size: 216 Extent Representation

55 Allocation Strategies When we do write to disk we must choose which block group and then allocate blocks within that group ZFS may span multiple disks Round robin between disks with some bias towards those with more free space Choose a block group Prefer spatial locality and continue in the block group where you last wrote Once a block group reaches a certain limit of free space, move on to the next (biasing selection based on free-space, location [nearby / outer-tracks of disk], etc.) Use first fit until the block group is close to full then use best-fit

56 COW Summary Versioning and Error-detection (checksumming) Much better write performance Comparable read performance Comparable file sizes (support for large volumes) Flash optimized