4

I am using different kind of disks on my server. Is it possible to use faster disk as SWAP and ask Linux to use it as Disk cache

As I understand Linux use SWAP only for application data not disk cache.

But I want to use faster disk as cache for slower disks like we do in dm-cache, flashcache and enhanceIO

Could someone suggest parameters or way to do it without using any third party driver

ondway
  • 71
  • 3

1 Answers1

4

I think you are confused. You do not need swap to cache a slow disk using a faster disk. Swap space is entirely unrelated to that task, it is used to increase the virtual memory available to a system (the kernel will swap out pages to a swap device when it needs more memory for something else - and, of course, using a fast disk like an SSD or a compresssed RAM swap device like zram is better than using a slow disk).

Anyway, ignore swap. It's irrelevant here. bcache or flashcache or dm-cache all do what you want.

BTW, linux already uses all available RAM to cache disks - and automatically release RAM from the cache when it is needed by a program. RAM caching is much faster than SSD caching.

You only need an SSD-based cache if you want to cache more data than will fit in RAM.

RAM is faster (approx $90 to $150 AUD for 16GB at the moment - June 2016 - depending on brand, type, and speed), but SSDs are bigger and cheaper (approx $80 to $240 for around 250GB). and SSDs will get cheaper and larger far quicker than RAM will....they're already becoming reasonably-priced for 500+ GB models, and even a 2TB Samsung SSD is less than 4 times the price of a high-end 7200 RPM 2TB HDD, and less than 8 times the price of the cheapest 2TB HDD.

I expect the price gap will rapidly close over the next few years and in the longer term, SSDs will be both cheaper and larger than HDDs (as well as much faster). I'm looking forward to it, I want to replace my HDD zpools with SSD zpools. Of course, by then, 64GB or larger RAM sticks will also be widely available and reasonably priced too.

Enough of that digression, back to caching...

From the descriptions in the Debian package:

bcache:

Bcache allows the use of SSDs to cache other block devices.

Documentation for the run-time interface is included in the kernel tree; in Documentation/bcache.txt.

flashcache:

Flashcache is a write-back block device cache for Linux. Using the Linux device mapper (DM) it provides an overlay mapper, to cache chunks of data on a high speed caching device like a solid-state drive for fast read access.

Flashcache supports FIFO and LRU cache sets, is configurable and error resistant. It comes with a DKMS kernel module and a corresponding user land for command and control.

Excerpt of dm-cache page from wikipedia:

dm-cache is a component (more specifically, a target) of the Linux kernel's device mapper, which is a framework for mapping block devices onto higher-level virtual block devices.

It allows one or more fast storage devices, such as flash-based solid-state drives (SSDs), to act as a cache for one or more slower storage devices such as hard disk drives (HDDs); this effectively creates hybrid volumes and provides secondary storage performance improvements.

Also, ZFS has built-in support for using a fast block device (such as an SSD) to cache the pool.

I use ZFS and haven't even looked at bcache or fastcache for years, so I can't recommend one over the other.

BTW, there's an interesting blog post on this topic at https://www.rath.org/ssd-caching-under-linux.html, which also mentions lvmcache and EnhanceIO - I know nothing about them aside from the fact that they exist.

Redhat / Fedora developer Vratislav Podzimek blogged a comparison of bcache vs lvmcache.

cas
  • 1
  • 7
  • 119
  • 185
  • 3
    I have gone through all of these options but did not get result I was expecting. At times, they have high miss penalty. I do understand that SWAP is not related to disk cache. But thats I wanted to do using SWAP. I thought if I can ask Linux to use SWAP as disk cache – ondway Jun 17 '16 at 05:48
  • 1
    In that case, the answer is "No". BTW, caches usually have high to very high cache-miss rates (because they're caching something much larger than themselves). It's completely normal. If they didn't, you may as well use the cache device as the storage device. You only get low cache-miss rates when you're repeatedly accessing the same data (and not much else). – cas Jun 17 '16 at 05:57
  • Seems that this sort of SSD caching starts to become really useful only at huge scales (e.g. busy file servers). Is that a fair assessment? – piedar Jun 07 '17 at 01:56
  • I find it useful on my home systems. e.g. 8 TB zfs pool (2 mirrored pairs, similar to RAID-10) with about 120GB of reasonably fast SSD L2ARC cache (using 4 partitions on the same drives as my root zfs pool). The SSD L2ARC isn't essential but does provide some benefit - it makes a noticeable difference on things like my daily debian mirror runs and regular apt-get upgrades of other machines on my home network. 8 TB barely even qualifies as medium-sized these days, let alone huge. BTW, it would make an even bigger difference if I was using PCI-e NVME drives rather than SATA SSDs. – cas Jun 07 '17 at 05:53
  • I also have an ~6TB zfs pool (4x2TB RAIDZ, similar to raid-5) for my mythtv box. It uses a smallish (~20GB) SSD partition for L2ARC. That makes a very noticeable difference during transcoding of recordings. – cas Jun 07 '17 at 05:56