{"id":991,"date":"2010-02-10T15:18:17","date_gmt":"2010-02-10T07:18:17","guid":{"rendered":"http:\/\/www.tzlee.com\/blog\/?p=991"},"modified":"2010-02-10T15:33:22","modified_gmt":"2010-02-10T07:33:22","slug":"tweaking-a-cfflash-linux-system","status":"publish","type":"post","link":"https:\/\/tzlee.com\/blog\/2010\/02\/tweaking-a-cfflash-linux-system\/","title":{"rendered":"Tweaking a CF\/Flash Linux System"},"content":{"rendered":"<p>This is a follow up to my post on Building a <a href=\"http:\/\/www.tzlee.com\/blog\/?p=957\">CF Card Disk Home Server<\/a>. I made some simple tweaks so that the system would work faster and more reliably.<\/p>\n<p>Just to answer JJ&#8217;s question on the speed of the CF disk, it&#8217;s not faster than a regular hard drive, but that could be due to my cheap CF card. If you&#8217;re willing to spend a <del>bit<\/del> lot more for a faster CF card, it should match the read speeds of regular hard drives, though write speeds may still be lacking.<\/p>\n<p>So, the focus here is to tweak the system for a CF\/flash drive. There are two key differences from hard drives to consider.<\/p>\n<ul>\n<li>Flash disks have no problem with random access while hard drives are best accessed sequentially.<\/li>\n<li>Flash disks have much more limited write cycles than hard drives.<\/li>\n<\/ul>\n<p>With these differences in mind, I picked out the following things to optimize.<\/p>\n<ul>\n<li><strong>Encourage random access.<\/strong> This is easily done by changing the default I\/O schedulers (e.g. <code>cfq<\/code> or <code>anticipatory<\/code>) 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 <code>noop<\/code> scheduler, which simply just a n00b (pun intended) FIFO queue. To use it, edit <code>\/etc\/grub.conf<\/code> and append <code>elevator=noop<\/code> at the end of the kernel line, e.g.<br \/>\n<blockquote><p><code>title CentOS (2.6.18-164.11.1.el5)<br \/>\n\troot (hd0,0)<br \/>\n\tkernel \/vmlinuz-2.6.18-164.11.1.el5 ro root=\/dev\/hda3 <strong>elevator=noop<\/strong><br \/>\n\tinitrd \/initrd-2.6.18-164.11.1.el5.img<br \/>\n<\/code><\/p><\/blockquote>\n<\/li>\n<li><strong>Discourage swapping to disk.<\/strong> Since the CF disk is slow and has limited write cycles, I reduced the swapping to disk by editing <code>\/etc\/sysctl.conf<\/code> and adding a line <code>vm.swappiness=0<\/code> at the end.<\/li>\n<li><strong>Don&#8217;t track file access.<\/strong> 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 <code>noatime,nodiratime<\/code> options to mount points in <code>\/etc\/fstab<\/code>, e.g.<br \/>\n<blockquote><p><code>\/dev\/hda3 \/ ext3 defaults<strong>,noatime,nodiratime<\/strong> 1 1<br \/>\n\/dev\/hda1 \/boot ext3\u00a0defaults<strong>,noatime,nodiratime<\/strong> 1 2<\/code><\/p><\/blockquote>\n<\/li>\n<li><strong>Don&#8217;t write unnecessary files (such as logs) to disk.<\/strong> If you need logs for debugging only <em>while the system is running<\/em>, mount them as <code>tmpfs<\/code>. I mounted <code>\/tmp<\/code> and <code>\/var\/log\/httpd<\/code> (Apache logs) as <code>tmpfs<\/code> by adding two entries to <code>\/etc\/fstab<\/code> as show below.<br \/>\n<blockquote><p><code>tmpfs \/tmp tmpfs defaults 0 0<br \/>\ntmpfs \/var\/log\/httpd tmpfs defaults 0 0<\/code><\/p><\/blockquote>\n<\/li>\n<\/ul>\n<p>Anyway, for the curious, here&#8217;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.<\/p>\n<blockquote><p><code># hdparm -t \/dev\/hda<br \/>\n\/dev\/hda:<br \/>\n Timing buffered disk reads:   58 MB in  3.05 seconds =  19.04 MB\/sec<br \/>\n<\/code><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s question on the speed of&#8230; <a class=\"more-link\" href=\"https:\/\/tzlee.com\/blog\/2010\/02\/tweaking-a-cfflash-linux-system\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8],"tags":[203,204,201,111,200,208,209,202,206,207],"class_list":["post-991","post","type-post","status-publish","format-standard","hentry","category-tech","tag-anticipatory","tag-cfq","tag-elevator","tag-flash","tag-linux","tag-noatime","tag-nodiratime","tag-noop","tag-tmpfs","tag-vm-swappiness"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/posts\/991","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/comments?post=991"}],"version-history":[{"count":16,"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/posts\/991\/revisions"}],"predecessor-version":[{"id":1009,"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/posts\/991\/revisions\/1009"}],"wp:attachment":[{"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/media?parent=991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/categories?post=991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/tags?post=991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}