This is a follow up to my post on Building a CF Card Disk Home Server. I made some simple tweaks so that the system would work faster and more reliably.

Just to answer JJ’s question on the speed of the CF disk, it’s not faster than a regular hard drive, but that could be due to my cheap CF card. If you’re willing to spend a bit lot more for a faster CF card, it should match the read speeds of regular hard drives, though write speeds may still be lacking.

So, the focus here is to tweak the system for a CF/flash drive. There are two key differences from hard drives to consider.

  • Flash disks have no problem with random access while hard drives are best accessed sequentially.
  • Flash disks have much more limited write cycles than hard drives.

With these differences in mind, I picked out the following things to optimize.

  • Encourage random access. This is easily done by changing the default I/O schedulers (e.g. cfq or anticipatory) that buffer I/O requests so that hard drives can process them sequentially. Buffering is not useful for flash disks at all. The best scheduler for random access drives is the noop scheduler, which simply just a n00b (pun intended) FIFO queue. To use it, edit /etc/grub.conf and append elevator=noop at the end of the kernel line, e.g.

    title CentOS (2.6.18-164.11.1.el5)
    root (hd0,0)
    kernel /vmlinuz-2.6.18-164.11.1.el5 ro root=/dev/hda3 elevator=noop
    initrd /initrd-2.6.18-164.11.1.el5.img

  • Discourage swapping to disk. Since the CF disk is slow and has limited write cycles, I reduced the swapping to disk by editing /etc/sysctl.conf and adding a line vm.swappiness=0 at the end.
  • Don’t track file access. Tracking file access means writing the last accessed time to disk every time a file is read, i.e. one write operation for every read. Disable tracking of file access by adding the noatime,nodiratime options to mount points in /etc/fstab, e.g.

    /dev/hda3 / ext3 defaults,noatime,nodiratime 1 1
    /dev/hda1 /boot ext3 defaults,noatime,nodiratime 1 2

  • Don’t write unnecessary files (such as logs) to disk. If you need logs for debugging only while the system is running, mount them as tmpfs. I mounted /tmp and /var/log/httpd (Apache logs) as tmpfs by adding two entries to /etc/fstab as show below.

    tmpfs /tmp tmpfs defaults 0 0
    tmpfs /var/log/httpd tmpfs defaults 0 0

Anyway, for the curious, here’s the speed of my CF drive. Modern SATA drives can get as much as 60MB/s, PATA drives a little slower around 30-40MB/s.

# hdparm -t /dev/hda
/dev/hda:
Timing buffered disk reads: 58 MB in 3.05 seconds = 19.04 MB/sec