Featured image of post BTRFS checksum benchmark

BTRFS checksum benchmark

Selecting the algorithm for BTRFS file system

Introduction

I’m switching to a new hardware and I’m using a clean SSD. Now, I’m facing the choice of the algorithm for the BTRFS file system. Here is a script that I used to determine which one was the fastest on my specific processor.

Body

I started by searching for an utility to measure the performance of different hash algorithms. Why? Because, no matter how fast an algorithm seems on paper, if it’s not supported by my processor - it will be slow. And how can I know what’s supported by my processor? In the specification online, I didn’t find any information.

I stumbled upon the rhash utility, which has a --speed key. That’s where I tried to measure performance, but the results of blake2b and crc32c were almost identical, which seemed strange to me. In the end, I came up with this script.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
set -eo pipefail

TMPFS="$(mktemp -d)"
SIZE="5G"

mount -t tmpfs -o size="${SIZE}" tmpfs "${TMPFS}"
cd "${TMPFS}"
fallocate -l 4GiB btrfs

for CSUM in crc32c xxhash sha256 blake2; do
  mkfs.btrfs -f -d single -m single --csum "${CSUM}" btrfs
  mount btrfs /mnt
  echo "
  cd /mnt
  echo "info: ${CSUM}"
  dd if=/dev/urandom of=test bs=4M count=1024 2>/dev/null
  rm -f test
  for i in {1..1000}; do
    dd if=/dev/urandom of="\$i" bs=4M count=1 2>/dev/null
  done
  rm -f /mnt/*
  " | /usr/bin/time bash
  umount /mnt
done

umount "${TMPFS}"
rm -rf "${TMPFS}"

What’s going on here?

  1. A tmpfs temporary mount point is created on 5 GB (right in the RAM, so it doesn’t depend on SSD/HDD)
  2. Inside a file of 4 GB is created and then formatted as BTRFS with different hash algorithms
  3. For each algorithm, two file writing modes are performed:
    1. One large file of 4 GB
    2. 1000 files of 4 MB
  4. At the end, the time command outputs the script execution time

On my 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz processor, the best result was shown by the old and good crc32c (~35 seconds), while the others were around ~52 seconds.

Licensed under Apache License, Version 2.0
Last updated on Nov 19, 2024 10:58 +0200
All rights reserved
Built with Hugo
Theme Stack designed by Jimmy