Re: [PATCH v4 2/9] btrfs: introduce compressed_bio::pending_sectors to trace compressed bio more elegantly
From: Qu Wenruo <hidden>
Date: 2021-06-18 05:18:18
On 2021/6/18 下午12:16, Anand Jain wrote:
On 17/06/2021 13:14, Qu Wenruo wrote:
[...]
quoted
+ atomic_inc(&cb->pending_bios); ret = btrfs_bio_wq_end_io(fs_info, comp_bio, BTRFS_WQ_ENDIO_DATA); BUG_ON(ret); /* -ENOMEM */ - /* - * inc the count before we submit the bio so - * we know the end IO handler won't happen before - * we inc the count. Otherwise, the cb might get - * freed before we're done setting it up - */ - refcount_inc(&cb->pending_bios); -Looks good so far. I understand pending_bios will go away in favour of pending_sectors. But here, is there any purpose atomic_inc(&cb->pending_bios) is called before btrfs_bio_wq_end_io() that might fail.
The pending_bios is increased before we may want to submit the bio. There is no special reason, but we will later merge refcount_inc(); btrfs_bio_wq_end_io(), btrfs_map_bio() into one call, thus I just choose btrfs_bio_wq_end_io() as a marker. Thanks, Qu
-Anandquoted
ret = btrfs_lookup_bio_sums(inode, comp_bio, sums); BUG_ON(ret); /* -ENOMEM */@@ -805,6 +816,7 @@ blk_status_t btrfs_submit_compressed_read(structinode *inode, struct bio *bio, cur_disk_byte += pg_len; } + atomic_inc(&cb->pending_bios); ret = btrfs_bio_wq_end_io(fs_info, comp_bio, BTRFS_WQ_ENDIO_DATA); BUG_ON(ret); /* -ENOMEM */diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index c359f20920d0..8940e9e9fed3 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h@@ -29,7 +29,10 @@ struct btrfs_inode;struct compressed_bio { /* number of bios pending for this compressed extent */ - refcount_t pending_bios; + atomic_t pending_bios; + + /* Number of sectors with unfinished IO (unsubmitted or unfinished) */ + refcount_t pending_sectors; /* Number of compressed pages in the array */ unsigned int nr_pages;