mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: Neil Brown <neilb@suse.de>
Cc: linux-kernel@vger.kernel.org, axboe@kernel.dk
Subject: Re: [PATCH 1/2] Avoid bio_endio recursion
Date: Tue, 24 Jun 2008 10:36:27 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0806241029120.23052@engineering.redhat.com> (raw)
In-Reply-To: <18528.36687.631672.462076@notabene.brown>



On Tue, 24 Jun 2008, Neil Brown wrote:

> On Tuesday June 24, mpatocka@redhat.com wrote:
>> Hi
>>
>> bio_endio calls bi_end_io callback. In case of stacked devices (raid, dm),
>> bio_end_io may call bio_endio again, up to an unspecified length.
>>
>> The crash because of stack overflow was really observed on sparc64. And
>> this recursion was one of the contributing factors (using 9 stack frames
>> --- that is 1728 bytes).
>>
>> This patch removes the recursion.
>
> This is very cool, thanks!  A close mirror of the recursion
> avoidance in generic_make_request.
>
> You use a per-cpu queue were generic_make_request uses a per-task
> queue.  This is fitting as bi_end_io doesn't have a process context,
> but is supposed to be fast and able to run with interrupts disabled,
> so tying to a cpu is no problem.

Yes. I think "current" variable can't be used in irq context, it would 
blow with irq-stacks (or access some weird unknown memory).

I had another version of the patch that doesn't disable interrupts and 
only disables preempt and uses local_t atomic cpu-local variables. It is 
somehow more tricky, because interrupt can be triggered any time while 
processing the queue and it can add anything to the queue. Then I realized 
that bio_endio runs most time with disabled interrupts anyway, so it'd be 
better to just disable interrupts and don't do that local_cmpxchg 
trickery.

Mikulas

>> +
>> +	bio_queue = NULL;
>> +queue_empty_next_bio:
>> +	*bio_end_queue_ptr = &bio_queue;
>> +next_bio:
>> +
>>   	if (error)
>>   		clear_bit(BIO_UPTODATE, &bio->bi_flags);
>>   	else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
>> @@ -1175,6 +1196,17 @@
>>
>>   	if (bio->bi_end_io)
>>   		bio->bi_end_io(bio, error);
>> +
>> +	if (bio_queue) {
>> +		bio = bio_queue;
>> +		bio_queue = bio->bi_next;
>> +		if (!bio_queue) goto queue_empty_next_bio;
>> +		goto next_bio;
>
> checkpatch.pl doesn't like that:
> ERROR: trailing statements should be on next line
>
> and I don't either.  I would not bother with the mini-optimisation at
> all.
> Discard the queue_empty_next_bio label and replace the "if () goto"
> with
>       if (!bio_queue)
> 		*bio_end_queue_ptr = &bio_queue;
>
> and leave gcc to optimise the assignment if it wants to.
>
> Reviewed-by: NeilBrown <neilb@suse.de>
>
> Thanks,
> NeilBrown
>

  reply	other threads:[~2008-06-24 14:36 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 [this message]
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
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.0806241029120.23052@engineering.redhat.com \
    --to=mpatocka@redhat.com \
    --cc=axboe@kernel.dk \
    --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