Flashcache基本使用及注意事项

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参数优化

[ root @ localhost  ] #sysctl dev.flashcache
dev . flashcache . sdc + sdb2 . io_latency_hist = 0
dev . flashcache . sdc + sdb2 . do_sync = 0
dev . flashcache . sdc + sdb2 . stop_sync = 0
dev . flashcache . sdc + sdb2 . dirty_thresh_pct = 20
dev . flashcache . sdc + sdb2 . max_clean_ios_total = 4
dev . flashcache . sdc + sdb2 . max_clean_ios_set = 2
dev . flashcache . sdc + sdb2 . do_pid_expiry = 0
dev . flashcache . sdc + sdb2 . max_pids = 100
dev . flashcache . sdc + sdb2 . pid_expiry_secs = 60
dev . flashcache . sdc + sdb2 . reclaim_policy = 0
dev . flashcache . sdc + sdb2 . zero_stats = 0
dev . flashcache . sdc + sdb2 . fast_remove = 0
dev . flashcache . sdc + sdb2 . cache_all = 1
dev . flashcache . sdc + sdb2 . fallow_clean_speed = 2
dev . flashcache . sdc + sdb2 . fallow_delay = 900
dev . flashcache . sdc + sdb2 . skip_seq_thresh_kb = 0
dev . flashcache . sdc + sdb2 . clean_on_read_miss = 0
dev . flashcache . sdc + sdb2 . clean_on_write_miss = 0
dev . flashcache . sdc + sdb2 . lru_promote_thresh = 2
dev . flashcache . sdc + sdb2 . lru_hot_pct = 75
dev . flashcache . sdc + sdb2 . new_style_write_merge = 0

参数介绍参考:https://github.com/facebook/flashcache/blob/master/doc/flashcache-sa-guide.txt


针对MySQL作此优化

dev.flashcache.sdc+sdb2.cache_all=1 默认值1表示缓存所有,0都不缓存,另外通过进程黑白名单控制
dev.flashcache.sdc+sdb2.reclaim_policy=1 缓存回收策略,0FIFO1LRU,可动态调整
dev.flashcache.sdbc+sdb2.fast_remove=1 0表示不同步脏块到磁盘,1表示同步脏块到磁盘
dev.flashcache.sdc+sdb2.dirty_thresh_pct=90 每组脏块占有的百分比,过低会减少块覆盖,增加磁盘写操作和读缓存
dev.flashcache.sdc+sdb2.new_style_write_merge=1 打开写入合并提升写磁盘的性能(旧版本dev.flashcache.sdc+sdb2.write_merge)
dev.flashcache.sdb1+sda6.skip_seq_thresh_kb=256 表示不缓存超过256kb的顺序IO(由于SSD的随机读写比SAS好,但顺序读写相差不大,故作此优化)

Flashcache状态监控
dmsetup status cachedev
dmsetup table   cachedev
 
错误日志报告 
/ proc / flashcache / sdc + sdb2 / flashcache_errors
 
状态报告
/ proc / flashcache / sdc + sdb2 / flashcache_stats
 
亦可使用 flashstat命令实时查看






  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值