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 dmc-setup.pl 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) nr_queued(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 full-time Linux kernel, device-driver and application developer for embedded and server platforms. He has been working in the data storage industry for more than six years and enjoys discussing the same technologies.
Free DevOps eBooks, Videos, and more!
Regardless of where you are in your DevOps process, Linux Journal can help!
We offer here the DEFINITIVE DevOps for Dummies, a mobile Application Development Primer, and advice & help from the expert sources like:
- Linux Journal
- Integrating Trac, Jenkins and Cobbler—Customizing Linux Operating Systems for Organizational Needs
- Tech Tip: Really Simple HTTP Server with Python
- EdgeRouter Lite
- Non-Linux FOSS: Remember Burning ISOs?
- Returning Values from Bash Functions
- Using Django and MongoDB to Build a Blog
- Cooking with Linux - Serious Cool, Sysadmin Style!
- RSS Feeds
- Hack and / - Linux Troubleshooting, Part I: High Load