🎓 BookMCQ
← Back to 12. File System Implementation

📝 Bit vector Free Space Management

Representing Available Disk Blocks with Bits

Bit-vector free-space management, also called bitmap management, is a file-system technique that represents the allocation status of disk blocks using a sequence of bits. Each bit corresponds to exactly one disk block and records whether that block is available or already allocated. The operating system maintains this bitmap to identify reusable storage locations, assign blocks when files are created or extended, and release them when files are deleted or reduced in size. A bitmap containing N bits can therefore represent the status of N disk blocks. Its compact structure makes allocation information relatively easy to store and search, while bitwise processor operations can examine several block states at once. The convention used for the bit values must be established clearly: some implementations use 1 for a free block and 0 for an allocated block, while others use the opposite convention. The following example uses 1 for allocated and 0 for free.

Bit Vector Free-Space Management in Operating SystemsA sixteen-block disk bitmap with blocks zero, one, five and nine allocated, the remaining blocks free, a contiguous free region, bitmap size calculation, processor scanning, and a comparison of four free-space management methods.Bit Vector Free-Space ManagementOne bit per disk block • Allocation status • Free-block searching1. Representing 16 Disk Blocks with a BitmapEach numbered bit represents the correspondingly numbered physical block.012345678910111213141511000100010000001 = Allocated0 = FreeConsecutive free blocks: 2, 3, 4Bitmap: 1100010001000000 | Allocated: 0, 1, 5, 9 | Free: 2, 3, 4, 6, 7, 8, 10–152. Bitmap Storage CalculationBitmap bytes = ⌈Number of blocks ÷ 8⌉Example: 1 GiB volume, 4 KiB block sizeBlocks = 2³⁰ ÷ 2¹² = 2¹⁸ blocksBitmap = 2¹⁸ bits ÷ 8 = 32,768 bytes = 32 KiBOne bit is required for every managed block.3. Searching and Updating BitsSearch bitmap wordsFind a zero bit when 1 = allocatedSelect a free blockCheck for required consecutive bitsAllocation: change 0 → 1Deallocation: change 1 → 0A cached bitmap can be searched without a disk read for every bit.Updates must still be kept consistent with persistent file-system metadata. 4. Four Free-Space Management MethodsBit VectorOne status bit per block.Supports bit and word scanning.Linked ListFree blocks hold next pointers.Traversal may require more I/O.GroupingStores several free-block addresses.Retrieves several addresses together.CountingStores starting block and run length.Compact for long free-space runs.Operating Systems • File System Implementation • Bit Vector Method
A bitmap represents each disk block with one bit. This illustration uses 1 for allocated and 0 for free and shows a contiguous free run, a storage-size calculation, and the four classical free-space-management methods. The layout adapts for mobile screens.

Why a Compact Allocation Map Simplifies Storage Tracking

A file system needs an efficient way to locate unused blocks whenever a file is created, extended, or deleted. A bitmap provides a direct representation of every block's allocation state and allows the operating system to examine several status bits in a machine word at once. Unlike a linked free-space list, which follows pointers between available blocks, a bitmap can scan a range of block positions and identify both individual free blocks and consecutive runs. Its main advantage is efficient searching and easier identification of contiguous storage. However, the bitmap records allocated blocks as well as free ones, so its storage requirement depends on the total number of managed blocks rather than only the number currently available. Other free-space methods offer different trade-offs: a linked list connects free blocks through pointers, grouping stores several free-block addresses together, and counting represents consecutive free regions using starting addresses and lengths. A bitmap is especially useful when the file system needs to search for particular free blocks or allocate consecutive regions, while the suitability of each representation depends on disk size, fragmentation, memory availability, and allocation patterns.

Setting and Clearing Allocation Bits

Each position in the bitmap corresponds to a block number, beginning at block zero. In the convention used here, a bit value of 1 means that the corresponding block is allocated, while 0 means that it is free. When a file system assigns a free block to a file, the allocator changes its bit from 0 to 1. When the block is released after deletion or a reduction in file allocation, the bit changes from 1 to 0, making the block available for reuse. The opposite convention is also used in operating-systems textbooks and file-system designs, where 1 represents free space and 0 represents allocated space. Therefore, bitmap interpretation must always follow the convention specified by the implementation or examination question. The bitmap is commonly maintained in persistent storage and may also be cached in memory so the allocator can search it quickly. Allocation updates must be coordinated with file-system metadata to avoid assigning the same block to multiple files or treating an occupied block as free. Reliable file systems use appropriate locking, transaction, or journaling mechanisms to keep these related updates consistent.

Tracking Allocated and Free Blocks with a Bitmap

Consider a file system containing 16 disk blocks numbered from 0 to 15, with blocks 0, 1, 5, and 9 already allocated. Under the convention that 1 means allocated and 0 means free, the bitmap becomes 1100010001000000 when the bits are listed in increasing block-number order. The first two positions contain 1 because blocks 0 and 1 are occupied. Positions 2, 3, and 4 contain 0 because those blocks are available. Block 5 is allocated, while blocks 6, 7, and 8 remain free. Block 9 is allocated, and positions 10 through 15 represent additional available blocks. If a file requires three consecutive blocks, the allocator can identify the free sequence 2, 3, and 4 and change their bits from 0 to 1 after assigning them. The updated bitmap becomes 1111110001000000, showing that blocks 0 through 5 and block 9 are allocated. This example demonstrates how a bitmap records individual block states while also helping the file system locate a continuous region suitable for contiguous or extent-based allocation.

Compact Storage and Consecutive-Block Detection

A bitmap requires one bit for every managed disk block, so its total storage can be calculated by dividing the number of blocks by eight and rounding upward to a whole byte. The number of blocks is obtained by dividing the volume's capacity by its block size. For example, a 1 GiB volume containing 4 KiB blocks has 2³⁰ ÷ 2¹² = 2¹⁸ blocks. Its bitmap therefore requires 2¹⁸ bits, equivalent to 2¹⁵ bytes or 32 KiB. This relatively small representation allows the allocation map to be cached in memory on many systems. To search efficiently, the processor can examine an entire machine word rather than testing each bit separately. When 1 means allocated, an all-ones word contains no free blocks and can be skipped; a word containing zero bits is examined to identify available positions. For a contiguous allocation request, the allocator must also locate the required number of consecutive free bits rather than merely finding scattered free blocks. Fragmentation may make this search more difficult even when the total number of free blocks is sufficient. Bitwise scanning, cached bitmap regions, and allocation policies that preserve contiguous runs can improve performance, but large volumes still require more bitmap storage and careful allocation management.

Common Misconceptions About Bitmap States

'One bitmap bit represents an entire file' is incorrect because each bit represents one managed storage block, and a file containing several blocks normally corresponds to several bitmap positions. 'A zero bit always means allocated' is incorrect because the convention varies between implementations; the bitmap may use 0 for free or 1 for free. 'The bitmap size depends on the number of free blocks' is incorrect because its basic size depends on the total number of blocks managed by the file system. 'A bitmap guarantees that every file receives contiguous blocks' is also incorrect because contiguous allocation depends on the actual arrangement of free positions, not simply on having enough free space overall. 'Searching a cached bitmap always requires a disk read for each bit' is incorrect because the in-memory representation can be examined using processor operations, although changes must eventually be made persistent. Finally, a bitmap is a space-tracking structure rather than a file-allocation method by itself; the file system uses its information when applying an allocation strategy.

Exam Focus: Bitmap Size and Free-Block Identification

Be prepared to explain how one bit represents each disk block and why the selected bit-value convention must be stated before interpreting a bitmap. Calculate the number of managed blocks by dividing disk capacity by block size, then calculate bitmap storage using the ceiling of the block count divided by eight. Given a list of allocated block numbers, construct the corresponding bitmap and identify all remaining free blocks. Practise locating the first free block by examining bitmap words and finding the first bit with the value representing availability. For contiguous allocation questions, identify sequences of consecutive free positions rather than simply counting all free blocks. Explain how allocation and deallocation change bitmap states, why caching improves search performance, and why fragmentation can still make contiguous allocation difficult. Compare bit-vector management with linked lists, grouping, and counting, including their differences in storage overhead, search operations, and suitability for consecutive free-space allocation.

Key Terms of Bit-Vector Management

  • Bitmap - A sequence of bits recording the allocation status of storage blocks.
  • Bit vector - An array in which each bit corresponds to one managed block.
  • Bit - A binary value representing the status of one storage block.
  • Free block - A storage block that is available for allocation.
  • Allocated block - A storage block already assigned to a file or system structure.
  • Allocation - Assigning an available block and updating its bitmap bit.
  • Deallocation - Releasing a block and marking its bitmap position as free.
  • Bit index - The position identifying the disk block represented by a particular bit.
  • Bit scanning - Examining bitmap bits or machine words to locate available blocks.
  • Contiguous free blocks - Consecutive available storage blocks that can satisfy a continuous allocation request.
  • Fragmentation - Distribution of free space into separated regions that makes contiguous allocation harder.
  • Linked free list - A structure that connects available blocks through pointers.
  • Grouping - A free-space method that stores several free-block addresses in one block.
  • Counting - A method that records the starting block and length of a consecutive run of free blocks.
2
Easy
4
Medium
3
Hard

📝 All Bit vector Free Space Management MCQs

Q1. What term describes the condition where free disk space is divided into many small, non‑contiguous pieces?

A.Internal fragmentation ✅
B.External fragmentation
C.Sparse allocation
D.Block clustering
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: External fragmentation occurs when free space is broken into many separate pieces that are too small to satisfy a new allocation request. This condition does not involve the internal layout of allocated blocks, so option A is incorrect. Sparse allocation and block clustering refer to different storage concepts, not the specific fragmentation described. Therefore, option B correctly identifies the phenomenon.

Q2. Why is the first‑fit allocation strategy generally faster than best‑fit when searching for a free hole?

A.It scans from the end of the list, reducing comparisons.
B.It stops at the first hole large enough, avoiding full list traversal.
C.It sorts holes by size before each allocation.
D.It uses a binary search tree, which is slower. ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: First‑fit examines the free‑hole list sequentially and stops as soon as it encounters a hole whose size meets the request, which usually requires fewer comparisons than scanning the entire list. Best‑fit must compare every hole to find the smallest sufficient one, increasing search time. Options A and C describe behaviors that are not characteristic of first‑fit, and option D misstates the data structure used, making B the correct choice.

Q3. A file system has free holes of sizes 5, 12, 7, and 20 blocks in that order. If a request for 8 blocks arrives, which hole will first‑fit allocate and which hole will best‑fit allocate?

A.First‑fit: 5; Best‑fit: 7 ✅
B.First‑fit: 12; Best‑fit: 7
C.First‑fit: 12; Best‑fit: 12
D.First‑fit: 20; Best‑fit: 12
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: First‑fit scans the list from the beginning and selects the first hole that can accommodate 8 blocks, which is the 12‑block hole (the 5‑block hole is too small). Best‑fit searches for the smallest hole that still fits the request, which is the 7‑block hole because it is the smallest size greater than or equal to 8. Option A incorrectly assigns the 5‑block hole to first‑fit, option C chooses the same hole for both strategies, and option D picks the last hole for first‑fit, all of which are inaccurate.

Q4. How does contiguous allocation enable direct access to the i‑th block of a file that starts at disk block b?

A.By storing a pointer to each block in a table. ✅
B.By computing the address as b + i at run time.
C.By using a linked list of block numbers.
D.By hashing the block index to a disk sector.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: In contiguous allocation, all blocks of a file reside sequentially on disk. To reach the i‑th block, the system simply adds the offset i to the starting block number b, yielding the address b + i, which can be calculated instantly. This eliminates the need for intermediate pointers or tables, making option A incorrect. Linked lists (option C) and hashing schemes (option D) belong to other allocation methods, not contiguous allocation, so option B is the correct description.

Q5. In a bit‑vector representation, each bit indicates whether a disk block is free (0) or allocated (1). If external fragmentation leaves many isolated free blocks, how does this affect the length of the bit vector needed to represent the disk?

A.The bit vector must be shortened because free blocks are fewer. ✅
B.The bit vector length remains unchanged; it always equals total blocks.
C.The bit vector must be expanded to include extra bits for each fragment.
D.The bit vector is replaced by a linked list of free blocks.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: A bit vector has one bit for every physical block on the disk, regardless of how those blocks are arranged. External fragmentation changes the distribution of free and allocated bits but does not alter the total number of blocks, so the vector’s length stays the same. Option A suggests shortening, which is false because the total block count does not change. Option C proposes adding extra bits for each fragment, which is unnecessary; the existing bits already represent each block. Option D replaces the bit vector entirely, which is not required. Therefore, option B correctly states that the length is unchanged.

Q6. A disk contains 100 blocks and its bit vector is initially all 0s (free). Three files are allocated contiguously with sizes 20, 30, and 10 blocks respectively. After these allocations, how many blocks remain free?

A.40 ✅
B.30
C.20
D.10
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The total number of blocks allocated is 20 + 30 + 10 = 60. Subtracting this from the total of 100 blocks leaves 100 − 60 = 40 blocks still free. Option A reflects this calculation. Options B, C, and D underestimate the remaining free space by ignoring part of the allocated total, leading to incorrect numbers. Hence, the correct answer is 40 free blocks, represented by option A.

Q7. Over time, which allocation strategy tends to produce less external fragmentation, first‑fit or best‑fit, and why does the difference matter for storage utilization?

A.First‑fit produces less fragmentation because it leaves larger holes untouched. ✅
B.Best‑fit produces less fragmentation by always using the smallest sufficient hole.
C.Both produce equal fragmentation; the difference is only in allocation speed.
D.Best‑fit creates more fragmentation because it splits holes into tiny pieces.
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Best‑fit consistently chooses the smallest hole that can satisfy a request, which reduces the size of leftover fragments and thus limits the creation of many tiny unusable pieces. First‑fit may leave larger holes partially used, potentially generating larger but fewer fragments, but it does not specifically aim to minimize leftover space. Option A reverses the effect, option C incorrectly claims equal fragmentation, and option D mischaracterizes best‑fit as causing more fragmentation. Therefore, option B correctly explains why best‑fit tends to yield lower external fragmentation, improving overall storage utilization.

Q8. A file of size 15 blocks must be placed. Current free holes are 8, 12, and 20 blocks. Which allocation strategy (first‑fit, best‑fit, worst‑fit) will leave the largest remaining contiguous free space after allocation?

A.First‑fit
B.Best‑fit
C.Worst‑fit ✅
D.All strategies leave the same amount of free space
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Worst‑fit selects the largest available hole, which is the 20‑block hole, and places the 15‑block file there, leaving a contiguous free fragment of 5 blocks. First‑fit would choose the first hole that fits (the 12‑block hole is too small, so it would take the 20‑block hole as well, leaving 5 blocks, but the initial 8‑block hole remains unused, resulting in two separate free regions). Best‑fit would choose the 12‑block hole, leaving a 3‑block fragment and preserving the 20‑block hole untouched, which does not maximize a single large free region. Thus, worst‑fit yields the largest contiguous free space, making option C correct.

Q9. Using a bit vector, a system scans bits sequentially to find a free run of 5 consecutive 0s. If the disk has 200 blocks and free blocks are randomly scattered, approximately how many bits must be examined in the worst case to locate such a run?

A.5
B.10
C.25
D.200 ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: In the worst‑case scenario, the system may have to examine every bit on the disk before encountering a suitable sequence of five consecutive 0s, especially when free blocks are sparsely and randomly distributed. Therefore, it could need to scan all 200 bits. Options A, B, and C underestimate the worst‑case effort by assuming a short scan, which is only possible under favorable distributions. Consequently, option D correctly reflects the maximum number of bits that might be examined.

🔗 Related Topics (MCQs)