Software Engineering Blog

Tipps und Tricks aus dem Leben eines Systemadministrators.

Tune bcache for large SSDs

von

As SSDs are getting cheaper, low HDD / SSD ratios of 10/1 or better become an option. This article describes how to tune bcache for this scenario from an empirical perspective.

I recently bought a 500GB Samsung 970 EVO SSD (M2 connector) for OS and as bcache caching device. I split the SSD into two partitions, one 50GB for the OS and the rest for a bcache caching device. The cache is intended to back a ~4TB, 5400RPM hard disk. This gives me a HDD vs SSD ratio of 10/1

Having the cache set up (for details, see here), I noticed that only around 10% of the cache are actually filled. However my cache-hit ratios (1 hour) were never better than 85%.

Hint: Read these values to get the ratio

# 5 min
cat /sys/block/bcache*/bcache/stats_five_minute/cache_hit_ratio
# 1 hour
cat /sys/block/bcache*/bcache/stats_hour/cache_hit_ratio

Tune Bcache

What we want to tune is the read-ahead size and the size to bypass the cache. Empirically I identified these values:

  • read_ahead_kb: 4096
  • sequential_cutoff: 64M

These values can be set during runtime:

sudo bash -c 'echo 64M > /sys/block/bcache0/bcache/sequential_cutoff'
sudo bash -c 'echo 4096 > /sys/block/bcache0/queue/read_ahead_kb'

To set them persistenly, add the above lines to your /etc/rc.local. A full rc.local file then could look like this:

#!/bin/bash

echo 64M > /sys/block/bcache0/bcache/sequential_cutoff
echo 4096 > /sys/block/bcache0/queue/read_ahead_kb
exit 0

If you want to live risky (but get best performance), enable write-back caching. This setting is persistent:

sudo bash -c 'echo writeback > /sys/block/bcache0/bcache/cache_mode'

Warmup Cache

A good starting point to warmup the cache is to pull in filesystem metadata. This can be achived by querying these data for all files, using ncdu. As we do not want to cross filesystem boundaries, use -x switch.

ncdu -x .

If you use btrfs on top bcache (which is still experimental!), you can issue a scrub. While still many reads bypass the cache, fs metadata is likely to be put into the cache. After doing that my cache was filled ~80% and I got hit-ratios of >97%.

sudo btrfs scrub start <mountpoint>

TL;DR

  • read_ahead_kb: 4096
  • sequential_cutoff: 64M
  • cache_mode: writeback

Warm up the cache:

  • ncdu -x .
  • scrub btrfs

Zurück

Kommentare

Einen Kommentar schreiben

Bitte rechnen Sie 5 plus 4.

Ähnliche Beiträge

von

We reverse engineer a Dotnet Monitor in Windbg to see how it is internally implemented.

von

As SSDs are getting cheaper, low HDD / SSD ratios of 10/1 or better become an option. This article describes how to tune bcache for this scenario from an empirical perspective.