On Tue, Nov 17, 2026 at 09:19:17PM +0800, Yongpeng Yang wrote:
> From: Yongpeng Yang <[email protected]>
> 
> dm_bufio_retain_bytes is a module-wide value shared by every dm-bufio
> user, so raising it to keep one device's metadata cached also makes
> every small, idle device hold on to memory it does not need.
> 
> Give each client its own target, initialized from the module parameter
> at creation.  The parameter keeps its meaning as the default for new
> clients; clients that already exist are not affected.
> 
> Signed-off-by: Yongpeng Yang <[email protected]>
> Assisted-by: LLM

Looks good except one minor nitpick.

> ---
>  drivers/md/dm-bufio.c    | 31 ++++++++++++++++++++++++++++++-
>  include/linux/dm-bufio.h |  7 +++++++
>  2 files changed, 37 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
> index 3b66cf1cb931..75b6e5c027ae 100644
> --- a/drivers/md/dm-bufio.c
> +++ b/drivers/md/dm-bufio.c

[ ... ]

> @@ -2284,6 +2286,32 @@ void dm_bufio_set_minimum_buffers(struct 
> dm_bufio_client *c, unsigned int n)
>  }
>  EXPORT_SYMBOL_GPL(dm_bufio_set_minimum_buffers);
>  
> +/*
> + * Set the number of bytes this client tries to keep cached; 0 resets it
> + * to the module default.  Non-zero values are rounded to a block
> + * boundary, at least one block.
> + */
> +void dm_bufio_set_retain_bytes(struct dm_bufio_client *c, unsigned long 
> bytes)
> +{
> +     if (!bytes) {
> +             WRITE_ONCE(c->retain_bytes, READ_ONCE(dm_bufio_retain_bytes));
> +             return;
> +     }
> +
> +     bytes -= bytes % c->block_size;
> +     if (!bytes)
> +             bytes = c->block_size;

Instead of rounding down, except when that would round to 0, why not
always round up, so dm_bufio retains at least as many bytes as
requested?

-Ben


Reply via email to