mbox series

[0/3] dm raid/raid1: enable discard support when any devices support discard

Message ID 20200419073026.197967-1-pabs3@bonedaddy.net (mailing list archive)
Headers show
Series dm raid/raid1: enable discard support when any devices support discard | expand

Message

Paul Wise April 19, 2020, 7:30 a.m. UTC
This makes dm raid and dm raid1 (mirroring) consistent with md raid,
which supports discard when only some of the devices support discard.

Another patch will be needed to fix the queue discard limits sysfs files,
fixing `fstrim --fstab`, but these patches suffice to fix `fstrim /` and
I haven't finished figuring out how the queue discard limits are set yet.

Paul Wise (3):
  dm: add support for targets that allow discard when one device does
  dm raid: only check for RAID 4/5/6 once during discard support setup
  dm raid/raid1: enable discard support when any devices support discard

 drivers/md/dm-cache-target.c  |  2 +-
 drivers/md/dm-clone-target.c  |  2 +-
 drivers/md/dm-log-writes.c    |  2 +-
 drivers/md/dm-raid.c          | 21 ++++++++++-----------
 drivers/md/dm-raid1.c         |  1 +
 drivers/md/dm-table.c         | 32 +++++++++++++++++++++-----------
 drivers/md/dm-thin.c          |  8 ++++----
 drivers/md/dm-zoned-target.c  |  2 +-
 include/linux/device-mapper.h | 13 ++++++++-----
 include/uapi/linux/dm-ioctl.h |  4 ++--
 10 files changed, 50 insertions(+), 37 deletions(-)

Comments

Paul Wise April 19, 2020, 2:48 p.m. UTC | #1
On Sun, 2020-04-19 at 09:19 -0400, Mike Snitzer wrote:

> You went overboard with implementation before checking to see if your
> work would be well received.  Your 2/3 patch header shows you're
> capable of analyzing past commits to explain the evolution of code,
> etc.  But yet you make no mention of this commit header which explicitly
> speaks to why what you're proposing is _not_ acceptable:
> 
> commit 8a74d29d541cd86569139c6f3f44b2d210458071
> Author: Mike Snitzer <snitzer@redhat.com>
> Date:   Tue Nov 14 15:40:52 2017 -0500
> 
>     dm: discard support requires all targets in a table support discards

I do remember seeing this commit while working on this, I guess I
ignored it in my attempts to get fstrim working on my rootfs, woops.

> I haven't looked closely at MD raid in this area but if you trully think
> underlying MD raid can cope with issuing discards to devices that don't
> support them (or that it avoids issuing them?) then please update
> dm-raid.c to conditionally set ti->discard_supported (if not all devices
> support discard).  That is how to inform DM core that the target knows
> better and it will manage discards issued to it.  It keeps the change
> local to dm-raid.c without the flag-day you're proposing.

On my system I have a HDD and an SSD, with /boot on MD RAID and / on
ext4 on DM RAID on 2 DM crypt volumes. In this setup fstrim works on
/boot but does not work on / and with my patches it works on / again.
In addition I don't see any messages in dmesg or other issues when
doing fstrim / with my patches.

I think I might have been worried that discards_supported has other
side effects but grepping the code now I see that was unfounded.
I'll switch the next version to just setting discards_supported.
I still think that my proposed overboard design is clearer though :)

You'll see from the following command that MD raid 0/1/10 arrays enable
discards when any device supports discards:

   git grep -wW discard_supported

It appears that the block layer ignores discard requests when the queue
for the block device indicates that discard is not supported on it:

   git grep -wW __blkdev_issue_discard

It seems to me that where possible DM/MD letting the block layer decide
to pass on or ignore discard requests is the right design. I'm possibly
incorrectly assuming that all block device drivers will correctly
advertise support for discard without false positive/negatives.

BTW, any idea where I should fix the `fstrim --fstab` issue? It is
expecting the queue/discard_granularity sysfs entry to be non-zero.
>From my initial debugging attempts it seems raid_io_hints is at fault.

Thanks for your initial response and any further insight you can give.
Ondrej Kozina April 20, 2020, 7:35 a.m. UTC | #2
On 4/19/20 4:48 PM, Paul Wise wrote:
> On Sun, 2020-04-19 at 09:19 -0400, Mike Snitzer wrote:
> 
>> You went overboard with implementation before checking to see if your
>> work would be well received.  Your 2/3 patch header shows you're
>> capable of analyzing past commits to explain the evolution of code,
>> etc.  But yet you make no mention of this commit header which explicitly
>> speaks to why what you're proposing is _not_ acceptable:
>>
>> commit 8a74d29d541cd86569139c6f3f44b2d210458071
>> Author: Mike Snitzer <snitzer@redhat.com>
>> Date:   Tue Nov 14 15:40:52 2017 -0500
>>
>>      dm: discard support requires all targets in a table support discards
> 
> I do remember seeing this commit while working on this, I guess I
> ignored it in my attempts to get fstrim working on my rootfs, woops.
> 
>> I haven't looked closely at MD raid in this area but if you trully think
>> underlying MD raid can cope with issuing discards to devices that don't
>> support them (or that it avoids issuing them?) then please update
>> dm-raid.c to conditionally set ti->discard_supported (if not all devices
>> support discard).  That is how to inform DM core that the target knows
>> better and it will manage discards issued to it.  It keeps the change
>> local to dm-raid.c without the flag-day you're proposing.
> 
> On my system I have a HDD and an SSD, with /boot on MD RAID and / on
> ext4 on DM RAID on 2 DM crypt volumes. In this setup fstrim works on
> /boot but does not work on / and with my patches it works on / again.
> In addition I don't see any messages in dmesg or other issues when
> doing fstrim / with my patches.

Did you have discard allowed on both dm-crypt devices? dm-crypt (kernel) 
does not allow discards by default.

Regards O.

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
Paul Wise April 20, 2020, 10:13 a.m. UTC | #3
On Mon, 2020-04-20 at 09:35 +0200, Ondrej Kozina wrote:

> Did you have discard allowed on both dm-crypt devices? dm-crypt
> (kernel) does not allow discards by default.

I did not, I guess that explains why I got no errors.
Ondrej Kozina April 20, 2020, 10:22 a.m. UTC | #4
On 4/20/20 12:13 PM, Paul Wise wrote:
> On Mon, 2020-04-20 at 09:35 +0200, Ondrej Kozina wrote:
> 
>> Did you have discard allowed on both dm-crypt devices? dm-crypt
>> (kernel) does not allow discards by default.
> 
> I did not, I guess that explains why I got no errors.
> 

FYI if you use LUKS2 metadata format for encrypted drives, you can 
enable discards by default once and for all by following command:

cryptsetup open /dev/sdx sdx_unlocked --allow-discards --persistent

Any following unlock will enable discards automatically.

Regards O.

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
Paul Wise April 25, 2020, 2:46 a.m. UTC | #5
On Sun, 2020-04-19 at 09:19 -0400, Mike Snitzer wrote:

> You went overboard with implementation before checking to see if your
> work would be well received.
...
> I haven't looked closely at MD raid in this area but if you trully think
> underlying MD raid can cope with issuing discards to devices that don't
> support them (or that it avoids issuing them?) then please update
> dm-raid.c to conditionally set ti->discard_supported (if not all devices
> support discard).  That is how to inform DM core that the target knows
> better and it will manage discards issued to it.  It keeps the change
> local to dm-raid.c without the flag-day you're proposing.

So, now that I know that my approach to this was completely bogus,
what *is* the correct way to safely enable mixed-discard support?

It seems to me that the right way would be one of these options:

 * a sysfs toggle for the block layer
 * an lvchange based option for the dm layer

I'm leaning towards the latter for my personal use-case but the former
would make Linux much more flexible but would touch more code and have
the potential for more damage.