On Mon, 21 Sep 2026, Henry Wong wrote:
> Hi Mikulas,
>
> I understand that the original motivation for dm-writecache is for use as a
> write buffer to absorb write bursts quickly onto non-volatile storage, and I
> think there was an implicit assumption that the size of the dm-writecache
> doesn't tend exceed the page cache size. In this scenario, recently-written
> data will indeed still be in the page cache and there isn't a need for
> dm-writecache to serve reads.
>
> My use case is a system with small RAM (~32 GB) with huge dm-writecache
> (~1TB). Here, "recently-written" means within the last few days, and the
> writecache is so big that "recently-written" data won't fit in the page cache.
> It's intended to target the usage pattern of "New data is written to disk,
> manipulated a few times over a few days, and then archived". A huge
> dm-writecache basically lets me keep the last few days of work cached.
>
> It's possible to achieve this effect by setting the watermark levels high and
> keeping the cache dirty. But keeping the cache dirty for multiple days
> increases the risk of data loss, and setting the watermark levels high reduces
> the ability to absorb a large write burst if it happens. Having a "clean"
> state allows cleaning the cache quickly while still having the "last 3 days of
> work are probably cached" behaviour.
Hi
I started to test and review your patch and it crashes immediatelly in the
persistent-memory mode.
[ 755.171158] kernel BUG at drivers/md/dm-writecache.c:2138!
BUG_ON(g->state != WC_VALID_DIRTY)
Also, there's a minor bug - these two lines should be added to
writecache_status, so that the arg counter is consistent with the number
of args.
if (!wc->evict_clean_blocks)
extra_args += 2;
Please, test and fix the pmem mode:
download the current device mapper tree from:
git clone
git://git.kernel.org:/pub/scm/linux/kernel/git/device-mapper/linux-dm.git
git checkout remotes/origin/for-next
(note that this repository contains important fixes for the dm-writecache
persistent memory mode, persistent memory mode doesn't work in the
upstream kernel).
enable the persistent memory mode in the kernel config:
In Device drivers, select
NVDIMM (Non-Volatile Memory Device) Support
DAX: direct access to differentiated memory
In Processor type and features, select
Support non-standard NVDIMMs and ADR protected memory
Add the argument "memmap" to the kernel command line, for example
"memmap=1G!4G" - this creates an emulated persistent memory device with
the size "1GiB" at address "4GiB" (you must have more than 5GiB of
memory). This persistent memory device will obviously lose data on power
failure, but it's good for testing if you don't have real persistent
memory.
After reboot, you should see a device /dev/pmem0 that should have 1GiB
size.
Download the "fsx" filesystem stress-testing tool.
Try these commands, they trigger the BUG:
# modprobe brd rd_size=524288
# dmsetup create lin1 <<EOF
0 1048576 linear /dev/ram0 0
1048576 1048576 linear /dev/ram1 0
2097152 1048576 linear /dev/ram2 0
EOF
# dd if=/dev/zero of=/dev/pmem0 bs=4k count=1 oflag=direct
# dmsetup create wb --table "0 3145728 writecache p /dev/mapper/lin1 /dev/pmem0
1024 0"
# mkfs.ext4 -b 1024 -E orphan_file_size=524288 /dev/mapper/wb
# sleep 1
# dmsetup remove wb
# dmsetup create wb --table "0 3145728 writecache p /dev/mapper/lin1 /dev/pmem0
1024 4 autocommit_time 2 evict_clean_blocks 0"
# fsck.ext4 -fn -C0 /dev/mapper/wb
# mount -t ext4 /dev/mapper/wb /mnt/test
# truncate -s 1400001536 /mnt/test/file
# fsx -Z -r 1024 -w 1024 -R -W -l 1400001536 -L /mnt/test/file
Mikulas