Skip to content

Commit 6f706f3

Browse files
adam900710kdave
authored andcommitted
btrfs: switch to btrfs_compress_bio() interface for compressed writes
This switch has the following benefits: - A single structure to handle all compression No more extra members like compressed_folios[] nor compress_type, all those members. This means the structure of async_extent is much smaller. - Simpler error handling A single cleanup_compressed_bio() will handle everything, no extra compressed_folios[] array to bother. Some extra notes: - Compressed folios releasing Now we go bio_for_each_folio_all() loop to release the folios of the bio. This will work for both the old compressed_folios[] array and the new pure bio method. For old compressed_folios[], all folios of that array is queued into the bio, thus releasing the folios from the bio is the same as releasing each folio of that array. We just need to be sure no double releasing from the array and bio. For the new pure bio method, that array is NULL, just usual folio releasing of the bio. The only extra note is for end_bbio_compressed_read(), as the folios are allocated using btrfs_alloc_folio_array(), thus the folios should only be released by regular folio_put(), not btrfs_free_compr_folio(). - Rounding up the bio to block size We cannot simply increase bi_size, as that will not increase the length of the last bvec. Thus we have to properly add the last part into the bio. This will be done by the helper, round_up_last_block(). The reason we do not round those bios up at compression time is to get the unaligned compressed size, so that they can be utilized for inline extents. If we round the bios up at *_compress_bio(), then every compressed bio will be larger than or equal to one fs block, resulting no inline compressed extent. Reviewed-by: Boris Burkov <boris@bur.io> Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent c511732 commit 6f706f3

2 files changed

Lines changed: 107 additions & 94 deletions

File tree

fs/btrfs/compression.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,6 @@ static int compression_decompress(int type, struct list_head *ws,
155155
}
156156
}
157157

158-
static void btrfs_free_compressed_folios(struct compressed_bio *cb)
159-
{
160-
for (unsigned int i = 0; i < cb->nr_folios; i++)
161-
btrfs_free_compr_folio(cb->compressed_folios[i]);
162-
kfree(cb->compressed_folios);
163-
}
164-
165158
static int btrfs_decompress_bio(struct compressed_bio *cb);
166159

167160
/*
@@ -270,12 +263,14 @@ static void end_bbio_compressed_read(struct btrfs_bio *bbio)
270263
{
271264
struct compressed_bio *cb = to_compressed_bio(bbio);
272265
blk_status_t status = bbio->bio.bi_status;
266+
struct folio_iter fi;
273267

274268
if (!status)
275269
status = errno_to_blk_status(btrfs_decompress_bio(cb));
276270

277-
btrfs_free_compressed_folios(cb);
278271
btrfs_bio_end_io(cb->orig_bbio, status);
272+
bio_for_each_folio_all(fi, &bbio->bio)
273+
folio_put(fi.folio);
279274
bio_put(&bbio->bio);
280275
}
281276

@@ -326,14 +321,17 @@ static noinline void end_compressed_writeback(const struct compressed_bio *cb)
326321
static void end_bbio_compressed_write(struct btrfs_bio *bbio)
327322
{
328323
struct compressed_bio *cb = to_compressed_bio(bbio);
324+
struct folio_iter fi;
329325

330326
btrfs_finish_ordered_extent(cb->bbio.ordered, NULL, cb->start, cb->len,
331327
cb->bbio.bio.bi_status == BLK_STS_OK);
332328

333329
if (cb->writeback)
334330
end_compressed_writeback(cb);
335331
/* Note, our inode could be gone now. */
336-
btrfs_free_compressed_folios(cb);
332+
bio_for_each_folio_all(fi, &bbio->bio)
333+
btrfs_free_compr_folio(fi.folio);
334+
kfree(cb->compressed_folios);
337335
bio_put(&cb->bbio.bio);
338336
}
339337

0 commit comments

Comments
 (0)