CS510 Operating System Foundations

Slides:



Advertisements
Similar presentations
Chapter 4 : File Systems What is a file system?
Advertisements

Operating Systems ECE344 Ashvin Goel ECE University of Toronto Disks and RAID.
File Systems.
Jonathan Walpole Computer Science Portland State University
1 File Systems Chapter Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems.
Other Disk Details. 2 Disk Formatting After manufacturing disk has no information –Is stack of platters coated with magnetizable metal oxide Before use,
CS 333 Introduction to Operating Systems Class 16 – Secondary Storage Management Jonathan Walpole Computer Science Portland State University.
Lecture 17 I/O Optimization. Disk Organization Tracks: concentric rings around disk surface Sectors: arc of track, minimum unit of transfer Cylinder:
File System Implementation CSCI 444/544 Operating Systems Fall 2008.
CS 333 Introduction to Operating Systems Class 18 - File System Performance Jonathan Walpole Computer Science Portland State University.
Ceng Operating Systems
1 Outline File Systems Implementation How disks work How to organize data (files) on disks Data structures Placement of files on disk.
CS 333 Introduction to Operating Systems Class 16 – Secondary Storage Management Jonathan Walpole Computer Science Portland State University.
1 Friday, July 07, 2006 “Vision without action is a daydream, Action without a vision is a nightmare.” - Japanese Proverb.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Avishai Wool lecture Introduction to Systems Programming Lecture 9 Input-Output Devices.
Secondary Storage CSCI 444/544 Operating Systems Fall 2008.
CS 333 Introduction to Operating Systems Class 19 - File System Performance Jonathan Walpole Computer Science Portland State University.
Secondary Storage Management Hank Levy. 8/7/20152 Secondary Storage • Secondary Storage is usually: –anything outside of “primary memory” –storage that.
Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money.
1 Recitation 8 Disk & File System. 2 Disk Scheduling Disks are at least four orders of magnitude slower than main memory –The performance of disk I/O.
1 File System Implementation Operating Systems Hebrew University Spring 2010.
File Systems (1). Readings r Silbershatz et al: 10.1,10.2,
Lecture 9 of Advanced Databases Storage and File Structure (Part II) Instructor: Mr.Ahmed Al Astal.
1 File Systems Chapter Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems.
Disk Structure Disk drives are addressed as large one- dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer.
File System Implementation Chapter 12. File system Organization Application programs Application programs Logical file system Logical file system manages.
CE Operating Systems Lecture 20 Disk I/O. Overview of lecture In this lecture we will look at: Disk Structure Disk Scheduling Disk Management Swap-Space.
Disks Chapter 5 Thursday, April 5, Today’s Schedule Input/Output – Disks (Chapter 5.4)  Magnetic vs. Optical Disks  RAID levels and functions.
CSC 322 Operating Systems Concepts Lecture - 20: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
OSes: 11. FS Impl. 1 Operating Systems v Objectives –discuss file storage and access on secondary storage (a hard disk) Certificate Program in Software.
CS333 Intro to Operating Systems Jonathan Walpole.
CS 153 Design of Operating Systems Spring 2015 Lecture 21: File Systems.
Why Do We Need Files? Must store large amounts of data. Information stored must survive the termination of the process using it - that is, be persistent.
CS333 Intro to Operating Systems Jonathan Walpole.
CS 333 Introduction to Operating Systems Class 17 - File Systems Jonathan Walpole Computer Science Portland State University.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems File systems.
Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.
CS399 New Beginnings Jonathan Walpole. Disk Technology & Secondary Storage Management.
Lecture Topics: 11/22 HW 7 File systems –block allocation Unix and NT –disk scheduling –file caches –RAID.
File organization Secondary Storage Devices Lec#7 Presenter: Dr Emad Nabil.
Magnetic Disks Have cylinders, sectors platters, tracks, heads virtual and real disk blocks (x cylinders, y heads, z sectors per track) Relatively slow,
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems DISK I/0.
File-System Management
Jonathan Walpole Computer Science Portland State University
Chapter 11: File System Implementation
Multiple Platters.
FileSystems.
Disks and RAID.
File System Structure How do I organize a disk into a file system?
Operating Systems (CS 340 D)
Operating System I/O System Monday, August 11, 2008.
Filesystems.
Mass-Storage Structure
Lecture 45 Syed Mansoor Sarwar
Disks.
Chapter 11: File System Implementation
CS510 Operating System Foundations
File Systems Implementation
Overview Continuation from Monday (File system implementation)
Jonathan Walpole Computer Science Portland State University
File Management – Implementation
Disks and scheduling algorithms
Secondary Storage Management Brian Bershad
Secondary Storage Management Hank Levy
CS333 Intro to Operating Systems
File system : Disk Space Management
Department of Computer Science
Chapter 5 File Systems -Compiled for MCA, PU
Disks Magnetic (hard) Disk arrays are used for reliable storage (RAID)
Presentation transcript:

CS510 Operating System Foundations Jonathan Walpole

Disk Technology & Secondary Storage Management

Disk Geometry Disk head, surfaces, tracks, sectors …

Disk Surface Geometry Constant rotation speed Constant bit density Variable bandwidth Inner tracks: Fewer sectors per track Outer tracks: More sectors per track

Virtual Geometry Physical Geometry The actual layout of sectors on the disk may be complicated The disk controller does the translation The OS sees a “virtual geometry”.

Virtual Geometry physical geometry virtual geometry

Sector Formatting A disk sector Typically 512 bytes / sector ECC = 16 bytes

Disk Scheduling Algorithms Time required to read or write a disk block is determined by 3 factors Seek time Rotational delay Data transfer time Seek time dominates - Schedule disk heads to minimize it!

Disk Scheduling Algorithms First-come first serve Shortest seek time first Scan  back and forth to ends of disk C-Scan  only one direction Look  back and forth to last request C-Look  only one direction

Shortest Seek First (SSF) Initial position Pending requests

Shortest Seek First (SSF) Cuts arm motion in half Fatal problem: - Starvation is possible!

The Elevator Algorithm Use one bit to track which direction the arm is moving Up Down Keep moving in that direction Service the next pending request in that direction When there are no more requests in the current direction, reverse direction

The Elevator Algorithm

Other Algorithms First-come first serve Shortest seek time first Scan  back and forth to ends of disk C-Scan  only one direction Look  back and forth to last request C-Look  only one direction

Disks Errors Transient errors v. hard errors Manufacturing defects are unavoidable - Some will be masked with the ECC in each sector Dealing with bad sectors - Allocate several spare sectors per track At the factory, some sectors are remapped to spares - Errors may also occur during the disk lifetime The sector must be remapped to a spare Either by the OS or by the disk controller (hardware)

Spare Sectors Substituting a new sector Shifting sectors

Software Handling of Bad Sectors Add all bad sectors to a special file The file is hidden; not in the file system Users will never see the bad sectors Backups Some backup programs copy entire tracks at a time Must be aware of bad sectors!

Stable Storage The model of possible errors: Disk writes a block and reads it back for confirmation If there is an error during a write it will be detected upon reading the block Disk blocks can go bad spontaneously but subsequent reads will detect the error CPU can fail during a write, but this is detectable

Stable Storage Use two disks for redundancy Each write is done twice, once on each disk Each disk has N blocks Each disk contains exactly the same data To read the data ... - you can read from either disk To perform a write ... - you must update the same block on both disks If the block on one disk goes bad ... - You can recover its contents from the other disk

Stable Storage Stable write Write block on disk # 1 Read back to verify If problems... - Try again several times to get the block written - Then declare the sector bad and remap the sector - Repeat until the write to disk #1 succeeds Write same data to corresponding block on disk #2 - Read back to verify - Retry until it also succeeds

Stable Storage Stable Read Read the block from disk # 1 If problems... - Try again several times to get the block If the block can not be read from disk #1... - Read the corresponding block from disk #2 Our Assumption: The same block will not simultaneously go bad on both disks …. but it will eventually go bad, given enough time

Stable Storage Crash Recovery Scan both disks Compare corresponding blocks For each pair of blocks... - If both are good and have same data... - Do nothing; go on to next pair of blocks - If one is bad (failed ECC)... - Copy the block from the good disk - If both are good, but contain different data... - (CPU must have crashed during a “Stable Write”) - Copy the data from disk #1 to disk #2

Crashes During a Stable Write

Stable Storage Disk blocks can spontaneously decay Given enough time... The same block on both disks may go bad - Data could be lost! Must scan both disks to watch for bad blocks (e.g., every day) Many variants to improve performance - Every stable write requires: 2 writes & 2 reads - Can we do better?

RAID Redundant Array of Independent Disks Redundant Array of Inexpensive Disks Two competing goals: - Increased reliability - Increased performance

RAID

RAID

Disk Space Management The OS must choose a disk “block” size... The amount of data written to/from a disk Must be some multiple of the disk’s sector size How big should a disk block be? = Memory page size? = Disk sector size? = Disk track size?

Disk Space Management Large block sizes: Internal fragmentation Last block has wasted space Lots of very small files; waste is greater Small block sizes: More seeks; file access will be slower

Block Size Tradeoff Smaller block size? Better disk space utilization Poor performance due to seek overhead Larger block size? Lower disk space utilization Better performance due to seek overhead But may transfer unnecessary data

Unix Example A Unix System 1000 users, 1M files Median file size = 1,680 bytes Mean file size = 10,845 bytes Many small files, a few really large files Challenge to balance disk space utilization, seek overhead and book keeping overhead.

Disk Space Management How to keep track of allocated vs free blocks How to choose a suitable block size What strategy to use for allocating free blocks to a file

Keeping Track of Free Blocks Approach #1: Keep a bitmap 1 bit per disk block Approach #2 Keep a free list

Keeping Track of Free Blocks Approach #1: Keep a bitmap 1 bit per disk block Example: 1 KB block size 16 GB Disk  16M blocks = 224 blocks Bitmap size = 224 bits  2K blocks 1/8192 space lost to bitmap Approach #2 Keep a free list

Free List of Disk Blocks Linked list of free blocks Each list block on disk holds A bunch of addresses of free blocks Address of next block in the list null

Free List of Disk Blocks Two kinds of blocks: Free Blocks Blocks containing pointers to free blocks Always keep one block of pointers in memory Ideally this block will be partially full

Comparison: Free List vs Bitmap Desirable: Keep all the blocks in one file close together

Comparison: Free List vs Bitmap Desirable: Keep all the blocks in one file close together Free Lists: Free blocks are all over the disk Allocation comes from (almost) random location

Comparison: Free List vs Bitmap Desirable: Keep all the blocks in one file close together Free Lists: Free blocks are all over the disk Allocation comes from (almost) random location Bitmap: Much easier to find a free block “close to” a given position Bitmap implementation: Keep entire bitmap in memory? Keep only one block of bitmap in memory at a time?

Allocation Strategies Contiguous allocation Linked allocation FAT file system Unix I-nodes

Contiguous Allocation After deleting D and F...

Contiguous Allocation After deleting D and F...

Contiguous Allocation Advantages: Simple to implement (Need only starting sector & length of file) Performance is good (for sequential reading)

Contiguous Allocation Advantages: - Simple to implement (Need only starting sector & length of file) - Performance is good (for sequential reading) Disadvantages: - After deletions, disk becomes fragmented - Will need periodic compaction (time-consuming) - Will need to manage free lists - If new file put at end of disk... - No problem - If new file is put into a “hole”... - Must know a file’s maximum possible size ... at the time it is created!

Contiguous Allocation Good for CD-ROMs All file sizes are known in advance Files are never deleted

Linked List Allocation Each file is a sequence of blocks First word in each block contains number of next block

Linked List Allocation Random access into the file is slow!

File Allocation Table (FAT) Keep a table in memory One entry per block on the disk Each entry contains the address of the “next” block End of file marker (-1) A special value (-2) indicates the block is free

File Allocation Table (FAT) Random access... Search the linked list (but all in memory Directory entry needs only one number Starting block number

File Allocation Table (FAT) Random access... Search the linked list (but all in memory) Directory Entry needs only one number Starting block number Disadvantage: Entire table must be in memory all at once! A problem for large file systems

File Allocation Table (FAT) Random access... Search the linked list (but all in memory) Directory Entry needs only one number Starting block number Disadvantage: Entire table must be in memory all at once! Example: 200 GB = disk size 1 KB = block size 4 bytes = FAT entry size 800 MB of memory used to store the FAT

I-nodes Each I-node (“index-node”) is a structure containing info about the file Attributes and location of the blocks containing the file Blocks on disk Other attributes I-node

I-nodes Enough space for 10 pointers Blocks on disk Other attributes

I-nodes Enough space for 10 pointers Blocks on disk Other attributes

The UNIX I-node

The UNIX File System

File Storage on Disk

File Storage On Disk Sector 0: “Master Boot Record” (MBR) Contains the partition map Rest of disk divided into “partitions” - Partition: sequence of consecutive sectors. Each partition can hold its own file system Unix file system Window file system Apple file system Every partition starts with a “boot block” Contains a small program This “boot program” reads in an OS from the file system in that partition OS Startup - Bios reads MBR , then reads & execs a boot block

An Example Disk Unix File System

File Bytes vs Disk Sectors Files are sequences of bytes - Granularity of file I/O is bytes Disks are arrays of sectors (512 bytes) - Granularity of disk I/O is sectors - Files data must be stored in sectors File systems define a block size - Block size = 2n * sector size - Contiguous sectors are allocated to a block File systems view the disk as an array of blocks - Must allocate blocks to file - Must manage free space on disk

The UNIX File System The layout of the disk (for early Unix systems):

Spare Slides

Managing Free Blocks Approach #1: Keep a bitmap 1 bit per disk block Keep a free list

Managing Free Blocks Approach #1: Keep a bitmap 1 bit per disk block Example: 1 KB block size 16 GB Disk  16M blocks = 224 blocks Bitmap size = 224 bits  2K blocks 1/8192 space lost to bitmap Approach #2 Keep a free list

Free List of Disk Blocks Linked List of Free Blocks Each block on disk holds A bunch of addresses of free blocks Address of next block in the list null

Free list of disk blocks Assumptions: Block size = 1K Each block addr = 4bytes Each block holds 255 ptrs to free blocks 1 ptr to the next block asd This approach takes more space than bitmap... But “free” blocks are used, so no real loss!

Free List of Disk Blocks Two kinds of blocks: Free Blocks Block containing pointers to free blocks Always keep one block of pointers in memory This block may be partially full Need a free block? This block gives access to 255 free blocks Need more? Look at the block’s “next” pointer Use the pointer block itself Read in the next block of pointers into memory

Free List of Disk Blocks To return a block (X) to the free list If the block of pointers (in memory) is not full, add X to it

Free List of Disk Blocks To return a block (X) to the free list If the block of pointers (in memory) is not full, add X to it If the block of pointers (in memory) is full Write it to out to the disk Start a new block in memory Use block X itself for a pointer block All empty pointers except for the next pointer

Free List of Disk Blocks Scenario: Assume the block of pointers in memory is almost empty A few free blocks are needed. This triggers disk read to get next pointer block Now the block in memory is almost full Next, a few blocks are freed The block fills up This triggers a disk write of the block of pointers Problem: - Numerous small allocates and frees, when block of pointers is right at boundary results in lots of disk I/O

Free list of disk blocks Solution Try to keep the block in memory about 1/2 full When the block in memory fills up... Break it into 2 blocks (each 1/2 full) Write one out to disk A similar solution Keep 2 blocks of pointers in memory at all times When both fill up Write out one When both become empty Read in one new block of pointers

Comparison: Free List vs Bitmap Desirable: Keep all the blocks in one file close together

Comparison: Free List vs Bitmap Desirable: Keep all the blocks in one file close together Free Lists: Free blocks are all over the disk Allocation comes from (almost) random location

Comparison: Free List vs Bitmap Desirable: Keep all the blocks in one file close together Free Lists: Free blocks are all over the disk Allocation comes from (almost) random location Bitmap: Much easier to find a free block “close to” a given position Bitmap implementation: Keep 2 MByte bitmap in memory Keep only one block of bitmap in memory at a time

Example Disk Characteristics

Cylinder Skew

Sector Interleaving No Interleaving Single Interleaving Double