CS3204: Operating Systems Project 4 Help Session

Slides:



Advertisements
Similar presentations
Tutorial 8 March 9, 2012 TA: Europa Shang
Advertisements

CS140 Review Session Project 4 – File Systems Samir Selman 02/27/09cs140 Review Session Due Thursday March,11.
CSCC69: Operating Systems
The Linux Kernel: Memory Management
Free Space and Allocation Issues
File Systems.
Memory Management (II)
Informationsteknologi Friday, November 16, 2007Computer Architecture I - Class 121 Today’s class Operating System Machine Level.
Ceng Operating Systems
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Christo Wilson Project 4: File System in Pintos
7/15/2015B.RamamurthyPage 1 File System B. Ramamurthy.
CS140 Review Session Project 4 – File Systems Varun Arora Based on Vincenzo Di Nicola’s slide 7/16/2015cs140 Review Session1.
Secondary Storage Management Hank Levy. 8/7/20152 Secondary Storage • Secondary Storage is usually: –anything outside of “primary memory” –storage that.
File System. NET+OS 6 File System Architecture Design Goals File System Layer Design Storage Services Layer Design RAM Services Layer Design Flash Services.
File Systems (1). Readings r Silbershatz et al: 10.1,10.2,
Disk Access. DISK STRUCTURE Sector: Smallest unit of data transfer from/to disk; 512B 2/4/8 adjacent sectors transferred together: Blocks Read/write heads.
SIMULATED UNIX FILE SYSTEM Implementation in C Tarek Youssef Bipanjit Sihra.
Chapter 4. INTERNAL REPRESENTATION OF FILES
CS 3204 Operating Systems Godmar Back Lecture 20.
CS 4284 Systems Capstone Project 4 Hints.
Chapter 4. INTERNAL REPRESENTATION OF FILES
CS 153 Design of Operating Systems Spring 2015 Lecture 21: File Systems.
Project 6 Unix File System. Administrative No Design Review – A design document instead 2-3 pages max No collaboration with peers – Piazza is for clarifications.
Disk & File System Management Disk Allocation Free Space Management Directory Structure Naming Disk Scheduling Protection CSE 331 Operating Systems Design.
CE Operating Systems Lecture 17 File systems – interface and implementation.
File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted).
Lecture 10 Page 1 CS 111 Summer 2013 File Systems Control Structures A file is a named collection of information Primary roles of file system: – To store.
CS 3204 Operating Systems Godmar Back Lecture 21.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 10 & 11: File-System Interface and Implementation.
Pintos project 3: Virtual Memory Management
4P13 Week 9 Talking Points
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
CS140 Project 4 Due Thursday March 10th Slides adapted from Samir Selman’s Kiyoshi Shikuma.
Disk Systems Operating Systems 1 Computer Science Dept Va Tech August 2007 ©2007 Back What Disks Look Like Hitachi Deskstar T7K500 SATA.
W4118 Operating Systems Instructor: Junfeng Yang.
File System Design David E. Culler CS162 – Operating Systems and Systems Programming Lecture 23 October 22, 2014 Reading: A&D a HW 4 out Proj 2 out.
Jonathan Walpole Computer Science Portland State University
Today topics: File System Implementation
Pintos Project 4 Hints.
Structure of Processes
CS 5204 Operating Systems Disks & File Systems Godmar Back.
Z502 File System Contains: Disk Structure Description System Calls
File System Structure How do I organize a disk into a file system?
Filesystems.
CS 4284 Systems Capstone Disks & File Systems Godmar Back.
Operation System Program 4
Circular Buffers, Linked Lists
CS Introduction to Operating Systems
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
CS 4284 Systems Capstone Disks & File Systems Godmar Back.
CS 3204 Operating Systems Lecture 22 Godmar Back.
Computer Architecture
Secondary Storage Management Brian Bershad
CSE 451: Operating Systems Autumn 2005 Memory Management
Chapter 10: File-System Interface
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Secondary Storage Management Hank Levy
CS 3204 Operating Systems Lecture 30 Godmar Back.
Internal Representation of Files
Structure of Processes
Lecture Topics: 11/20 HW 7 What happens on a memory reference Traps
The File Manager Implementation issues
Introduction to Operating Systems
Presentation transcript:

CS3204: Operating Systems Project 4 Help Session Presenter: Ali R. Butt Based on slides from Godmar Back

Project 4: Build a simple file system File systems provides persistent storage No room for errors Key tasks: Buffer Cache Extensible Files Subdirectories An open-ended design problem Synchronization

How Pintos’s filesystem is used pintos script writes/reads files get bootloader kernel (0,0) filesystem disk (0,1) scratch disk (1,0) swap disk (1,1) put VM swapping is loaded from your kernel pintos applications

Project requirements Format the disk when asked (write structures for an initial, empty filesystem on it) Support copying of files onto it when called from fsutil_put() (which happens before process_execute is called for the first time) – and copy files off of it Support required system calls New calls: mkdir, readdir, inumber, isdir, chdir Write data back to persistent storage Copy files from from storage when called from fsutil_get()

Project requirements (cont’d) Kernel is the only entity to write and read from your disk Choose your own layout Can pick any layout strategy that doesn’t suffer from external fragmentation and can grow files recommend Unix-style direct, single indirect, double indirect inode layout – but feel free to be creative Can pick any on-disk inode layout (you must design your own, the existing one does not work) Can pick any directory layout (although existing directory layout suffices)

Base filesystem layout Freemap File Inode Start=2 Length=4 Free Map 11100101 Root Directory (16 entries à 20bytes < 1 sector) inode # name[15] inuse=0 inode #7 multi-oom inuse=1 Root Directory Inode Start=6 Length=1 File Inode Start=8 Length=5 multi-oom executable 1 2 3 4 5 6 7 8 9 . Disk Sectors

Recommended implementation order Buffer Cache – implement & pass all regression tests Extensible Files – implement & pass file growth tests Subdirectories Miscellaneous: cache readahead, reader/writer fairness, deletion etc. Synchronization (at some point) drop global fslock You should think about synchronization throughout

The BIG picture PCB files (including directories) inodes, index blocks Per-process file descriptor table Data structures to keep track of open files struct file inode + position struct dir struct inode Buffer Cache … 5 4 3 2 1 ? PCB Root Dir Inode Open file table Cached data and metadata in buffer cache Free Map On-Disk Data Structures

Buffer cache: Overview Should cache accessed disk blocks in memory Buffer cache should be only interface to disk: all disk accesses should go through it Ensures consistency! system calls, fs utils file_*() dir_*() inode_*() cache_*() disk_*()

Buffer cache: Design Cache Block Descriptor disk_sector_id, if in use dirty bit valid bit # of readers # of writers # of pending read/write requests lock to protect above variables signaling variables to signal availability changes usage information for eviction policy data (pointer or embedded) desc 512 bytes desc 512 bytes desc 512 bytes desc 512 bytes 64 desc 512 bytes desc 512 bytes desc 512 bytes

Buffer cache: Interface // cache.h struct cache_block; // opaque type // reserve a block in buffer cache dedicated to hold this sector // possibly evicting some other unused buffer // either grant exclusive or shared access struct cache_block * cache_get_block (disk_sector_t sector, bool exclusive); // release access to cache block void cache_put_block(struct cache_block *b); // read cache block from disk, returns pointer to data void *cache_read_block(struct cache_block *b); // fill cache block with zeros, returns pointer to data void *cache_zero_block(struct cache_block *b); // mark cache block dirty (must be written back) void cache_mark_block_dirty(struct cache_block *b); // not shown: initialization, readahead, shutdown

Buffer cache: Notes Interface is just a suggestion Definition as static array of 64 blocks ok Use structure hiding (don’t export cache_block struct outside cache.c) Must have explicit per-block locking (can’t use Pintos’s lock since they do not allow for multiple readers) Should provide solution to multiple reader, single writer synchronization problem that starves neither readers nor writers: Use condition variables! Eviction: use LRU (or better) Can use Pintos list_elem to implement eviction policy, such as LRU via stack implementation

Prefetching b = cache_get_block(n, _); cache_read_block(b); cache_readahead(next(n)); Would like to bring next block to be accessed into cache before it’s accessed Must be done in parallel use daemon thread and producer/consumer pattern Note: next(n) not always equal to n+1 Don’t initiate read_ahead if next(n) is unknown or would require another disk access to find out queue q; cache_readahead(sector s) { q.lock(); q.add(request(s)); qcond.signal(); q.unlock(); } cache_readahead_daemon() { while (true) { q.lock(); while (q.empty()) qcond.wait(); s = q.pop(); read sector(s);

Multi-Level indices 1 2 3 .. N FLI SLI TLI 1 Need only single&double indirect blocks 2 1 2 3 .. N FLI SLI TLI Direct Blocks N N+1 N+I index Indirect Block index N+I+1 Double Indirect Block index2 index Triple Indirect Block index3 index2 N+I+I2 index

Logical View (Per File) offset in file Inode Index Data Index2 1 2 3 4 5 6 7 12 13 14 20 21 27 28 34 35 Physical View (On Disk) (ignoring other files) sector numbers on disk

Logical View (Per File) offset in file … 18 19 17 16 15 14 … 5 12 4 3 2 1 … 10 11 9 8 7 6 … -1 34 27 20 13 Inode Index Data Index2 1 2 3 4 5 6 7 12 13 14 20 21 27 28 34 35 Physical View (On Disk) (ignoring other files) sector numbers on disk

More on multi-level indices How many levels do we need? Max Disk size: 8MB = 16,384 Sectors Assume sector number takes 2 or 4 bytes, can store 256 or 128 in one sector Filesize(using only direct blocks) < 256 Filesize(direct + single indirect block) < 2*256 File (direct + single indirect + double indirect) < 2*256 + 256^2 = 66,048

Files vs. Inode vs. Directories Offset management in struct file etc. should not need any changes If there’s no sharing of struct file/dir instances between processes, then there are no concurrency issues since Pintos’s processes are single-threaded! You have to completely redesign struct inode_disk to fit your layout You will have to change struct inode struct inode are necessarily shared between processes – since they represent files on disk! struct inode can no longer embed struct inode_disk (inode_disk should be stored in buffer cache)

struct inode vs struct inode_disk { disk_sector_t start; /* First data sector. */ off_t length; /* File size in bytes. */ unsigned magic; /* Magic number. */ uint32_t unused[125];/* Not used. */ }; redesign for indexed approach /* In-memory inode. */ struct inode { struct list_elem elem; /* Element in inode list. */ disk_sector_t sector; /* Sector number of disk location. */ int open_cnt; /* Number of openers. */ bool removed; /* True if deleted, false otherwise. */ int deny_write_cnt; /* 0: writes ok, >0: deny writes. */ struct inode_disk data; /* Inode content. */ }; store in buffer cache

Extending a file Seek past end of file & write extends a file Space in between is filled with zeros Can extend sparsely (use “nothing here” marker in index blocks) Consistency guarantee on file extension: If A extends & B reads, B may read all, some, or none of what A wrote But never something else! Implication: do not update & unlock metadata structures (e.g., inode length) until data is in buffer cache

Subdirectories Support nested directories (work as usual) Requires: Keeping track of type of file in on-disk inode Distinction between file descriptors in syscall layer – e.g., must reject write() to open directory Should only require minor changes to how individual directories are implemented (e.g., as a linear list – should be able to reuse existing code) Must implement “.” and “..” – simple solution is to create the two entries on disk when a directory is created. Must support path names such as ///a/b/../c/./d Path components can remain <= 14 in length Once file growth works, directory growth should work “automatically” Implement system calls: readdir, mkdir, rmdir Need a way to test whether directory is empty readdir() should not return . and ..

Subdirectories: Lookup Implement absolute & relative paths Use strtok_r to split path Recall that strtok_r() destroys its argument - make sure you create copy if necessary Make sure you operate on copied-in string Walk hierarchy, starting from root directory (for absolute paths); current directory (for relative paths) All components except last must exist & be directories Make sure you don’t leak memory, or you fail dir-vine.

Current Directory Need to keep track of current directory in struct thread be aware of possible initialization order issues: before first task starts, get/put must work but process_execute hasn’t been called When an attempt is made to delete the current directory, or any open directory, either Reject Allow, but don’t allow further use

Synchronization Issues (1) Always consider: what lock (or other protection mechanism) protects which field: If lock L protects data D, then all accesses to D must be within lock_acquire(&L); …. Update D …; lock_release(&L); Embed locks in objects or define as static variables where appropriate (struct inode) For buffer cache entries, must build new synchronization structure (Single Writer/Multiple Reader lock without starvation) on top of existing ones (locks + condition variables) For directories, can use lock on underlying inode directly to guarantee exclusive access

Synchronization Issues (2) Should be fine-grained: independent operations should proceed in parallel, for example Don’t lock entire buffer cache when waiting for read/write access of individual buffer cache entry Example: don’t lock entire path resolution component when looking up file along /a/b/c/d Files should support multiple readers & writers Data writes do not require exclusive access to buffer cache block holding the data! Process removing a file in directory A should not wait for removing file in directory B For full credit, must have dropped global fs lock Can’t see whether any of this works until you have done so

Free Map Management Can leave almost unchanged Read from disk on startup, flush on shutdown Instead of allocating n sectors at file creation time, now allocate 1 sector at a time, and only when file is growing Implement extents for extra performance + credit But: must still support creating files that have an initial size greater than 0; easy to do: If file_create(“…”, m) is called with m > 0, simulate write_at(offset=m, 1byte of data); to expand to appropriate length Don’t forget to protect free_map() with lock

Grading Hints Extended tests won’t fully pass until file growth + subdirectories are sufficiently implemented such that ‘tar’ works. No persistency X points Full persistency X+Y points Core parts (majority of credit) of assignment are Buffer cache Extensible files Subdirectories For this assignment, credit for regression tests will depend on how many parts (n = 0, 1, 2) of the assignment you’ve implemented Credit for regression tests = Reported TestScore * n/3 Don’t get credit for resubmitting P2. Tests will not detect If you keep global fslock or not If you have a buffer cache TAs will grade those aspects by inspection/reading your design document Good Luck! They need 1 update in the "grading hints" section, and that is with respect to the persistency testing, which is now counted separately. This means that they pass a test, get X points, and if they are able to shutdown the machine and reboot it, then are able to tar off the results of the test from their disk and it matches the expected result, they get another Y points. (Previously, they got 0 points if the second part didn't work, X+Y points otherwise.)