Curriculum / Part 1 · Foundations: what storage even is
Lesson 1

Bits to blocks

How bytes become sectors and blocks, why 4 KiB is everywhere, and what logical vs physical block size means for alignment.

⏱ 30 min5-question quiz

The simple version

Think of a huge library. Nobody hands the librarian single letters; they hand over whole pages. Pages are stored on shelves of a fixed size, and if you want to change one word, the librarian takes the whole page down, fixes it and puts it back.

A disk works the same way. Letters are bytes. The page is a sector or block. The disk never reads or writes less than one block, even if you only wanted one byte.

Bits, bytes and the two kinds of kilo

A bit is 0 or 1; a byte is 8 bits. Storage vendors count in powers of ten (1 TB = 1012 bytes) while operating systems often count in powers of two (1 TiB = 240 bytes). That gap is why a "7.68 TB" drive shows up as about 6.98 TiB.

7.68 × 10¹² ÷ 2⁴⁰ ≈ 6.98 TiB
Same bytes, different unit. Always say which one you mean in a design doc.

Sectors, logical and physical block size

The device exposes a logical block size (the smallest unit you can address) and has a physical block size (the unit it really writes internally). Common combinations:

FormatLogicalPhysicalNotes
512n512 B512 BOlder drives
512e512 B4096 BEmulates 512 B; a misaligned 512 B write forces a read-modify-write of 4 KiB
4Kn4096 B4096 BNative 4K; common on NVMe namespaces formatted for 4K
Alignment. If a partition or a write starts in the middle of a physical block, one logical write turns into two physical ones. Modern tools align partitions to 1 MiB by default, which is a multiple of every common block size.

Filesystem blocks vs device blocks

On top of the device, the filesystem has its own block size (usually 4 KiB for ext4 and XFS). The page cache also works in 4 KiB pages on x86-64. When all three line up at 4 KiB, one application write of 4 KiB can map cleanly to one device write.

AI datasets rarely care about one 4 KiB block. They care about many blocks, which is where IOPS and throughput (Lesson 2) take over.

Tools

lsblk -o NAME,SIZE,PHY-SEC,LOG-SEC
Show each device's physical and logical sector size.
blockdev --getss /dev/nvme0n1
Logical sector size in bytes.
blockdev --getpbsz /dev/nvme0n1
Physical block size in bytes.
nvme id-ns -H /dev/nvme0n1
List the LBA formats a namespace supports and which one is in use.

Quiz

Lab

Related lab

Lab 1.1 · fio shows low IOPS

A colleague benchmarked a new drive with fio --name=t --filename=/dev/nvme1n1 --rw=randread --bs=4k --runtime=60 --time_based --readonly and got about 12k IOPS. The datasheet promises far more. They think the drive is faulty.

Start lab 1.1 →

Try it now in the simulator (opens with the command ready; press Enter):

$ lsblk -o NAME,SIZE,PHY-SEC,LOG-SEC$ blockdev --getss /dev/nvme0n1$ blockdev --getsize64 /dev/nvme0n1