From: Pavel Tatashin <pasha.tatashin@oracle.com>
To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com,
pasha.tatashin@oracle.com, m.mizuma@jp.fujitsu.com,
akpm@linux-foundation.org, mhocko@suse.com,
catalin.marinas@arm.com, takahiro.akashi@linaro.org,
gi-oh.kim@profitbricks.com, heiko.carstens@de.ibm.com,
baiyaowei@cmss.chinamobile.com, richard.weiyang@gmail.com,
paul.burton@mips.com, miles.chen@mediatek.com, vbabka@suse.cz,
mgorman@suse.de, hannes@cmpxchg.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH] mm: might_sleep warning
Date: Tue, 6 Mar 2018 14:20:22 -0500 [thread overview]
Message-ID: <20180306192022.28289-1-pasha.tatashin@oracle.com> (raw)
Robot reported this issue:
https://lkml.org/lkml/2018/2/27/851
That is introduced by:
mm: initialize pages on demand during boot
The problem is caused by changing static branch value within spin lock.
Spin lock disables preemption, and changing static branch value takes
mutex lock in its path, and thus may sleep.
The fix is to add another boolean variable to avoid the need to change
static branch within spinlock.
Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com>
---
mm/page_alloc.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index b337a026007c..52edc6695b2b 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1579,6 +1579,7 @@ static int __init deferred_init_memmap(void *data)
* page_alloc_init_late() soon after smp_init() is complete.
*/
static __initdata DEFINE_SPINLOCK(deferred_zone_grow_lock);
+static bool deferred_zone_grow __initdata = true;
static DEFINE_STATIC_KEY_TRUE(deferred_pages);
/*
@@ -1616,7 +1617,7 @@ deferred_grow_zone(struct zone *zone, unsigned int order)
* Bail if we raced with another thread that disabled on demand
* initialization.
*/
- if (!static_branch_unlikely(&deferred_pages)) {
+ if (!static_branch_unlikely(&deferred_pages) || !deferred_zone_grow) {
spin_unlock_irqrestore(&deferred_zone_grow_lock, flags);
return false;
}
@@ -1683,10 +1684,15 @@ void __init page_alloc_init_late(void)
/*
* We are about to initialize the rest of deferred pages, permanently
* disable on-demand struct page initialization.
+ *
+ * Note: it is prohibited to modify static branches in non-preemptible
+ * context. Since, spin_lock() disables preemption, we must use an
+ * extra boolean deferred_zone_grow.
*/
spin_lock(&deferred_zone_grow_lock);
- static_branch_disable(&deferred_pages);
+ deferred_zone_grow = false;
spin_unlock(&deferred_zone_grow_lock);
+ static_branch_disable(&deferred_pages);
/* There will be num_node_state(N_MEMORY) threads */
atomic_set(&pgdat_init_n_undone, num_node_state(N_MEMORY));
--
2.16.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next reply other threads:[~2018-03-06 19:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-06 19:20 Pavel Tatashin [this message]
2018-03-06 20:36 ` Andrew Morton
2018-03-06 20:48 ` Pavel Tatashin
2018-03-06 20:56 ` Andrew Morton
2018-03-06 21:04 ` Pavel Tatashin
2018-03-06 21:21 ` Andrew Morton
2018-03-06 21:48 ` Pavel Tatashin
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=20180306192022.28289-1-pasha.tatashin@oracle.com \
--to=pasha.tatashin@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baiyaowei@cmss.chinamobile.com \
--cc=catalin.marinas@arm.com \
--cc=daniel.m.jordan@oracle.com \
--cc=gi-oh.kim@profitbricks.com \
--cc=hannes@cmpxchg.org \
--cc=heiko.carstens@de.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=m.mizuma@jp.fujitsu.com \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=miles.chen@mediatek.com \
--cc=paul.burton@mips.com \
--cc=richard.weiyang@gmail.com \
--cc=steven.sistare@oracle.com \
--cc=takahiro.akashi@linaro.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