Slow Writes 4k Sectors

From Granizada

Jump to: navigation, search

Contents

The Problem

New large (>1Tb) drives, fast computer, known-working standard Linux install, but woefully slow disk write performance and acceptable but not stunning read performance. Nothing untoward in logs, no tuning parameters. No hardware RAID (ie no potentially bad RAID firmware). Also can be a problem on smaller new SSD drives.

Diagnosis

Look at the output of 'fdisk -l /dev/$device'. Chances are the first partition will start at logical (512k) sector 63. Modern disk drives have moved to physical 4k sector sizes from 512 bytes. All filesystem data in a partition that starts in logical 512k sector 63 will start at logical 512k sector 64 due to the boot sector. The start of the filesystem data is not at the beginning of a 4k block, so all 4k logical sectors in the rest of the partition will be span two physical 4k sectors. All data is misaligned, which means write operations on that partition will never be optimised for the hardware, since they are off-by-one. Read operations are not so badly affected, because you can do read-aheads and caching. But you can't do write-aheads :-)

Fix

Repartition so the first sector of the filesystem starts on a logical sector divisible by 4, such as 64. You can do this manually with any of the Linux partitioning tools.

Detail

The issue was that modern drives are moving to 4k block sizes, from 512k.

Background:

As the Wikipedia article explains, the main point isn't 4096-byte sectors, it's about implementing flexibility so we can use whatever is appropriate for future media and software. Unfortunately there's a lot of 512-byte hardcoding in common software stacks, including some in Linux.

Worked example for fixing the problem:

Personal tools
Navigation