First written 8 January 2011.
Updated 25 July 2015.
I bought a Western Digital WD20EARS-00MVWB0
hard-disk to use in a FreeBSD 8.2 system. These disks have a 4KB physical sector size but lie about it:
# camcontrol identify ada0 | grep size sector size logical 512, physical 512, offset 0
Simple disk timings:
# dd if=/dev/ada0 of=/dev/null bs=1M count=1024
Sequential read: 124,100,265 bytes/sec. (median of 11 samples)
# dd if=/dev/zero of=/dev/ada0 bs=1M count=1024
Sequential write: 123,152,588 bytes/sec. (median of 11 samples again)
For UFS tests, I did this:
# fdisk -I -B ada0 # bsdlabel -w -B /dev/ada0s1 # bsdlabel -e /dev/ada0s1 size offset fstype [fsize bsize bps/cpg] a: 8388608 $ofs unused 0 0 # newfs -f $frag /dev/ada0s1a # mount /dev/ada0s1a /mnt # ( cd /mnt; time sh -c 'tar xf ~/tarball.tar; sync' )
I measured that ada0s1
starts at offset 0x7e00 in ada0
. (32256 in decimal, or 63 sectors of 512 bytes)
With bsdlabel
defaulting to an offset of 16 sectors, ada0s1a
starts at 0x9e00 (40448 in decimal, or 79 sectors of 512 bytes), which is exactly one sector away from being 4K-aligned.
The UFS results (time is median of 5 samples):
ofs | frag | time | |
---|---|---|---|
16 | 2048 | 40.38s | |
17 | 2048 | 27.74s | |
17 | 4096 | 20.09s | ← |
18 | 4096 | 35.96s | |
19 | 4096 | 36.29s | |
20 | 4096 | 35.73s | |
21 | 4096 | 38.50s | |
22 | 4096 | 38.13s | |
23 | 4096 | 37.44s | |
24 | 4096 | 37.33s | |
25 | 4096 | 18.41s | ← |
26 | 4096 | 38.97s |
Timings with ZFS - median of seven runs, zpool
on geli
provider with 4K sectorsize, timing untar and sync:
aligned partition: | 10.09 secs |
unaligned partition: | 12.09 secs |
I was expecting a bigger difference, but ZFS is excellent at batching writes. Watching zpool iostat 1
shows it sustaining platter speed for 2-3 seconds during its flush cycle.
In conclusion:
- Where
bsdlabel
says 16, change it to 17 and your partitions will be aligned to your drive's 4K sectors. - Make sure your partition sizes are multiples of 8.
- For small filesystems, use
newfs -f 4096
to specify a 4K fragment size.
Update: (25 June 2011) Newer disks have stopped lying.
For comparison:
device model WDC WD20EARS-00MVWB0 (2TB) sector size logical 512, physical 512, offset 0 device model WDC WD20EARX-00PASB0 (2TB) sector size logical 512, physical 4096, offset 0
Update: (30 October 2011) My first 3TB disk:
device model WDC WD30EZRX-00MMMB0 sector size logical 512, physical 4096, offset 0
Update: (17 May 2013) My first 4TB disk:
device model ST4000DM000-1F2168 sector size logical 512, physical 4096, offset 0
Update (25 July 2015) An assortment of disks:
Device Model: WDC WD10EACS-00ZJB0 (1TB) Sector Size: 512 bytes logical/physical Device Model: ST31000528AS (1TB) Sector Size: 512 bytes logical/physical Device Model: ST31500341AS (1.5TB) Sector Size: 512 bytes logical/physical Device Model: ST2000DM001-1ER164 (2TB) Sector Sizes: 512 bytes logical, 4096 bytes physical