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

OS Module V

The document discusses secondary storage structures and file systems. It provides an overview of disk structure and common disk terms. It then describes different disk scheduling algorithms like FCFS, SSTF, SCAN, C-SCAN, LOOK, and C-LOOK. The document also discusses file concepts, access methods, allocation methods, directory structures, and different logical directory structures like single-level, two-level, tree-structured, and graph directories.

Uploaded by

sitsekhar
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)
10 views

OS Module V

The document discusses secondary storage structures and file systems. It provides an overview of disk structure and common disk terms. It then describes different disk scheduling algorithms like FCFS, SSTF, SCAN, C-SCAN, LOOK, and C-LOOK. The document also discusses file concepts, access methods, allocation methods, directory structures, and different logical directory structures like single-level, two-level, tree-structured, and graph directories.

Uploaded by

sitsekhar
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/ 57

Module-V

by:
Dr. Soumya Priyadarsini Panda
Assistant Professor
Dept. of CSE
Silicon Institute of Technology, Bhubaneswar
Secondary Storage Structure

 Secondary Storage Structure:

 Overview of mass storage structure

 Disk structure

Self study: Refer Text book( page No. 467-471)


Some Common Terms
 Transfer rate: The rate at which data flow between the drive and the
computer

 Seek Time: The time necessary to move the disk arm to the desired
cylinder

 Rotational latency: The time necessary for the desired sector to rotate
to the disk head

 Disk bandwidth: 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 Access Time: Seek Time + Rotational Latency + Transfer Time


Disk Scheduling
 One of the responsibilities of the operating system is to use the
hardware efficiently.

 For the disk drives, the focus is on fast access time and large disk
bandwidth.

 Both the access time and the bandwidth can be increased by managing
the order in which disk I/O requests are serviced.

 Whenever a process needs I/O to or from the disk, it issues a system


call to the operating system.

 The request specifies several pieces of information about the request.


Cont…
 If the desired disk drive and controller are available, the request can be
serviced immediately.

 If the drive or controller is busy, any new requests for service will be
placed in the queue of pending requests for that drive.

 For a multiprogramming system with many processes, the disk queue


may have several pending requests.

 The operating system chooses which pending request to service next


using a disk scheduling algorithm.
Disk scheduling Algorithms

 FCFS
 SSTF
 SCAN
 C-SCAN
 LOOK
 C-LOOK
FCFS
 The first-come, first-served (FCFS) is the simplest form of disk
scheduling algorithm.
 In FCFS, the requests are addressed in the order they arrive in the disk
queue
 This algorithm is intrinsically fair, but it generally does not provide the
fastest service.

Example: A disk queue with requests for I/O to blocks on cylinders: 98, 183,
37, 122, 14, 124, 65, 67

If the disk head is initially at


cylinder 53

Total head movement= 640


cylinders
SSTF
 The shortest-seek-time-first (SSTF) algorithm, selects the request with
the least seek time from the current head position.

 In other words, SSTF chooses the pending request closest to the current
head position.

Example:

Total head movement=


236 cylinders
SCAN
 In the SCAN algorithm, the disk arm starts at one end of the disk and
moves toward the other end, servicing requests as it reaches each
cylinder, until it gets to the other end of the disk.

 At the other end, the direction of head movement is reversed, and


servicing continues.

 The head continuously scans back and forth across the disk.

 The SCAN algorithm is sometimes called the elevator algorithm,

 since the disk arm behaves just like an elevator in a building, first
servicing all the requests going up and then reversing to service
requests the other way.
SCAN Cont…
Example:
Assuming that the disk arm is moving toward 0 and that the initial head
position is again 53, the head will next service 37 and then 14.
At cylinder 0, the arm will reverse and will move toward the other end of
the disk, servicin the requests at 65, 67, 98, 122, 124, and 183
C-SCAN
 Circular SCAN (C-SCAN) scheduling is a variant of SCAN designed
to provide a more uniform wait time.

 Like SCAN, C-SCAN moves the head from one end of the disk to the
other, servicing requests along the way.

 When the head reaches the other end, however, it immediately returns
to the beginning of the disk without servicing any requests on the
return trip.

 The C-SCAN scheduling algorithm essentially treats the cylinders as a


circular list that wraps around from the final cylinder to the first one.
C-SCAN Cont…

Example:
LOOK
 Both SCAN and C-SCAN move the disk arm across the full width of
the disk.

 In practice, neither algorithm is often implemented this way.

 More commonly, 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.

 The versions of SCAN and C-SCAN that follow this pattern are called
LOOK and C-LOOK scheduling, because they look for a request
before continuing to move in a given direction.
C-LOOK

 Example:
File System
Background
 For most users, the file system is the most visible aspect of an
operating system.

 It provides the mechanism for storage and access to both data and
programs of the operating system and all the users of the computer
system.

 The File system consists of two distinct parts:


 a collection of files, each storing related data, and
 a directory structure, which organizes and provides information
about all the files in the system.
 The operating system abstracts from the physical properties of its
storage devices to define a logical storage unit, the file.

 Files are mapped by the operating system onto physical devices.


File Concept
 A file is a named collection of related information that is recorded on
secondary storage.

 Files represent programs (both source and object forms) and data.

 Data files may be numeric, alphabetic, alphanumeric, or binary.

 Files may be free form, such as text files, or may be formatted rigidly

 In general, a file is a sequence of bits, bytes, lines, or records, the


meaning of which is defined by the file’s creator and user.
File Access Methods
 Files store information.
 When it is used, this information must be accessed and read into
computer memory.

 The information in the file can be accessed in several ways.

 Access methods:
 Sequential Access
 Direct Access
 Other Access Methods
Sequential Access
 Information in the file is processed in order, one record after the other.

 This mode of access is the most common;


 for example, editors and compilers usually access files in this
fashion.
Direct Access
 Random access file organization provides, accessing the records
directly.

 Each record has its own address on the file with by the help of which it
can be directly accessed for reading or writing.

 The records need not be in any sequence within the file and they need
not be in adjacent locations on the storage medium.
Other Access Methods
 Other access methods can be built on top of a direct-access method.

 These methods generally involve the construction of an index for the


file.

 The index, like an index in the back of a book, contains pointers to the
various blocks

 To find a record in the file, first search the index and then use the
pointer to access the file directly and to find the desired record
File Allocation Methods
 Files are allocated disk spaces by operating system.

 Operating systems deploy following three methods to allocate disk


space to files.

 Contiguous Allocation
 Linked Allocation
 Indexed Allocation
Contiguous Allocation
 In Contiguous Allocation-

 Each file occupies a contiguous address space on disk.

 Assigned disk address is in linear order.

 Easy to implement.

 External fragmentation is a major issue with this type of allocation


technique.
Linked Allocation
 In Linked Allocation-
 Each file carries a list of links to disk blocks.

 Directory contains link / pointer to first block of a file.

 No external fragmentation

 Effectively used in sequential access file.

 Inefficient in case of direct access file.


Indexed Allocation
 In Indexed Allocation

 Provides solutions to problems of contiguous and linked allocation.

 A index block is created having all pointers to files.

 Each file has its own index block which stores the addresses of disk
space occupied by the file.

 Directory contains the addresses of index blocks of files.


Directory Structure
 The information about all files is kept in the directory structure, which
also resides on secondary storage.

 A directory is a container that is used to contain folders and file.

 It organizes files and folders into a hierarchical manner.


Logical Structures of a directory

 Single-level directory

 Two-level directory

 Tree-structured directory

 Acyclic graph directory

 General graph directory structure


Single-level directory
 In Single level directory, all files are contained in same directory which
make it easy to support and understand.

 A single level directory has a significant limitation when the number of


files increases or when the system has more than one user.

 Since all the files are in the same directory, they must have the unique
name.
 If two users call their dataset test, then the unique name rule violated.
Cont…
Advantages:
 Since it is a single directory, so its implementation is very easy.
 If the files are smaller in size, searching will become faster.
 The operations like file creation, searching, deletion, updating are very
easy in such a directory structure.

Disadvantages:
 There may chance of name collision because two files can not have the
same name.
 Searching will become time taking if the directory is large.
 It can not group the same type of files together.
Two-level directory
 A single level directory often leads to confusion of files names among
different users.

 In the two-level directory structure, each user has there own user files
directory (UFD).

 The UFDs has similar structures, but each lists only the files of a single
user.

 System’s master file directory (MFD) is searches whenever a new user id


is logged in.

 The MFD is indexed by username or account number, and each entry


points to the UFD for that user.
Cont…
Cont…
Advantages:
 We can give full path like /User-name/directory-name/.
 Different users can have same directory as well as file name.
 Searching of files become more easy due to path name and user-
grouping.

Disadvantages:
 A user is not allowed to share files with other users.
 Still it is not very scalable, two files of the same type cannot be grouped
together in the same user.
Tree-structured directory
 Once we have seen a two-level directory as a tree of height 2, the natural
generalization is to extend the directory structure to a tree of arbitrary
height.

 This generalization allows the user to create there own subdirectories and
to organize on their files accordingly.

 A tree structure is the most common directory structure.

 The tree has a root directory, and every file in the system have a unique
path.
Cont…
Cont…
Advantages:
 Very generalize, since full path name can be given.
 Very scalable, the probability of name collision is less.
 Searching becomes very easy, we can use both absolute path as well as
relative.

Disadvantages:
 Every file does not fit into the hierarchical model, files may be saved
into multiple directories.
 We can not share files.
 It is inefficient, because accessing a file may go under multiple
directories.
Acyclic graph directory
 An acyclic graph is a graph with no cycle and allows to share
subdirectories and files.

 The same file or subdirectories may be in two different directories.

 It is a natural generalization of the tree-structured directory.


Cont…
 It is used in the situation like when two programmers are working on a
joint project and they need to access files.

 The associated files are stored in a subdirectory, separating them from


other projects and files of other programmers.

 The common subdirectories should be shared. So here we use Acyclic


directories.

 It is the point to note that shared file is not the same as copy file .

 If any programmer makes some changes in the subdirectory it will reflect


in both subdirectories.
Cont…
Advantages:
 We can share files.
 Searching is easy due to different-different paths.

Disadvantages:
 We share the files via linking, in case of deletion, it may create problem
 If the link is softlink then after deleting the file we left with a dangling
pointer.
 In case of hardlink, to delete a file we have to delete all the reference
associated with it.
General graph directory structure
 In general graph directory structure, cycles are allowed within a directory
structure where multiple directories can be derived from more than one
parent directory.

 The main problem with this kind of directory structure is to calculate


total size or space that has been taken by the files and directories.
Cont…
Advantages:
 It allows cycles.
 It is more flexible than other directories structure.

Disadvantages:
 It is more costly than others.
 It needs garbage collection.
Directory Implementation
 The selection of an appropriate directory implementation algorithm
may significantly affects the efficiency, performance, and reliability of
the file system.

 The directory implementation algorithms are classified according to the


data structure they are using.

 There are mainly two algorithms which are used for directory
implementation:

 Linear List

 Hash Table
Linear List
 In this algorithm, all the files in a directory are maintained as singly lined
list.

 Each file contains the pointers to the data blocks which are assigned to it
and the next file in the directory.
Cont…
Characteristics
 When a new file is created, then the entire list is checked whether the new
file name is matching to a existing file name or not.

 In case, it doesn't exist, the file can be created at the beginning or at the
end.

 Therefore, searching for a unique name is a big concern because


traversing the whole list takes time.

 The list needs to be traversed in case of every operation (creation,


deletion, updating, etc) on the files therefore, the systems become
inefficient.
Hash Table
 To overcome the drawbacks of singly linked list implementation of
directories, there is an alternative approach that is hash table.

 This approach suggests to use hash table along with the linked lists.
Cont…
 A key-value pair for each file in the directory gets generated and stored
in the hash table.

 The key can be determined by applying the hash function on the file
name while the key points to the corresponding file stored in the
directory.

 Searching becomes efficient due to the fact that, entire list will not be
searched on every operating.

 Only hash table entries are checked using the key and if an entry found
then the corresponding file will be fetched using the value.
Allocation Methods

 Contiguous Allocation

 Linked Allocation

 Indexed Allocation
Contiguous Allocation
 If the blocks are allocated to the file in such a way that all the logical
blocks of the file get the contiguous physical block in the hard disk.
Cont…
Advantages:
 It is simple to implement.

 Excellent read performance is obtained.

 Supports Random Access into files.

Disadvantages:
 The disk will become fragmented.

 It may be difficult to have a file grow.


Linked List Allocation
 Linked List allocation solves all problems of contiguous allocation.

 In linked list allocation, each file is considered as the linked list of disk
blocks.

 However, the disks blocks allocated to a particular file need not to be


contiguous on the disk.

 Each disk block allocated to a file contains a pointer which points to the
next disk block allocated to the same file.
Cont…
Advantages:
 There is no external fragmentation with linked allocation.
 Any free block can be utilized in order to satisfy the file block requests.
 File can continue to grow as long as the free blocks are available.
 Directory entry will only contain the starting block address.

Disadvantages:
 Random Access is not provided.
 Pointers require some space in the disk blocks.
 Any of the pointers in the linked list must not be broken otherwise the
file will get corrupted.
 Need to traverse each block.
Indexed Allocation
 In Indexed Allocation Scheme, all the disk pointers are stored in one of
the blocks called as indexed block.

 Indexed block doesn't hold the file data, but it holds the pointers to all the
disk blocks allocated to that particular file.

 Directory entry will only contain the index block address.


Cont…
Advantages:
 Supports direct access
 A bad data block causes the lost of only that block.

Disadvantages:
 A bad index block could cause the lost of entire file.
 Size of a file depends upon the number of pointers, a index block can hold.
 Having an index block for a small file is totally wastage.
 More pointer overhead

 Variations of Indexed allocation method: Linked scheme, Multilevel


scheme
linked Scheme
 The file size depends on the size of a disk block.
 To allow large files, nk several index blocks can be linked together.

 For example, an index block might contain a small header giving the
name of the file and a set of the first 100 disk-block addresses.

 Advantage: It removes file size limitations


 Disadvantage: Random Access becomes a bit harder
Multilevel Index
 In Multilevel index allocation, we have various levels of indices.

 There are outer level index blocks which contain the pointers to the
inner level index blocks and the inner level index blocks contain the
pointers to the file data.

 The outer level index is used to find the inner level index.

 The inner level index is used to find the desired data block.

 Advantage: Random Access becomes better and efficient.

 Disadvantage: Access time for a file will be higher.


Cont…
For further details refer Text book
I/O System

 I/O System:
 Polling

 Interrupts

 DMA

Self study: Refer Text book( page No. 587)

You might also like