public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] dm-pcache: fix metadata indexing and persistence issues
@ 2025-12-02 12:11 Li Chen
  2025-12-02 12:11 ` [PATCH 1/2] dm pcache: fix cache info indexing Li Chen
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Li Chen @ 2025-12-02 12:11 UTC (permalink / raw)
  To: dm-devel, linux-kernel, Dongsheng Yang, Zheng Gu

From: Li Chen <chenl311@chinatelecom.cn>

dm-pcache stores metadata (cache_info and segment_info) in 4K-aligned
slots on the cache device, using sequence numbers and CRC to identify
the latest valid copy.

However, the cache_info and segment_info paths were computing their
on-media index using sizeof(struct) instead of the 4K metadata stride.
As a result:

  * cache_info updates (including gc_percent set via a dmsetup message)
    were written to invalid offsets between metadata slots and failed
    to persist across table reloads or reboots.

  * segment_info indexing became desynchronized, so rotation to the
    "next" slot no longer matched the location returned by
    pcache_meta_find_latest().

The issue can be reproduced with:

  dmsetup create pcache_vdb --table \
    "0 $(blockdev --getsz /dev/vdb) pcache /dev/pmem0 /dev/vdb 4 \
     cache_mode writeback data_crc false"

  # Check default gc_percent (70)
  dmsetup status pcache_vdb

  # Change gc_percent to 10
  dmsetup message pcache_vdb 0 "gc_percent 10"

  # Verify change is active in memory
  dmsetup status pcache_vdb

  # Reboot the system...

  # Without patch (gc_percent reverts to 70):
  dmsetup status pcache_vdb

  # With patch (gc_percent persists as 10):
  dmsetup status pcache_vdb

This series fixes the issue by deriving the metadata slot index from
the pointer returned by pcache_meta_find_latest(), using the 4K stride
(CACHE_INFO_SIZE / SEG_INFO_SIZE). This ensures that updates to
cache_info and segment_info are written to valid slots and remain
consistent with the on-media layout.

Li Chen (2):
  dm pcache: fix cache info indexing
  dm pcache: fix segment info indexing

 drivers/md/dm-pcache/cache.c         | 13 ++++++++++---
 drivers/md/dm-pcache/cache_segment.c |  6 +++++-
 2 files changed, 15 insertions(+), 4 deletions(-)

-- 
2.51.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-12-05  9:13 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-02 12:11 [PATCH 0/2] dm-pcache: fix metadata indexing and persistence issues Li Chen
2025-12-02 12:11 ` [PATCH 1/2] dm pcache: fix cache info indexing Li Chen
2025-12-03  5:56   ` Dongsheng Yang
2025-12-03 23:38     ` Dongsheng Yang
2025-12-02 12:11 ` [PATCH 2/2] dm pcache: fix segment " Li Chen
2025-12-03  5:57   ` Dongsheng Yang
2025-12-03 23:38     ` Dongsheng Yang
2025-12-02 19:09 ` [PATCH 0/2] dm-pcache: fix metadata indexing and persistence issues Mikulas Patocka
2025-12-03  5:56 ` Dongsheng Yang
2025-12-03 23:38   ` Dongsheng Yang
2025-12-04  1:38     ` Dongsheng Yang
2025-12-05  9:12       ` Li Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox