linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dong Aisheng <dongas86@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Dong Aisheng <aisheng.dong@nxp.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org, shawnguo@kernel.org,
	linux-imx@nxp.com,  m.szyprowski@samsung.com,
	lecopzer.chen@mediatek.com, david@redhat.com,  vbabka@suse.cz,
	stable@vger.kernel.org, shijie.qin@nxp.com
Subject: Re: [PATCH v3 1/2] mm: cma: fix allocation may fail sometimes
Date: Thu, 17 Mar 2022 11:49:16 +0800	[thread overview]
Message-ID: <CAA+hA=QEtxeCZX7K+sW0KUZbErjr9NFMN6ZaidaXCL+1m6=F+w@mail.gmail.com> (raw)
In-Reply-To: <20220316140904.513fe0e8180b4e3fcad24e3b@linux-foundation.org>

On Thu, Mar 17, 2022 at 5:09 AM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Wed, 16 Mar 2022 11:41:37 +0800 Dong Aisheng <dongas86@gmail.com> wrote:
>
> > On Wed, Mar 16, 2022 at 6:58 AM Andrew Morton <akpm@linux-foundation.org> wrote:
> > >
> > > On Tue, 15 Mar 2022 22:45:20 +0800 Dong Aisheng <aisheng.dong@nxp.com> wrote:
> > >
> > > > --- a/mm/cma.c
> > > > +++ b/mm/cma.c
> > > >
> > > > ...
> > > >
> > > > @@ -457,6 +458,16 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
> > > >                               offset);
> > > >               if (bitmap_no >= bitmap_maxno) {
> > > >                       spin_unlock_irq(&cma->lock);
> > > > +                     pr_debug("%s(): alloc fail, retry loop %d\n", __func__, loop++);
> > > > +                     /*
> > > > +                      * rescan as others may finish the memory migration
> > > > +                      * and quit if no available CMA memory found finally
> > > > +                      */
> > > > +                     if (start) {
> > > > +                             schedule();
> > > > +                             start = 0;
> > > > +                             continue;
> > > > +                     }
> > > >                       break;
> > >
> > > The schedule() is problematic. For a start, we'd normally use
> > > cond_resched() here, so we avoid calling the more expensive schedule()
> > > if we know it won't perform any action.
> > >
> > > But cond_resched() is problematic if this thread has realtime
> > > scheduling policy and the process we're waiting on does not.  One way
> > > to address that is to use an unconditional msleep(1), but that's still
> > > just a hack.
> > >
> >
> > I think we can simply drop schedule() here during the second round of retry
> > as the estimated delay may not be really needed.
>
> That will simply cause a tight loop, so I'm obviously not understanding
> the proposal.
>

IIUC the original code is already a tight loop, isn't it?
You could also see my observation, thousands of retries, in patch 2.
The logic in this patch is just retry the original loop in case in case there's
a false possive error return.

Or you mean infinite loop? The loop will break out when meet an non EBUSY
error in alloc_contig_range().

BTW, the tight loop situation could be improved a lot by my patch 2.

And after Zi Yan's patchset [1] got merged, the situation could be
further improved by retring in pageblock step.
1. [v7,0/5] Use pageblock_order for cma and alloc_contig_range
alignment. - Patchwork (kernel.org)

So generally i wonder it seems still better than simply revert.
Please fix me if i still missed something.

Regards
Aisheng


  reply	other threads:[~2022-03-17  3:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15 14:45 [PATCH v3 0/2] mm: fix cma allocation " Dong Aisheng
2022-03-15 14:45 ` [PATCH v3 1/2] mm: cma: fix allocation may " Dong Aisheng
2022-03-15 22:58   ` Andrew Morton
2022-03-16  3:41     ` Dong Aisheng
2022-03-16 21:09       ` Andrew Morton
2022-03-17  3:49         ` Dong Aisheng [this message]
2022-03-17 10:55   ` David Hildenbrand
2022-03-17 14:26     ` Dong Aisheng
2022-03-17 17:12       ` Minchan Kim
2022-03-18  3:43         ` Dong Aisheng
2022-03-18 16:20           ` Minchan Kim
2022-05-04 15:52             ` Dong Aisheng
2022-05-04 23:25               ` Minchan Kim
2022-03-15 14:45 ` [PATCH v3 2/2] mm: cma: try next MAX_ORDER_NR_PAGES during retry Dong Aisheng

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='CAA+hA=QEtxeCZX7K+sW0KUZbErjr9NFMN6ZaidaXCL+1m6=F+w@mail.gmail.com' \
    --to=dongas86@gmail.com \
    --cc=aisheng.dong@nxp.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=lecopzer.chen@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=m.szyprowski@samsung.com \
    --cc=shawnguo@kernel.org \
    --cc=shijie.qin@nxp.com \
    --cc=stable@vger.kernel.org \
    --cc=vbabka@suse.cz \
    /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