+ All Categories
Home > Documents > CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of...

CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of...

Date post: 09-Nov-2020
Category:
Upload: others
View: 9 times
Download: 0 times
Share this document with a friend
33
CS 350 Operating Systems Fall 2019 File System 1
Transcript
Page 1: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

CS 350 Operating SystemsFall 2019

File System

1

Page 2: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

OS Abstractions

• Process: virtualization of CPU

• Address space: virtualization of memory

• The above to allow a program to run as if it is in its own private, isolated world (CPU and memory)

• Persistent storage: hard disk drive and solid-state drive

• Management of persistent data: two goals

– performance

– reliability

2

Page 3: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

HDD vs. SSD

FLASH OR SSDHDD OR DISK DRIVE

3

SEEK

TRACK

Page 4: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

What is a File System?• File system is the OS component that organizes data on the raw storage

device.

• Data, by itself, is just a meaningless sequence of bits and bytes.

• Metadata is the information that describes the data.

– Also called attributes.

– Without meta-data, data itself will be incomprehensible.

• A File System defines

– Format of the data objects.

– The format/meaning of meta-data associated with each data object. E.g. File name, permissions, and size of a file.

– Location of the individual data blocks of for each data object.

– A framework to manage free space on the raw storage.

4

Page 5: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Metadata — Examples

5

Page 6: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

File Types

• Regular files

– Contains actual data

• Directories

– Files that help locate other files

• Character Special Files

– Typically for byte-oriented I/O operations

• Block special files

– For block-oriented I/O operations

6

Page 7: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Basic File System Operations

• Create a file

• Open an existing file

• Write to a file

• Read from a file

• Seek to somewhere in a file

• Close an open file

• Delete a file

7

Page 8: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Virtual File System (VFS)• VFS provides

1. A common system call interface to user applications to access different file systems implemented in the OS.

2. A common interface to file systems to “plug into” the operating system and provide services to user applications.

User Applications

System Calls

Virtual File System

File System 1 File System 2File System

N……

File System Cache

Device Drivers

Storage 1 Storage 2 Storage 3……

8

Page 9: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Partitions and File-system Layout

File System 1 File System 2 File System 3 …

9

Page 10: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Organizing Files on Disk: Contiguous Allocation

(a) Contiguous allocation of disk space for 7 files

(b) State of the disk after files D and E have been removed

10

Page 11: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Organizing Files on Disk: Singly Linked List of Blocks

• Advantage: Logically contiguous blocks can be discontiguous on disk

• Disadvantage:

– Space for pointers.

– Random seeks are expensive. Requires traversal from the start.11

Page 12: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Organizing Files on Disk: File Allocation Table

• Linked list allocation using a file allocation table in RAM

• Doesn’t need a separate “next” pointer within each block

• But random seeks are still expensive

12

Page 13: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

i-nodes (index nodes)

• Each file is described by an i-node• i-node stores the metadata for the file• Metadata = file info + location of data blocks• i-nodes are stored on the disk

• An i-node to a file is what a page-table is to a virtual address space

– Page table maps • virtual page number in a virtual address space ——>

physical page frame number in DRAM– i-node maps

• logical block number in a file ——> physical block location on disk

13

Page 14: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Unix i-node (index node)• Small files can be accessed

quickly

• If each block is 4KB, each block address is 4 bytes– First 48KB of file reachable

from 12 direct blocks– Next 4MB available from

single-indirect blocks– Next 4GB available from

double-indirect blocks– Next 4TB available through

the triple-indirect blocks

– To access any one block of a 4TB file, how many disk accesses at most do we need?

14

1024 direct blocks (4 KB/ 4 bytes)

1024 indirect blocks (4 KB/ 4 bytes)

Page 15: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Managing Free Space on Disk

Linked list

15

Page 16: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

File System Cache

User Applications

System Calls

Virtual File System

File System 1 File System 2File System

N……

File System Cache

Device Drivers

Storage 1 Storage 2 Storage 3……

16

Page 17: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

File System Cache (Page Cache)

• Small area in main memory that stores frequently accessed data blocks in the file system.

• Before accessing the disk, look in the FS cache.

• If data block is in FS cache, no need to go to disk.

• Periodically, purge the cache of infrequently used data blocks.

• Claim: If the cache works well, then most I/O accesses to the physical disk will be writes. Why?

17

Page 18: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Data Structure for File-System Cache

• Cache Lookup:

– Pages in cache are looked up via a hash table for fast access.

• Cache Eviction:

– Another doubly-linked list maintained to identify least-recently used (LRU) victim pages that are periodically purged.

– Is the victim page dirty? Then write to disk. Else discard.18

Page 19: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Log-Structured File Systems• With CPUs faster, memory larger

– disk caches are also getting larger

– increasing number of read requests come from file system cache

– Thus, most disk accesses will be writes

• LFS treats the entire disk as a log

– all writes are initially buffered in memory

– periodically commit the writes to the end of the disk log

– When file is opened, locate i-node, then find blocks

19

Page 20: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Hierarchical Directory Systems

20

Page 21: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Path Names

21

Page 22: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Implementing Directories

(a) A simple directory with fixed size entries. Disk addresses and attributes are stored in directory entry

(b) Directory in which each entry just refers to an i-node

I-nodes

22

Page 23: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Path lookup in a typical Unix File SystemThe steps in looking up /usr/ast/mbox

Next, lookup i-node 60 to locate the data blocks of the file /usr/ast/mbox23

Page 24: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

References

• OSTEP: Chapter 36, 37, 39, 43

24

Page 25: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Questions on I-nodes• All blocks in a disk are of size 4KB (4096 bytes). A disk block can store either data or

metadata (but not both).

• Each block address, i.e. a block’s location on the disk, is 8-bytes in size

• Last three entries of the top-level block of inode contain single, double, and tripleindirect block addresses.

• Assume that all file attributes other than data block addresses, take up negligible space in the top-level block of inode block.

• Rest of the space in the top-level inode (between end of attributes and single-indirect block address) is used to store direct block addresses.

• Question 1: What is the largest size of a file that can be accessed through – direct block entries?– direct + single indirect block entries?– direct + single + double indirect block entries?– direct + single + double + triple indirect block entries?

• Question 2: What is the size of an inode (in bytes) for a 32GB file?

25

Page 26: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Sample Questions

• 1. What is a File system?

• 2. What’s an i-node? Where is it stored?

• 3. What’s the simplest data structure for an i-node? Then why is UNIX i-node so complicated?

• 4. In a file-system, (a) What is meta-data? (b) Where is meta-data stored? (c) Why is it important for a file system to maintain the meta-data information? (d) List some of the typical information that is part of the meta-data.

26

Page 27: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Sample Questions

• 5. If you collect a trace of I/O operations below the file system cache (at device driver or physical disk level), what type of I/O operations do you expect to see more of -- write I/O requests or read I/O requests? Explain why.

• 6. (a) Suppose you collect a trace of I/O operations above the file system layer (in applications or in system calls). Do you expect to see more write I/O operations or read I/O operations? (b) Now suppose you collect a similar trace of I/O operations below the block device layer (in the disk or device driver). Do you expect to see more write I/O operations or read I/O operations? Explain why?

27

Page 28: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Sample Questions

• 7. If you increase or decrease the disk block size in a file system, how (and why) will it affect (a) the size of the inode, and (b) the maximum size of a file accessible only through direct block addresses?

• 8. How does the inode structure in UNIX-based file-systems support fast access to small files and at the same time support large file sizes.

28

Page 29: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Sample Questions

• 9. Explain the role of file system cache during (a) read I/O operations and (b) write I/O operations.

• 10. Describe two different data structures using which file system can track free space on the storage device. Explain relative advantages/disadvantages of each.

• 11. Explain the structure of a UNIX i-node. Why is it better than having just a single array that maps logical block addresses in a file to physical block addresses on disk?

29

Page 30: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Sample Questions

• Assume that:(i) Size of each disk block is B bytes. (ii) Address of each disk block is A bytes long. (iii) The top level of a UNIX i-node contains D direct

block addresses, one single-indirect block address, one double-indirect block address, and one triple-indirect block address.

(a) What is the size of the largest “small” file that can be addressed through direct block addresses?

(b) What is the size of the largest file that can be supported by a UNIX inode?

30

Page 31: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Sample Questions

• In a UNIX-like i-node, suppose you need to store a file of size 32 Terabytes (32 * 240 bytes). Approximately how large is the i-node (in bytes)? Assume 8096 bytes (8KB) block size, 8 bytes for each block pointer (entry in the inode)., and that i-node can have more than three levels of indirection. For simplicity, you can ignore any space occupied by file attributes (owner, permissions etc) and also focus on the dominant contributors to the i-node size.

31

Page 32: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Sample Questions

• In a UNIX-based filesystems, approximately how big (in bytes) will be an inode for a 200 Terabyte (200 * 240 bytes) file? Assume 4096 bytes block size and 8 bytes for each entry in the inode that references one data block.

• Assume that the size of each disk block is 4KB. Address of each block is 4 bytes long. What is the size of the largest file that can be supported by a UNIX inode? What is the size of the largest “small” file that can be addressed through direct block addresses? Explain how you derived your answer.

32

Page 33: CS 350 Operating Systems Fall 2019huilu/cs350/20-os-filesystem.pdf•Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All

Sample Questions

• Assume all disk blocks are of size 8KB. Top level of a UNIX inode is also stored in a disk block of size 8KB. All file attributes, except data block locations, take up 256 bytes of the top-level of inode. Each direct block address takes up 8 bytes of space and gives the address of a disk block of size 8KB. Last three entries of the first level of the inode point to single, double, and triple indirect blocks respectively. Calculate (a) the largest size of a file that can be accessed through the direct block entries of the inode. (b) The largest size of a file that can be accessed using the entire inode.

33


Recommended