{"id":819,"date":"2014-08-28T09:09:14","date_gmt":"2014-08-28T09:09:14","guid":{"rendered":"http:\/\/10sa.com\/sql_stories\/?p=819"},"modified":"2016-03-11T08:14:00","modified_gmt":"2016-03-11T08:14:00","slug":"bcache","status":"publish","type":"post","link":"http:\/\/10sa.com\/sql_stories\/?p=819","title":{"rendered":"bcache"},"content":{"rendered":"<p>Necessity_is_the_mother_of_invention<\/p>\n<p>I needed some cheap solution for my slow HDDs in one of MySQL node. The box was limited to 4 HDD slots and the actual configuration w\/o RAID 1 stopped working \ud83d\ude42<br \/>\nAt the same time I read about Fedora 20 and found some pretty io mechanism called bcache.<br \/>\nIt works in a similar way to FastCache in EMC (<a href=\"https:\/\/www.emc.com\/collateral\/software\/white-papers\/h8046-clariion-celerra-unified-fast-cache-wp.pdf\">https:\/\/www.emc.com<\/a>)<\/p>\n<p>However, my node was using CentOS w\/ kernel 2.6.x. Below, I present my steps to install and configure bcache.<\/p>\n<p>This is <a href=\"http:\/\/xmodulo.com\/2013\/07\/how-to-upgrade-the-kernel-on-centos.html\">http:\/\/xmodulo.com<\/a> where you will find how to upgrade kernel (you must remember that you need at least 3.10, and that 3.2 < 3.10 :)). You have to mark the adequate module:\n<a href=\"http:\/\/10sa.com\/sql_stories\/wp-content\/uploads\/2014\/08\/bcache-kernel.png\"><img loading=\"lazy\" src=\"http:\/\/10sa.com\/sql_stories\/wp-content\/uploads\/2014\/08\/bcache-kernel-300x127.png\" alt=\"bcache-kernel\" width=\"300\" height=\"127\" class=\"alignnone size-medium wp-image-893\" srcset=\"http:\/\/10sa.com\/sql_stories\/wp-content\/uploads\/2014\/08\/bcache-kernel-300x127.png 300w, http:\/\/10sa.com\/sql_stories\/wp-content\/uploads\/2014\/08\/bcache-kernel.png 982w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre lang=\"bash\">\r\ngit clone http:\/\/evilpiepirate.org\/git\/bcache-tools.git\r\nyum install libblkid-devel -y\r\nyum install libuuid-devel -y\r\nmake install \r\n\r\nmake-bcache --cache \/dev\/mapper\/vg_system-database\r\nmake-bcache --bdev \/dev\/mapper\/hot-mysql \r\n\r\n\r\n# Register our backing device with the new cache set:\r\necho CSET-UUID of cache device >\/sys\/block\/bcache0\/bcache\/attach\r\n<\/pre>\n<p>check writeback (what happened after it is turned off)<\/p>\n<p>Important notes:<\/p>\n<p> &#8211; Bad write performance<\/p>\n<p>   If write performance is not what you expected, you probably wanted to be<br \/>\n   running in writeback mode, which isn&#8217;t the default (not due to a lack of<br \/>\n   maturity, but simply because in writeback mode you&#8217;ll lose data if something<br \/>\n   happens to your SSD)<br \/>\n(source: documantion)<br \/>\n   To set it back to the default (4 mb), do<\/p>\n<p>   # echo 4M > \/sys\/block\/bcache0\/bcache\/sequential_cutoff<\/p>\n<p>simple device information:<\/p>\n<pre lang=\"bash\">\r\nbcache-super-show \/dev\/mapper\/vg_system-database\r\n<\/pre>\n<pre lang=\"bash\">\r\n# Backand device stats:\r\ntail -f \/sys\/block\/bcache0\/bcache\/stats_total\/*\r\n# Concrete cache device stats:\r\ntail -f \/sys\/fs\/bcache\/d09433aa-e685-4dd4-968e-dae77bb2de18\/stats_total\/*\r\n<\/pre>\n<p>How to turn off bcache?<br \/>\nunregister<br \/>\n  Detaches all backing devices and closes the cache devices; if dirty data is<br \/>\n  present it will disable writeback caching and wait for it to be flushed.<\/p>\n<pre lang=\"bash\">\r\necho 1 > \/sys\/fs\/bcache\/d09433aa-e685-4dd4-968e-dae77bb2de18\/unregister\r\n# now  \r\nbcache-super-show \/dev\/mapper\/hot-mysql \r\ndev.data.cache_state\t0 [detached]\r\ncat \/sys\/block\/bcache0\/bcache\/dirty_data \r\n<\/pre>\n<p># revert the device<br \/>\necho \/dev\/mapper\/vg_system-database > \/sys\/fs\/bcache\/register<br \/>\n# attach the cache (cest-uuid)<br \/>\necho d09433aa-e685-4dd4-968e-dae77bb2de18 > \/sys\/block\/bcache0\/bcache\/attach <\/p>\n<p># you will obtain the cest-uuid with (condition that \/dev\/xvdg was registered as cache device)<br \/>\nbcache-super-show \/dev\/xvdg | grep &#8220;cset.uuid&#8221;<\/p>\n<p>You&#8217;ll see in dmesg:<\/p>\n<pre lang=\"bash\">\r\nroot>dmesg\r\nXFS (bcache0): Mounting Filesystem\r\nXFS (bcache0): Ending clean mount\r\nbcache: bch_journal_replay() journal replay done, 3 keys in 3 entries, seq 333449\r\nbcache: register_cache() registered cache device dm-4\r\nbcache: bch_cached_dev_attach() Caching dm-2 as bcache0 on set d09433aa-e685-4dd4-968e-dae77bb2de18\r\n<\/pre>\n<pre lang=\"bash\">\r\nroot> bcache-super-show \/dev\/mapper\/hot-mysql  | grep cache_state\r\ndev.data.cache_state\t1 [clean]\r\n<\/pre>\n<p>Or you can disable caching with the following command:<\/p>\n<pre lang=\"bash\">\r\necho none > \/sys\/block\/bcache0\/bcache\/cache_mode\r\n<\/pre>\n<p>Very nice command!<br \/>\nlsblk -o NAME,MAJ:MIN,RM,SIZE,TYPE,FSTYPE,MOUNTPOINT,UUID<\/p>\n<p>I have used bcache for last 2 months in production environment and it works fine.<\/p>\n<p>sources:<br \/>\nhttp:\/\/www.linux.com\/learn\/tutorials\/754674-using-bcache-to-soup-up-your-sata-drive\t \thttp:\/\/forums.gentoo.org\/viewtopic-t-959542.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Necessity_is_the_mother_of_invention I needed some cheap solution for my slow HDDs in one of MySQL node. The box was limited to 4 HDD slots and the actual configuration w\/o RAID 1 stopped working \ud83d\ude42 At the same time I read about Fedora 20 and found some pretty io mechanism called bcache. It works in a similar [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts\/819"}],"collection":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=819"}],"version-history":[{"count":20,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts\/819\/revisions"}],"predecessor-version":[{"id":1176,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=\/wp\/v2\/posts\/819\/revisions\/1176"}],"wp:attachment":[{"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=819"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10sa.com\/sql_stories\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}