December 21, 2010
I was recently given a shiny new ThinkPad T510 at work with nearly identical specs to my MacBook Pro, including a solid state drive (SSD). I quickly wiped Windows 7, and decided on Ubuntu 10.10. Being fresh off the heals of doing a load of research (see here and here) into SSDs and optimizing performance in OS X, I already knew what I was looking at for Linux tweaks. Again, I'll discuss disabling file access time. The important optimization, however, is partition alignment. Recall that HFS+ partitions are 4KB aligned, and to my knowledge, manual alignment is not possible. Under Linux, this is relatively simple and has a huge impact on performance.
I'll start with a brief explanation of why partition alignment is important for SSDs. The links above have a more thorough discussion.
SSDs are flash-based, and arranged in blocks. In order to write to one of these blocks, the entire block must be read, the underlying flash erased, the read value modified with the data to be written, and finally the data is written back on to the flash. The erasure block size corresponds to the size of these blocks, and is 512KB on most current drives, including my OCZ Vertex 2. When these blocks are aligned with the file system, small writes should only involve one block. However, if misaligned, small writes could possibly involve two due the data overlapping two erasure blocks. This is what can give SSDs a bad random write performance. So, beginning partitions at the beginning of erasure blocks can significantly improve SSD performance.
Boot up a Linux live CD. Since I'm using Ubuntu 10.10, it's right there. I'll assume the drive to be partitioned is
/dev/sda and the erasure block size of the drive is 512KB. Remove all partitions on the drive with
sudo fdisk /dev/sda
In fdisk, use the
d command to remove all partitions. Write changes and exit with
w. Now, as explained here, launch fdisk as follows:
sudo fdisk -S 32 -H 32 /dev/sda
This will force the fdisk unit size to be 512KB (verify with
p in fdisk), exactly that of the erasure block size of the drive itself. Now, create your partitions using
n in fdisk, starting on block 2 (a workaround for fdisk's automatic shift discussed here) and everything should be aligned to erasure blocks.
When creating partitions, you can use the +size (+100M) notation to specify size automatically, or it can be calculated. Take the desired size (100MB for
/boot), convert to KB (multiply by 1024), then convert to 512KB blocks (divide by 512). Thus, a 100MB
/boot partition should take up 200 512KB blocks, beginning at block 2. I also created a
swap partition of 8GB (16384 blocks starting at block 203), and used the rest of the drive for
/ (starting at block 16588). Save changes and exit fdisk using
Print out the partition table:
sudo fdisk -lu /dev/sda
This results in the following for my drive:
Disk /dev/sda: 128.0 GB, 128035676160 bytes 32 heads, 32 sectors/track, 244208 cylinders, total 250069680 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000de7d9 Device Boot Start End Blocks Id System /dev/sda1 * 1024 206847 102912 83 Linux /dev/sda2 206848 16985087 8389120 82 Linux swap / Solaris /dev/sda3 16985088 250068991 116541952 83 Linux
As you can see, the beginning of all three partitions is divisible by 512KB, and thus aligned to the erasure block size of the SSD. When installing Linux, partitions must be specified manually.
Once you've installed Linux, disabling access time involves editing
/etc/fstab. Add the parameter
noatime to the appropriate entry. For example, the relevant line form mine is:
# / was on /dev/sda3 during installation UUID=07eaa728-68e8-44aa-89a1-7c922513fc71 / ext4 errors=remount-ro,noatime 0 1
Save changes and reboot. Verify the drive is mounted with the
noatime parameter with
mount | grep " / "
You should see the
noatime parameter present, for example.
/dev/sda3 on / type ext4 (rw,noatime,errors=remount-ro,commit=0)
comments powered by Disqus