Advanced Hard Drive Caching Techniques

Using a benchmarking utility, the numbers will vary. On read operations, it is wholly dependent on whether the desired data resides in cache or whether the module needs to retrieve it from the slower disk. On write operations, it depends on the Flash technology itself, and whether it needs to go through a typical programmable erase (PE) cycle to write the new data. Regardless of this, the random read/write access to the slower drive has been increased significantly:

  • Sequential read: 105MB/s

  • Sequential write: 50MB/s

  • Random read: 67MB/s

  • Random write: 51MB/s

You can continue monitoring the cache status by typing:

$ sudo dmsetup status cache 
0 20971520 cache stats: reads(301319), writes(353216), 
 ↪cache hits(24485, 0.3),replacement(345972), 
 ↪replaced dirty blocks(92857)

To remove the cache mapping, unmount the drive and invoke dmsetup:

$ sudo umount /mnt/cache
$ sudo dmsetup remove cache


FlashCache is a project developed and maintained by Facebook. It was inspired by dm-cache. Much like dm-cache, it too is built from the device-mapper framework. It currently is hosted on GitHub and can be cloned from there. The repository encompasses the kernel module and administration utilities. Once built and installed, load the kernel module and in a similar fashion to the previous examples, create a mapping of the SSD and HDD:

$ sudo modprobe flashcache
$ sudo flashcache_create -p back -b 8 cache /dev/sdb /dev/sda3
cachedev cache, ssd_devname /dev/sdb, disk_devname /dev/sda3 
 ↪cache mode WRITE_BACK block_size 8, md_block_size 8, 
 ↪cache_size 0
FlashCache metadata will use 223MB of your 3944MB main memory

The flashcache_create administration utility is similar to the Perl script used for dm-cache. It is a wrapper utility designed to simplify the dmsetup process. As with the dm-cache module, once the mapping has been created, you can view mapping details by typing:

$ sudo dmsetup table cache
0 20971520 flashcache conf:
    ssd dev (/dev/sdb), disk dev (/dev/sda3) cache mode(WRITE_BACK)
    capacity(57018M), associativity(512), data block size(4K) 
     ↪metadata block size(4096b)
    skip sequential thresh(0K)
    total blocks(14596608), cached blocks(83), cache percent(0)
    dirty blocks(0), dirty percent(0)
Size Hist: 4096:83 
$ sudo dmsetup status cache
0 20971520 flashcache stats: 
    reads(83), writes(0)
    read hits(0), read hit percent(0)
    write hits(0) write hit percent(0)
    dirty write hits(0) dirty write hit percent(0)
    replacement(0), write replacement(0)
    write invalidates(0), read invalidates(0)
    pending enqueues(0), pending inval(0)
    metadata dirties(0), metadata cleans(0)
    metadata batch(0) metadata ssd writes(0)
    cleanings(0) fallow cleanings(0)
    no room(0) front merge(0) back merge(0)
    disk reads(83), disk writes(0) ssd reads(0) ssd writes(83)
    uncached reads(0), uncached writes(0), uncached IO requeue(0)
    disk read errors(0), disk write errors(0) ssd read errors(0) 
     ↪ssd write errors(0)
    uncached sequential reads(0), uncached sequential writes(0)
    pid_adds(0), pid_dels(0), pid_drops(0) pid_expiry(0)

Mount the mapping for file accessibility:

$ sudo mount /dev/mapper/cache /mnt/cache

Using the same benchmarking utility, observe the differences between FlashCache and the previous module:

  • Sequential read: 284MB/s

  • Sequential write: 72MB/s

  • Random read: 284MB/s

  • Random write: 71MB/s

The numbers look more like the native SSD performance. However, I want to note that this article is not intended to prove that one solution performs better than the other, but instead to enlighten readers of the many methods you can use to accelerate data access to existing and slower configurations.

To unmount and remove the drive mapping, type the following in the terminal:

$ sudo umount /mnt/cache
$ sudo dmsetup remove /dev/mapper/cache


Petros Koutoupis is a software developer at IBM for its Cloud Object Storage division (formerly Cleversafe). He is also the creator and maintainer of the RapidDisk Project. Petros has worked in the data storage industry for more than a decade.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Also on my list is new spark

sollen's picture

Also on my list is new spark plugs and wires. The engine 27W Forklift driving lamps LED has some minor leaks, so I’m going to go ahead and replace the valve cover gasket and intake manifold gasket.

Rapid[Disk,Cache] better than native ram caching?

Bucky's picture

The kernel has been doing ram caching for a loooong time. It would take a lot to convince me that the ram caching these guys have come up with is somehow better, ESPECIALLY when you consider all the other RAM needs of the system. If it's hoarding memory while other processes have to do without or dip into swap then that's not a good thing.

The SSD stuff looks cool, though. I'll have to play with this soon.

The kernel doesn't really

Anonymous's picture

The kernel doesn't really cache block level data just file level within VFS and even that is limited. Besides, when writing to a physical device, it is written like Direct I/O. With RapidDisk and in turn RapidCache mapping a RAM drive to your slower disk, you can allocate multiple gigabytes and even terabytes of data to slower volumes. The OS does need memory but nowadays, we are packing more than the typical OS uses. What are you going to do with all 16 GBytes on your laptop? Or 512 GBytes to 1 Terabyte on your servers?

Correction (Page 3)

Petros Koutoupis's picture

There is a typo, one I wish I would have caught before submitting; so it is my fault alone. On page 3, following the example of inserting the rxdsk module, the next line is not supposed to read the removal of the module, but instead the insertion of the rxcache module. So the following:

$ sudo modprobe rxdsk
$ sudo modprobe -r rxdsk

Should read:

$ sudo modprobe rxdsk
$ sudo modprobe rxcache

Petros Koutoupis is a software developer at IBM for its Cloud Object Storage division (formerly Cleversafe). He is also the creator and maintainer of the RapidDisk Project. Petros has worked in the data storage industry for more than a decade.