Operating System Unit 5
Operating System Unit 5
Operating System Unit 5
Topics
Magnetic Disks
• Traditional magnetic disks have the following basic structure:
• One or more platters in the form of disks covered with magnetic media.
• Hard disk platters are made of rigid metal, while "floppy" disks are made of more flexible plastic.
• Each platter has two working surfaces. Older hard disk drives would sometimes not use the very top or
bottom surface of a stack of platters, as these surfaces were more susceptible to potential damage.
• Each working surface is divided into a number of concentric rings called tracks.
• The collection of all tracks that are the same distance from the edge of the platter, ( i.e. all tracks
immediately above one another in the following diagram ) is called a cylinder.
• Each track is further divided into sectors, traditionally containing 512 bytes of data each, although some
modern disks occasionally use larger sector sizes.
• The data on a hard drive is read by read-write heads.
• The storage capacity of a traditional disk drive is equal to the number of heads ( i.e. the number of working
surfaces ), times the number of tracks per surface, times the number of sectors per track, times the
number of bytes per sector.
• A particular physical block of data is specified by providing the head-sector-cylinder number at which it is
located.
Secondary Storage
Disc Structure
Magnetic Disks
• Disk heads "fly" over the surface on a very thin cushion of air. If they should accidentally contact the disk,
then a head crash occurs, which may or may not permanently damage the disk or even destroy it
completely. For this reason it is normal to park the disk heads when turning a computer off, which means
to move the heads off the disk or to an area of the disk where there is no data stored.
• Floppy disks are normally removable. Hard drives can also be removable, and some are even hot-
swappable, meaning they can be removed while the computer is running, and a new hard drive inserted
in their place.
• Disk drives are connected to the computer via a cable known as the I/O Bus. Some of the common
interface formats include Enhanced Integrated Drive Electronics, EIDE; Advanced Technology Attachment,
ATA; Serial ATA, SATA, Universal Serial Bus, USB; Fiber Channel, FC, and Small Computer Systems Interface,
SCSI.
• The host controller is at the computer end of the I/O bus, and the disk controller is built into the disk
itself. The CPU issues commands to the host controller via I/O ports. Data is transferred between the
magnetic surface and onboard cache by the disk controller, and then the data is transferred from that
cache to the host controller and the motherboard memory at electronic speeds.
Mass Storage Structures- Overview
Magnetic Tape
• Magnetic tapes were once used for common secondary storage before the days of hard disk drives, but today
are used primarily for backups.
• Accessing a particular spot on a magnetic tape can be slow, but once reading or writing commences, access
speeds are comparable to disk drives.
• Capacities of tape drives can range from 20 to 200 GB, and compression can double that capacity.
Mass Storage Structures- Overview
• Total Seek time = 60ns+60ns = 120ns. Rotation Rate = 3600 rpm. • Transfer Rate
• Rotation Time • RT=1/60 s
3600 rotation 60 sec • 1/60 s 512*2^10B
So, 1 rotation 60/3600 sec = 1/120sec • So, 1s 512*2^10*60B
R.T = 2*1/120 = 1/60 Sec = 2^9*2^10*2*30B
• Now, 2^10*512 1/60 sec = 2^20*30B
1 (1/60)*(1/ 2^10*512) = 30MB
2*512 1/(30*2^10) sec
• Time to read 2 Random Sector = 120ns+ 1/60s + 1/(30*2^10) s
Mass Storage Structures- Overview
Disc Scheduling
• As mentioned earlier, disk transfer speeds are limited primarily by seek times and rotational latency. When multiple requests
are to be processed there is also some inherent delay in waiting for other requests to be processed.
• Bandwidth is measured by the amount of data transferred divided by the total amount of time from the first request being
made to the last transfer being completed, ( for a series of disk requests. )
• Both bandwidth and access time can be improved by processing requests in a good order.
• Disk requests include the disk address, memory address, number of sectors to transfer, and whether the request is for reading
or writing.
Mass Storage Structures- Overview
FCFS Scheduling
• First-Come First-Serve is simple and intrinsically fair, but not very efficient. Consider in the following sequence
the wild swing from cylinder 122 to 14 and then back to 124:
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 System Concept
File Operations
• File is an abstract data type
• Create
• Write – at write pointer location
• Read – at read pointer location
• Reposition within file - seek
• Delete
• Truncate
• Open(Fi) – search the directory structure on disk for entry Fi, and move the content of entry to
memory
• Close (Fi) – move the content of entry Fi in memory to directory structure on disk
File System Concept
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
File System Concept
import java.io.*; // this locks the second half of the file - shared
import java.nio.channels.*; sharedLock = ch.lock(raf.length()/2+1, raf.length(),
public class LockingExample { SHARED);
public static final boolean EXCLUSIVE = false; /** Now read the data . . . */
public static final boolean SHARED = true; // release the lock
public static void main(String arsg[]) throws IOException { sharedLock.release();
} catch (java.io.IOException ioe) {
FileLock sharedLock = null;
System.err.println(ioe);
FileLock exclusiveLock = null; }finally {
try { if (exclusiveLock != null)
RandomAccessFile raf = new RandomAccessFile("file.txt", exclusiveLock.release();
"rw");
// get the channel for the file if (sharedLock != null)
FileChannel ch = raf.getChannel(); sharedLock.release();
// this locks the first half of the file - exclusive
}
exclusiveLock = ch.lock(0, raf.length()/2, EXCLUSIVE);
}
/** Now modify the data . . . */
}
// release the lock
exclusiveLock.release();
File System Concept
File System Concept
• Many newer file systems (i.e., Veritas File System) use a modified contiguous
allocation scheme
Extents can be added to an existing file that needs space to grow. A block can be found
given by the location of the first block in the file and the block count, plus a link to the first
exten
File System Implementation
Performance
• 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
• Adding instructions to the execution path to save one disk I/O is reasonable
Intel Core i7 Extreme Edition 990x (2011) at 3.46Ghz = 159,000 MIPS
http://en.wikipedia.org/wiki/Instructions_per_second
Typical disk drive at 250 I/O s per second 159,000 MIPS / 250 = 630 million instructions during one
disk I/O
Fast SSD drives provide 60,000 IOPS 159,000 MIPS / 60,000 = 2.65 millions instructions during one
disk I/O
File System Implementation
• Divides device space into metaslab units and manages metaslabs Given volume can contain hundreds of metaslabs
• But records to log file rather than file system Log of all block activity, in time order, in counting format
• Metaslab activity -> load space map into memory in balanced-tree structure, indexed by offset Replay log into that
structure
• Combine contiguous free blocks into single entry
File System Implementation
Directory Structure
• A collection of nodes containing information about all files
Disk Structure
Directory Organization
• Naming problem
• Grouping problem
File System Concept
Directory Organization
• Efficient searching
• Grouping Capability
• deletion of a directory?
• File-System Structure
• File-System Implementation
• Directory Implementation
• Allocation Methods
• Free-Space Management
File System Implementation
Objective
• To describe the details of implementing local file systems and directory
structures
• To describe the implementation of remote file systems
• To discuss block allocation and free-block algorithms and trade-offs
File System Implementation
Objective
• File structure
Logical storage unit
Collection of related information
• File system resides on secondary storage (disks)
Provided user interface to storage, mapping logical to physical
Provides efficient and convenient access to disk by allowing data to be stored,
located retrieved easily
• Disk provides in-place rewrite and random access
I/O transfers performed in blocks of sectors (usually 512 bytes)
• File control block – storage structure consisting of information about a file
• Device driver controls the physical device
• File system organized into layers
File System Implementation
• We have system calls at the API level, but how do we implement their
functions?
On-disk and in-memory structures
• Boot control block contains info needed by system to boot OS from that
volume.
Needed if volume contains OS, usually first block of volume
• Volume control block (superblock, master file table) contains volume
details –
• Total # of blocks, # of free blocks, block size, free block pointers or array
• Directory structure organizes the files
Names and inode numbers, master file table
File System Implementation
• Per-file File Control Block (FCB) contains many details about the file
inode number, permissions, size, dates
NFTS stores into in master file table using relational DB structures
File System Implementation
• Partition can be a volume containing a file system (“cooked”) or raw – just a sequence of
blocks with no file system
• Boot block can point to boot volume or boot loader set of blocks that contain enough code to
know how to load the kernel from the file system Or a boot management program for multi-os
booting
• Root partition contains the OS, other partitions can hold other Oses, other file systems, or
be raw Mounted at boot time
• Other partitions can mount automatically or manually
• At mount time, file system consistency checked Is all metadata correct? If not, fix it, try
again
• If yes, add to mount table, allow access
File System Implementation
• Virtual File Systems (VFS) on Unix provide an object-oriented way of implementing file
systems
• VFS allows the same system call interface (the API) to be used for different types of file
systems
• Separates file-system generic operations from implementation details
• Implementation can be one of many file systems types, or network file system
• Implements vnodes which hold inodes or network file details
For example, Linux has four object types: inode, file, superblock, dentry
Directory Implementation
Linear list of file names with pointer to the data blocks
Simple to program
Time-consuming to execute
->Linear search time
->Could keep ordered alphabetically via linked list or use B+ tree
2) double caching, requires caching file-system data twice. Not only does it waste memory but it also
wastes significant CPU and I/O cycles due to the extra data movement within system memory. In addition,
inconsistencies between the two caches can result in corrupt files.