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

OS_12__Mass-Storage_and_File_System

Uploaded by

wbmsheikh
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)
9 views

OS_12__Mass-Storage_and_File_System

Uploaded by

wbmsheikh
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/ 38

Mass-Storage

and
File System
Outline
• HDD Scheduling
• File Access Methods
• File Sharing
• File Protection
• File Allocation Methods
• Free-Space Management
HDD Scheduling
• The operating system is responsible for using hardware efficiently
— for the disk drives, this means having a fast access time and disk
bandwidth
• Minimize seek time
• Seek time  seek distance
• Disk bandwidth is the total number of bytes transferred, divided by
the total time between the first request for service and the
completion of the last transfer
Disk Scheduling (Cont.)
• There are many sources of disk I/O request
• OS
• System processes
• Users processes
• I/O request includes input or output mode, disk address,
memory address, number of sectors to transfer
• OS maintains queue of requests, per disk or device
• Idle disk can immediately work on I/O request, busy disk means
work must queue
• Optimization algorithms only make sense when a queue exists
Disk Scheduling (Cont.)
• In the past, operating system responsible for queue
management, disk drive head scheduling
• Now, built into the storage devices, controllers
• Just provide Logical Block Addressing (LBA), handle sorting of
requests
• Some of the algorithms they use described next
Disk Scheduling (Cont.)
• Note that drive controllers have small buffers and can manage a
queue of I/O requests (of varying “depth”)
• Several algorithms exist to schedule the servicing of disk I/O
requests
• The analysis is true for one or many platters
• We illustrate scheduling algorithms with a request queue (0-199)
98, 183, 37, 122, 14, 124, 65, 67
Head pointer 53
First-Come, First-Served (FCFS) Algorithm
Illustration shows total head movement of 640 cylinders
Shortest-Seek-Time-First (SSTF) Algorithm
• Shortest Seek Time First selects the request with the
minimum seek time from the current head position
• SSTF scheduling is a form of SJF scheduling; may cause
starvation of some requests
• Illustration shows total head movement of 236 cylinders
SCAN Algorithm
• The disk arm starts at one end of the disk, and moves
toward the other end, servicing requests until it gets to
the other end of the disk, where the head movement is
reversed and servicing continues.
• SCAN algorithm Sometimes called the elevator algorithm
• Illustration shows total head movement of 236 cylinders
(Suppose head is currently at 53 and was previously at 58)
• But note that if requests are uniformly dense, largest
density at other end of disk and those wait the longest
SCAN (Cont.)
Circular SCAN (C-SCAN) Algorithm
• Provides a more uniform wait time than SCAN
• The head moves from one end of the disk to the other,
servicing requests as it goes
• When it reaches the other end, however, it immediately returns
to the beginning of the disk, without servicing any requests on
the return trip
• Treats the cylinders as a circular list that wraps around
from the last cylinder to the first one

• Suppose head is currently at 53 and was previously at 51


• Total number of cylinders = 382
C-SCAN (Cont.)
LOOK Algorithm
• Version of SCAN algorithm
• The arm goes only as far as the final request in each
direction. Then, it reverses direction immediately,
without going all the way to the end of the disk.
• Look for a request before continuing to move in a given
direction.
• Reading in both directions.

• Suppose head is currently at 53 and was previously at 51


• Total number of cylinders = 299
Circular LOOK (C-LOOK) Algorithm
• Version of C-SCAN algorithm
• The arm goes only as far as the final request in each
direction. Then, it reverses direction immediately,
without going all the way to the end of the disk.
• Reading in one direction only.

• Suppose head is currently at 53 and was previously at 51


• Total number of cylinders = 322
C-LOOK (cont.)
Selecting a Disk-Scheduling Algorithm
• SSTF is common and has a natural appeal
• SCAN and C-SCAN perform better for systems that place a heavy load on the
disk
• Less starvation, but still possible
File Access Methods
• Sequential Access
• Direct Access
Sequential Access
• Operations
• read next
• write next
• Reset
• no read after last write (rewrite)

• Figure
Direct Access
• A file is fixed length logical records
• Operations
• read n
• write n
• position to n
• read next
• write next
• rewrite n
n = relative block number

• Relative block numbers allow OS to decide


where file should be placed
Simulation of Sequential Access on Direct-access File
Other Access Methods
• Can be built on top of base methods
• Generally involve creation of an index for the file
• Keep index in memory for fast determination of
location of data to be operated on (consider Universal
Produce Code (UPC code) plus record of data about
that item)
• If too large, index (in memory) of the index (on disk)
• IBM indexed sequential-access method (ISAM)
• Small master index, points to disk blocks of secondary index
• File kept sorted on a defined key
• All done by the OS
• VMS operating system provides index and relative files
as another example (see next slide)
Example of Index and Relative Files
File Sharing
• Sharing of files on multi-user systems is desirable
• Sharing may be done through a protection scheme
• On distributed systems, files may be shared across a network
• Network File System (NFS) is a common distributed file-sharing
method
• If multi-user system
• User IDs identify users, allowing permissions and protections to be per-
user
Group IDs allow users to be in groups, permitting group access rights
• Owner of a file / directory
• Group of a file / directory
File Protection
• File owner/creator should be able to control:
• what can be done
• by whom
• Types of access
• Read
• Write
• Execute
• Append
• Delete
• List
Access Lists and Groups in Unix

• Mode of access: read, write, execute


• Three classes of users on Unix / Linux
RWX
a) owner access 7  111
RWX
b) group access 6  110
RWX
c) public access 1  001
• Ask manager to create a group (unique name), say G, and add
some users to the group.
• For a file (say game) or subdirectory, define an appropriate
access.

Attach a group to a file


chgrp G game
Windows 7 Access-Control List Management
File Allocation Methods
An allocation method refers to how disk blocks are allocated
for files.

Methods:
1. Contiguous Allocation
2. Linked Allocation
3. Indexed Allocation
Contiguous Allocation
Each file occupies set of contiguous blocks
• Best performance in most cases
• Simple – only starting location (block #) and length (number of blocks) are
required
• Problems include:
 Finding space for file,
 Knowing file size,
 External fragmentation, need for compaction off-line (downtime) or
on-line
Extent-Based Systems

• Many newer file systems (i.e., Veritas File System) use a modified
contiguous allocation scheme
• Extent-based file systems allocate disk blocks in extents
• An extent is a contiguous block of disks
• Extents are allocated for file allocation
• A file consists of one or more extents
Linked Allocation

• Each file a linked list of blocks


• File ends at nil pointer
• No external fragmentation
• Each block contains pointer to next block
• No compaction, external fragmentation
• Free space management system called when new block needed
• Improve efficiency by clustering blocks into groups but increases internal
fragmentation
• Reliability can be a problem
• Locating a block can take many I/Os and disk seeks
Linked Allocation (cont.)

• Each file is a linked list of disk blocks: blocks may be


scattered anywhere on the disk
• Scheme
File-Allocation Table
Indexed Allocation
• Each file has its own index block(s) of pointers to its data blocks
Performance of File Allocation Methods
• Best method depends on file access type
• Contiguous great for sequential and random
• Linked good for sequential, not random
• Declare access type at creation -> select either contiguous or linked
• Indexed more complex
• Single block access could require 2 index block reads then data block read
• Clustering can help improve throughput, reduce CPU overhead
Free-Space Management
• File system maintains free-space list to track available blocks/clusters (Using
term “block” for simplicity)

• Bit vector or bit map (n blocks):


0 1 2 n-1


1  block[i] free
bit[i] =
0  block[i] occupied

Block number calculation


(number of bits per word) *
(number of 0-value words) +
offset of first 1 bit
CPUs have instructions to return offset within word of first “1” bit
Free-Space Management (Cont.)

• Bit map requires extra space


• Example:
block size = 4KB = 212 bytes
disk size = 240 bytes (1 terabyte)
n = 240/212 = 228 bits (or 32MB)
if clusters of 4 blocks -> 8MB of memory

• Easy to get contiguous files


Free-Space Management (Cont.)

Linked Free Space List on Disk:

 Linked list (free list)


• Cannot get contiguous
space easily
• No waste of space
• No need to traverse the
entire list (if # free
blocks recorded)
Reference: Operating System Concepts, Abraham Silberschatz,
Peter Baer Galvin, Greg Gagne, Wiley Publications

Slides downloaded from: https://codex.cs.yale.edu/avi/os-


book/OSE2/slide-dir/index.html

You might also like