btrfs: avoid unnecessary double loop usage in RAID56
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v3 Latest5 patches 1 replyIn review
- v25 patches 1 replySuperseded
- v15 patches 1 replySuperseded
Changes in v3 from the cover letter
- Fix a crash in btrfs/125
This is caused by the 4th patch, which the original code is only iterating data sectors, but not touching P/Q stripes. This triggeres a BUG_ON().
Patches in v3 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/5 | btrfs: avoid double for loop inside finish_rmw()fs/ | +54 | 0 replies | |
| 2/5 | btrfs: avoid double for loop inside __raid56_parity_recover()fs/ | +19 | 0 replies | |
| 3/5 | btrfs: avoid double for loop inside alloc_rbio_essential_pages()fs/ | +14 | 0 replies | |
| 4/5 | btrfs: avoid double for loop inside raid56_rmw_stripe()fs/ | +28 | 0 replies | |
| 5/5 | btrfs: avoid double for loop inside raid56_parity_scrub_stripe()fs/ | +32 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.
Cover letter [PATCH v3 0/5] btrfs: avoid unnecessary double loop usage in RAID56
[CHANGELOG]
v3:
- Fix a crash in btrfs/125
This is caused by the 4th patch, which the original code is only iterating data sectors, but not touching P/Q stripes. This triggeres a BUG_ON().
v2:
- Fix a bug in the 2nd patch that @stripe_nsector should be used instead of @nr_sectors
This can cause btrfs/157 crash reliably
There are a lot of call patterns used in RAID56 like this:
for (stripe = 0; stripe < rbio->real_stripes; stripe++) {
for (sectornr = 0; sectornr < rbio->stripe_nsectors; sectornr++) {
struct sector_ptr *sector;
sector = sector_in_rbio(rbio, stripe, sectornr, 1);
/* Do something with the sector */
}
}Such double for loop could cause problems for continue/break, as we have to keep in mind which layer we're continuing or breaking out.
In fact, for most call sites, they are just iterating all the sectors in their bytenr order.
Thus there is really no need to do such double for loop.
This patchset will convert all these unnecessary call sites to something like this:
for (total_sector_nr = 0; total_sector_nr < rbio->nr_sectors;
total_sector_nr++) {
struct sector_ptr *sector;
sector = sector_in_rbio(rbio, stripe, sectornr, 1);
/* Do something with the sector */
}So we don't need to bother if the break/continue is for which layer, and reduce one indent.
There are some cases that, we may want to skip the full stripe. In that case, it can be done by modifying @total_sector_nr manually.
Since modifying the iterator is not a good practice, every time we do that, there will be an ASSERT() (making sure we're the first sector), and a comment on the fact we're skipping the whole stripe.
There are still call sites doing much smaller double loop, mostly for cases that explicitly want to handling a vertical stripe. For those call sites, just keep them as is.
Qu Wenruo (5):
btrfs: avoid double for loop inside finish_rmw()
btrfs: avoid double for loop inside __raid56_parity_recover()
btrfs: avoid double for loop inside alloc_rbio_essential_pages()
btrfs: avoid double for loop inside raid56_rmw_stripe()
btrfs: avoid double for loop inside raid56_parity_scrub_stripe()
fs/btrfs/raid56.c | 284 ++++++++++++++++++++++++---------------------- 1 file changed, 147 insertions(+), 137 deletions(-)
Signature · 1 line
2.36.1