linux系統中ssd當塊設備緩存

 原理ios

 寫操做先緩存到ssd硬盤上,而後經過必定策略寫到普通硬盤上;centos

 讀操做熱點數據能夠緩存到ssd硬盤上,提升讀取數據的速度。緩存

 

軟件 ssd 緩存開源軟件主要有bcache flashcacheapp

 

bcache 須要編譯最新的內核,要求比較高,配置比較複雜,目前主要用於測試環境;less

flashcache facebook內部使用的ssd cache軟件,開源出來供你們使用,目前有人編譯出rhel6rpm包,在centos6上能夠直接安裝使用。ide

 

本次初步測試了flashcache測試

 

測試環境this

sdc ssd 硬盤     160G*4 raid 10     fio測試 4k iops 5433spa

sdb 普通sas硬盤 146G*2 raid  1    fio測試 4k iops 447orm

 

初步簡單測試結果:

    4k 隨機寫能夠達到 5014

    4k隨機讀能夠達到45874

 

flashcache 安裝配置方法

 

安裝

rpm --import http://elrepo.org/RPM-GPG-KEY-elrepo.org

rpm -Uvh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm

yum install flashcache-utils kmod-flashcache

 

配置:

sdc sdb的緩存

 

flashcache_create -p back  cachedev /dev/sdc /dev/sdb    

cachedev cachedev, ssd_devname /dev/sdc, disk_devname /dev/sdb cache mode WRITE_BACK

block_size 8, md_block_size 8, cache_size 0

Flashcache metadata will use 1192MB of your 24016MB main memory

 

能夠用3種方式:

 

 

Writethrough - safest, all writes are cached to ssd but also written to disk

immediately.  If your ssd has slower write performance than your disk (likely

for early generation SSDs purchased in 2008-2010), this may limit your system

write performance.  All disk reads are cached (tunable). 

數據同時寫到ssd和普通硬盤

 

Writearound - again, very safe, writes are not written to ssd but directly to

disk.  Disk blocks will only be cached after they are read.  All disk reads

are cached (tunable).

數據同時繞過ssd,直接寫到普通硬盤

Writeback - fastest but less safe.  Writes only go to the ssd initially, and

based on various policies are written to disk later.  All disk reads are

cached (tunable). 

數據先寫到ssd,隨後寫到普通硬盤

 

 

 

查看

 flashstat

======================================================================================================

Flashstat: a tool for flashcache status per second

Author   : NinGoo(seaman.ning@gmail.com)

Version  : 0.3

======================================================================================================

          SSD Device:   /dev/sdc         Disk Device:   /dev/sdb          Cache Mode: WRITE_BACK

            Capacity:    303998M          Block Size:         4K     Meta Block Size:      4096b

        Total Blocks:   77823488       Cached Blocks:          9      Cached Percent:          0

         Set Numbers:        512        Dirty Blocks:          0       Dirty Percent:          0

           cache_all:          1      reclaim_policy:       FIFO    dirty_thresh_pct:         20

   max_clean_ios_set:          2 max_clean_ios_total:          4     skip_seq_thresh:         0K

======================================================================================================

          time  read/s write/s diskr/s diskw/s  ssdr/s  ssdw/s uread/s uwrit/s metaw/s clean/s  repl/s wrepl/s   hit%  whit% dwhit%

03-13 14:51:20       0       0       0       0       0       0       0       0       0       0       0       0   0|10    0|0    0|0

 

 

 

fdisk -l /dev/mapper/cachedev  能夠看到一個設備

 

Disk /dev/mapper/cachedev: 146.8 GB, 146778685440 bytes

255 heads, 63 sectors/track, 17844 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0002da0a

 

               Device Boot      Start         End      Blocks   Id  System

 

使用:

 

能夠當一個塊設備來使用,劃分vg lv

 

 pvcreate /dev/mapper/cachedev

  Physical volume "/dev/mapper/cachedev" successfully created

 vgcreate ssdcachetest /dev/mapper/cachedev  

  Volume group "ssdcachetest" successfully created

 lvcreate -L 100G -n ssdcache_test_lv1 ssdcachetest

  Logical volume "ssdcache_test_lv1" created

 

 

刪除

dmsetup  remove cachedev

flashcache_destroy /dev/sdc

相關文章
相關標籤/搜索