0
0
Operating Systemsknowledge~6 mins

Contiguous allocation in Operating Systems - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine trying to store a large file on a disk, but the disk space is scattered in small pieces. Contiguous allocation solves this by placing the entire file in one continuous block of storage, making it easier and faster to access.
Explanation
Basic idea
Contiguous allocation means storing a file in one single continuous area on the disk. This way, the file's data blocks are all next to each other, which simplifies finding and reading the file.
Files are stored in one continuous block of disk space.
Advantages
Because the file is stored continuously, the system can quickly calculate where each part of the file is. This leads to faster reading and writing since the disk head moves less.
Contiguous storage allows fast and simple access to files.
Disadvantages
Over time, as files are created and deleted, free space breaks into small pieces. This fragmentation makes it hard to find a large enough continuous space for new files, causing wasted space or delays.
Fragmentation can cause inefficient use of disk space.
Managing fragmentation
To fix fragmentation, systems may rearrange files to create larger continuous free spaces, a process called defragmentation. However, this takes time and resources.
Defragmentation helps restore large continuous free spaces but requires extra effort.
Real World Analogy

Think of a bookshelf where you want to place a long book that takes up several shelves in a row. If the shelves are all together, you can place the book easily. But if the shelves are scattered, you can't fit the book without breaking it.

Basic idea → Placing a long book on consecutive shelves without gaps.
Advantages → Easily finding and reading the book because it is all in one place.
Disadvantages → When shelves are broken up by other books, it’s hard to find enough space for the long book.
Managing fragmentation → Rearranging books to clear enough consecutive shelves for the long book.
Diagram
Diagram
┌─────────────────────────────┐
│ Disk Space                  │
├─────────────┬───────────────┤
│ File A      │ Free Space    │
│ [Contiguous │               │
│ Blocks]    │               │
├─────────────┴───────────────┤
│ Fragmented Free Spaces       │
│ [Small scattered blocks]     │
└─────────────────────────────┘
Diagram showing a file stored in one continuous block and free space fragmented into small pieces.
Key Facts
Contiguous allocationStoring a file in one continuous block of disk space.
FragmentationBreaking of free disk space into small scattered pieces.
DefragmentationProcess of rearranging files to create larger continuous free spaces.
Disk head movementThe physical movement of the read/write arm on a disk drive.
Common Confusions
Believing contiguous allocation means files can be split anywhere on disk.
Believing contiguous allocation means files can be split anywhere on disk. Contiguous allocation requires all parts of a file to be stored together without gaps.
Thinking fragmentation only affects file storage speed.
Thinking fragmentation only affects file storage speed. Fragmentation also causes inefficient use of disk space and can prevent storing large files.
Summary
Contiguous allocation stores files in one continuous block, making access fast and simple.
Fragmentation happens when free space breaks into small pieces, causing storage problems.
Defragmentation rearranges files to restore large continuous free spaces but needs extra time.