You are on page 1of 16

22CS301 - Operating Systems

22CS301 OPERATING SYSTEM

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Module 3- File and Device Management


Session Topic
3.1 File-System Interface: File concept – Access Methods

3.2 Directory Structure – Directory Organization

3.3 File system mounting - File Sharing and Protection;

3.4 File System Implementation: File System


Structure- Directory implementation
3.5 Allocation Methods
3.6 Free Space Management

3.7 Mass Storage Structure


3.8 Disk Scheduling
3.9 Disk Management

3.10 I/O Systems


3.11 System Protection and Security,
3.12 System Threats

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

3.5.File System Implementation: Allocation Methods

Course Outcome:
Upon completion of the session, students shall have ability to

CO5 Apply concepts of file system interface, implementation, and disk management [AP]
to optimize storage utilization and random access to files.

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Allocation Method

• The allocation methods define how the files are stored in the disk
blocks.

There are three main disk space or file allocation methods.


• Contiguous Allocation
• Linked Allocation
• Indexed Allocation

The main idea behind these methods is to provide:


• Efficient disk space utilization.
• Fast access to the file blocks.

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Contiguous Allocation Method


• Each file occupies set of contiguous blocks
• For example, if a file requires n blocks and is given a block b as the
starting location, then the blocks assigned to the file will be: b, b+1, b+2,
……b+n-1.
• Given the starting block address and the length of the file , determine
the blocks occupied by the file.

The directory entry for a file with contiguous allocation contains


• Address of starting block
• Length of the allocated portion.

– Problems include:
• Finding space on the disk for a file,
• Knowing file size,
• External fragmentation, need for compaction off-line (downtime)
or on-line

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Contiguous Allocation (Cont.)

• Mapping from logical to physical


(block size =512 bytes) Q

LA/512

• Block to be accessed = starting


address + Q
The file ‘mail’ in the following figure starts from the
• Displacement into block = R block 19 with length = 6 blocks. Therefore, it
occupies 19, 20, 21, 22, 23, 24 blocks.

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Extent-Based Systems

• Many newer file systems (i.e., Veritas File System) use a modified
contiguous allocation scheme
• Extent-based file systems allocate disk blocks in extents
• An extent is a contiguous block of disks
– Extents are allocated for file allocation
– A file consists of one or more extents

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Linked Allocation

• Each file is a linked list of blocks


• File ends at nil pointer
• No external fragmentation
• Each block contains pointer to next block
• No compaction, external fragmentation
• Free space management system called when new block needed
• Improve efficiency by clustering blocks into groups but increases
internal fragmentation
• Reliability can be a problem
• Locating a block can take many I/Os and disk seeks

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Linked Allocation Example

• Each file is a linked list of disk blocks: blocks may be scattered


anywhere on the disk
• Scheme

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Linked Allocation (Cont.)

• Mapping
Q
LA/511
R

• Block to be accessed is the Qth block in the linked chain of


blocks representing the file.
• Displacement into block = R + 1

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Indexed Allocation Method

• Each file has its own index block(s) of pointers to its data blocks
• Logical view

index table

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Example of Indexed Allocation

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

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
• For NVM, no disk head so different algorithms and optimizations needed
– Using old algorithm uses many CPU cycles trying to avoid non-
existent head movement
– Goal is to reduce CPU cycles and overall path needed for I/O

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Try……..
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. Then the free space bitmap would
be _____________

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Answer
• 001111001111110001100000011100000

MODULE 3 -3.5.File System Implementation: Allocation Methods


22CS301 - Operating Systems

Next Session…
3.6 Free Space Management

MODULE 3 -3.5.File System Implementation: Allocation Methods

You might also like