COMS W4118 Operating Systems I

Block Allocation Strategies

Motivation

Typical file access patterns

HDD geometry still affects file access patterns.

Sequential access

Random access

Disk Management

  1. track where file data is on disk
    • order disk sectors to minimize seek time for sequential access
  2. track where metadata is on disk

  3. track free vs. allocated areas of disk
    • maintain block allocation bitmaps to track free blocks

Allocation Strategies

Overview

Various approaches exist for disk management (similar to memory allocation):

Key metrics to assess allocation strategies:

Contiguous Allocation

Each file occupies contiguous blocks on disk:

contiguous-allocation
(source: OSCE figure 11.5)

Pros:

Cons:

Extent-based allocation

Multiple contiguous regions per file (like segmentation).
Metadata is an array of extents, where each extend has a start and size..

Easier to grow files compared to contiguous allocation, but still suffers from external fragmentation.

Linked allocation

All data blocks are part of a linked list

linked-allocation
(source: OSCE figure 11.6)

To read the entire contents of the file jeep, need to start at block 9 and follow pointers until block 25.

Pros:

Cons:

File Allocation Table (FAT)

Variation of linked allocation: store linked-list pointers outside of data block in a dedicated pointer table.

FAT
(source: OSCE figure 11.7)

FAT has one entry per data block on disk:

Pros:

Cons:

Indexed Allocation

File metadata: array of pointers (index) to data blocks

indexed-allocation

Pros:

Cons:

Multi-level Indexed Allocation

Instead of having a single index block of having direct data block pointers, maintain indirect pointers to have larger file size

In addition to direct blocks, like we saw in indexed allocation, inodes (index nodes) can also refer to:

multi-level-indexed

Assume that sizeof(data block) == BLKSIZE and that sizeof(pointer) == 4. The given inode contains NDIRECT data blocks, and 1 of each: indirect, double indirect, and triple indirect blocks:

Max file size: (NDIRECT + BLKSIZE/4 + (BLKSIZE/4)^2 + (BLKSIZE/4)^3) * BLKSIZE.

Note that we don’t allocate indirect blocks until we need them – small files (common case) will only use the direct blocks.

Adding on to the pros/cons of index allocation above:

Advanced Data Structures

bplustree


Last updated: 2023-04-05