0% found this document useful (0 votes)
86 views82 pages

Unit-5 (I-O Management and Disk Scheduling)

OS UNIT 5 AKTU NOTES BTECH CSE

Uploaded by

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

Unit-5 (I-O Management and Disk Scheduling)

OS UNIT 5 AKTU NOTES BTECH CSE

Uploaded by

Sseiepr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Chapter 10: Mass-Storage

Systems
Mass-Storage Systems

Overview of Mass Storage Structure


Disk Structure
Disk Attachment
Disk Scheduling
Disk Management
Swap-Space Management
RAID Structure
Stable-Storage Implementation
Objectives

To describe the physical structure of


secondary storage devices and its effects
on the uses of the devices
To explain the performance characteristics
of mass-storage devices
To evaluate disk scheduling algorithms
To discuss operating-system services
provided for mass storage, including RAID
Overview of Mass Storage
Structure
 Magnetic disks provide bulk of secondary storage
of modern computers
 Drives rotate at 60 to 250 times per second
 Transfer rate is rate at which data flow between drive
and computer
 Positioning time (random-access time) is time to
move disk arm to desired cylinder (seek time) and time
for desired sector to rotate under the disk head
(rotational latency)
 Head crash results from disk head making contact with
the disk surface -- That’s bad
 Disks can be removable
 Drive attached to computer via I/O bus
 Busses vary, including EIDE, ATA, SATA, USB, Fibre
Channel, SCSI, SAS, Firewire
 Host controller in computer uses bus to talk to disk
controller built into drive or storage array
Moving-head Disk Mechanism
Hard Disks
 Platters range from .85” to 14”
(historically)
 Commonly 3.5”, 2.5”, and 1.8”
 Range from 30GB to 3TB per
drive
 Performance
 Transfer Rate – theoretical – 6
Gb/sec
 Effective Transfer Rate – real –
1Gb/sec
 Seek time from 3ms to 12ms –
9ms common for desktop drives
 Average seek time measured or
calculated based on 1/3 of
tracks
 Latency based on spindle speed
 1 / (RPM / 60) = 60 / RPM
 Average latency = ½ latency
Hard Disk Performance
Access Latency = Average access time =
average seek time + average latency
 For fastest disk 3ms + 2ms = 5ms
 For slow disk 9ms + 5.56ms = 14.56ms
Average I/O time = average access time +
(amount to transfer / transfer rate) + controller
overhead
For example to transfer a 4KB block on a 7200
RPM disk with a 5ms average seek time, 1Gb/sec
transfer rate with a .1ms controller overhead =
 5ms + 4.17ms + 0.1ms + transfer time =
 Transfer time = 4KB / 1Gb/s * 8Gb / GB * 1GB /
10242KB = 32 / (10242) = 0.031 ms
 Average I/O time for 4KB block = 9.27ms + .031ms
= 9.301ms
The First Commercial Disk Drive

1956
IBM RAMDAC computer
included the IBM Model 350
disk storage system

5M (7 bit) characters
50 x 24” platters
Access time = < 1 second
Disk Structure
Disk drives are addressed as large 1-dimensional
arrays of logical blocks, where the logical block is
the smallest unit of transfer
 Low-level formatting creates logical blocks on
physical media
The 1-dimensional array of logical blocks is
mapped into the sectors of the disk sequentially
 Sector 0 is the first sector of the first track on the
outermost cylinder
 Mapping proceeds in order through that track, then
the rest of the tracks in that cylinder, and then
through the rest of the cylinders from outermost to
innermost
 Logical to physical address should be easy
 Except for bad sectors
 Non-constant # of sectors per track via constant angular
velocity
Disk 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.)
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
FCFS
Illustration shows total head movement of 640 cylinders
Shortest Seek Time First
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
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
But note that if requests are uniformly dense,
largest density at other end of disk and those
wait the longest
SCAN (Cont.)
C-SCAN
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
Total number of cylinders?
C-SCAN (Cont.)
C-LOOK
C-LOOK is a version of C-SCAN
Arm only goes as far as the last request in
each direction, then reverses direction
immediately, without first going all the way
to the end of the disk
Total number of cylinders?
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
 Performance depends on the number and types of requests
 Requests for disk service can be influenced by the file-
allocation method
And metadata layout
 The disk-scheduling algorithm should be written as a separate
module of the operating system, allowing it to be replaced
with a different algorithm if necessary
 Either SSTF or LOOK is a reasonable choice for the default
algorithm
 What about rotational latency?
Difficult for OS to calculate
 How does disk-based queueing effect OS queue ordering
efforts?
RAID Structure
RAID – redundant array of independent disks. It is a
way of storing the same data in different places on
multiple hard disks or solid-state drives (SSDs) to
protect data in the case of a drive failure. There are
different RAID levels, however, and not all have the
goal of providing redundancy.
 multiple disk drives provides reliability via
redundancy
Increases the mean time to failure- Indicates the
average amount of time before the system fails to
produce the expected results.
Mean time to repair – it is the average of times
required to recover from its failures
Mean time to data loss- the average time, in a
large population of storage elements, from first use
until a failure results in a permanent loss of user
data
If mirrored disks fail independently, consider disk
with 1300,000 mean time to failure and 10 hour
mean time to repair
 Mean time to data loss is 100, 0002 / (2 ∗ 10) = 500 ∗
106 hours, or 57,000 years!
Several improvements in disk-use techniques involve
the use of multiple disks working cooperatively.
RAID is arranged into six different levels. RAID
schemes improve performance and improve the
reliability of the storage system by storing redundant
data
RAID within a storage array can still fail if the array
fails, so automatic replication of the data between
arrays is common
Frequently, a small number of hot-spare disks are
left unallocated, automatically replacing a failed disk
and having data rebuilt onto them
RAID (Cont.)
Disk striping uses a group of disks as one
storage unit
With disk striping ( RAID 0 ), two or more volumes
– each on a separate drive – are configured as a
striped set, the operating system will act like it
has only one drive. Data written to the striped set
is broken into blocks that are called stripes.
 Mirroring or shadowing (RAID 1) keeps duplicate
of each disk
 Striped mirrors (RAID 1+0) or mirrored stripes
(RAID 0+1) provides high performance and high
reliability
 Block interleaved parity (RAID 4, 5, 6) uses
much less redundancy
End of Chapter 10
Chapter 11:
File-System Interface
Chapter 11: File-System
Interface

File Concept
Access Methods
Disk and Directory Structure
File-System Mounting
File Sharing
Protection
Objectives

To explain the function of file systems


To describe the interfaces to file systems
To discuss file-system design tradeoffs,
including access methods, file sharing, file
locking, and directory structures
To explore file-system protection
File Concept
Computer can store information on several
different media such as magnetic disks,
magnetic tapes and optical disks.
The O/S abstract the physical properties of
these media and provide a uniform logical
view called files. Provides contiguous logical
address space.
A file is a named collection of related
information. A file is a sequence of bits,
bytes, lines or records. Contents of a file is
defined by file’s creator.
 Many types
 Consider text file, source file, executable file
File Attributes
 Name – only information kept in human-readable form
 Identifier – unique tag (number) identifies file within file
system
 Type – needed for systems that support different types
 Location – pointer to file location on device
 Size – current file size
 Protection – controls who can do reading, writing,
executing
 Time, date, and user identification – data for
protection, security, and usage monitoring
 Information about files are kept in the directory structure,
which is maintained on the disk
 Many variations, including extended file attributes such as
file checksum
 Information kept in the directory structure
File Operations
The O/S provides the system calls to create,
write, read, reposition, delete and truncate a
file.
Create
Write – at write pointer location
Read – at read pointer location
Reposition within file - seek
Delete
Truncate
Open(F ) – search the directory structure on
i
disk for entry Fi, and move the content of entry
to memory
Close (F ) – move the content of entry F in
i i
memory to directory structure on disk
Open Files
Several pieces of data are needed to manage
open files:
Open-file table: tracks open files
File pointer: pointer to last read/write location,
per process that has the file open
File-open count: counter of number of times a
file is open – to allow removal of data from
open-file table when last processes closes it
Disk location of the file: cache of data access
information
Access rights: per-process access mode
information
Open File Locking
Provided by some operating systems and file
systems
Similar to reader-writer locks
Shared lock similar to reader lock – several
processes can acquire concurrently
Exclusive lock similar to writer lock
Mediates access to a file
Mandatory or advisory:
Mandatory – access is denied depending on
locks held and requested
Advisory – processes can find status of locks
and decide what to do
File Types – Name, Extension
File Structure
File must conform to a required structure that
is understood by operating system.
Simple record structure
Lines
Fixed length
Variable length
Complex Structures
Formatted document
Relocatable load file
Can simulate last two with first method by
inserting appropriate control characters
Who decides:
Operating system
Program
Access Methods
 Sequential Access- process one record after another
read next
write next
reset
no read after last write
(rewrite)
 Direct Access – allow arbitrary blocks to be read or
written. File is fixed length logical records
read n
write n
position to n
read next
write next
rewrite n
n = relative block number
Sequential-access of a File
Simulation of Sequential Access on Direct-
access File
Other Access Methods
 Can be built on top of base methods
 In general involve creation of an index table or
the index file
 Keep index in memory for fast determination of
location of data to be operated on (consider UPC
code plus record of data about that item)
 If too large, index (in memory) of the index (on
disk)
Directory Structure
 A collection of nodes containing information about all files

Directory

Files
F1 F2 F4
F3
Fn

Both the directory structure and the files reside on disk


Disk Structure
Disk can be subdivided into partitions
Disks or partitions can be RAID protected against
failure
Disk or partition can be used raw – without a file
system, or formatted with a file system
Partitions also known as minidisks, slices
Entity containing file system known as a volume
Each volume containing file system also tracks that
file system’s info in device directory or volume
table of contents
As well as general-purpose file systems there are
many special-purpose file systems, frequently all
within the same operating system or computer
A Typical File-system Organization
Operations Performed on Directory
Search for a file

Create a file

Delete a file

List a directory

Rename a file

Traverse the file system


Directory Organization

The directory is organized logically to obtain

Efficiency – locating a file quickly


Naming – convenient to users
Two users can have same name for different
files
The same file can have several different
names
Grouping – logical grouping of files by
properties, (e.g., all Java programs, all
games, …)
Single-Level Directory
A single directory for all users

Naming problem
Grouping problem
Two-Level Directory
Separate directory for each user

 Path name
 Can have the same file name for different user
 Efficient searching
 No grouping capability
Tree-Structured Directories
Tree-Structured Directories (Cont.)
Efficient searching

Grouping Capability

Current directory (working directory)


cd /spell/mail/prog
type list
Tree-Structured Directories (Cont)
 Absolute or relative path name
 Creating a new file is done in current directory
 Delete a file
rm <file-name>
 Creating a new subdirectory is done in current
directory
mkdir <dir-name>
Example: if in current directory /mail
mkdir count

Deleting “mail”  deleting the entire subtree rooted by “mail”


Acyclic-Graph Directories
Have shared subdirectories and files
Acyclic-Graph Directories (Cont.)
Two different names (aliasing)
If dict deletes list  dangling pointer
Solutions:
Backpointers, so we can delete all pointers
Variable size records a problem
Backpointers using a daisy chain organization
Entry-hold-count solution
New directory entry type
Link – another name (pointer) to an existing file
Resolve the link – follow pointer to locate the
file
General Graph Directory
General Graph Directory (Cont.)
How do we guarantee no cycles?
Allow only links to file not subdirectories
Garbage collection
Every time a new link is added use a
cycle detection algorithm to determine
whether it is OK
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 Sharing – Remote File Systems
 Uses networking to allow file system access between
systems
Manually via programs like FTP
Automatically, seamlessly using distributed file systems
Semi automatically via the world wide web
 Client-server model allows clients to mount remote file
systems from servers
Server can serve multiple clients
Client and user-on-client identification is insecure or
complicated
NFS is standard UNIX client-server file sharing protocol
CIFS is standard Windows protocol
Standard operating system file calls are translated into
remote calls
 Distributed Information Systems (distributed naming
services) such as LDAP, DNS, NIS, Active Directory
implement unified access to information needed for
remote computing
File Sharing – Failure Modes

All file systems have failure modes


For example corruption of directory
structures or other non-user data, called
metadata
Remote file systems add new failure
modes, due to network failure, server
failure
Recovery from failure can involve state
information about status of each remote
request
Stateless protocols such as NFS v3
include all information in each request,
allowing easy recovery but less security
File Sharing – Consistency
Semantics
Specify how multiple users are to access a
shared file simultaneously
 Similar to Ch 5 process synchronization algorithms
 Tend to be less complex due to disk I/O and network
latency (for remote file systems
 Andrew File System (AFS) implemented complex
remote file sharing semantics
 Unix file system (UFS) implements:
 Writes to an open file visible immediately to other users
of the same open file
 Sharing file pointer to allow multiple users to read and
write concurrently
 AFS has session semantics
 Writes only visible to sessions starting after the file is
closed
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
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 particular file (say game) or
subdirectory, define an appropriate access.

Attach a group to a file


chgrp G game
Windows 7 Access-Control List
Management
Contiguous
An allocation method refers to how disk
blocks are allocated for files:
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
Contiguous Allocation
Mapping from
logical to physical
Q

LA/512

Block to be accessed = Q +
starting address
Displacement into block = R
Linked Allocation
 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
 FAT (File Allocation Table) variation
 Beginning of volume has table, indexed by block number
 Much like a linked list, but faster on disk and cacheable
 New block allocation simple
Linked Allocation
Each file is a linked list of disk blocks: blocks may
be scattered anywhere on the disk

block = pointer

 Mapping
Q
LA/511
R
Block to be accessed is the Qth block in the linked chain of blocks
representing the file.

Displacement into block = R + 1


Linked Allocation
File-Allocation Table
Allocation Methods - Indexed

Indexed allocation
Each file has its own index block(s) of
pointers to its data blocks

Logical view

index table
Example of Indexed Allocation
Indexed Allocation (Cont.)
Need index table

Random access

Dynamic access without external fragmentation,


but have overhead of index block
Mapping from logical to physical in a file of
maximum size of 256K bytes and block size of
512 bytes. We need only 1 block for index table

Q
LA/512
R
Q = displacement into index table
R = displacement into block
Indexed Allocation – Mapping
(Cont.)
Mapping from logical to physical in a file of unbounded length
(block size of 512 words)

Linked scheme – Link blocks of index table (no limit on size)

Q1
LA / (512 x 511)
R1
Q1 = block of index table
R1 is used as follows:
Q2
R1 / 512
R2

Q2 = displacement into block of index table


R2 displacement into block of file:
Indexed Allocation – Mapping
(Cont.)
Two-level index (4K blocks could store 1,024 four-byte pointers in outer
index -> 1,048,567 data blocks and file size of up to 4GB)

Q1
LA / (512 x 512)
R1

Q1 = displacement into outer-index


R1 is used as follows:
Q2
R1 / 512
R2

Q2 = displacement into block of index table


R2 displacement into block of file:
Indexed Allocation – Mapping
(Cont.)
End of Chapter 11

You might also like