0% found this document useful (0 votes)
17 views10 pages

OS Presentatio Topic

Uploaded by

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

OS Presentatio Topic

Uploaded by

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

OS presentation topic:

File allocation methods

Overview of Disk Allocation Methods

 Disk Allocation refers to how space on a disk is assigned to store


files.

 Disks offer direct access, meaning any block on the disk can be
accessed directly without following a sequence.

 The challenge is to manage the allocation efficiently, ensuring


minimal wasted space (fragmentation) and quick access to files.

The three primary methods of disk space allocation are:

1. Contiguous Allocation

2. Linked Allocation

3. Indexed Allocation

Each method has its own set of strengths and weaknesses, and while
some systems support all three, a typical file system usually adopts just
one method.

1. Contiguous Allocation

 How it works: Files are allocated in contiguous blocks on the


disk. This means that the blocks for a single file are adjacent to each
other, which makes accessing them very fast.

 File Structure: The file's starting block is recorded in the directory,


along with its length (the number of blocks it occupies). For
example, if a file starts at block 10 and is 5 blocks long, it occupies
blocks 10, 11, 12, 13, and 14.

 Accessing Files:

o Sequential Access: You can read the next block without


seeking the disk head for a new position if the blocks are
contiguous.

o Direct Access: To directly access any block in the file, the


system just computes its address.

Advantages:
 Fast Access: Minimal disk head movement is required for
sequential access.

 Simple Allocation: Allocation is straightforward as you just need to


find a large enough contiguous space.

Disadvantages:

 External Fragmentation: As files are created and deleted, free


space becomes fragmented, making it harder to find large
contiguous blocks.

 Space Estimation: It’s difficult to predict the exact size of a file


when it’s created. If a file needs more space than initially allocated,
the system must move the file (which is slow and costly).

 Wasted Space: If you overestimate the file's size, the remaining


space in the allocated blocks is wasted.

2. Linked Allocation

 How it works: Files are stored as linked lists of blocks, meaning


the blocks can be scattered anywhere on the disk. Each block
contains a pointer to the next block in the file, and the last block
contains a null pointer to indicate the end of the file.

 File Structure: Only the pointer to the first block is stored in the
directory. The rest of the blocks can be anywhere on the disk, and
they are linked through the pointers in the blocks themselves.

Advantages:

 No Fragmentation: There’s no external fragmentation since any


free block can be used for the file, regardless of where it is on the
disk.

 Flexible File Size: The file can grow without having to pre-allocate
space, as new blocks can be added as needed.

Disadvantages:

 Slower Access: For sequential access, you need to follow the


pointers from the first block to the last, which requires disk head
movement. Direct access to a specific block is inefficient because
the system must traverse the linked list to find the target block.

 Pointer Overhead: Each block needs extra space for a pointer to


the next block. This reduces the actual usable space in each block.
 Reliability: If a pointer is corrupted or lost, the file may become
inaccessible. Additionally, bugs or hardware failures could lead to
incorrect pointers.

3. Indexed Allocation

 How it works: Instead of linking blocks together, each file has an


index block that contains pointers to all its data blocks. The index
block itself is a separate disk block.

 File Structure: The directory entry contains the address of the


index block. Each entry in the index block points to a specific data
block in the file. For example, if the file consists of 10 blocks, the
index block will have 10 entries, each pointing to one of the 10
blocks.

 Accessing Files: To access a block in the file, the system first looks
up the index block, finds the correct pointer, and then accesses the
data block.

Advantages:

 Direct Access: Supports direct access to any block in the file


because the pointers are all in one place (the index block). You don’t
need to follow links like in linked allocation.

 No Fragmentation: No external fragmentation, since files can be


allocated anywhere on the disk as long as the index block has the
correct pointers.

Disadvantages:

 Space Overhead: The index block takes up space, and for small
files, it can waste a lot of space. For instance, if a file only requires 2
blocks, the system might still allocate an entire index block, which is
inefficient.

 Complexity: For larger files, the index block might need to be split
into multiple index blocks (called multilevel indexing), which can
make accessing files slightly more complex.

 Performance: While indexed allocation supports direct access,


there may still be some performance issues related to caching the
index blocks and accessing scattered data blocks.

Summary Comparison
 Contiguous Allocation: Fast and simple, but suffers from external
fragmentation and space allocation challenges.

 Linked Allocation: No fragmentation, supports dynamic file


growth, but is slow for direct access.

 Indexed Allocation: Fast direct access, no fragmentation, but


suffers from pointer overhead and additional complexity.

Contiguous Allocation Explanation

Contiguous allocation is a disk space allocation method where each file


occupies a set of contiguous blocks on the disk. This method ensures that
all blocks of a file are stored in consecutive, adjacent locations on the
disk. Here's an in-depth explanation of its features, advantages, and
challenges.

How Contiguous Allocation Works

 File Structure: In contiguous allocation, each file is defined by two


parameters:

o Starting Block Address: The address of the first block


allocated to the file.

o File Length: The number of blocks the file occupies. For


example, if a file starts at block b and has a length of n blocks,
it will occupy blocks b, b+1, ..., b+n-1.

 Accessing Files:

o Sequential Access: The system remembers the address of


the last block read, so accessing the next block is efficient
with minimal head movement, as the blocks are contiguous.

o Direct Access: To access any block i of the file, the system


can directly calculate its address (i.e., block b + i), providing
fast random access.

Advantages of Contiguous Allocation

1. Efficient Access:
o Fast Sequential Access: Since the file occupies consecutive
blocks, accessing the next block is fast, with minimal or no
disk head movement.

o Efficient Random Access: With direct access to any block in


the file, the system can quickly retrieve a specific block, which
is advantageous for file systems that support direct access.

2. Minimal Seek Time: For a file stored contiguously, the head


movement required to access consecutive blocks is minimal,
reducing the average seek time.

Challenges with Contiguous Allocation

1. External Fragmentation:

o As files are created and deleted, free space on the disk


becomes fragmented into small, non-contiguous blocks
(holes). When new files are allocated, it becomes difficult to
find a large enough contiguous space for them, especially as
files grow in size over time.

o Example: If a file needs 10 blocks, but the disk only has 10


small gaps, the system cannot allocate space unless one of
those gaps is large enough to hold the file.

2. Space Estimation:

o Predicting File Size: At the time of file creation, it is


challenging to predict the file’s final size, especially for files
that grow over time. If the initial allocation is too small, the file
might need to be relocated, which can be inefficient.

o Overestimation: If space is overestimated, large portions of


allocated blocks may remain unused, leading to wasted space
(internal fragmentation).

3. File Growth:

o Difficulties in Expanding Files: If a file needs to expand


and there is no contiguous space available near the file, the
system may need to relocate the entire file to a new
contiguous space, a costly operation.

o Internal Fragmentation: Even when the file's final size is


known, preallocating too much space for files that will grow
slowly can lead to inefficient use of disk space, as unused
portions of the allocated space cannot be used by other files.

Solutions to Contiguous Allocation Issues

1. Free Space Management:

o Managing free space is a crucial challenge in contiguous


allocation. Systems may use strategies like First Fit or Best
Fit to allocate contiguous blocks for files. While these
strategies help in managing free space, they still suffer from
fragmentation over time.

2. Compaction:

o Disk Compaction: To resolve external fragmentation,


systems may perform compaction, where the entire file
system is copied to another disk, reallocated in large
contiguous spaces, and then returned to the original disk.
However, this process is time-consuming, particularly for large
disks, and is typically done offline.

o Online Compaction: Modern systems attempt to perform


defragmentation while the system is online, but this can come
with significant performance penalties.

3. Extent-based Allocation:

o Extent Allocation: Instead of allocating a single contiguous


chunk, the system allocates a contiguous chunk initially,
and if more space is needed, another contiguous chunk
(extent) is allocated. The system keeps track of multiple
extents in the file’s metadata, which helps manage file growth
while maintaining some contiguous space.

o Advantages: This reduces the need for allocating large


contiguous blocks at once and helps manage file growth
efficiently.

o Challenges: External fragmentation can still occur between


extents, and if extents are not properly sized, there can be
internal fragmentation within each extent.

4. Optimized File Systems (e.g., Veritas):

o Some high-performance file systems, like Veritas (used in


UNIX), optimize file allocation by using extents to balance
performance and fragmentation. These file systems provide
better handling of file growth while minimizing fragmentation

Linked Allocation Explanation

Linked allocation is another method of disk space allocation, designed to


overcome the problems associated with contiguous allocation. In linked
allocation, each file is stored as a linked list of disk blocks, and these
blocks may be scattered across the disk. Here's a detailed explanation of
its workings, advantages, and challenges.

How Linked Allocation Works

 File Structure: A file is a linked list of disk blocks. Each disk block
contains data, along with a pointer to the next block in the file. The
last block in the chain contains a special marker indicating the end
of the file (e.g., a null pointer).

o Directory Entry: The directory holds a pointer to the first


block of the file. When writing to the file, the system finds a
free block, writes to it, and updates the pointer in the previous
block to link to this new block.

o File Expansion: A file can grow dynamically, with new blocks


being allocated and linked to the end of the file without
needing to pre-allocate space.

Advantages of Linked Allocation

1. No External Fragmentation:

o Since the blocks of the file can be scattered across the disk,
there is no issue of external fragmentation (i.e., unused gaps
between files), and any available block can be used to extend
a file.

2. Dynamic File Growth:

o Files can grow as needed, and no fixed space allocation is


required at the time of file creation. This flexibility makes
linked allocation ideal for files that are expected to expand
over time.

3. Efficient Space Utilization:


o As the system doesn't need to allocate contiguous space for
files, it avoids wasted space (internal fragmentation) that
occurs when files are overestimated in size.

4. Simple File Creation:

o A new file is created by simply adding an entry in the directory


pointing to the first block. As the file grows, new blocks are
allocated and linked to the existing chain, making it simple to
manage.

Disadvantages of Linked Allocation

1. Inefficient Random Access:

o Sequential Access Only: Linked allocation works best for


sequential access, where data is read or written in a linear
fashion. To access a specific block, the system must start at
the first block and follow the pointers one by one until it
reaches the desired block.

o Disk Head Movements: Each pointer traversal requires a


separate disk read, and some may require disk seeks to
different locations, making random access inefficient. This
limits the system's ability to support direct access to file
blocks quickly.

2. Pointer Overhead:

o Pointer Space Usage: Each block needs space for a pointer


to the next block. For example, if a block is 512 bytes and the
pointer is 4 bytes, only 508 bytes are used for file data. This
can result in wasted space, especially for large files with many
blocks.

o Clusterization: To reduce the overhead, some systems group


blocks into clusters, where a group of blocks is managed
together. However, this approach can increase internal
fragmentation if the cluster is not completely filled.

3. Reliability Concerns:

o Pointer Corruption: Since the file is composed of a series of


linked blocks, a failure in one of the pointers (due to a
hardware or software issue) can disrupt the entire file
structure. The pointer might get lost, or a pointer might point
to an invalid block, corrupting the file.
o Potential Solutions: Some systems use doubly linked lists
(where each block points to both the next and previous block)
to mitigate this risk. However, this increases overhead, as
each block now requires two pointers.

4. Performance Issues with File Allocation Table (FAT):

o FAT-Based Allocation: One common implementation of


linked allocation is through the File Allocation Table (FAT).
The FAT is a table stored at the beginning of the disk volume,
with one entry per disk block. The directory entry points to the
first block of a file, and the FAT table maps the chain of blocks.

o Performance Drawbacks: Accessing a file may require


multiple disk head seeks to read both the FAT and the data
blocks. This can lead to significant overhead if the FAT is not
cached, as each block access requires checking the FAT and
then accessing the physical block.

Enhancements to Linked Allocation

1. Clustered Allocation:

o To address the pointer overhead, many systems use


clustered allocation, where multiple blocks are grouped into
a cluster. Instead of having a pointer for each block, the
system maintains pointers for clusters of blocks, reducing the
number of pointer operations and improving throughput.

o Drawback: This increases internal fragmentation since a


cluster can be underutilized if the file doesn't fill up all the
blocks in the cluster.

2. File Allocation Table (FAT):

o FAT Implementation: In this method, the FAT stores the


chain of block pointers for a file. Each table entry points to the
next block in the file. The last block has an end-of-file marker.

o Disk Head Seeks: When reading a block, the system first


checks the FAT to find the next block, resulting in potentially
more disk head seeks. However, if the FAT is cached in
memory, this overhead can be minimized.

o Improved Random Access: While FAT helps manage file


allocation, it also allows better random access to file blocks by
providing a clear mapping of blocks across the disk.
Summary

Linked allocation is an efficient method for handling dynamic file growth


and solving external fragmentation problems. However, it is less efficient
for random access due to the need to traverse a chain of blocks. Its
overhead in terms of pointer storage and potential reliability issues, such
as pointer corruption, can be mitigated with techniques like clustered
allocation or the use of a File Allocation Table (FAT). Despite its
disadvantages, linked allocation remains an important technique,
especially in file systems that handle large, sequentially accessed files.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy