On Mon, Aug 18, 2025 at 12:05:08PM -0700, John Rinehart wrote: > I'm using dm-cache in writeback mode and I'm trying to figure out how > I can see the cache stats in "real-time" (poll every second). Like, I > want to poll for the values in this data structure: > https://github.com/torvalds/linux/blob/be48bcf004f9d0c9207ff21d0edb3b42f253829e/drivers/md/dm-cache-target.c#L283-L295. > > But, I'm at a loss for how to do that.
That's the internal data structure that tracks the cache stats: you could write a bpf or systemtap script to dump the contents periodically if you really want to get at every field. > There are also these DMEMIT messages that I'm really interested in > printing to dmesg or subscribing to, or whatever, but I don't know how > to access them (CONFIG_DM_DEBUG didn't do anything useful - which > makes sense after reading the source a bit): > https://github.com/torvalds/linux/blob/be48bcf004f9d0c9207ff21d0edb3b42f253829e/drivers/md/dm-cache-target.c#L3184-L3197. This is the 'status' handler for the cache target - the DMEMIT() is what prints the status values for the target in response to the DM_TABLE_STATUS ioctl. The easiest way to retrieve it is with the 'dmsetup status' command. I don't have a dm-cache device to hand right now, but here's how it behaves for a dm-snapshot device and a thin pool. The cache target follows the same pattern (with the fields described in the comment above the code you linked to, on line 3134): # dmsetup status /dev/mapper/fedora-root--snapset_before 0 20971520 snapshot 168344/21061632 664 # dmsetup status /dev/mapper/fedora-pool0-tpool 0 4194304 thin-pool 815 124/1024 1883/32768 - rw discard_passdown queue_if_no_space - 256 There's a slightly more detailed description of the status fields in the docs: Documentation/admin-guide/device-mapper/cache.rst (other files in that directory describe the other DM targets). Regards, Bryn.