linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: "Huang, Ying" <ying.huang@intel.com>,
	Mel Gorman <mgorman@techsingularity.net>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>, linux-mm <linux-mm@kvack.org>
Subject: Re: [PATCH v2] mm/page_alloc: don't wake kswapd from rmqueue() unless __GFP_KSWAPD_RECLAIM is specified
Date: Mon, 22 May 2023 22:57:03 +0900	[thread overview]
Message-ID: <65c99fe7-c6b8-aca9-e74a-754d882e64ba@I-love.SAKURA.ne.jp> (raw)
In-Reply-To: <87wn196oew.fsf@yhuang6-desk2.ccr.corp.intel.com>

On 2023/05/16 10:44, Huang, Ying wrote:
> Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> writes:
> 
>> On 2023/05/15 16:38, Mel Gorman wrote:
>>> On Sun, May 14, 2023 at 09:28:56AM +0900, Tetsuo Handa wrote:
>>>> Commit 73444bc4d8f9 ("mm, page_alloc: do not wake kswapd with zone lock
>>>> held") moved wakeup_kswapd() from steal_suitable_fallback() to rmqueue()
>>>> using ZONE_BOOSTED_WATERMARK flag.
>>>>
>>>> Only allocation contexts that include ALLOC_KSWAPD (which corresponds to
>>>> __GFP_KSWAPD_RECLAIM) should wake kswapd, for callers are supposed to
>>>> remove __GFP_KSWAPD_RECLAIM if trying to hold pgdat->kswapd_wait has a
>>>> risk of deadlock.
>>>
>>> kswapd_wait is a waitqueue so what is being held? It's safe for kswapd
>>> to try wake itself as the waitqueue will be active when wakeup_kswapd()
>>> is called so no wakeup occurs. If there is a deadlock, it needs a better
>>> explanation. I believe I already stated why this patch is fixing a bug
>>> but it wasn't deadlock related.
>>>
>>
>> I noticed this problem ( pgdat->kswapd_wait might be held without
>> __GFP_KSWAPD_RECLAIM ) when analyzing a different problem ( debugobject code
>> is holding pgdat->kswapd_wait due to __GFP_KSWAPD_RECLAIM ) reported at
>> https://syzkaller.appspot.com/bug?extid=fe0c72f0ccbb93786380 .
>>
>> I'm calling pgdat->kswapd_wait a lock, as lockdep uses it as a lock name.
> 
> This has confused me much before.  IIUC, the deadlock is unrelated with
> kswapd wakeup itself.  pgdat->kswapd_wait is the lock name and the lock
> in fact is the spinlock: pgdat->kswapd_wait.lock.  So the deadlock is,
> 
> pgdat->kswapd_wait.lock holders take the pi lock
> pi lock holders take the rq lock
> rq lock holders take the timer base lock
> timer base lock holders take the pgdat->kswapd_wait.lock (missing __GFP_KSWAPD_RECLAIM check)

Yes, thank you for explanation.

> 
> The above is based on analysis in
> 
> https://lore.kernel.org/all/20190107204627.GA25526@cmpxchg.org/
> https://lore.kernel.org/linux-mm/d642e597-cf7d-b410-16ce-22dff483fd8e@I-love.SAKURA.ne.jp/
> 
> Tetsuo's patch avoids to take pgdat->kswapd_wait.lock when timer base
> lock is held via adding check for __GFP_KSWAPD_RECLAIM, so breaks the
> circular dependency chain.

Yes. Mel, any questions on this patch?

Thomas Gleixner described this lock as kswapd_wait::lock at
https://lkml.kernel.org/r/168476016890.404.6911447269153588182.tip-bot2@tip-bot2 .
Should I resubmit this patch with s/pgdat->kswapd_wait/pgdat->kswapd_wait.lock/ or
s/pgdat->kswapd_wait/kswapd_wait::lock/ ?

> 
>> The latter was explained at
>> https://lore.kernel.org/linux-mm/d642e597-cf7d-b410-16ce-22dff483fd8e@I-love.SAKURA.ne.jp/
>> and we agreed that debugobject code needs to drop __GFP_KSWAPD_RECLAIM at
>> https://lore.kernel.org/linux-mm/87fs809fwk.ffs@tglx/ .
>>
>> This patch is for making sure that debugobject code will not try to hold
>> pgdat->kswapd_wait after debugobject code dropped __GFP_KSWAPD_RECLAIM.
>>
>> Thus, the problem this patch will fix is a deadlock related, isn't it?
> 
> Best Regards,
> Huang, Ying



  reply	other threads:[~2023-05-22 13:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-11 13:47 [PATCH] mm/page_alloc: don't wake up " Tetsuo Handa
2023-05-12  3:45 ` Andrew Morton
2023-05-13  9:38   ` Tetsuo Handa
2023-05-13 10:23 ` Mel Gorman
2023-05-14  0:28   ` [PATCH v2] mm/page_alloc: don't wake " Tetsuo Handa
2023-05-15  6:03     ` Huang, Ying
2023-05-15  6:35       ` Huang, Ying
2023-05-15  7:38     ` Mel Gorman
2023-05-15 10:17       ` Tetsuo Handa
2023-05-16  1:44         ` Huang, Ying
2023-05-22 13:57           ` Tetsuo Handa [this message]
2023-05-22 14:58             ` Mel Gorman

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=65c99fe7-c6b8-aca9-e74a-754d882e64ba@I-love.SAKURA.ne.jp \
    --to=penguin-kernel@i-love.sakura.ne.jp \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=vbabka@suse.cz \
    --cc=ying.huang@intel.com \
    /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