Master the fundamental concepts of storage fundamentals through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksOperating systems and devices prefer I/O sizes and offsets that are multiples of the block size (often 4096). An unaligned range may require reading two blocks, modifying the middle, and writing both back even if the application wanted a few bytes.
Align start down to block boundary, end up to boundary, compute span in blocks.
cLoading…
O_DIRECT bypasses page cache and enforces alignment strictlyKeep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will compute how many blocks an unaligned range touches versus an aligned range. This exercise asks you to print overhead for sub-page updates.
A disk reads and writes whole blocks. A write that starts or ends in the middle of a block forces a read-modify-write (RMW): read the block, change the bytes, write the whole block back. Measure what one write costs:
offset / block, last block = (offset + size - 1) / block.offset is not a multiple of the block size, and the last block when offset + size is not. When the write is inside a single block, that one block counts once.This is why databases allocate I/O buffers with posix_memalign and use block-sized pages: with O_DIRECT, an unaligned write is refused instead of quietly paying for an RMW.
Three integers: offset size block, with size and block at least 1.
cLoading…
The amplification has two decimals, and aligned is yes only when no block needs an RMW.