0% found this document useful (0 votes)
1 views

fs-caching

The document discusses the role of file systems in operating systems, focusing on caching and consistency. It highlights how accessing data and metadata from disk affects performance and the importance of caching mechanisms to improve efficiency. Additionally, it addresses potential inconsistencies that can arise from caching and the need for system call guarantees to maintain file system integrity.

Uploaded by

RishavGoel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

fs-caching

The document discusses the role of file systems in operating systems, focusing on caching and consistency. It highlights how accessing data and metadata from disk affects performance and the importance of caching mechanisms to improve efficiency. Additionally, it addresses potential inconsistencies that can arise from caching and the need for system call guarantees to maintain file system integrity.

Uploaded by

RishavGoel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

CS330: Operating Systems

Filesystem: caching and consistency


Recap: file system
USER Storage devices
OS
/ Hard disk
drive

File system
etc bin sbin home lib SSD
layer

code file.txt
Others

- File system is an important OS subsystem


- Provides abstractions like files and directories
- Hides the complexity of underlying storage devices
Recap: file system organization
- File
SB Blocksystems
bitmap maintain severalInode
Inode bitmap meta-data
table structures
Datalike super blocks, inodes,
blocks

directory entries to provide a file system - Givenabstractions like files,load


any inode number, directories
the
- HowSupertoblock
search/lookup files/directoriesinode in a given path?
structure into memory
- Read the content of the root inode and search the next level dir using the
Inode bitmap address
name and find out its inode number inode_t *get_inode(SB *sb, long ino){
-Inode
Readtable address
the inode to check permissionsinode_t *inode
and repeat the =process
alloc_mem_inode( );
- Total
Inode
(Max) inodes the index structures read_disk(inode,
contains to deduce the disksbblock
→ inode_table +
address given
an logical
Other offset
information ino * sizeof(inode));
return inode;
}
File system and caching
- Accessing data and metadata from disk impacts performance
- Many file operations require multiple block access
File system and caching
- Accessing data and metadata from disk impacts performance
- Many file operations require multiple block access
- Examples:
- Opening a file

fd = open(“/home/user/test.c”, O_RDWR);
File system and caching
- Accessing data and metadata from disk impacts performance
- Many file operations require multiple block access
- Examples:
- Opening a file

fd = open(“/home/user/test.c”, O_RDWR);

- Normal shell operations

/home/user$ ls
File system and caching
- Accessing data and metadata from disk impacts performance
- Many file operations require multiple block access
- Executables,
Examples: configuration files, library etc. are accessed frequently
- Many directories
- Opening a filecontaining executables, configuration files are also accessed
very frequently. Metadata blocks storing inodes, indirect block pointers are
fd = open(“/home/user/test.c”, O_RDWR);
also accessed frequently
- Normal shell operations

/home/user$ ls
File system and caching
- Accessing data and metadata from disk impacts performance
- Can
Manywefilestore frequently
operations accessed
require diskblock
multiple data in memory?
access
- - What is the storage and lookup mechanism? Are the data and metadata
Examples:
- caching
Openingmechanisms
a file same?
- Are there any complications because of caching?
fd = open(“/home/user/test.c”, O_RDWR);
- How the cache managed? What should be the eviction policy?
- Normal shell operations

/home/user$ ls
Block layer caching
Cached I/O - Lookup memory cache using the
block number as the key
User processes
- How does the scheme work for data
read, write, stat
and metadata?
File system
lookup
read
write
blk_read
Disk cache Disk
blk_write
Block layer caching
Cached I/O - Lookup memory cache using the
block number as the key
User processes
- How does the scheme work for data
read, write, stat
and metadata?
File system - For data caching, file offset to block
lookup
read
address mapping is required before
write
blk_read using the cache
Disk cache Disk
blk_write
Block layer caching
Cached I/O - Lookup memory cache using the
block number as the key
User processes
- How does the scheme work for data
read, write, stat
and metadata?
File system - For data caching, file offset to block
lookup
read
address mapping is required before
write
blk_read using the cache
Disk cache
blk_write
Disk - Works fine for metadata as they are
addressed using block numbers
File layer caching (Linux page cache)
Cached I/O - Store and lookup memory cache
using {inode number, file offset} as
User processes
the key
read, write, stat
- For data, index translation is not
File system required for file access
lookup
read
- Metadata may not have a file
write
blk_read association, should be handled
Disk cache
blk_write
Disk differently (using a special inode
may be!)
File system and caching
- Accessing data and metadata from disk impacts performance
- Can
Manywefilestore frequently
operations accessed
require diskblock
multiple data in memory?
access
- - What is the storage and lookup mechanism? Are the data and metadata
Examples:
- caching
Openingmechanisms
a file same?
- File layer caching is desirable as it avoids index accesses on hit, special
fd = open(“/home/user/test.c”, O_RDWR);
mechanism required for metadata.
- Are thereshell
Normal anyoperations
complications because of caching?
- How the cache managed? What should be the eviction policy?
/home/user$ ls
Caching and consistency
- Caching may result in inconsistency, but what type of consistency?
Caching and consistency
- Caching may result in inconsistency, but what type of consistency?
- System call level guarantees
- Example-1: If a write( ) system call is successful, data must be written
- Example-2: If a file creation is successful then, file is created.
- Difficult to achieve with asynchronous I/O
Caching and consistency
- Caching may result in inconsistency, but what type of consistency?
- System call level guarantees
- Example-1: If a write( ) system call is successful, data must be written
- Example-2: If a file creation is successful then, file is created.
- Difficult to achieve with asynchronous I/O
- Consistency w.r.t. file system invariants
- Example-1: If a block is pointed to by an inode data pointers then,
corresponding block bitmap must be set
- Example-2: Directory entry contains an inode, inode must be valid
- Possible, require special techniques
File system inconsistency: root causes
- No consistency issues if user operation
Update contents of disk
blocks translates to read-only operations on
Disk block caching
the disk blocks
(delayed write)
Possible
inconsistent
file system
System crash (software,
power failure)
- Always keep in mind: device level
Storage medium failure atomicity guarantees
(sector(s) damaged)

You might also like