{"id":1600,"date":"2015-03-12T01:19:25","date_gmt":"2015-03-12T00:19:25","guid":{"rendered":"http:\/\/majek.mamy.to\/?p=1600"},"modified":"2015-04-07T01:03:25","modified_gmt":"2015-04-06T23:03:25","slug":"dm-cache-in-slackware","status":"publish","type":"post","link":"https:\/\/majek.sh\/en\/dm-cache-in-slackware\/","title":{"rendered":"dm-cache in Slackware"},"content":{"rendered":"<p><\/p>\n<h1>bcache vs. dm-cache<\/h1>\n<p>I tested <strong>bcache<\/strong> about year ago on my spare\/backup server and it worked quite fine. But since then every newer kernel had new issues, even on mailing list there were suggestions that <strong>bcache<\/strong> should be marked back as <em>experimental<\/em>. So, after some time I abandoned <strong>bcache<\/strong> and started to wait for something more stable and configuration friendly. In the same time <strong>dm-cache<\/strong> was also available, but it&#8217;s setup was quite challenging and dangerous (using <em>dmsetup<\/em> and raw calculated numbers &#8211; very easy way to make a horrible mistake). There was also quite friendly way to manage <strong>dm-cache<\/strong> using <strong>LVM2<\/strong> tools, but only in plans \ud83d\ude42<\/p>\n<p>Right now, <strong>LVM2<\/strong> have all promised featured for managing <strong>dm-cache<\/strong>, so I gave it a try \ud83d\ude42<\/p>\n<p>Just to sum up my experience:<\/p>\n<ul>\n<li><strong>bcache<\/strong>\n<ul>\n<li>+ quite good documentation about cache policies, monitoring interface, disk format, disaster recovery etc.<\/li>\n<li>+ cache works on block device layer, so you can cache whole PV device regardless how many LV you have on top of it (one cache for all)<\/li>\n<li>+ no need for resize as you are caching whole physical device<\/li>\n<li>+ you can tweak cache parameters on the fly, including cache policy (writethrough\/writeback)<\/li>\n<li>&#8211; you can&#8217;t convert backing device on the fly to cached with data on it<\/li>\n<li>&#8211; unstable<\/li>\n<li>~ doesn&#8217;t require LVM support<\/li>\n<\/ul>\n<\/li>\n<li><strong>dm-cache<\/strong>\n<ul>\n<li>+ stable<\/li>\n<li>+ easy to setup<\/li>\n<li>+ you can convert any LVM volume to use cache or not to use it, online, without any problem<\/li>\n<li>&#8211; one cache for one LV, so if you have multiple LVs and you want to cache it all, you&#8217;d need to divide cache device (ssd disk) to many small chunks for every LV &#8211; space wasted<\/li>\n<li>&#8211; very brief documentation &#8211; enough to set up things, but without any info about how to tune or monitor it<\/li>\n<li>&#8211; resizing LVs must be done by uncaching, resizing and caching again, so you loose all cache contents<\/li>\n<li>~it&#8217;s part of LVM<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h1>Requirements<\/h1>\n<p>It&#8217;s time to get back to <strong>Slackware<\/strong>. Current version is 14.1, so everything described here is based on this version.<\/p>\n<h2>Recent kernel<\/h2>\n<p>Stock 3.10.17 kernel is little too old for good dm-cache work, so I recommend to get something at least from 3.14 series. You could compile it yourself or grab from <a href=\"ftp:\/\/ftp.osuosl.org\/pub\/slackware\/slackware64-current\/slackware64\/a\/\" target=\"_blank\">slackware-current tree<\/a> which have currently 3.14.33.<\/p>\n<h2>Recent LVM2<\/h2>\n<p><strong>LVM2<\/strong> version shipped with Slackware 14.1 is almost last version without <strong>dm-cache<\/strong> support, so there is a need to grab latest version and compile it. For complete support you need also <strong>thin-provisioning-tools<\/strong> with fsck-like tools for <strong>dm-cache<\/strong>.<\/p>\n<h3>Hard way (compile everything yourself)<\/h3>\n<ol>\n<li>Get sources of LVM2 package from <a href=\"ftp:\/\/ftp.osuosl.org\/pub\/slackware\/slackware64-14.1\/source\/a\/lvm2\/\" target=\"_blank\">ftp:\/\/ftp.osuosl.org\/pub\/slackware\/slackware64-14.1\/source\/a\/lvm2\/<\/a><\/li>\n<li>Get more recent LVM2 sources from <a href=\"ftp:\/\/sources.redhat.com\/pub\/lvm2\/releases\/LVM2.2.02.116.tgz\" target=\"_blank\">ftp:\/\/sources.redhat.com\/pub\/lvm2\/releases\/LVM2.2.02.116.tgz<\/a><\/li>\n<li>Get thin-provisioning-tools from <a href=\"https:\/\/github.com\/jthornber\/thin-provisioning-tools\/archive\/v0.4.1.tar.gz\" target=\"_blank\">https:\/\/github.com\/jthornber\/thin-provisioning-tools\/archive\/v0.4.1.tar.gz<\/a> and save it as <strong>thin-provisioning-tools-0.4.1.tar.gz<\/strong><\/li>\n<li>Get my patch for <em>SlackBuild<\/em> from <a href=\"https:\/\/majek.sh\/dm-cache\/slackware-lvm2-dm-cache.patch\" target=\"_blank\">https:\/\/majek.sh\/dm-cache\/slackware-lvm2-dm-cache.patch<\/a> and apply it in lvm2 directory:\n<div class=\"codecolorer-container text railscasts\" style=\"overflow:auto;white-space:nowrap;width:550px;\"><div class=\"text codecolorer\">patch -p0 &lt; slackware-lvm2-dm-cache.patch<\/div><\/div>\n<\/li>\n<li>Make package:\n<div class=\"codecolorer-container text railscasts\" style=\"overflow:auto;white-space:nowrap;width:550px;\"><div class=\"text codecolorer\">sh lvm2.SlackBuild<\/div><\/div>\n<\/li>\n<li>Upgrade lvm2 package with new one found in <em>\/tmp<\/em><\/li>\n<li>If you want cached root volume, you&#8217;d need also to patch <strong>mkinitrd<\/strong> and rebuild <em>initrd<\/em>.<br \/>\nPatch: <a href=\"https:\/\/majek.sh\/dm-cache\/slackware-mkinitrd-dm-cache.patch\" target=\"_blank\">slackware-mkinitrd-dm-cache.patch<\/a>.<br \/>\nApply:<\/p>\n<div class=\"codecolorer-container text railscasts\" style=\"overflow:auto;white-space:nowrap;width:550px;\"><div class=\"text codecolorer\">cd \/sbin<br \/>\npatch -p0 &lt; \/somewhere\/slackware-mkinitrd-dm-cache.patch<\/div><\/div>\n<\/li>\n<li>Use it \ud83d\ude42<\/li>\n<\/ol>\n<h3>Lazy way<\/h3>\n<p>Just get <a href=\"https:\/\/majek.sh\/dm-cache\/lvm2-2.02.116-x86_64-1.txz\">my lvm2 package<\/a> and install it. You may also need mkinitrd patch (see above).<\/p>\n<h1>Configuration<\/h1>\n<p>Start is easy and well documented in <strong>man lvmcache<\/strong>.<br \/>\nJust quick howto assuming that you have volume group named <strong>vg_group<\/strong>, your physical cache device (ssd) is <strong>\/dev\/sdb1<\/strong> and you want to cache volume named <strong>lv_home<\/strong>.<\/p>\n<ol>\n<li>First, cache\/ssd disk must be part of volume group:\n<div class=\"codecolorer-container text railscasts\" style=\"overflow:auto;white-space:nowrap;width:550px;\"><div class=\"text codecolorer\">vgextend vg_group \/dev\/sdb1<\/div><\/div>\n<\/li>\n<li>Create cache pool on fast device (default mode is <em>writethrough<\/em> &#8211; safer but slower, so for <em>writeback<\/em>, there is a need to add &#8211;<em>-cachemode<\/em> option):\n<div class=\"codecolorer-container text railscasts\" style=\"overflow:auto;white-space:nowrap;width:550px;\"><div class=\"text codecolorer\">lvcreate --type cache-pool --cachemode writeback -L 10G -n cacheX vg_group \/dev\/sdb1<\/div><\/div>\n<\/li>\n<li>Attach cache to logical volume:\n<div class=\"codecolorer-container text railscasts\" style=\"overflow:auto;white-space:nowrap;width:550px;\"><div class=\"text codecolorer\">lvconvert --type cache --cachepool vg_group\/cacheX vg_group\/lv_home<\/div><\/div>\n<\/li>\n<li>Enjoy \ud83d\ude42<\/li>\n<\/ol>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>bcache vs. dm-cache I tested bcache about year ago on my spare\/backup server and it worked quite fine. But since then every newer kernel had new issues, even on mailing list there were suggestions that bcache should be marked back <span class=\"excerpt-dots\">&hellip;<\/span> <a class=\"more-link\" href=\"https:\/\/majek.sh\/en\/dm-cache-in-slackware\/\"><span class=\"more-msg\">Continue reading &rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[65],"_links":{"self":[{"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/posts\/1600"}],"collection":[{"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/comments?post=1600"}],"version-history":[{"count":36,"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/posts\/1600\/revisions"}],"predecessor-version":[{"id":1632,"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/posts\/1600\/revisions\/1632"}],"wp:attachment":[{"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/media?parent=1600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/categories?post=1600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/tags?post=1600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}