From: Mikulas Patocka <mpatocka@redhat.com>
To: Jens Axboe <jens.axboe@oracle.com>
Cc: linux-kernel@vger.kernel.org, Neil Brown <neilb@suse.de>
Subject: Re: [PATCH 1/2] Avoid bio_endio recursion
Date: Wed, 2 Jul 2008 00:09:22 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0807020001290.9097@engineering.redhat.com> (raw)
In-Reply-To: <20080626070723.GL20851@kernel.dk>
> Right, that wont work of course. Completions are typically done through
> a softirq, so it is not currently done with hard interrupts disabled.
I thought, from hardirq - that's what IDE is doing. And they are called
with interrupts disabled (maybe unless you specify unmaskirq, which is not
default). What block driver does completions with softirq? ... and why?
> So it's a bit of a shame to impose this extra restriction, bio unrolling
> is necessarily a really short operation. We could reenable around the
> bi_end_io() call, but then we'd need to save and restore for each bio.
I found another weird thing --- why does local_irq_save() execute that
microcoded "cli" instruction even if interrupts are already disabled? That
could be definitely optimized.
And does local_irq_restore() need to execute even more costy "popf" when
it makes a transition from disabled to disabled state? What's
local_irq_restore semantics --- is it allowed to use local_irq_restore for
transition from interrupt-enabled state into interrupt-disabled state?
> Please make that
>
> bio->bi_flags &= ~(1 << BIO_SEG_VALID);
> bio->bi_phys_segments = error;
OK, here is the updated patch:
Avoid recursion on bio_endio. bio_endio calls bio->bi_end_io which may in turn
call bio_endio again. When this recursion happens, put the new bio to the queue
and process it later, from the top-level bio_endio.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
---
fs/bio.c | 39 ++++++++++++++++++++++++++++++++++++---
include/linux/bio.h | 3 +++
2 files changed, 39 insertions(+), 3 deletions(-)
Index: linux-2.6.26-rc8-devel/fs/bio.c
===================================================================
--- linux-2.6.26-rc8-devel.orig/fs/bio.c 2008-07-02 04:20:43.000000000 +0200
+++ linux-2.6.26-rc8-devel/fs/bio.c 2008-07-02 04:22:15.000000000 +0200
@@ -1166,15 +1166,48 @@ void bio_check_pages_dirty(struct bio *b
* bio unless they own it and thus know that it has an end_io
* function.
**/
+static DEFINE_PER_CPU(struct bio **, bio_end_queue) = { NULL };
+
void bio_endio(struct bio *bio, int error)
{
+ struct bio ***bio_end_queue_ptr;
+ struct bio *bio_queue;
+
+ unsigned long flags;
+
+ bio->bi_flags &= ~(1 << BIO_SEG_VALID);
+ bio->bi_phys_segments = error;
if (error)
clear_bit(BIO_UPTODATE, &bio->bi_flags);
else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
- error = -EIO;
+ bio->bi_phys_segments = -EIO;
+
+ local_irq_save(flags);
+ bio_end_queue_ptr = &__get_cpu_var(bio_end_queue);
+
+ if (*bio_end_queue_ptr) {
+ **bio_end_queue_ptr = bio;
+ *bio_end_queue_ptr = &bio->bi_next;
+ bio->bi_next = NULL;
+ } else {
+ bio_queue = NULL;
+ *bio_end_queue_ptr = &bio_queue;
+
+next_bio:
+ if (bio->bi_end_io)
+ bio->bi_end_io(bio, (short)bio->bi_phys_segments);
+
+ if (bio_queue) {
+ bio = bio_queue;
+ bio_queue = bio->bi_next;
+ if (!bio_queue)
+ *bio_end_queue_ptr = &bio_queue;
+ goto next_bio;
+ }
+ *bio_end_queue_ptr = NULL;
+ }
- if (bio->bi_end_io)
- bio->bi_end_io(bio, error);
+ local_irq_restore(flags);
}
void bio_pair_release(struct bio_pair *bp)
Index: linux-2.6.26-rc8-devel/include/linux/bio.h
===================================================================
--- linux-2.6.26-rc8-devel.orig/include/linux/bio.h 2008-07-02 04:20:43.000000000 +0200
+++ linux-2.6.26-rc8-devel/include/linux/bio.h 2008-07-02 04:21:16.000000000 +0200
@@ -86,6 +86,9 @@ struct bio {
/* Number of segments in this BIO after
* physical address coalescing is performed.
+ *
+ * When ending a bio request in bio_endio, this field is temporarily
+ * (ab)used to keep the error code.
*/
unsigned short bi_phys_segments;
next prev parent reply other threads:[~2008-07-02 4:10 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-24 5:22 Mikulas Patocka
2008-06-24 6:08 ` Neil Brown
2008-06-24 14:36 ` Mikulas Patocka
2008-06-24 8:07 ` Jens Axboe
2008-06-24 14:27 ` Mikulas Patocka
2008-06-25 8:24 ` Jens Axboe
2008-06-26 0:13 ` Mikulas Patocka
2008-06-26 7:07 ` Jens Axboe
2008-07-02 4:09 ` Mikulas Patocka [this message]
2008-07-02 8:00 ` Alan Cox
2008-07-03 21:03 ` Mikulas Patocka
2008-07-02 8:25 ` Jens Axboe
2008-07-03 21:08 ` Mikulas Patocka
2008-07-03 21:04 ` Alan Cox
2008-07-03 22:54 ` Mikulas Patocka
2008-07-03 23:00 ` Alan Cox
2008-07-03 23:51 ` Mikulas Patocka
2008-07-03 23:44 ` Alan Cox
2008-07-04 3:26 ` Mikulas Patocka
2008-07-04 8:11 ` Alan Cox
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=Pine.LNX.4.64.0807020001290.9097@engineering.redhat.com \
--to=mpatocka@redhat.com \
--cc=jens.axboe@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=neilb@suse.de \
/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
Powered by JetHome