0% found this document useful (0 votes)
13 views94 pages

OS-Unit4 - 2

This document covers the mass storage structure in operating systems, detailing magnetic disks, solid-state disks, and magnetic tape as storage mediums. It discusses disk scheduling algorithms, disk management tasks like formatting, booting, and bad block recovery, as well as swap space management for virtual memory. Additionally, it highlights the differences between host-attached storage and network-attached storage systems.

Uploaded by

himeshpulikanti
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)
13 views94 pages

OS-Unit4 - 2

This document covers the mass storage structure in operating systems, detailing magnetic disks, solid-state disks, and magnetic tape as storage mediums. It discusses disk scheduling algorithms, disk management tasks like formatting, booting, and bad block recovery, as well as swap space management for virtual memory. Additionally, it highlights the differences between host-attached storage and network-attached storage systems.

Uploaded by

himeshpulikanti
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/ 94

OPERATING SYSTEMS

UNIT-IV
Mass Storage Structure

• Overview of Mass-storage structure


• Disk structure
• Disk attachment
• Disk scheduling
• Swap-space management.
Overview
a) Magnetic Disk
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)
• A head crash normally cannot be repaired; the entire disk must be replaced.
• Disks can be removable.Other forms of removable disks include CDs, DVDs, and
Blu-ray discs as well as removable flash-memory devices known as flash drives.
• A disk drive is attached to a computer by a set of wires called an I/O bus.
• Several kinds of buses are available
– Advanced Technology Attachment (ATA)
– Serial ATA (SATA)
– Universal Serial Bus (USB), and
– Fibre Channel (FC).
• The data transfers on a bus are carried out by special electronic processors called controllers.
The host controller is the controller at the computer end of the bus. A disk controller is built
into each disk drive.
Moving-head Disk Mechanism
Overview of Mass Storage Structure
b) Solid-State Disks
• Sometimes old technologies are used in new ways as economics
change or the technologies evolve. An example is the growing
importance of solid-state disks, or SSDs.
• SSD is nonvolatile memory that is used like a hard drive.
• SSDs have the same characteristics as traditional hard disks but can
be more reliable because they have no moving parts and faster
because they have no seek time or latency They consume less
power.
• They are more expensive per megabyte than traditional hard disks,
have less capacity than the larger hard disks, and may have shorter
life spans than hard disks.
• SSDs are also used in some laptop computers to make them smaller,
faster, and more energy-efficient.
Overview of Mass Storage Structure
b) Solid-State Disks
• Sometimes old technologies are used in new ways as economics
change or the technologies evolve. An example is the growing
importance of solid-state disks, or SSDs.
• SSD is nonvolatile memory that is used like a hard drive.
• SSDs have the same characteristics as traditional hard disks but can be
more reliable because they have no moving parts and faster because
they have no seek time or latency They consume less power.
• They are more expensive per megabyte than traditional hard disks,
have less capacity than the larger hard disks, and may have shorter
life spans than hard disks.
• SSDs are also used in some laptop computers to make them smaller,
faster, and more energy-efficient.
Overview of Mass Storage Structure
c) Magnetic Tape
• Was early secondary-storage medium
• Relatively permanent and holds large quantities of data
• Access time is slow compared to Magnetic Disk
• Random access to magnetic tape is ~1000 times slower than disk
• Mainly used for backup, storage of infrequently-used data, transfer
medium between systems
• A tape is kept in a spool and is wound or rewound past a read–write
head.
• Moving to the correct spot on a tape can take minutes, but once
positioned, tape drives can write data at speeds comparable to disk
drives.
• Some are named according to technology, such as LTO-5 and SDLT.
Disk Structure
• Disk drives are addressed as large 1-dimensional arrays of logical
blocks, where the logical block is the smallest unit of transfer.
• 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
• By using this mapping, we can convert a logical block number into an
old-style disk address that consists of a cylinder number, a track
number within that cylinder, and a sector number within that track
• In practice, it is difficult to perform this translation, for two reasons.
First, most disks have some defective sectors, but the mapping hides
this by substituting spare sectors from elsewhere on the disk.
Second, the number of sectors per track is not a constant on some
drives
Disk Attachment
• Computers access disk storage in two ways:-
– via I/O ports(host-attached storage)
– via remote host in a distributed file
system(network-attached storage)
• Host-attached storage is storage accessed through
local I/O ports.
• High-end workstations and servers generally use more
sophisticated I/O architectures such as fibre channel
(FC), a high-speed serial architecture that can operate
over optical fiber or over a four-conductor copper
cable.
• A wide variety of storage devices are suitable for use
as host-attached storage. Among these are hard disk
drives, RAID arrays, and CD, DVD, and tape drives
Network Attached Storage
• A network-attached storage (NAS) device is a special-purpose
storage system that is accessed remotely over a data network.
• Clients access network-attached storage via a
remote-procedure-call interface such as NFS(Network File System)
for UNIX systems or CIFS(Common Internet File System) for
Windows machines.
• Network-attached storage provides a convenient way for all the
computers on a LAN to share a pool of storage with the same ease
of naming and access enjoyed with local host-attached storage.
• Less efficient and have lower performance than some
direct-attached storage options.
• iSCSI((Internet Small Computer System Interface) is the latest
network-attached storage protocol.
Network Attached Storage
Storage Area Network
• One drawback of network-attached storage systems is that the
storage I/O operations consume bandwidth on the data network,
thereby increasing the latency of network communication. This
problem can be particularly acute in large client–server
installations.
• A storage-area network (SAN) is a private network (using storage
protocols rather than networking protocols) connecting servers and
storage units.
• The power of a SAN lies in its flexibility. Multiple hosts and multiple
storage arrays can attach to the same SAN, and storage can be
dynamically allocated to hosts.
• As one example, if a host is running low on disk space, the SAN can
be configured to allocate more storage to that host. SANs make it
possible for clusters of servers to share the same storage and for
storage arrays to include multiple direct host connections.
Storage Area Network
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
• OS maintains queue of requests, per disk or device
• Idle disk can immediately work on I/O request
• Optimization algorithms only make sense when a queue exists
• Drive controllers and can manage a queue of I/O requests (of varying
“depth”)
• Several algorithms exist to schedule the servicing of disk I/O requests
• Scheduling algorithms use request queue (0-199)
98, 183, 37, 122, 14, 124, 65, 67
Head pointer 53
FCFS

If the disk head is initially at cylinder 53, it will first move from 53 to 98,
then to 183, 37, 122, 14, 124, 65, and finally to 67, for a total head
movement of 640
cylinders.(98-53)+(183-98)+(183-37)+(122-37)+(122-14)+(124-14)+(124-65)+(
67-65)=45+85+146+85+108+110+59+2=640
SSTF
• 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
SSTF (Cont.)
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 208 cylinders


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.
C-SCAN (Cont.)
C-LOOK
• LOOK a version of SCAN, C-LOOK 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
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
• 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
Exercise on Disk-Scheduling Algorithm
Disk Management
Disk Management of the OS includes the various aspects, such
as:
• A) Disk Format B) Booting from disk C) Bad block recovery
Disk Formatting:
A new magnetic disk is mainly a blank slate. It is platters of the
magnetic recording material. Before a disk may hold data, it
must be partitioned into sectors that may be read and written by
the disk controller. It is known as physical
formatting and low-level formatting.
Low-level formatting creates a unique data structure for every
sector on the drive. A data structure for a sector is made up of a
header, a data region, and a trailer. The disk controller uses the
header and trailer to store information like an error-correcting
code (ECC) and a sector number.
Disk Management
The OS must require recording its own data structures on the
disk drive to utilize it as a storage medium for files. It
accomplishes this in two phases.
• The initial step is to divide the disk drive into one or more
cylinder groups. The OS may treat every partition as it were a
separate disk. For example, one partition could contain a copy
of the OS executable code, while another could contain user
files.
• The second stage after partitioning is logical formatting. The
operating store stores the initial file system data structure on
the disk drive in this second stage.

OS by Dr.V.Srilakshmi. Associate Professor,


CSE
Disk Management
• 2. Boot Block
• When a system is turned on or restarted, it must execute an
initial program. The start program of the system is called the
bootstrap program.
• It starts the OS after initializing all components of the system.
The bootstrap program works by looking for the OS kernel on
disk, loading it into memory, and jumping to an initial address
to start the OS execution.
• The bootstrap is usually kept in read-only memory on most
computer systems. It is useful since read-only memory does
not require initialization and is at a fixed location where the
CPU may begin executing whether powered on or reset.
Disk Management
• Furthermore, it may not be affected by a computer system
virus because ROM is read-only. The issue is that updating this
bootstrap code needs replacing the ROM hardware chips.
• As a result, most computer systems include small bootstrap
loader software in the boot ROM, whose primary function is
to load a full bootstrap program from a disk drive. The entire
bootstrap program can be modified easily, and the disk is
rewritten with a fresh version.
• The bootstrap program is stored in a partition and is referred
to as the boot block. A boot disk or system disk is a type of
disk that contains a boot partition.
Disk Management
• 3. Bad Blocks
• Disks are prone to failure due to their moving parts and tight
tolerances. When a disk drive fails, it must be replaced and
the contents transferred to the replacement disk using backup
media. For some time, one or more sectors become faulty.
Most disks also come from the company with bad blocks.
These blocks are handled in various ways, depending on the
use of disk and controller.
• On the disk, the controller keeps a list of bad blocks. The list is
initialized during the factory's low-level format and updated
during the disk's life. Each bad sector may be replaced with
one of the spare sectors by directing the controller. This
process is referred to as sector sparing.
Swap space Management
• Swap-space management is another low-level task of the
operating system.
• Swap space is a space on a hard disk that is a substitute for
physical memory. It is used as virtual memory, which contains
process memory images. Whenever our computer runs short
of physical memory, it uses its virtual memory and stores
information in memory on a disk.
• Swap space is used in various ways by different operating
systems, depending on the memory-management algorithms
in use. For example, systems that implement swapping may
use swap space to hold an entire process image, including the
code and data segments. . The amount of swap space needed
on a system can vary depending on the amount of physical
memory,. It can range from a few megabytes of disk space
to gigabytes.
Swap space Management
• The following table shows different systems using the amount
of swap space:

S.No. System Swap Space

1. Solaris Swap space is equal


to the amount of
physical memory.

2. Linux Swap space is


double the amount of
physical memory.
Where does the Swap Space Reside?

• Swap space can reside in one of these two places: The normal
file system or Separate disk partition.

OS by Dr.V.Srilakshmi. Associate Professor,


CSE
Example of Swap Space Management
• In the Linux system, one or more swap areas can be
established.
Example of Swap Space Management
• A swap area may be in a swap file on a regular file system or a
dedicated file partition.
• Each swap area consists of 4-KB page slots used to hold the
swapped pages.
• An array of integers counters associated with each swap area
is a swap-map corresponding to a page slot in the swap area.
• If the value of a counter is 0, the corresponding page slot is
available.
• If the values are greater than 0, it indicates that a swapped
page occupies the page slot.
• The value of the counter indicates the number of mappings to
the swapped page. For example, a value of 3 indicates that
the swapped page is mapped to the 3 different processes.
File System Implementation
• Access Methods
• File system structure
File system implementation
• Directory implementation
• Allocation methods
• Free-space management

OS by Dr.V.Srilakshmi. Associate Professor,


CSE
File Concept
• A file is a logical storage unit.
• Commonly, files represent programs (both source and object
forms) and data.
• Data files may be numeric, alphabetic, alphanumeric, or
binary.
• A file is a sequence of bits, bytes, lines, or records.
• A text file is a sequence of characters organized into lines (and
possibly pages).
• A source file is a sequence of functions, each of which is
further organized as declarations followed by executable
statements.
• An executable file is a series of code sections that the loader
can bring into memory and execute.
File Attributes

• Name. The symbolic file name is the only


information kept in human readable form.
• Identifier. This unique tag, usually a number,
identifies the file within the file system; it is the
non-human-readable name for the file.
• Type. This information is needed for systems that
support different types of files.
• Location. This information is a pointer to a device
and to the location of the file on that device.
File Attributes
• Size. The current size of the file (in bytes, words, or
blocks) and possibly the maximum allowed size are
included in this attribute.
• Protection. Access-control information determines
who can do reading,writing, executing, and so on.
• Time, date, and user identification. This information
may be kept for creation, last modification, and last
use. These data can be useful for protection, security,
and usage monitoring.
File Attributes
• Size. The current size of the file (in bytes, words, or
blocks) and possibly the maximum allowed size are
included in this attribute.
• Protection. Access-control information determines
who can do reading, writing, executing, and so on.
• Time, date, and user identification. This information
may be kept for creation, last modification, and last
use. These data can be useful for protection, security,
and usage monitoring.
File Operations
• Create a file
• Writing a file
• Reading a file
• Repositioning within a file
• Deleting a file
• Truncating a file
File Types
File Access Methods

• The file can be referred to as the collection of data


which is in the form of bits/ bytes which are stored in
secondary storage like hard drives.
• File access methods in OS refer to the techniques
used to access read and write data from and to a file.
There are various file access methods in OS like:
– Sequential Access
– Direct Access
– Indexed Access
Sequential File Access Method
• Sequential access is one of the simplest and oldest
file access methods in OS.
• In this, the data is accessed in sequential order, one
record at a time.
• This is useful for log files or media files as they are
large files and the file is processed by accessing the
data sequentially.
• We do not have to keep the track of the location of
the data as the data is accessed sequentially.
• In this method, the data is read from the beginning
of the file until the desired result is found.
Sequential File Access Method
• It is used in devices like tapes as they have
continuous steam of data and the data is written and
read sequentially.
Advantages of Sequential File Access Method
• It is simple to implement this file access mechanism.
• It uses lexicographic order to quickly access the next
entry.
• It is less prone to data corruption as the data is
written sequentially and not randomly.
• It is a more efficient method for reading large files, as
it only reads the required data and does not waste
time reading unnecessary data.
• It is a reliable method for backup and restore
operations, as the data is stored sequentially and can
be easily restored if required.
Disadvantages of Sequential File Access Method
• If the file record that needs to be accessed next is not
present next to the current record, this type of file
access method is slow.
• Moving a sizable chunk of the file may be necessary
to insert a new record.
• It does not allow for quick access to specific records
in the file. The entire file must be searched
sequentially to find a specific record, which can be
time-consuming.
• It is not well-suited for applications that require
frequent updates or modifications to the file.
Direct Access Method

• Another method is direct access method also known


as relative access method.
• A fixed-length logical record that allows the program to read
and write record rapidly in no particular order.
• The direct access is based on the disk model of a file since
disk allows random access to any file block. For direct access,
the file is viewed as a numbered sequence of block or record.
Thus, we may read block 14 then block 59, and then we can
write block 17. There is no restriction on the order of reading
and writing for a direct access file.
Advantages & Disadvantages of Direct Access Method
• The files can be immediately accessed decreasing the average access time.
• In the direct access method, in order to access a block, there is no need of
traversing all the blocks present before it.
• It has a higher overhead compared to sequential access as we need to
determine the location of data before accessing it.
Indexed Access Method
• The indexed access method is one of the file access methods
in OS that uses the index to locate the data within a file.
• In this method, we will create an index that will contain the
address of all the data blocks within the file.
• When a user request to access any part of the data the
request is first passed to the index with the help of the index
will find the address of that data block and will locate it, then
the block is read forms the storage medium.
• It provides an efficient way to access all the data blocks or
records within a large file without having to search the entire
file for the data. This method is commonly used in database
management systems where efficient and quick access to
records is required.
Indexed Access Method
Advantages & Disadvantages of Indexed Access Method

• Advantages − Provides fast and efficient access to


files by name or attributes, making it suitable for
applications that require searching and retrieving
specific files quickly.
• Disadvantages − The index must be maintained,
which can require additional disk space and
processing time.
File System Structure
File System Structure
• File systems provide efficient and convenient access
to the disk by allowing data to be stored, located,
and retrieved easily.
• The application program requests for a file, the
request is sent to the logical file system.
• The logical file system stores the meta data of the
file and the directory structure. If the application
program does not have the required permissions,
then the logical file system shows an error. It is also
responsible for verifying the path to the file.
File System Structure
• Files are stored in the hard disks from where it is to be
retrieved. The files are divided into logical blocks. To store and
retrieve data from the file, the logical blocks need to be mapped
to the physical blocks.
• This mapping is done by the file organization module. It also
looks over space management. The file organization module
decided which physical block is to be allocated to the
applications.
• Once the decision is made, it passes the information to the
basic file system. The basic file system issues a command to the
I\O Control to fetch the blocks.
• The I\O control handles any interrupts and contains the device
drivers to access the hard disk.
File System Structure
• Layering can introduce more operating-system overhead, which
may result in decreased performance.
• UNIX uses the UNIX file system (UFS)
• Windows supports disk file-system formats of FAT(File
Allocation Table), FAT32, and NTFS (or Windows NT File System)
File System Implementation
• Several on-disk and in-memory structures are used to
implement a file system. These structures vary depending on
the operating system and the file system.
• On disk, the file system may contain information about how to
boot an operating system stored there, the total number of
blocks, the number and location of free blocks, the directory
structure, and individual files.
• The different structures are :-
• A boot control block (per volume) can contain information
needed by the system to boot an operating system from that
volume. If the disk does not contain an operating system, this
block can be empty. It is typically the first block of a volume. In
UFS, it is called the boot block. In NTFS, it is the partition boot
sector.
File System Implementation
• A volume control block (per volume) contains volume (or
partition) details, such as the number of blocks in the partition,
the size of the blocks, a free-block count and free-block
pointers, and a free-(File Control Block)FCB count and FCB
pointers.
• In UFS, this is called a superblock. In NTFS, it is stored in the
master file table.
• A directory structure (per file system) is used to organize the
files. In UFS, this includes file names and associated inode
numbers. In NTFS, it is stored in the master file table.
• A per-file FCB contains many details about the file. It has a
unique identifier number to allow association with a directory
entry..
File System Implementation
• The in-memory information is used for both file-system
management and performance improvement via caching. The
data are loaded at mount time, updated during file-system
operations, and discarded at dismount.
• Several types of structures may be included.
• An in-memory mount table contains information about each
mounted volume.
• An in-memory directory-structure cache holds the directory
information of recently accessed directories. (For directories at
which volumes are mounted, it can contain a pointer to the
volume table.).
• The system-wide open-file table contains a copy of the FCB of
each open file, as well as other information.
File System Implementation
• The per-process open-file table contains a pointer to the
appropriate entry in the system-wide open-file table, as well as
other information.
• Buffers hold file-system blocks when they are being read from
disk or written to disk.
• To create a new file, an application program calls the logical file
system. The logical file system knows the format of the
directory structures. To create a new file, it allocates a new FCB.
The system then reads the appropriate directory into memory,
updates it with the new file name and FCB, and writes it back to
the disk
A Typical File Control Block
File System Implementation
File System Implementation-partitioning and mounting
• The layout of a disk can have many variations, depending on the
operating system. A disk can be sliced into multiple partitions,
or a volume can span multiple partitions on multiple disks.
• Each partition can be either “raw,” containing no file system, or
“cooked,” containing a file system. Raw disk is used where no
file system is appropriate.
• Boot information can be stored in a separate partition. Boot
information is usually a sequential series of blocks, loaded as an
image into memory. Execution of the image starts at a
predefined location, such as the first byte.
• The root partition, which contains the operating-system kernel
and sometimes other system files, is mounted at boot time.
Other volumes can be automatically mounted at boot or
manually mounted later, depending on the operating system.
File System Implementation
• Microsoft Windows–based systems mount each volume in a
separate name space, denoted by a letter and a colon. (F:).
• Thus, the file-system implementation consists of differentlayers,
as depicted schematically in Figure 12.4. The first layer is the
file-system interface, based on the open(), read(), write(), and
close() calls and on file descriptors.
• The second layer is called the virtual file system (VFS) layer. The
VFS layer serves two important functions:
• It separates file-system-generic operations from their
implementation by defining a clean VFS interface.
• It provides a mechanism for uniquely representing a file
throughout a network. The VFS is based on a file-representation
structure, called a vnode, that contains a numerical designator
for a network-wide unique file.
File System Implementation
File System Implementation
The four main object types defined by the Linux
VFS are:
• The inode object, which represents an
individual file.
• The file object, which represents an open file.
• The superblock object, which represents an
entire file system.
• The dentry object, which represents an
individual directory entry.
Directory Implementation
• Directory implementation in the operating
system can be done using Singly Linked List and
Hash table.
1) Directory Implementation using Singly Linked List
• The implementation of directories using a single
linked list is easy to program but is
time-consuming to execute. Here we
implement a directory by using a linear list of
filenames with pointers to the data blocks.
Directory Implementation
Directory Implementation
• To create a new file the entire list has to be checked such
that the new directory does not exist previously.
• The new directory then can be added to the end of the list
or at the beginning of the list.
• In order to delete a file, we first search the directory with
the name of the file to be deleted. After searching we can
delete that file by releasing the space allocated to it.
• To reuse the directory entry we can mark that entry as
unused or we can append it to the list of free directories.
• To delete a file linked list is the best choice as it takes less
time.
Disadvantage :- when the user needs to find a file the user has
to do a linear search and this results in slow access to a file.
Directory Implementation
• 2) Using Hash Table :-
• An alternative data structure that can be used for directory
implementation is a Hash table. It overcomes the major
drawbacks of directory implementation using a linked list. In
this method, we use a hash table along with the linked list. Here
the linked list stores the directory entries, but a hash data
structure is used in combination with the linked list.
• In the hash table for each pair in the directory key-value pair is
generated. The hash function on the file name determines the
key and this key points to the corresponding file stored in the
directory. This method efficiently decreases the directory search
time as the entire list will not be searched on every operation.
Using the keys the hash table entries are checked and when the
file is found it is fetched.
Directory Implementation
Directory Implementation
• Disadvantage:
• The major drawback of using the hash
table is that generally, it has a fixed size
and its dependency on size. But this
method is usually faster than linear search
through an entire directory using a linked
list.
Allocation methods
• Many files are stored on the same disk. The main problem is
how to allocate space to these files so that disk space is utilized
effectively and files can be accessed quickly.
• Three major methods of allocating disk space are in wide use:
contiguous, linked, and indexed.
• Contiguous Allocation:-
• Contiguous allocation requires that each file occupy a set of
contiguous blocks on the disk.
• Disk addresses define a linear ordering on the disk.
• Contiguous allocation of a file is defined by the disk address and
length (in block units).
• If the file is n blocks long and starts at location b, then it
occupies blocks b, b + 1, b + 2, ..., b + n − 1.
Contiguous Allocation method
Contiguous Allocation method
• Both sequential and direct access can be
supported by contiguous allocation.
▪ For sequential access, the file system
remembers the disk address of the last block
referenced and, when necessary, reads the
next block.
▪ For direct access to block i of a file that starts
at block b, we can immediately access block b
+ i.
Contiguous Allocation method
Contiguous allocation method suffers from the problem of
finding space for a new file. If we allocate too little space
to a file, we may find that the file cannot be extended.
The contiguous-allocation problem can be seen as a
particular application of the general dynamic
storage-allocation problem which involves how to satisfy a
request of size n from a list of free holes.
• First fit and best fit are the most common strategies
used to select a free hole from the set of available
holes. Simulations have shown that both first fit and
best fit are more efficient than worst fit in terms of
both time and storage utilization.
Contiguous Allocation method
• All these algorithms suffer from the problem of
external fragmentation. As files are allocated and
deleted, the free disk space is broken into little pieces.
• External fragmentation exists whenever free space is
broken into chunks. It becomes a problem when the
largest contiguous chunk is insufficient for a request.
• Many newer file systems (i.e., Veritas File System) use
a modified contiguous allocation scheme.
• Here, a contiguous chunk of space is allocated initially.
Then, if that amount proves not to be large enough,
another chunk of contiguous space, known as an
extent, is added.
Linked Allocation method
• Linked allocation solves all problems of contiguous
allocation. With linked allocation, each file is a linked
list of disk blocks.
• The disk blocks may be scattered anywhere on the
disk. The directory contains a pointer to the first and
last blocks of the file.
• For example, a file of five blocks might start at block 9
and continue at block 16, then block 1, then block 10,
and finally block 25.Each block contains a pointer to
the next block. These pointers are not made available
to the user.
Linked Allocation method
Linked Allocation method
• To create a new file, we simply create a new entry in the
directory. With linked allocation, each directory entry has a
pointer to the first disk block of the file. This pointer is
initialized to null (the end-of-list pointer value) to signify an
empty file.
• A write to the file causes the free-space management system to
find a free block, and this new block is written to and is linked to
the end of the file.
• To read a file, we simply read blocks by following the pointers
from block to block. There is no external fragmentation with
linked allocation, and any free block on the free-space list can
be used to satisfy a request.
• The size of a file need not be declared when the file is created.
A file can continue to grow as long as free blocks are available.
Consequently, it is never necessary to compact disk space.
Linked Allocation method
• Linked allocation does have disadvantages, the major problem is
that it can be used effectively only for sequential-access files.
• To find the ith block of a file, we must start at the beginning of
that file and follow the pointers until we get to the ith block.
Each access to a pointer requires a disk read, and some require
a disk seek. Consequently, it is inefficient to support a
direct-access capability for linked-allocation files.
• Another disadvantage is the space required for the pointers.
• Another problem of linked allocation is reliability.
• The files are linked together by pointers scattered all over the
disk, and what would happen if a pointer were lost or
damaged.
Linked Allocation method
• An important variation on linked allocation is the use of a
file-allocation table (FAT). This simple but efficient method of
disk-space allocation was used by the MS-DOS operating
system.
• A section of disk at the beginning of each volume is set aside to
contain the table. The table has one entry for each disk block
and is indexed by block number.
• The directory entry contains the block number of the first block
of the file. The table entry indexed by that block number
contains the block number of the next block in the file. This
chain continues until it reaches the last block, which has a
special end-of-file value as the table entry. An unused block is
indicated by a table value of 0.
Linked Allocation method
Indexed Allocation method
• Linked allocation solves the external-fragmentation and
size-declaration problems of contiguous allocation. However, in the
absence of a FAT, linked allocation cannot support efficient direct
access, since the pointers to the blocks are scattered with the blocks
themselves all over the disk and must be retrieved in order.
• Indexed allocation solves this problem by bringing all the pointers
together into one location: the index block.
• Each file has its own index block, which is an array of disk-block
addresses. The ith entry in the index block points to the ith block of
the file. The directory contains the address of the index block.
• Indexed allocation supports direct access, without suffering from
external fragmentation, because any free block on the disk can satisfy
a request for more space. Indexed allocation does suffer from wasted
space.
Indexed Allocation method
Indexed Allocation method
• The pointer overhead of Indexed block is greater than the
pointer overhead of linked allocation.
• How large the index block should be?
• Every file must have an index block, so we want the index block
to be as small as possible. If the index block is too small,
however, it will not be able to hold enough pointers for a large
file. Mechanisms for this purpose include the following:
• Linked scheme: An index block is normally one disk block. Thus,
it can be read and written directly by itself. To allow for large
files, we can link together several index blocks.
• Multilevel index: A variant of linked representation uses a
first-level index block to point to a set of second-level index
blocks, which in turn point to the file blocks.
Indexed Allocation method
• Combined scheme. Another alternative, used in UNIX-based file
systems, is to keep the first, say, 15 pointers of the index block
in the file’s inode. The first 12 of these pointers point to direct
blocks. The next three pointers point to indirect blocks.
Free Space Management
• Since disk space is limited, we need to reuse the space from
deleted files for new files, if possible.
• To keep track of free disk space, the system maintains a
free-space list. The free-space list records all free disk
blocks—those not allocated to some file or directory.
• To create a file, we search the free-space list for the required
amount of space and allocate that space to the new file. This
space is then removed from the free-space list.
• When a file is deleted, its disk space is added to the free-space
list.
• 1) Bit Vector
Frequently, the free-space list is implemented as a bit map or bit
vector. Each block is represented by 1 bit. If the block is free, the
bit is 1; if the block is allocated, the bit is 0.
Free Space Management
• For example, consider a disk where blocks 2, 3, 4, 5, 8, 9, 10, 11,
12, 13, 17, 18, 25, 26, and 27 are free and the rest of the blocks
are allocated. The free-space bit map would be
001111001111110001100000011100000 ...
• The main advantage of this approach is its relative simplicity
and its efficiency in finding the first free block or n consecutive
free blocks on the disk.
2) Linked List :-
• Another approach to free-space management is to link together
all the free disk blocks, keeping a pointer to the first free block
in a special location on the disk and caching it in memory.
• This first block contains a pointer to the next free disk block,
and so on.
Free Space Management-Linked List

• In the example in which blocks 2, 3, 4, 5, 8, 9, 10, 11,


12, 13, 17, 18, 25, 26, and 27 were free and the rest of
the blocks were allocated. In this situation, we would
keep a pointer to block 2 as the first free block. Block 2
would contain a pointer to block 3, which would point
to block 4, which would point to block 5, which would
point to block 8, and so on.
• This scheme is not efficient; to traverse the list, we
must read each block, which requires substantial I/O
time.
Free Space Management-Linked List
Free Space Management-Grouping

• 3) Grouping
A modification of the free-list approach stores the
addresses of n free blocks in the first free block.
The first n−1 of these blocks are actually free. The
last block contains the addresses of another n
free blocks, and so on. The addresses of a large
number of free blocks can now be found quickly,
unlike the situation when the standard linked-list
approach is used.
Free Space Management- Counting

• 4) Counting
Rather than keeping a list of n free disk addresses,
we can keep the address of the first free block
and the number (n) of free contiguous blocks that
follow the first block. Each entry in the free-space
list then consists of a disk address and a count.

You might also like