Re: RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
On Thu, Mar 30 2017 at 11:22am -0400, Martin K. Petersenwrote: > Mike Snitzer writes: > > > Would be very useful, particularly for testing, if > > drivers/scsi/scsi_debug.c were updated to support WRITE ZEROES. > > There is no WRITE ZEROES in SCSI. You should be able to get the right > behavior with lbpws=1 lbprz=1. OK, thanks.
Re: RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
Mike Snitzerwrites: > Would be very useful, particularly for testing, if > drivers/scsi/scsi_debug.c were updated to support WRITE ZEROES. There is no WRITE ZEROES in SCSI. You should be able to get the right behavior with lbpws=1 lbprz=1. -- Martin K. Petersen Oracle Linux Engineering
Re: RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
Would be very useful, particularly for testing, if drivers/scsi/scsi_debug.c were updated to support WRITE ZEROES.
Re: RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
Lars, can you please take a look a patch 22 and check if it's safe? That's the big thing I want to know before posting the next version of the series. If it's not safe I'd like to drop that patch.
Re: RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
On 23/03/2017 23:53, Lars Ellenberg wrote: > Thin does not claim to zero data on discard. which is ok, and correct, > because it only punches holes on full chunks (or whatever you call > them), and leaves the rest in the mapping tree as is. > > And that behaviour would prevent DRBD from exposing discards if > configured on top of thin. (see above) > > But thin *could* easily guarantee zeroing, by simply punching holes > where it can, and zeroing out the not fully-aligned partial start and > end of the range. That's the difference between REQ_OP_DISCARD (only punches holes on full chunks) and REQ_OP_WRITE_ZEROES with the REQ_UNMAP flag (punches holes + zeroes incomplete chunks). dm-thinp's REQ_OP_DISCARD should not do anything for unaligned parts. Instead, layers above should use REQ_OP_WRITE_ZEROES (with or without REQ_UNMAP, as required) if they need zeroes. dm-thinp would have to split off the partial chunks, and zero them in the lower-level device with REQ_OP_WRITE_ZEROES. Paolo
Re: [Drbd-dev] RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
On Mon, 2017-03-27 at 10:03 -0400, Mike Snitzer wrote: > As for the blkdev_issue_zeroout() resorting to manually zeroing the > range, if the discard fails or dzd not supported, that certainly > requires DM thinp to implement manual zeroing of the head and tail of > the range if partial blocks are being zeroed. So I welcome any advances > there. It is probably something that is best left to Joe or myself to > tackle. But I'll gladly accept patches ;) Some time ago I posted a patch series for the block layer that zeroes start and tail for nonaligned discard requests if dzd has been set. See also "[PATCH v3 0/5] Make blkdev_issue_discard() submit aligned discard requests" (https://www.spinics.net/lists/linux-block/msg02360.html). Bart.
Re: RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
On Mon, Mar 27, 2017 at 10:03:07AM -0400, Mike Snitzer wrote: > By "you" I assume you're referring to Lars? Yes. > Lars' approach for discard, > when drbd is layered on dm-thinp, feels over-engineered. Not his fault, > the way discard and zeroing got conflated certainly lends itself to > these ugly hacks. SO I do appreciate that for anything to leverage > discard_zeroes_data it needs to be reliable. Which runs counter to how > discard was implemented (discard may get silently dropped!) But that is > why dm-thinp doesn't advertise dzd. Anyway... That's exactly what this series does - remove discard_zeroes_data and use the new REQ_OP_WRITE_ZEROES for anything that wants zeroing offload. > As for the blkdev_issue_zeroout() resorting to manually zeroing the > range, if the discard fails or dzd not supported, that certainly > requires DM thinp to implement manual zeroing of the head and tail of > the range if partial blocks are being zeroed. So I welcome any advances > there. It is probably something that is best left to Joe or myself to > tackle. But I'll gladly accept patches ;) Ok, I'll happily leave this to the two of you..
Re: RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
On Mon, Mar 27 2017 at 5:10am -0400, Christoph Hellwigwrote: > It sounds like you don't want to support traditional discard at all, > but only WRITE ZEROES. So in many ways this series is the right way > forward. It would be nice if we could do a full blown > REQ_OP_WRITE_ZEROES for dm_think that zeroes out partial blocks, > similar to what hardware that implements WRITE SAME of zeroes > or WRITE ZEROES would do. I'll see if I could include that in my > series. By "you" I assume you're referring to Lars? Lars' approach for discard, when drbd is layered on dm-thinp, feels over-engineered. Not his fault, the way discard and zeroing got conflated certainly lends itself to these ugly hacks. SO I do appreciate that for anything to leverage discard_zeroes_data it needs to be reliable. Which runs counter to how discard was implemented (discard may get silently dropped!) But that is why dm-thinp doesn't advertise dzd. Anyway... As for the blkdev_issue_zeroout() resorting to manually zeroing the range, if the discard fails or dzd not supported, that certainly requires DM thinp to implement manual zeroing of the head and tail of the range if partial blocks are being zeroed. So I welcome any advances there. It is probably something that is best left to Joe or myself to tackle. But I'll gladly accept patches ;)
Re: RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
It sounds like you don't want to support traditional discard at all, but only WRITE ZEROES. So in many ways this series is the right way forward. It would be nice if we could do a full blown REQ_OP_WRITE_ZEROES for dm_think that zeroes out partial blocks, similar to what hardware that implements WRITE SAME of zeroes or WRITE ZEROES would do. I'll see if I could include that in my series.
Re: RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
On Thu, Mar 23, 2017 at 01:02:22PM -0400, Mike Snitzer wrote: > On Thu, Mar 23 2017 at 11:54am -0400, > Lars Ellenbergwrote: > > > On Thu, Mar 23, 2017 at 10:33:18AM -0400, Christoph Hellwig wrote: > > > This series makes REQ_OP_WRITE_ZEROES the only zeroing offload > > > supported by the block layer, and switches existing implementations > > > of REQ_OP_DISCARD that correctly set discard_zeroes_data to it, > > > removes incorrect discard_zeroes_data, and also switches WRITE SAME > > > based zeroing in SCSI to this new method. > > > > > > I've done testing with ATA, SCSI and NVMe setups, but there are > > > a few things that will need more attention: > > > > > > > > - The DRBD code in this area was very odd, > > > > DRBD wants all replicas to give back identical data. > > If what comes back after a discard is "undefined", > > we cannot really use that. > > > > We used to "stack" discard only if our local backend claimed > > "discard_zeroes_data". We replicate that IO request to the peer > > as discard, and if the peer cannot do discards itself, or has > > discard_zeroes_data == 0, the peer will use zeroout instead. > > > > One use-case for this is the device mapper "thin provisioning". > > At the time I wrote those "odd" hacks, dm thin targets > > would set discard_zeroes_data=0, NOT change discard granularity, > > but only actually discard (drop from the tree) whole "chunks", > > leaving partial start/end chunks in the mapping tree unchanged. > > > > The logic of "only stack discard, if backend discard_zeroes_data" That is DRBDs logic I just explained above. And the "backend" (to DRBD) in that sentence would be thin, and not the "real" hardware below thin, which may not even support discard. > > would mean that we would not be able to accept and pass down discards > > to dm-thin targets. But with data on dm-thin, you would really like > > to do the occasional fstrim. > > Are you sure you aren't thinking of MD raid? Yes. > To this day, dm-thin.c has: ti->discard_zeroes_data_unsupported = true That is exactly what I was saying. Thin does not claim to zero data on discard. which is ok, and correct, because it only punches holes on full chunks (or whatever you call them), and leaves the rest in the mapping tree as is. And that behaviour would prevent DRBD from exposing discards if configured on top of thin. (see above) But thin *could* easily guarantee zeroing, by simply punching holes where it can, and zeroing out the not fully-aligned partial start and end of the range. Which is what I added as an option between DRBD and whatever is below, with the use-case of dm-thin in mind. And that made it possible for DRBD to a) expose "discard" to upper layers, even if we would usually only do if the DRBD Primary sits on top of a device that guarantees discard zeros data, b) still use discards on a secondary, without falling back to zero-out, which would unexpectedly fully allocate, instead of trim, a thinly provisioned device-mapper target. Thanks, Lars
Re: RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
On Thu, Mar 23 2017 at 11:54am -0400, Lars Ellenbergwrote: > On Thu, Mar 23, 2017 at 10:33:18AM -0400, Christoph Hellwig wrote: > > This series makes REQ_OP_WRITE_ZEROES the only zeroing offload > > supported by the block layer, and switches existing implementations > > of REQ_OP_DISCARD that correctly set discard_zeroes_data to it, > > removes incorrect discard_zeroes_data, and also switches WRITE SAME > > based zeroing in SCSI to this new method. > > > > I've done testing with ATA, SCSI and NVMe setups, but there are > > a few things that will need more attention: > > > > > - The DRBD code in this area was very odd, > > DRBD wants all replicas to give back identical data. > If what comes back after a discard is "undefined", > we cannot really use that. > > We used to "stack" discard only if our local backend claimed > "discard_zeroes_data". We replicate that IO request to the peer > as discard, and if the peer cannot do discards itself, or has > discard_zeroes_data == 0, the peer will use zeroout instead. > > One use-case for this is the device mapper "thin provisioning". > At the time I wrote those "odd" hacks, dm thin targets > would set discard_zeroes_data=0, NOT change discard granularity, > but only actually discard (drop from the tree) whole "chunks", > leaving partial start/end chunks in the mapping tree unchanged. > > The logic of "only stack discard, if backend discard_zeroes_data" > would mean that we would not be able to accept and pass down discards > to dm-thin targets. But with data on dm-thin, you would really like > to do the occasional fstrim. Are you sure you aren't thinking of MD raid? E.g. raid5's "devices_handle_discard_safely": parm: devices_handle_discard_safely:Set to Y if all devices in each array reliably return zeroes on reads from discarded regions (bool) I don't recall DM thinp's discard support ever having a requirement for discard_zeroes_data. In fact, see header from commit b60ab990ccdf3 ("dm thin: do not expose non-zero discard limits if discards disabled"): Also, always set discard_zeroes_data_unsupported in targets because they should never advertise the 'discard_zeroes_data' capability (even if the pool's data device supports it). To this day, dm-thin.c has: ti->discard_zeroes_data_unsupported = true
Re: RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
On Thu, Mar 23, 2017 at 10:33:18AM -0400, Christoph Hellwig wrote: > This series makes REQ_OP_WRITE_ZEROES the only zeroing offload > supported by the block layer, and switches existing implementations > of REQ_OP_DISCARD that correctly set discard_zeroes_data to it, > removes incorrect discard_zeroes_data, and also switches WRITE SAME > based zeroing in SCSI to this new method. > > I've done testing with ATA, SCSI and NVMe setups, but there are > a few things that will need more attention: > > - The DRBD code in this area was very odd, DRBD wants all replicas to give back identical data. If what comes back after a discard is "undefined", we cannot really use that. We used to "stack" discard only if our local backend claimed "discard_zeroes_data". We replicate that IO request to the peer as discard, and if the peer cannot do discards itself, or has discard_zeroes_data == 0, the peer will use zeroout instead. One use-case for this is the device mapper "thin provisioning". At the time I wrote those "odd" hacks, dm thin targets would set discard_zeroes_data=0, NOT change discard granularity, but only actually discard (drop from the tree) whole "chunks", leaving partial start/end chunks in the mapping tree unchanged. The logic of "only stack discard, if backend discard_zeroes_data" would mean that we would not be able to accept and pass down discards to dm-thin targets. But with data on dm-thin, you would really like to do the occasional fstrim. Also, IO backends on the peers do not have to have the same characteristics. You could have the DRBD Primary on some SSD, and the Secondary on some thin-pool LV, scheduling thin snapthots in intervals or on demand. With the logic of "use zero-out instead", fstrim would cause it to fully allocate what was supposed to be thinly provisioned :-( So what I did there was optionally tell DRBD that "discard_zeroes_data == 0" on that peer would actually mean "discard_zeroes_data == 1, IF you zero-out the partial chunks of this granularity yourself". And implemented this "discard aligned chunks of that granularity, and zero-out partial start/end chunks, if any". And then claim to upper layers that, yes, discard_zeroes_data=1, in that case, if so configured, even if our backend (dm-thin) would say discard_zeroes_data=0. Does that make sense? Can we still do that? Has something like that been done in block core or device mapper meanwhile? > and will need an audit from the maintainers. Will need to make some time for review and testing. Thanks, Lars
RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload
This series makes REQ_OP_WRITE_ZEROES the only zeroing offload supported by the block layer, and switches existing implementations of REQ_OP_DISCARD that correctly set discard_zeroes_data to it, removes incorrect discard_zeroes_data, and also switches WRITE SAME based zeroing in SCSI to this new method. I've done testing with ATA, SCSI and NVMe setups, but there are a few things that will need more attention: - what is dm-kcopyd doing with the current WRITE SAME usage that gets multiple biovecs? Can we fix it up in any way. - what are we going to do with discards through parity raid? I suspect we should either just disable it for now entirely or modify raid5.c to issue REQ_OP_WRITE_ZEROES to the underlying devices. But I need someone with such a setup to test it. - The DRBD code in this area was very odd, and will need an audit from the maintainers. Note that this series needs to be applied on top of the "support ranges TRIM for libata" series. A git tree is also avaiable at: git://git.infradead.org/users/hch/block.git discard-rework Gitweb: http://git.infradead.org/users/hch/block.git/shortlog/refs/heads/discard-rework