Data Travel Guide

Just for fun

View on GitHub

PCache v4

This document summarizes dm-pcache patch set v4. It describes the current feature set, architecture and workflow of the persistent cache and highlights changes made since earlier revisions.

Mail

https://www.spinics.net/lists/dm-devel/msg63536.html

Code

https://github.com/DataTravelGuide/linux/tree/pcache_v4

Changelog

V4 from V3

V3 from V2

V2 from V1

V1 from RFC-V2

Key features

Architecture overview

The implementation is composed of three layers:

  1. pmem access layer – reads use copy_mc_to_kernel() so media errors are detected; writes go through memcpy_flushcache() to ensure durability on persistent memory.
  2. cache-logic layer – manages 16 MiB segments with log‑structured allocation, maintains multiple RB-tree indexes for parallelism, verifies data CRCs, handles background write‑back and garbage collection, and replays key-sets from key_tail after a crash.
  3. dm-pcache target integration – exposes a table line pcache <pmem_dev> <origin_dev> writeback <true|false> and advertises support for PREFLUSH/FUA. Discard and dynamic reload are not yet implemented. Runtime GC control is available via dmsetup message <dev> 0 gc_percent <0-90>.

Status information

dmsetup status <dev> prints:

<sb_flags> <seg_total> <cache_segs> <segs_used> \
<gc_percent> <cache_flags> \
<key_head_seg>:<key_head_off> \
<dirty_tail_seg>:<dirty_tail_off> \
<key_tail_seg>:<key_tail_off>

Important fields:

Messages

Adjust the GC trigger:

dmsetup message <dev> 0 gc_percent <0-90>

Operation overview

Failure handling

Limitations

Example workflow

# 1. create devices
pmem=/dev/pmem0
ssd=/dev/sdb

# 2. map a pcache device
dmsetup create pcache_sdb --table \
  "0 $(blockdev --getsz $ssd) pcache $pmem $ssd writeback true"

# 3. format and mount
mkfs.ext4 /dev/mapper/pcache_sdb
mount /dev/mapper/pcache_sdb /mnt

# 4. tune GC to 80%
dmsetup message pcache_sdb 0 gc_percent 80

# 5. monitor status
watch -n1 'dmsetup status pcache_sdb'

# 6. shutdown
umount /mnt
dmsetup remove pcache_sdb

Test result

We used the pcache test suite from dtg-tests to validate the target in various scenarios. The tests create pcache devices with different parameters, verify data read and write correctness and run xfstests under each configuration. Detailed results are available in the test reports: