Re: [PATCH] block: stack max_user_discard_sectors
From: Benjamin Marzinski
Date: Sun Nov 22 2026 - 14:44:08 EST
On Sat, Nov 21, 2026 at 01:13:34AM +0100, Christoph Hellwig wrote:
> On Fri, Nov 20, 2026 at 02:43:59PM -0500, Benjamin Marzinski wrote:
> > > I don't think we should take the underlying max_user_discard_sectors
> > > into account here, just max_discard_sectors.
> >
> > Is that to handle devices that call blk_queue_disable_discard()? I
> > didn't think about that. Makes sense.
>
> That too. But also because user limits on lower devices shouldn't
> really affect upper devices for consistency, as new updates on the
> lower device after the upper one was created don't get picked up
> either.
Um... Now it doesn't make sense again.
If I do something like:
t->max_user_discard_sectors = min(t->max_user_discard_sectors,
b->max_discard_sectors);
That mean that changes to underlying device user limits can effect upper
device user limits (since adjusting max_user_discard_sectors
via sysfs automatically adjusts max_discard_sectors).
Also, while this does make blk_stack_limits() disable discards on upper
devices that have a lower device that dissabled discards with
blk_queue_disable_discard(), it doesn't disable discards on upper
devices that have lower devices that have discards disabled normally
(since blk_validate_limits() sets discard_granularity to 0 for devices
that set max_discard_sectors to 0, and this part of blk_stack_limits()
only runs if the bottom device has discard_granularity != 0). That
seems wrong. So perhaps handling blk_queue_disable_discard() isn't the
right answer. Alternatively, blk_stack_limits() could disable discards
on upper device is any of the lower device has max_discard_sectors. But
I assume there's a good reason why it currently doesn't.
Additionally, if we use max_user_discard_sectors to clamp the upper
device's max_discard_sectors to the lower device's. It allows users to
just override it by changing max_user_discard_sectors to something that
doesn't work with the underlying device. That also seems wrong.
So what do you think about doing this instead:
t->max_hw_discard_sectors = min(t->max_hw_discard_sectors,
b->max_discard_sectors);
This doesn't handle blk_queue_disable_discard(), but like I said, the
other patch didn't handle it well either. It also keep users from being
able to send too large discards by setting max_user_discard_sectors too
high on stacked devices. I'll send a v2 that does this.
-Ben