Case Study: Ext2 FS

Case Study: Ext2 FS

Case study: ext2 FS 1 The ext2 file system • Second Extended Filesystem – The main Linux FS before ext3 – Evolved from Minix filesystem (via “Extended Filesystem”) • Features – Block size (1024, 2048, and 4096) configured at FS creation – inode-based FS – Performance optimisations to improve locality (from BSD FFS) • Main Problem: unclean unmount e2fsck – Ext3fs keeps a journal of (meta-data) updates – Journal is a file where updates are logged – Compatible with ext2fs Recap: i-nodes • Each file is represented by an inode on disk • Inode contains the fundamental file metadata – Access rights, owner, accounting info – (partial) block index table of a file • Each inode has a unique number – System oriented name – Try ‘ls –i’ on Unix (Linux) • Directories map file names to inode numbers – Map human-oriented to system-oriented names 3 Recap: i-nodes mode uid Ext2 i-nodes gid atime ctime • Mode mtime – Type size • Regular file or directory block count – Access mode • rwxrwxrwx reference count • Uid direct blocks – User ID (12) • Gid single indirect – Group ID double indirect triple indirect 5 mode uid Inode Contents gid atime ctime • atime mtime – Time of last access size • ctime block count – Time when file was created reference count • mtime direct blocks – Time when file was last (12) modified single indirect double indirect triple indirect 6 mode uid Inode Contents - Size gid • What does ‘size of a file’ really atime mean? ctime – The space consumed on disk? mtime • With or without the metadata? size – The number of bytes written to the file? block count – The highest byte written to the file? reference count direct blocks 0 N (12) single indirect File system double indirect triple indirect 4 7 8 2 5 1 6 3 7 mode uid Inode Contents - Size gid • What does ‘size of a file’ really atime mean? ctime – The space consumed on disk? mtime • With or without the metadata? size – The number of bytes written to the file? block count – The highest byte written to the file? reference count direct blocks 0 N (12) single indirect File system double indirect triple indirect 7 8 5 1 8 mode uid Inode Contents - Size gid • What does ‘size of a file’ really atime mean? ctime – The space consumed on disk? mtime • With or without the metadata? size – The number of bytes written to the file? block count – The highest byte written to the file? reference count direct blocks 0 N (12) single indirect File system double indirect triple indirect 8 9 mode uid Inode Contents gid • Size atime – Offset of the highest byte written ctime • Block count mtime – Number of disk blocks used by the file. size – Note that number of blocks can be much block count less than expected given the file size reference count • Files can be sparsely populated – E.g. write(f,“hello”); lseek(f, 1000000); direct blocks write(f, “world”); (12) – Only needs to store the start and end of file, single indirect not all the empty blocks in between. double indirect – Size = 1000005 – Blocks = 2 + any indirect blocks triple indirect 10 mode uid Inode Contents File gid • Direct Blocks atime – Block numbers of first 12 blocks in the 11 ctime file 10 mtime – Most files are small 9 • We can find blocks of file directly from the 8 size inode block count 7 0 10 7 6 reference count 3 8 4 direct blocks (12) 5 40,58,26,8,12, 11 4 44,62,30,10,42,3,21 2 7 3 single indirect 2 double indirect 0 9 5 1 triple indirect 0 56 1 6 63 Disk 11 Problem • How do we store files with data at offsets greater than 12 blocks? – Adding significantly more direct entries in the inode results in many unused entries most of the time. 12 mode 17 uid Inode Contents 16 gid 15 •Single Indirect Block 14 atime –Block number of a block containing ctime block numbers 13 mtime 12 11 size 10 block count 0 10 7 9 reference count 3 8 4 8 direct blocks (12) 40,58,26,8,12, 28 11 7 44,62,30,10,42,3,21 29 2 12 13 7 6 single indirect: 32 38 SI 14 5 double indirect 46 0 9 17 5 15 4 triple indirect 61 3 43 56 1 16 6 63 2 1 Disk 13 0 Single Indirection • Requires two disk access to read – One for the indirect block; one for the target block • Max File Size – Assume 1Kbyte block size, 4 byte block numbers 12 * 1K + 1K/4 * 1K = 268 KiB • For large majority of files (< 268 KiB), given the inode, only one or two further accesses required to read any block in file. 14 mode uid Inode Contents gid •Double Indirect Block atime –Block number of a block containing ctime block numbers of blocks containing mtime block numbers size block count reference count direct blocks (12) 40,58,26,8,12, 44,62,30,10,42,3,21 single indirect: 32 double indirect triple indirect 15 mode uid Inode Contents gid •Double Indirect Block atime –Block number of a block containing ctime block numbers of blocks containing mtime block numbers size •Triple Indirect –Block number of a block containing block count block numbers of blocks containing reference count block numbers of blocks containing direct blocks (12) block numbers 40,58,26,8,12, 44,62,30,10,42,3,21 single indirect: 32 double indirect triple indirect 16 UNIX Inode Block Addressing Scheme 17 UNIX Inode Block Addressing Scheme • Assume 8 byte blocks, containing 4 byte block numbers • => each block can contain 2 block numbers (1-bit index) • Assume a single direct block number in inode A 0 Block numbers for Single Indirect corresponding file offset Block 58 direct blocks (1) B 1 26 40 C 2 8 D 3 single indirect: 32 Level 2 Double 12 E 4 Indirect Blocks 18 double indirect:6 F 5 44 34 triple indirect: 16 Level 1 Double Subset of Inode G 6 62 Indirect Block H 7 I 8 30 0 K Di1 7 J 9 10 D I E Level 1 Triple K 10 42 31 Indirect Block Ti1 Di2 L L 11 3 47 57 C M N H Ti3 M 12 23 45 50 Si Di2 O N 13 28 A J F Ti3 Ti3 O 14 53 Level 2 Triple Ti2 Ti3 29 Indirect Block Level 3 Triple 56 Ti2 B G 63 Indirect Block 38 Disk 19 Max File Size • Assume 4 bytes block numbers and 1K blocks • The number of addressable blocks – Direct Blocks = 12 – Single Indirect Blocks = 256 – Double Indirect Blocks = 256 * 256 = 65536 – Triple Indirect Blocks = 256 * 256 * 256 = 16777216 • Max File Size 12 + 256 + 65536 + 16777216 = 16843020 blocks ≈ 16 GB 20 Where is the data block number stored? • Assume 4K blocks, 4 byte block numbers, 12 direct blocks • A 1 byte file produced by – lseek(fd, 1048576, SEEK_SET) /* 1 megabyte */ – write(fd, “x”, 1) • What if we add – lseek(fd, 5242880, SEEK_SET) /* 5 megabytes */ – write(fd, “x”, 1) 21 Where is the block number is this tree? 22 Solution? 4K blocks, 4 byte block numbers => 1024 block numbers in indirect blocks (10 bit index) Block # range location 0---11 Direct blocks 12 --- 1035 (11 + 1024) Single-indirect blocks 1036 --- 1049611 (1035 + 1024 Double-indirect blocks * 1024) 1049612 --- ???? Triple-indirect blocks File (not to scale) 0 N Solution Address = 1048576 ==> Block # range location block number=1048576/4096=256 0 ---11 Direct blocks 12---1035 Single-indirect blocks Single indirect offset = 256 – 12 1036 ---1049611 Double-indirect blocks = 244 1049612 --- ???? Triple-indirect blocks Where is the block number is this tree? 244th entry 25 Solution Address = 5242880 ==> Block # range location 0 ---11 Direct blocks Block number = 5242880/4096 =1280 12---1035 Single-indirect blocks Double indirect offset (20-bit) 1036 ---1049611 Double-indirect blocks = 1280 – 1036 1049612 --- ???? Triple-indirect blocks = 244 Top 10 bits = 0 Lower 10 bits = 244 Where is the block number is this tree? 244th entry 0th entry 27 Some Best and Worst Case Access Patterns Assume Inode already in memory • To read 1 byte – Best: • 1 access via direct block – Worst: • 4 accesses via the triple indirect block • To write 1 byte – Best: • 1 write via direct block (with no previous content) – Worst: • 4 reads (to get previous contents of block via triple indirect) + 1 write (to write modified block back) 28 Worst Case Access Patterns with Unallocated Indirect Blocks • Worst to write 1 byte – 4 writes (3 indirect blocks; 1 data) – 1 read, 4 writes (read-write 1 indirect, write 2; write 1 data) – 2 reads, 3 writes (read 1 indirect, read-write 1 indirect, write 1; write 1 data) – 3 reads, 2 writes (read 2, read-write 1; write 1 data) • Worst to read 1 byte – If reading writes a zero-filled block on disk – Worst case is same as write 1 byte – If not, worst-case depends on how deep is the current indirect block tree. 29 Inode Summary • The inode (and indirect blocks) contains the on-disk metadata associated with a file – Contains mode, owner, and other bookkeeping – Efficient random and sequential access via indexed allocation – Small files (the majority of files) require only a single access – Larger files require progressively more disk accesses for random access • Sequential access is still efficient – Can support really large files via increasing levels of indirection 30 Where/How are Inodes Stored Boot Super Inode Data Blocks Block Block Array • System V Disk Layout (s5fs) – Boot Block • contain code to bootstrap the OS – Super Block • Contains attributes of the file system itself • e.g.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    54 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us