Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1390402

Re: [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively

From Mikulas Patocka <mpatocka@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively
Date 2016-04-28 19:00 +0200
Message-ID <rsXsf-74R-17@gated-at.bofh.it> (permalink)
References (1 earlier) <rsIMy-2Nw-13@gated-at.bofh.it> <rsW39-5Ij-51@gated-at.bofh.it> <rsWwa-5ZT-7@gated-at.bofh.it> <rsWwa-5ZT-5@gated-at.bofh.it> <rsWPH-6Ft-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



On Fri, 29 Apr 2016, Ming Lei wrote:

> On Thu, Apr 28, 2016 at 11:58 PM, Mikulas Patocka <mpatocka@redhat.com> wrote:
> >
> >
> > On Thu, 28 Apr 2016, Ming Lei wrote:
> >
> >> Hi Mikulas,
> >>
> >> On Thu, Apr 28, 2016 at 11:29 PM, Mikulas Patocka <mpatocka@redhat.com> wrote:
> >> >
> >> >
> >> > On Thu, 28 Apr 2016, Ming Lei wrote:
> >> >
> >> >> There were reports about heavy stack use by recursive calling
> >> >> .bi_end_io()([1][2][3]). For example, more than 16K stack is
> >> >> consumed in a single bio complete path[3], and in [2] stack
> >> >> overflow can be triggered if 20 nested dm-crypt is used.
> >> >>
> >> >> Also patches[1] [2] [3] were posted for addressing the issue,
> >> >> but never be merged. And the idea in these patches is basically
> >> >> similar, all serializes the recursive calling of .bi_end_io() by
> >> >> percpu list.
> >> >>
> >> >> This patch still takes the same idea, but uses bio_list to
> >> >> implement it, which turns out more simple and the code becomes
> >> >> more readable meantime.
> >> >>
> >> >> One corner case which wasn't covered before is that
> >> >> bi_endio() may be scheduled to run in process context(such
> >> >> as btrfs), and this patch just bypasses the optimizing for
> >> >> that case because one new context should have enough stack space,
> >> >> and this approach isn't capable of optimizing it too because
> >> >> there isn't easy way to get a per-task linked list head.
> >> >
> >> > Hi
> >> >
> >> > You could use preempt_disable() and then you could use per-cpu list even
> >> > in the process context.
> >>
> >> Image why the .bi_end_io() is scheduled to process context, and the only
> >> workable/simple way I thought of is to use per-task list because it may sleep.
> >
> > The bi_end_io callback should not sleep, even if it is called from the
> > process context.
> 
> If it shouldn't sleep, why is it scheduled to run in process context by paying
> extra context switch cost?

Some device mapper (and other) drivers use a worker thread to process 
bios. So the bio may be finished from the worker thread. It would be 
advantageous to prevent stack overflow even in this case.

> And you can find that btrfs_subio_endio_read() does sleep for checksum stuff.

I'm not an expert on btrfs. What happens if it is called from an 
interrupt? Do you have an actual stracktrace when this function is called 
from bio_endio and when it sleeps?

> Thanks,
> Ming

Mikulas

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v3 1/3] fs: direct-io: handle error in dio_end_io() Ming Lei <ming.lei@canonical.com> - 2016-04-28 03:20 +0200
  [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively Ming Lei <ming.lei@canonical.com> - 2016-04-28 03:20 +0200
    Re: [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively Mikulas Patocka <mpatocka@redhat.com> - 2016-04-28 17:30 +0200
      Re: [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively Mikulas Patocka <mpatocka@redhat.com> - 2016-04-28 18:00 +0200
        Re: [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively Ming Lei <ming.lei@canonical.com> - 2016-04-28 18:20 +0200
          Re: [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively Mikulas Patocka <mpatocka@redhat.com> - 2016-04-28 19:00 +0200
            Re: [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively Ming Lei <ming.lei@canonical.com> - 2016-04-29 08:00 +0200
              Re: [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively Mikulas Patocka <mpatocka@redhat.com> - 2016-04-29 10:50 +0200
                Re: [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively Ming Lei <ming.lei@canonical.com> - 2016-04-29 11:40 +0200
                Re: [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively Mikulas Patocka <mpatocka@redhat.com> - 2016-04-29 12:00 +0200
      Re: [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively Ming Lei <ming.lei@canonical.com> - 2016-04-28 18:00 +0200
    Re: [PATCH v3 3/3] block: avoid to call .bi_end_io() recursively Jens Axboe <axboe@kernel.dk> - 2016-05-02 18:30 +0200

csiph-web