File Systems Main Points File layout Directory layout - - PowerPoint PPT Presentation

file systems main points
SMART_READER_LITE
LIVE PREVIEW

File Systems Main Points File layout Directory layout - - PowerPoint PPT Presentation

File Systems Main Points File layout Directory layout File System Design Constraints For small files: Small blocks for storage efficiency


slide-1
SLIDE 1

File ¡Systems ¡

slide-2
SLIDE 2

Main ¡Points ¡

  • File ¡layout ¡
  • Directory ¡layout ¡
slide-3
SLIDE 3

File ¡System ¡Design ¡Constraints ¡

  • For ¡small ¡files: ¡

– Small ¡blocks ¡for ¡storage ¡efficiency ¡ – Files ¡used ¡together ¡should ¡be ¡stored ¡together ¡

  • For ¡large ¡files: ¡

– Con>guous ¡alloca>on ¡for ¡sequen>al ¡access ¡ – Efficient ¡lookup ¡for ¡random ¡access ¡

  • May ¡not ¡know ¡at ¡file ¡crea>on ¡

– Whether ¡file ¡will ¡become ¡small ¡or ¡large ¡

slide-4
SLIDE 4

File ¡System ¡Design ¡

  • Data ¡structures ¡

– Directories: ¡file ¡name ¡-­‑> ¡file ¡metadata ¡

  • Store ¡directories ¡as ¡files ¡

– File ¡metadata: ¡how ¡to ¡find ¡file ¡data ¡blocks ¡ – Free ¡map: ¡list ¡of ¡free ¡disk ¡blocks ¡

  • How ¡do ¡we ¡organize ¡these ¡data ¡structures? ¡

– Device ¡has ¡non-­‑uniform ¡performance ¡

slide-5
SLIDE 5

Design ¡Challenges ¡

  • Index ¡structure ¡

– How ¡do ¡we ¡locate ¡the ¡blocks ¡of ¡a ¡file? ¡

  • Index ¡granularity ¡

– What ¡block ¡size ¡do ¡we ¡use? ¡

  • Free ¡space ¡

– How ¡do ¡we ¡find ¡unused ¡blocks ¡on ¡disk? ¡

  • Locality ¡

– How ¡do ¡we ¡preserve ¡spa>al ¡locality? ¡

  • Reliability ¡

– What ¡if ¡machine ¡crashes ¡in ¡middle ¡of ¡a ¡file ¡system ¡op? ¡

slide-6
SLIDE 6

File ¡System ¡Design ¡Op>ons ¡

FAT ¡ FFS ¡ NTFS ¡ Index ¡ structure ¡ Linked ¡list ¡ Tree ¡ (fixed, ¡assym) ¡ Tree ¡ (dynamic) ¡ granularity ¡ block ¡ block ¡ extent ¡ free ¡space ¡ alloca>on ¡ FAT ¡array ¡ Bitmap ¡ (fixed ¡ loca>on) ¡ Bitmap ¡ ¡ (file) ¡ Locality ¡ defragmenta>on ¡ Block ¡groups ¡ + ¡reserve ¡ space ¡ Extents ¡ Best ¡fit ¡ defrag ¡

slide-7
SLIDE 7

Named ¡Data ¡in ¡a ¡File ¡System ¡

fjle name

  • fgset

directory fjle number

  • fgset

storage block index structure

slide-8
SLIDE 8

MicrosoW ¡File ¡Alloca>on ¡Table ¡(FAT) ¡

  • Linked ¡list ¡index ¡structure ¡

– Simple, ¡easy ¡to ¡implement ¡ – S>ll ¡widely ¡used ¡(e.g., ¡thumb ¡drives) ¡

  • File ¡table: ¡

– Linear ¡map ¡of ¡all ¡blocks ¡on ¡disk ¡ – Each ¡file ¡a ¡linked ¡list ¡of ¡blocks ¡

slide-9
SLIDE 9

FAT ¡

fjle 9 block 3 fjle 9 block 0 fjle 9 block 1 fjle 9 block 2 fjle 12 block 0 fjle 12 block 1 fjle 9 block 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

MFT Data Blocks

slide-10
SLIDE 10

FAT ¡

  • Pros: ¡

– Easy ¡to ¡find ¡free ¡block ¡ – Easy ¡to ¡append ¡to ¡a ¡file ¡ – Easy ¡to ¡delete ¡a ¡file ¡

  • Cons: ¡

– Small ¡file ¡access ¡is ¡slow ¡ – Random ¡access ¡is ¡very ¡slow ¡ – Fragmenta>on ¡

  • File ¡blocks ¡for ¡a ¡given ¡file ¡may ¡be ¡scaYered ¡
  • Files ¡in ¡the ¡same ¡directory ¡may ¡be ¡scaYered ¡
  • Problem ¡becomes ¡worse ¡as ¡disk ¡fills ¡
slide-11
SLIDE 11

Berkeley ¡UNIX ¡FFS ¡(Fast ¡File ¡System) ¡

  • inode ¡table ¡

– Analogous ¡to ¡FAT ¡table ¡

  • inode ¡

– Metadata ¡

  • File ¡owner, ¡access ¡permissions, ¡access ¡>mes, ¡… ¡

– Set ¡of ¡12 ¡data ¡pointers ¡ – With ¡4KB ¡blocks ¡=> ¡max ¡size ¡of ¡48KB ¡files ¡

¡

slide-12
SLIDE 12

FFS ¡inode ¡

  • Metadata ¡

– File ¡owner, ¡access ¡permissions, ¡access ¡>mes, ¡… ¡

  • Set ¡of ¡12 ¡data ¡pointers ¡

– With ¡4KB ¡blocks ¡=> ¡max ¡size ¡of ¡48KB ¡files ¡

  • Indirect ¡block ¡pointer ¡

– pointer ¡to ¡disk ¡block ¡of ¡data ¡pointers ¡

  • Indirect ¡block: ¡1K ¡data ¡blocks ¡=> ¡4MB ¡(+48KB) ¡
slide-13
SLIDE 13

FFS ¡inode ¡

  • Metadata ¡

– File ¡owner, ¡access ¡permissions, ¡access ¡>mes, ¡… ¡

  • Set ¡of ¡12 ¡data ¡pointers ¡

– With ¡4KB ¡blocks ¡=> ¡max ¡size ¡of ¡48KB ¡

  • Indirect ¡block ¡pointer ¡

– pointer ¡to ¡disk ¡block ¡of ¡data ¡pointers ¡ – 4KB ¡block ¡size ¡=> ¡1K ¡data ¡blocks ¡=> ¡4MB ¡

  • Doubly ¡indirect ¡block ¡pointer ¡

– Doubly ¡indirect ¡block ¡=> ¡1K ¡indirect ¡blocks ¡ – 4GB ¡(+ ¡4MB ¡+ ¡48KB) ¡

slide-14
SLIDE 14

FFS ¡inode ¡

  • Metadata ¡

– File ¡owner, ¡access ¡permissions, ¡access ¡>mes, ¡… ¡

  • Set ¡of ¡12 ¡data ¡pointers ¡

– With ¡4KB ¡blocks ¡=> ¡max ¡size ¡of ¡48KB ¡

  • Indirect ¡block ¡pointer ¡

– pointer ¡to ¡disk ¡block ¡of ¡data ¡pointers ¡ – 4KB ¡block ¡size ¡=> ¡1K ¡data ¡blocks ¡=> ¡4MB ¡

  • Doubly ¡indirect ¡block ¡pointer ¡

– Doubly ¡indirect ¡block ¡=> ¡1K ¡indirect ¡blocks ¡ – 4GB ¡(+ ¡4MB ¡+ ¡48KB) ¡

  • Triply ¡indirect ¡block ¡pointer ¡

– Triply ¡indirect ¡block ¡=> ¡1K ¡doubly ¡indirect ¡blocks ¡ – 4TB ¡(+ ¡4GB ¡+ ¡4MB ¡+ ¡48KB) ¡

slide-15
SLIDE 15

Inode Array

File Metadata Indirect Pointer

  • Dbl. Indirect Ptr.
  • Tripl. Indirect Ptr.

Inode Data Blocks Indirect Blocks Double Indirect Blocks Triple Indirect Blocks

DP Direct Pointer DP DP DP DP DP DP DP DP DP Direct Pointer

slide-16
SLIDE 16

FFS ¡Asymmetric ¡Tree ¡

  • Small ¡files: ¡shallow ¡tree ¡

– Efficient ¡storage ¡for ¡small ¡files ¡

  • Large ¡files: ¡deep ¡tree ¡

– Efficient ¡lookup ¡for ¡random ¡access ¡in ¡large ¡files ¡

  • Sparse ¡files: ¡only ¡fill ¡pointers ¡if ¡needed ¡
slide-17
SLIDE 17

FFS ¡Locality ¡

  • Block ¡group ¡alloca>on ¡

– Block ¡group ¡is ¡a ¡set ¡of ¡nearby ¡cylinders ¡ – Files ¡in ¡same ¡directory ¡located ¡in ¡same ¡group ¡ – Subdirectories ¡located ¡in ¡different ¡block ¡groups ¡

  • inode ¡table ¡spread ¡throughout ¡disk ¡

– inodes, ¡bitmap ¡near ¡file ¡blocks ¡

  • First ¡fit ¡alloca>on ¡

– Small ¡files ¡fragmented, ¡large ¡files ¡con>guous ¡ ¡

slide-18
SLIDE 18

F r e e S p a c e B i t m a p F r e e S p a c e B i t m a p I n

  • d

e s D a t a B l

  • c

k s f

  • r

fj l e s i n d i r e c t

  • r

i e s / b , / a / g , / z F r e e S p a c e B i t m a p I n

  • d

e s D a t a B l

  • c

k s f

  • r

fj l e s i n d i r e c t

  • r

i e s / d / q , / c , a n d / a / p

Block Group 0 Block Group 1 Block Group 2

I n

  • d

e s D a t a B l

  • c

k s f

  • r

fj l e s i n d i r e c t

  • r

i e s / a , / d , a n d / b / c

slide-19
SLIDE 19

FFS ¡First ¡Fit ¡Block ¡Alloca>on ¡

...

In-Use Block Start of Block Group Free Block

slide-20
SLIDE 20

FFS ¡First ¡Fit ¡Block ¡Alloca>on ¡

...

Start of Block Group Write Two Block File

slide-21
SLIDE 21

FFS ¡First ¡Fit ¡Block ¡Alloca>on ¡

...

Start of Block Group Write Large File

slide-22
SLIDE 22

FFS ¡

  • Pros ¡

– Efficient ¡storage ¡for ¡both ¡small ¡and ¡large ¡files ¡ – Locality ¡for ¡both ¡small ¡and ¡large ¡files ¡ – Locality ¡for ¡metadata ¡and ¡data ¡

  • Cons ¡

– Inefficient ¡for ¡>ny ¡files ¡(a ¡1 ¡byte ¡file ¡requires ¡both ¡an ¡ inode ¡and ¡a ¡data ¡block) ¡ – Inefficient ¡encoding ¡when ¡file ¡is ¡mostly ¡con>guous ¡on ¡ disk ¡(no ¡equivalent ¡to ¡superpages) ¡ – Need ¡to ¡reserve ¡10-­‑20% ¡of ¡free ¡space ¡to ¡prevent ¡ fragmenta>on ¡

slide-23
SLIDE 23

NTFS ¡

  • Master ¡File ¡Table ¡

– Flexible ¡1KB ¡storage ¡for ¡metadata ¡and ¡data ¡

  • Extents ¡

– Block ¡pointers ¡cover ¡runs ¡of ¡blocks ¡ – Similar ¡approach ¡in ¡linux ¡(ext4) ¡ – File ¡create ¡can ¡provide ¡hint ¡as ¡to ¡size ¡of ¡file ¡

  • Journalling ¡for ¡reliability ¡

– Next ¡chapter ¡

slide-24
SLIDE 24

NTFS ¡Small ¡File ¡

  • Std. Info.

File Name Data (resident) (free)

MFT Record (small fjle) Master File Table

slide-25
SLIDE 25

NTFS ¡Medium-­‑Sized ¡File ¡

MFT MFT Record

Start Length Start Length

  • Std. Info.

File Name (free) Data (nonresident) Data Extent Data Extent

slide-26
SLIDE 26

NTFS ¡Indirect ¡Block ¡

MFT MFT Record (part 2)

  • Std. Info.

(free) Data (nonresident) MFT Record (part 1)

  • Std. Info.

Attr.list Data (nonresident) File Name

Data Extent Data Extent Data Extent Data Extent Data Extent

slide-27
SLIDE 27

MFT Record (normal file) MFT

  • Std. Info.

Data (nonresident)

MFT Record (small file)

  • Std. Info.

Data (resident)

MFT Record (big/fragmented file)

  • Std. Info.

Attr.list Data (nonresident) Data (nonresident) Data (nonresident) Data (nonresident)

MFT MFT Record (huge/badly-fragmented file)

  • Std. Info.

Attr.list (nonresident) Data (nonresident) Data (nonresident) Data (nonresident) Data (nonresident) Extent with part of attribute list Extent with part of attribute list Data (nonresident)

slide-28
SLIDE 28

Named ¡Data ¡in ¡a ¡File ¡System ¡

fjle name

  • fgset

directory fjle number

  • fgset

storage block index structure

slide-29
SLIDE 29

Directories ¡Are ¡Files ¡

music 320 work 219 foo.txt 871

slide-30
SLIDE 30

Recursive ¡Filename ¡Lookup ¡

music 320 work 219 foo.txt 871 File 830

  • /home/tom

mike 682 ada 818 tom 830 File 158

  • /home

File 871

  • /home/tom/foo.txt

bin 737 usr 924 home 158 File 2

  • /

The quick brown fox jumped

  • ver the

lazy dog.

slide-31
SLIDE 31

Directory ¡Layout ¡

File 830 /home/tom

End of File Name File Number Next

. 830 .. 158 music 320 work 219

Free Space

foo.txt 871

Free Space

Directory ¡stored ¡as ¡a ¡file ¡ Linear ¡search ¡to ¡find ¡filename ¡(small ¡directories) ¡

slide-32
SLIDE 32

Large ¡Directories: ¡B ¡Trees ¡

Search for Hash (foo.txt) = 0x30

Before Child Pointer

240 510 730 980 Root

Hash Entry Pointer

15 30 44 58 Leaf . 830 .. 158 30 foo.txt 871 music 320 ... ... work 219 code 3 bin 014 ... ... test 324 Leaf

Hash Number Name File Number Before Child Pointer

58 121 180 240 Child 780 841 930 980 Child

slide-33
SLIDE 33

Large ¡Directories: ¡Layout ¡

Directory Entries B+Tree Nodes

... work 219 ... music 320 ... Child Root Leaf Leaf ... Child

Name File Number

File Containing Directory