All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] dm-bufio: per-client retain target, sysfs and dm-verity cache control
@ 2026-11-18 17:21 Yongpeng Yang
  2026-11-18 17:21 ` [PATCH v2 1/4] dm-bufio: make the retain target per client Yongpeng Yang
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Yongpeng Yang @ 2026-11-18 17:21 UTC (permalink / raw)
  To: agk, bmarzins, dm-devel, mpatocka, snitzer; +Cc: yangyongpeng

From: Yongpeng Yang <yangyongpeng@xiaomi.com>

Device-mapper's verity targets read their hash trees, and FEC parity
when FEC is enabled, through dm-bufio.  dm-bufio has a single
module-wide retain_bytes value shared by every client, no way to see
or change one client's memory use, and no way to warm the cache ahead
of the reads that need it.

That fits poorly systems with many verified devices of very different
sizes, such as Android, which mounts a dozen verity partitions plus
per-app verified images: a large partition's hash tree (tens of MB) is
evicted and re-read under memory pressure with the 256 KiB default,
while raising the global value would make every small, idle verity
device hold memory it does not need, and would still be the wrong size
for most of them.  The same system also wants to preload a device's
hash blocks at boot and to release the memory when the device is no
longer in use, which today requires dropping caches globally.

This series adds per-client granularity to dm-bufio and lets dm-verity
size and manage its caches:

 1. Move the retain target into struct dm_bufio_client, initialized
    from the module parameter at creation.  The parameter keeps its
    meaning as the default for new clients.

 2. Add dm_bufio_client_sysfs_add(), publishing a client in sysfs
    under a caller-chosen kobject and name, with a writable
    retain_bytes and the rest of the state read-only.  It is opt-in,
    so targets that do not want it pay nothing.

 3. dm-verity: size the hash client's retain target as
    hash_retain_percent (default 10) of the hash area, and register
    the hash, FEC parity and FEC data clients under
    /sys/block/dm-N/dm-bufio/<hash|fec|fec-data>/.

 4. dm-verity: add messages to report or set a client's retain target
    and to prefetch or drop hash blocks, for warming the cache ahead
    of use and releasing it afterwards.

Nothing changes for existing users: every client starts with the value
the module parameter holds, and only dm-verity opts into sysfs.

Changes since v1 [1]:
 - Publish the sysfs directories from ->resume and detach them in
   ->presuspend, keeping the kobjects until the table is destroyed.
   A table reload then publishes its directories synchronously with
   no collision, and no kernfs drain ever runs while the queue is
   frozen, which would deadlock against userspace (udev) probing the
   suspended device.
 - Round a non-zero retain target up to a block boundary, so the
   target keeps at least as many bytes as requested (Benjamin
   Marzinski).
 - Compute the percentage with mul_u64_u32_div() and clamp the result
   at ULONG_MAX, the same way dm-bufio sizes its own cache, so a
   large area cannot truncate to near-zero on 32-bit.
 - Zero the kobject after a failed dm_bufio_client_sysfs_add() so a
   retried call cannot free the already-freed name again.
 - Destroy the FEC bufio clients before releasing the data and hash
   devices in verity_dtr(), so a concurrent sysfs read cannot
   dereference the block device after it is put.
 - Reject prefetch_hash on try_verify_in_tasklet devices
   (-EOPNOTSUPP): their no-sleep bufio client cannot evict or wait
   for a buffer still being read.
 - Accept prefetch_hash/drop_hash with no hash blocks (levels == 0)
   as a no-op instead of failing.
 - Document dm_verity.hash_retain_percent= in kernel-parameters.txt.

Tested on a VM running v7.4-rc1: message and sysfs write paths, the
shrinker retain floor under memory pressure, suspend/resume cycles,
table reloads, 100 create/destroy cycles watching slab counters for
leaks, and error-path injection.  No kernel warnings.

[1] https://lore.kernel.org/all/20261117131918.2745193-1-yangyongpeng.storage@gmail.com/

Comments welcome.

Signed-off-by: Yongpeng Yang <yangyongpeng@xiaomi.com>
Assisted-by: LLM

Yongpeng Yang (4):
  dm-bufio: make the retain target per client
  dm-bufio: allow exposing a client in sysfs under a caller-chosen
    kobject
  dm-verity: size the hash retain target from the hash area
  dm-verity: add messages to inspect, prefetch and drop hash blocks

 .../ABI/testing/sysfs-kernel-dm-bufio         |  76 +++++
 .../admin-guide/device-mapper/dm-bufio.rst    |  54 ++++
 .../admin-guide/device-mapper/index.rst       |   1 +
 .../admin-guide/device-mapper/verity.rst      |  43 +++
 .../admin-guide/kernel-parameters.txt         |   6 +
 drivers/md/dm-bufio.c                         | 200 +++++++++++-
 drivers/md/dm-verity-target.c                 | 292 +++++++++++++++++-
 drivers/md/dm-verity.h                        |   2 +
 include/linux/dm-bufio.h                      |  16 +
 9 files changed, 688 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-dm-bufio
 create mode 100644 Documentation/admin-guide/device-mapper/dm-bufio.rst

-- 
2.43.0


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

end of thread, other threads:[~2026-11-18 17:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 17:21 [PATCH v2 0/4] dm-bufio: per-client retain target, sysfs and dm-verity cache control Yongpeng Yang
2026-11-18 17:21 ` [PATCH v2 1/4] dm-bufio: make the retain target per client Yongpeng Yang
2026-11-18 17:21 ` [PATCH v2 2/4] dm-bufio: allow exposing a client in sysfs under a caller-chosen kobject Yongpeng Yang
2026-11-18 17:57   ` sashiko-bot
2026-11-18 17:21 ` [PATCH v2 3/4] dm-verity: size the hash retain target from the hash area Yongpeng Yang
2026-11-18 17:50   ` sashiko-bot
2026-11-18 17:21 ` [PATCH v2 4/4] dm-verity: add messages to inspect, prefetch and drop hash blocks Yongpeng Yang
2026-11-18 17:43   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.