bcache
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 🙂
At the same time I read about Fedora 20 and found some pretty io mechanism called bcache.
It works in a similar way to FastCache in EMC (https://www.emc.com)
However, my node was using CentOS w/ kernel 2.6.x. Below, I present my steps to install and configure bcache.
This is http://xmodulo.com 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:
git clone http://evilpiepirate.org/git/bcache-tools.git
yum install libblkid-devel -y
yum install libuuid-devel -y
make install
make-bcache --cache /dev/mapper/vg_system-database
make-bcache --bdev /dev/mapper/hot-mysql
# Register our backing device with the new cache set:
echo CSET-UUID of cache device >/sys/block/bcache0/bcache/attach
check writeback (what happened after it is turned off)
Important notes:
– Bad write performance
If write performance is not what you expected, you probably wanted to be
running in writeback mode, which isn’t the default (not due to a lack of
maturity, but simply because in writeback mode you’ll lose data if something
happens to your SSD)
(source: documantion)
To set it back to the default (4 mb), do
# echo 4M > /sys/block/bcache0/bcache/sequential_cutoff
simple device information:
bcache-super-show /dev/mapper/vg_system-database
# Backand device stats:
tail -f /sys/block/bcache0/bcache/stats_total/*
# Concrete cache device stats:
tail -f /sys/fs/bcache/d09433aa-e685-4dd4-968e-dae77bb2de18/stats_total/*
How to turn off bcache?
unregister
Detaches all backing devices and closes the cache devices; if dirty data is
present it will disable writeback caching and wait for it to be flushed.
echo 1 > /sys/fs/bcache/d09433aa-e685-4dd4-968e-dae77bb2de18/unregister
# now
bcache-super-show /dev/mapper/hot-mysql
dev.data.cache_state 0 [detached]
cat /sys/block/bcache0/bcache/dirty_data
# revert the device
echo /dev/mapper/vg_system-database > /sys/fs/bcache/register
# attach the cache (cest-uuid)
echo d09433aa-e685-4dd4-968e-dae77bb2de18 > /sys/block/bcache0/bcache/attach
# you will obtain the cest-uuid with (condition that /dev/xvdg was registered as cache device)
bcache-super-show /dev/xvdg | grep “cset.uuid”
You’ll see in dmesg:
root>dmesg
XFS (bcache0): Mounting Filesystem
XFS (bcache0): Ending clean mount
bcache: bch_journal_replay() journal replay done, 3 keys in 3 entries, seq 333449
bcache: register_cache() registered cache device dm-4
bcache: bch_cached_dev_attach() Caching dm-2 as bcache0 on set d09433aa-e685-4dd4-968e-dae77bb2de18
root> bcache-super-show /dev/mapper/hot-mysql | grep cache_state
dev.data.cache_state 1 [clean]
Or you can disable caching with the following command:
echo none > /sys/block/bcache0/bcache/cache_mode
Very nice command!
lsblk -o NAME,MAJ:MIN,RM,SIZE,TYPE,FSTYPE,MOUNTPOINT,UUID
I have used bcache for last 2 months in production environment and it works fine.
sources:
http://www.linux.com/learn/tutorials/754674-using-bcache-to-soup-up-your-sata-drive http://forums.gentoo.org/viewtopic-t-959542.html
No comments yet.