Flashcache安装配置
安装flashcache
wgethttps://github.com/facebook/flashcache/archive/master.zip
下载下来的文件可能不是以.zip结尾的文件,使用file查看属性后解压进入文件夹安装
cd flashcache-master
make
make install
配置
# flashcache_create --help
flashcache_create: invalid option -- '-'
Usage: flashcache_create [-v] [-pback|thru|around] [-b block size] [-m md block size] [-s cache size] [-aassociativity] cachedev ssd_devname disk_devname
Usage : flashcache_create Cache Modeback|thru|around is required argument
Usage : flashcache_create Default units for-b, -m, -s are sectors, or specify in k/M/G. Default associativity is 512.
flashcache_create相关参数说明:
-p:缓存模式 writeback(数据先写到SSD,随后写到普通硬盘),
writethrough(数据同时写到SSD和普通硬盘),
writearound(数据绕过SSD,直接写到普通硬盘)三种,三种模式的所有读都会被缓存到flashcache可以通过dev.flashcache.<cachedev>.cache_all参数调整
-s:缓存大小,可选项,如果未指定则整个SSD设备被用于缓存,默认的计数单位是扇区(sectors),但是可以接受k/m/g单位。
-b:指定块大小,可选项,默认为4KB,必须为2的指数。默认单位为扇区。也可以用K作为单位,一般选4KB。
-f:强制创建,不进行检查
-m:设备元数据块大小,只有writeback需要存储metadata块,默认4K
有三种模式:
Writethrough - safest, all writes arecached to ssd but also written to disk
immediately. If your ssd has slower writeperformance than your disk (likely
for early generation SSDs purchased in2008-2010), this may limit your system
write performance. All disk reads arecached (tunable).
数据同时写到ssd和普通硬盘
Writearound - again, very safe, writes arenot written to ssd but directly to
disk. Disk blocks will only be cached afterthey are read. All disk reads
are cached (tunable).
数据绕过ssd,直接写到普通硬盘
Writeback - fastest but less safe. Writesonly go to the ssd initially, and
based on various policies are written todisk later. All disk reads are
cached (tunable).
数据先写到ssd,随后写到普通硬盘
使用50G用sdb1的空间,做sdc1的缓存,块大小为4KB
[root@zhongbo utils]# flashcache_create -v-p back -s 50G cachedev /dev/sdb1/dev/sdc1
cachedev cachedev, ssd_devname /dev/sdb1,disk_devname /dev/sdc1 cache mode WRITE_BACK
block_size 8, md_block_size 8, cache_size104857600
Flashcache metadata will use 275MB of your7889MB main memory
Flashcache Module already loaded
version string "git commit:
"
Creating FlashCache Volume : "echo 03907016904 flashcache /dev/sdc1 /dev/sdb1 cachedev 1 2 8 104857600 512 0 0 8 |dmsetup create cachedev"
查看刚刚创建的DM设备
[root@zhongbo utils]# dmsetup status
cachedev: 0 3907016904 flashcache stats:
reads(83),writes(0)
readhits(0), read hit percent(0)
writehits(0) write hit percent(0)
dirtywrite hits(0) dirty write hit percent(0)
replacement(0),write replacement(0)
writeinvalidates(0), read invalidates(0)
pendingenqueues(0), pending inval(0)
metadatadirties(0), metadata cleans(0)
metadatabatch(0) metadata ssd writes(0)
cleanings(0)fallow cleanings(0)
noroom(0) front merge(0) back merge(0)
force_clean_block(0)
diskreads(83), disk writes(0) ssd reads(0) ssd writes(83)
uncachedreads(0), uncached writes(0), uncached IO requeue(0)
diskread errors(0), disk write errors(0) ssd read errors(0) ssd write errors(0)
uncachedsequential reads(0), uncached sequential writes(0)
pid_adds(0),pid_dels(0), pid_drops(0) pid_expiry(0)
lruhot blocks(6527744), lru warm blocks(6527744)
lrupromotions(0), lru demotions(0)
查看状态
可以在下面的路径查看到一个设备
[root@zhongbo utils]# mount /dev/mapper/cachedev /test -t xfs
挂载
[root@zhongbo /]# mount/dev/mapper/cachedev /test -t xfs
删除
dmsetup remove cachedev
flashcache destory /dev/sdb1
自动加载模块
开机自动加载模块配置:vim /etc/sysconfig/modules/flashcache.modules
#! /bin/sh
/sbin/modinfo -F filename flashcache > /dev/null 2>&1
if [ $? -eq 0 ]; then
/sbin/modprobe flashcache
fi
chmod +x /etc/sysconfig/modules/flashcache.modules
模块的自动加载最好不要采用写入/etc/rc.local的方式
##加载flashcache模块
modprobe flashcache
##查看flashcache模块是否加载
[root@localhost ~]# lsmod |grep flashcache
flashcache 92068 0
dm_mod 84209 14 flashcache,dm_mirror,dm_log
##删除flashcache模块
rmmod flashcache
Flashcache参数优化
参数介绍参考:https://github.com/facebook/flashcache/blob/master/doc/flashcache-sa-guide.txt
针对MySQL作此优化
Flashcache状态监控
参考文档
http://blog.163.com/digoal%40126/blog/static/163877040201463101652528/
https://github.com/facebook/flashcache/blob/master/doc/flashcache-sa-guide.txt