public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH RFC 1/3] btrfs: add btrfs_bio::bioc pointer for further modification
Date: Wed, 22 Sep 2021 16:27:04 +0800	[thread overview]
Message-ID: <20210922082706.55650-2-wqu@suse.com> (raw)
In-Reply-To: <20210922082706.55650-1-wqu@suse.com>

Currently we use btrfs_io_context for dual purposes:

- As bio->private for mirror based bio submission
  For those profiles, we assign bio->private to btrfs_io_context and
  save the old private/endio, and utilize bioc::stripes_pending.

- As pure stripe maps for RAID56
  For RAID56, btrfs will assemble its own raid_bio for physical
  submission. In that case, btrfs_io_context only provides stripe
  mapping, thus no need to utilize things like
  end_io/private/stripes_pending.

To make future members modifications, here we do a small change, by
introducing btrfs_bio::bioc pointer.

This modification will increase memory usage for btrfs_bio by 8 bytes,
but reduces btrfs_io_context by 8 bytes.
Overall it's still a net increase as btrfs_bio will be created for each
stripe, while btrfs_io_context exists once for all those involved
stripes.

This memory usage will be reduced by later commits.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/volumes.c | 7 +++----
 fs/btrfs/volumes.h | 3 ++-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index d7cc24ed9620..86ff268369ec 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6557,16 +6557,16 @@ int btrfs_map_sblock(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
 
 static inline void btrfs_end_bioc(struct btrfs_io_context *bioc, struct bio *bio)
 {
-	bio->bi_private = bioc->private;
 	bio->bi_end_io = bioc->end_io;
 	bio_endio(bio);
+	btrfs_bio(bio)->bioc = NULL;
 
 	btrfs_put_bioc(bioc);
 }
 
 static void btrfs_end_bio(struct bio *bio)
 {
-	struct btrfs_io_context *bioc = bio->bi_private;
+	struct btrfs_io_context *bioc = btrfs_bio(bio)->bioc;
 	int is_orig_bio = 0;
 
 	if (bio->bi_status) {
@@ -6624,7 +6624,7 @@ static void submit_stripe_bio(struct btrfs_io_context *bioc, struct bio *bio,
 {
 	struct btrfs_fs_info *fs_info = bioc->fs_info;
 
-	bio->bi_private = bioc;
+	btrfs_bio(bio)->bioc = bioc;
 	btrfs_bio(bio)->device = dev;
 	bio->bi_end_io = btrfs_end_bio;
 	bio->bi_iter.bi_sector = physical >> 9;
@@ -6697,7 +6697,6 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
 
 	total_devs = bioc->num_stripes;
 	bioc->orig_bio = first_bio;
-	bioc->private = first_bio->bi_private;
 	bioc->end_io = first_bio->bi_end_io;
 	bioc->fs_info = fs_info;
 	atomic_set(&bioc->stripes_pending, bioc->num_stripes);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 83075d6855db..384c483d2cef 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -311,6 +311,8 @@ struct btrfs_fs_devices {
 struct btrfs_bio {
 	unsigned int mirror_num;
 
+	struct btrfs_io_context *bioc;
+
 	/* @device is for stripe IO submission. */
 	struct btrfs_device *device;
 	u64 logical;
@@ -367,7 +369,6 @@ struct btrfs_io_context {
 	u64 map_type; /* get from map_lookup->type */
 	bio_end_io_t *end_io;
 	struct bio *orig_bio;
-	void *private;
 	atomic_t error;
 	int max_errors;
 	int num_stripes;
-- 
2.33.0


  reply	other threads:[~2021-09-22  8:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22  8:27 [PATCH RFC 0/3] btrfs: refactor how we handle btrfs_io_context and slightly reduce memory usage for both btrfs_bio and btrfs_io_context Qu Wenruo
2021-09-22  8:27 ` Qu Wenruo [this message]
2021-09-22  8:27 ` [PATCH RFC 2/3] btrfs: remove redundant parameters for submit_stripe_bio() Qu Wenruo
2021-09-22  8:27 ` [PATCH RFC 3/3] btrfs: replace btrfs_bio::device member with stripe_num Qu Wenruo
2021-09-22  9:57 ` [PATCH RFC 0/3] btrfs: refactor how we handle btrfs_io_context and slightly reduce memory usage for both btrfs_bio and btrfs_io_context Qu Wenruo
2021-10-06 19:38 ` David Sterba
2021-10-07  2:24   ` Qu Wenruo
2021-10-07 11:04     ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210922082706.55650-2-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox