From: Yongpeng Yang <[email protected]>
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. The hash areas we see range from a few MB to
tens of MB: with the 256 KiB default, a large partition's hash blocks
are evicted under memory pressure and re-read later, while a uniform
large value makes every cold, idle device hold memory it does not
need -- and most verity devices are cold most of the time. What is
wanted is a lifecycle: prefetch when the device is about to be used,
drop when it goes cold again.
This series adds per-client granularity to dm-bufio and gives
dm-verity message-based control over its caches:
1. Move the retain target into struct dm_bufio_client, initialized
from the module parameter at creation, and export set/get plus a
cached-buffer count. The parameter keeps its meaning as the
default for new clients.
2. dm-verity: size the hash client's retain target as
hash_retain_percent (default 10) of the hash area, so a small
device keeps little and a large one keeps enough.
3. dm-verity: add the retain_bytes message to report or set a
client's retain target; the reply also reports current_bytes and
buffers, so memory use can be watched through the message.
4. dm-verity: add prefetch_hash and drop_hash messages to warm the
cache ahead of use and release it afterwards.
Nothing changes for existing users: every client starts with the
value the module parameter holds.
Changes since v2:
- The sysfs interface (per-client directories, ABI documentation and
the suspend/reload handling around them) is dropped entirely.
- The retain_bytes reply now carries current_bytes and buffers instead.
Tested on a VM running v7.4-rc1: message write paths and the memory
reporting in the reply, the shrinker retain floor under memory
pressure, prefetch/drop lifecycles, suspend/resume cycles, and
error-path injection. No kernel warnings.
[1] v1:
https://lore.kernel.org/all/[email protected]/
[2] v2:
https://lore.kernel.org/all/[email protected]/
Comments welcome.
Signed-off-by: Yongpeng Yang <[email protected]>
Assisted-by: LLM
Yongpeng Yang (4):
dm-bufio: make the retain target per client
dm-verity: size the hash retain target from the hash area
dm-verity: add retain_bytes message to inspect and tune the cache
floor
dm-verity: add messages to prefetch and drop the hash cache
.../admin-guide/device-mapper/verity.rst | 41 ++++
.../admin-guide/kernel-parameters.txt | 6 +
drivers/md/dm-bufio.c | 41 +++-
drivers/md/dm-verity-target.c | 200 +++++++++++++++++-
include/linux/dm-bufio.h | 8 +
5 files changed, 293 insertions(+), 3 deletions(-)
--
2.43.0