Skip to content

btrfs: compression: refactor and enhancement preparing for subpage compression support

Qu Wenruo linux-btrfs 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest9 patches 7 repliesIn review
  2. v39 patches 8 repliesSuperseded
  3. v29 patches 0 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v19 patches13 repliesSuperseded

Changes in v4 from the cover letter

- Use formal words for BUG_ON() removal patch titles

- Remove compressed_bio::pending_bios
As compressed_bio::pending_sectors can replace it completely

- Remove unnecessary comments and BUG_ON()s

- Use wait_var_event() APIs to reduce the memory overhead

- Comments update to follow the same schema for moved comments

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9btrfs: remove a dead comment for btrfs_decompress_bio()fs/btrfs/compression.c+0 -140 replies
2/9btrfs: introduce compressed_bio::pending_sectors to trace compressed bio more elegantlyfs/btrfs/compression.c fs/btrfs/compression.h+49 -342 replies
3/9btrfs: handle errors properly inside btrfs_submit_compressed_read()fs/btrfs/compression.c+77 -440 replies
4/9btrfs: handle errors properly inside btrfs_submit_compressed_write()fs/btrfs/compression.c+64 -370 replies
5/9btrfs: introduce submit_compressed_bio() for compressionfs/btrfs/compression.c+19 -260 replies
6/9btrfs: introduce alloc_compressed_bio() for compressionfs/btrfs/compression.c+57 -280 replies
7/9btrfs: make btrfs_submit_compressed_read() to determine stripe boundary at bio allocation timefs/btrfs/compression.c+93 -710 replies
8/9btrfs: make btrfs_submit_compressed_write() to determine stripe boundary at bio allocation timefs/btrfs/compression.c fs/btrfs/compression.h+62 -860 replies
9/9btrfs: remove unused function btrfs_bio_fits_in_stripe()fs/btrfs/ctree.h fs/btrfs/inode.c+0 -440 replies

Reviews trailers per patch

1 of 9 patches has a Reviewed-by or Acked-by.

PatchAnand JainJohannes Thumshirn
1/9R-b R-b
2/9
3/9
4/9
5/9
6/9
7/9
8/9
9/9

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/9] btrfs: compression: refactor and enhancement preparing for subpage compression support

There are quite some problems in compression code:

- Weird compressed_bio::pending_bios dance
If we just don't want compressed_bio being freed halfway, we have more sane methods, just like btrfs_subpage::readers.

So here we fix it by introducing compressed_bio::io_sectors to do the job.

- BUG_ON()s inside btrfs_submit_compressed_*()
Even they are just ENOMEM, we should handle them.
With io_sectors introduced, we have a way to finish compressed_bio all by ourselves, as long as we haven't submitted last bio.

If we have last bio submitted, then endio will handle it well.

- Duplicated code for compressed bio allocation and submission Just small refactor can handle it

- Stripe boundary is checked every time one page is added This is overkilled.
Just learn from extent_io.c refactor which use bio_ctrl to do the boundary check only once for each bio.

Although in compression context, we don't need extra checks in extent_io.c, thus we don't need bio_ctrl structure, but can afford to do it locally.

- Dead code removal
One dead comment and a new zombie function,
btrfs_bio_fits_in_stripe(), can be removed now.

Changelog:
v2:
- Rebased to latest misc-next

- Fix a bug in btrfs_submit_compressed_write() where zoned write is not taken into consideration

- Reuse the existing chunk mapping of btrfs_get_chunk_map()

v3:
- Fix a bug that zoned device can't even pass btrfs/001
This is because at endio time, bi_size for zoned device is always 0. We have to use bio_for_each_segment_all() to calculate the real bio size instead.
In theory, it should also happen more frequently for non-zoned device, but no catch for all test cases (with "-o compress") except btrfs/011.

- Fix btrfs/011 hang when tested with "-o compress" This is caused by checking both atomic value without protection. Checking two atomic values is no longer atomic.

In fact, with compressed_bio::io_sectors introduced, pending_bios is only used to wait for any pending bio to finish in error path.

Thus dec_and_test_compressed_bio() only need to check if io_sectors is zero

- Fix a error that in error handling path, we may hang due to missing wake_up() in dec_and_test_compressed_bio()

v4:
- Use formal words for BUG_ON() removal patch titles

- Remove compressed_bio::pending_bios
As compressed_bio::pending_sectors can replace it completely

- Remove unnecessary comments and BUG_ON()s

- Use wait_var_event() APIs to reduce the memory overhead

- Comments update to follow the same schema for moved comments

Qu Wenruo (9):
btrfs: remove a dead comment for btrfs_decompress_bio()
btrfs: introduce compressed_bio::pending_sectors to trace compressed
bio more elegantly
btrfs: handle errors properly inside btrfs_submit_compressed_read()
btrfs: handle errors properly inside btrfs_submit_compressed_write()
btrfs: introduce submit_compressed_bio() for compression
btrfs: introduce alloc_compressed_bio() for compression
btrfs: make btrfs_submit_compressed_read() to determine stripe
boundary at bio allocation time
btrfs: make btrfs_submit_compressed_write() to determine stripe
boundary at bio allocation time
btrfs: remove unused function btrfs_bio_fits_in_stripe()

 fs/btrfs/compression.c | 587 +++++++++++++++++++++++------------------
 fs/btrfs/compression.h |   4 +-
 fs/btrfs/ctree.h       |   2 -
 fs/btrfs/inode.c       |  42 ---
 4 files changed, 336 insertions(+), 299 deletions(-)
Signature · 1 line
2.32.0