0% found this document useful (0 votes)
19 views24 pages

8. Allocation Methods (1)

The document discusses three primary methods for allocating secondary storage space: Contiguous Allocation, Linked Allocation, and Indexed Allocation. Each method has its advantages and disadvantages, addressing issues like external fragmentation, file size management, and access efficiency. Solutions such as compaction, clustering, and various indexing schemes are proposed to mitigate the limitations of each allocation method.

Uploaded by

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

8. Allocation Methods (1)

The document discusses three primary methods for allocating secondary storage space: Contiguous Allocation, Linked Allocation, and Indexed Allocation. Each method has its advantages and disadvantages, addressing issues like external fragmentation, file size management, and access efficiency. Solutions such as compaction, clustering, and various indexing schemes are proposed to mitigate the limitations of each allocation method.

Uploaded by

imsubash2707
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Allocation Methods

Unit IV – Topic 8 – Chapter 14


Contents
• Contiguous Allocation
• Linked Allocation
• Indexed Allocation
Introduction
• Idea: To allocate space to the files in a system so
that
 The storage space is utilized effectively and
 Files can be accessed quickly.
• Three major methods of allocating secondary
storage space
 Contiguous Allocation.
 Linked Allocation.
 Indexed Allocation.
1. Contiguous Allocation
• Contiguous allocation requires that each file occupy a
set of contiguous blocks on the device
• Device addresses define a linear ordering on the device
• If only 1 job is accessing the storage location,
 Accessing block b + one after block b  normally requires no
head movement
 At most, the head need only move from one track to the next.
• Hence, for HDDs, the number of disk seeks required for
accessing contiguously allocated files is minimum
• Contiguous allocation of a file is defined by
 The address of the first block and
 Length (in block units) of the file.
• If a file’s starting address is “b” and its length is “n”
blocks, then
 It occupies blocks b, b + 1, b + 2, ..., b + n − 1.
• The directory entry for each file indicates
 The address of the starting block and the
 Length of the area allocated for this file
Contiguous allocation of disk space.
• Drawbacks:
 Finding space for a new file.
 Free space management is required.
 Equivalent to Dynamic Storage-Allocation problem:
 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.
 External fragmentation issue:
 The free storage space is broken into little pieces
 Problem when the largest contiguous chunk is
insufficient for a request;
• Identification of the space for the file
 When a file is created, the total amount of space required
must be found and allocated
 Fairly tough to identify the size while creation
 Allotting little space – leads to the file tough to be extended
 To resolve this issue
 Terminate the user program, with an appropriate error message
 The user must then allocate more space and run the program
again
 Repeated runs – which may be costly
 User overestimate the amount of space needed
 Resulting in considerable wasted space.
• Solution for external fragmentation
 Compacting
 Copy an entire file system onto another device
 The original device is then freed completely, creating one
large contiguous free space.
 Then copy the files back onto the original device by
allocating contiguous space from this one large hole
 Offline Compacting reduces the issues further more
 During this down time, normal system operation
generally cannot be permitted,
 Cost of this compaction time is avoided on production
machines
• Solution for file size issue
 Modified contiguous-allocation scheme
 Here, contiguous chunk of space is allocated initially.
 If that amount proves not to be large enough, another
chunk of contiguous space, known as an extent, is added
2. Linked Allocation
• Linked allocation solves all problems of contiguous
allocation
• Here, each file is a linked list of storage blocks;
 The blocks may be scattered anywhere on the device.
 The directory contains a pointer to the first and last blocks of
the file.
• E.g.., Consider a file with 5 blocks are stored in the
following block locations
 Block 9, Block 16, Block 1, Block 10 and Block 25
 Each block contains a pointer to the next block
Linked allocation of disk space.

Block 9, Block 16, Block 1, Block


10 and Block 25
• To create a file
 Create a new entry in the directory
 The pointer to the first block of this file = NULL (Being a
new empty file)
 The size field is also set to 0.
• After writing contents to the file
 Free space management system finds a free block where the
contents are written
 This block is now linked to the end of the file.
• To read contents from a file
 Read blocks by following the pointers from block to block.
• Advantages
 No external fragmentation – Any free block can be used.
 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
 No compaction is required
• Disadvantages
 It can be used effectively only for sequential-access files
 To find ith block, its required to read from 1st block
 Each access to a pointer requires a storage device read and
HDD seek
 Additional space is required for the pointers
 Unreliable – in case if pointers are lost or damaged.
• Solution to reduce additional space
 Collect blocks into multiples, called clusters
 Allocate clusters rather than blocks. E.g.., if a cluster = 4 blocks
 Thus 4 blocks will be sequential
 Clusters are linked through pointers – Reduces the number of
pointers when used for each block.
 Improves HDD throughput
 Decreases the space needed for block allocation and free-list
management.
• Solution for unreliability
 Use doubly linked list
 Store the file name and relative block number in each block
File-Allocation Table (FAT)
• A variation of linked allocation
• Used by MS-DOS operating system
• Working of FAT
 A section of storage at the beginning of each volume is set
aside to contain the table.
 The table has one entry for each block and is indexed by block
number.
 Accessed similar to linked list
 Directory entry:
 Contains the block number of the first block of the file.
 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 = end-of-file value
 An unused block is indicated by a table value of 0
FAT - File-allocation table.

FAT structure for a file consisting of disk blocks 217, 618, and
339.
• Allocating a new block to a file in FAT
 Find the first 0-valued table entry
 Replace the previous end of file value with the address of the
new block
 The 0 is then replaced with the end-of-file value.
• Drawbacks:
 Results in a significant number of disk head seeks
 The disk head must move to the start of the volume to read
the FAT and find the location of the block in question, then
move to the location of the block itself.
 Solution: Cache shall be used.
• Advantages: Random Access is improved
3. Indexed Allocation
• Idea:
 Bringing all the pointers together into one location  the index
block
• Each file has its own index block, which is an array of
storage-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
 To find and read the ith block, we use the pointer in the ith
index-block entry
• When file is created:
 All pointers in the index block are set to null
 When the ith block is first written, a block is obtained from the free-space
manager
 Its address is put in the ith index-block entry
• Advantages
 Indexed allocation supports direct access
 No external fragmentation - any free block on the storage device shall be
used
• Disadvantages
 Suffers from wasted space
 The pointer overhead of the index block is generally greater than the
pointer overhead of linked allocation
 E.g.., in case where, a file have only one/ two blocks
• Solution: Index block should be in optimal size: not too large
& too small. 3 mechanisms are used to resolve this:
 Linked scheme:
 An index block is normally one storage block
 To allow for large files, we can link together several index blocks
 Multilevel index:
 This uses a first-level index block that points to a set of second-
level index blocks, which in turn points to the file blocks.
 Combined scheme:
 Used in UNIX-based file systems. Keeps 15 pointers of the index
block in the file’s inode.
 The first 12 pointers point to direct blocks.
 The next 3 to indirect blocks - single indirect, double indirect & triple
indirect block
The UNIX inode

You might also like