All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@kernel.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: Dennis Zhou <dennis@kernel.org>,
	tj@kernel.org, axboe@kernel.dk, linux-block@vger.kernel.org,
	dm-devel@redhat.com
Subject: Re: can we reduce bio_set_dev overhead due to bio_associate_blkg?
Date: Mon, 11 Apr 2022 12:58:18 -0400	[thread overview]
Message-ID: <YlReKjjWhvTZjfg/@redhat.com> (raw)
In-Reply-To: <YlEWfc39+H+esrQm@infradead.org>

On Sat, Apr 09 2022 at  1:15P -0400,
Christoph Hellwig <hch@infradead.org> wrote:

> On Fri, Apr 08, 2022 at 11:42:51AM -0400, Mike Snitzer wrote:
> > I think we can achieve the goal of efficient cloning/remapping for
> > both usecases simply by splitting out the bio_set_dev() and leaving it
> > to the caller to pick which interface to use (e.g. clone vs
> > clone_and_remap).
> 
> You can just pass a NULL bdev to bio_alloc_clone/bio_init_clone.
> I've been hoping to get rid of that, but if we have a clear use case
> it will have to stay.

DM core is just using bio_alloc_clone. And bio_alloc_bioset() allows
bdev to be NULL -- so you're likely referring to that (which will skip
bio_init's bio_associate_blkg).

Circling back to earlier in this thread, Dennis and you agreed that it
doesn't make sense to have __bio_clone() do blkcg work if the clone
bio will be remapped (via bio_set_dev).  Given that, and the fact that
bio_clone_blkg_association() assumes both bios are from same bdev,
this change makes sense:

diff --git a/block/bio.c b/block/bio.c
index 7892f1108ca6..0340acc283a0 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -772,14 +772,16 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp)
	bio_set_flag(bio, BIO_CLONED);
	if (bio_flagged(bio_src, BIO_THROTTLED))
		bio_set_flag(bio, BIO_THROTTLED);
-	if (bio->bi_bdev == bio_src->bi_bdev &&
-	    bio_flagged(bio_src, BIO_REMAPPED))
-		bio_set_flag(bio, BIO_REMAPPED);
	bio->bi_ioprio = bio_src->bi_ioprio;
	bio->bi_iter = bio_src->bi_iter;

-	bio_clone_blkg_association(bio, bio_src);
-	blkcg_bio_issue_init(bio);
+	if (bio->bi_bdev == bio_src->bi_bdev) {
+		if (bio_flagged(bio_src, BIO_REMAPPED))
+			bio_set_flag(bio, BIO_REMAPPED);
+
+		bio_clone_blkg_association(bio, bio_src);
+		blkcg_bio_issue_init(bio);
+	}

	if (bio_crypt_clone(bio, bio_src, gfp) < 0)
		return -ENOMEM;

Think this will fix some of the performance penalty of redundant blkcg
initialization that I reported (though like was also discussed: more
work likely needed to further optimize bio_associate_blkg).

I'll audit DM targets and test to verify my changes and will post
proper patch(es) once done.

Mike

WARNING: multiple messages have this Message-ID (diff)
From: Mike Snitzer <snitzer@kernel.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: tj@kernel.org, Dennis Zhou <dennis@kernel.org>,
	dm-devel@redhat.com, linux-block@vger.kernel.org,
	axboe@kernel.dk
Subject: Re: [dm-devel] can we reduce bio_set_dev overhead due to bio_associate_blkg?
Date: Mon, 11 Apr 2022 12:58:18 -0400	[thread overview]
Message-ID: <YlReKjjWhvTZjfg/@redhat.com> (raw)
In-Reply-To: <YlEWfc39+H+esrQm@infradead.org>

On Sat, Apr 09 2022 at  1:15P -0400,
Christoph Hellwig <hch@infradead.org> wrote:

> On Fri, Apr 08, 2022 at 11:42:51AM -0400, Mike Snitzer wrote:
> > I think we can achieve the goal of efficient cloning/remapping for
> > both usecases simply by splitting out the bio_set_dev() and leaving it
> > to the caller to pick which interface to use (e.g. clone vs
> > clone_and_remap).
> 
> You can just pass a NULL bdev to bio_alloc_clone/bio_init_clone.
> I've been hoping to get rid of that, but if we have a clear use case
> it will have to stay.

DM core is just using bio_alloc_clone. And bio_alloc_bioset() allows
bdev to be NULL -- so you're likely referring to that (which will skip
bio_init's bio_associate_blkg).

Circling back to earlier in this thread, Dennis and you agreed that it
doesn't make sense to have __bio_clone() do blkcg work if the clone
bio will be remapped (via bio_set_dev).  Given that, and the fact that
bio_clone_blkg_association() assumes both bios are from same bdev,
this change makes sense:

diff --git a/block/bio.c b/block/bio.c
index 7892f1108ca6..0340acc283a0 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -772,14 +772,16 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp)
	bio_set_flag(bio, BIO_CLONED);
	if (bio_flagged(bio_src, BIO_THROTTLED))
		bio_set_flag(bio, BIO_THROTTLED);
-	if (bio->bi_bdev == bio_src->bi_bdev &&
-	    bio_flagged(bio_src, BIO_REMAPPED))
-		bio_set_flag(bio, BIO_REMAPPED);
	bio->bi_ioprio = bio_src->bi_ioprio;
	bio->bi_iter = bio_src->bi_iter;

-	bio_clone_blkg_association(bio, bio_src);
-	blkcg_bio_issue_init(bio);
+	if (bio->bi_bdev == bio_src->bi_bdev) {
+		if (bio_flagged(bio_src, BIO_REMAPPED))
+			bio_set_flag(bio, BIO_REMAPPED);
+
+		bio_clone_blkg_association(bio, bio_src);
+		blkcg_bio_issue_init(bio);
+	}

	if (bio_crypt_clone(bio, bio_src, gfp) < 0)
		return -ENOMEM;

Think this will fix some of the performance penalty of redundant blkcg
initialization that I reported (though like was also discussed: more
work likely needed to further optimize bio_associate_blkg).

I'll audit DM targets and test to verify my changes and will post
proper patch(es) once done.

Mike

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


  reply	other threads:[~2022-04-11 16:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-30 16:52 can we reduce bio_set_dev overhead due to bio_associate_blkg? Mike Snitzer
2022-03-30 16:52 ` [dm-devel] " Mike Snitzer
2022-03-30 12:28 ` Dennis Zhou
2022-03-30 12:28   ` [dm-devel] " Dennis Zhou
2022-03-31  4:39   ` Christoph Hellwig
2022-03-31  4:39     ` [dm-devel] " Christoph Hellwig
2022-03-31  5:52     ` Dennis Zhou
2022-03-31  5:52       ` [dm-devel] " Dennis Zhou
2022-03-31  9:15       ` Christoph Hellwig
2022-03-31  9:15         ` [dm-devel] " Christoph Hellwig
2022-04-08 15:42         ` Mike Snitzer
2022-04-08 15:42           ` [dm-devel] " Mike Snitzer
2022-04-09  5:15           ` Christoph Hellwig
2022-04-09  5:15             ` [dm-devel] " Christoph Hellwig
2022-04-11 16:58             ` Mike Snitzer [this message]
2022-04-11 16:58               ` Mike Snitzer
2022-04-11 17:16               ` Mike Snitzer
2022-04-11 17:16                 ` [dm-devel] " Mike Snitzer
2022-04-11 17:33                 ` [PATCH] block: remove redundant blk-cgroup init from __bio_clone Mike Snitzer
2022-04-11 17:33                   ` [dm-devel] " Mike Snitzer
2022-04-12  5:27                   ` Christoph Hellwig
2022-04-12  5:27                     ` [dm-devel] " Christoph Hellwig
2022-04-12  7:52                     ` Dennis Zhou
2022-04-12  7:52                       ` Dennis Zhou
2022-04-23 16:55                   ` Christoph Hellwig
2022-04-23 16:55                     ` [dm-devel] " Christoph Hellwig
2022-04-26 17:30                     ` Mike Snitzer
2022-04-26 17:30                       ` [dm-devel] " Mike Snitzer

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=YlReKjjWhvTZjfg/@redhat.com \
    --to=snitzer@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=dennis@kernel.org \
    --cc=dm-devel@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=tj@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.