From: Brendan Jackman <jackmanb@google.com>
To: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@redhat.com>,
Oscar Salvador <osalvador@suse.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
Vlastimil Babka <vbabka@suse.cz>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Brendan Jackman <jackmanb@google.com>
Subject: [PATCH v2] mm/page_alloc: Add lockdep assertion for pageblock type change
Date: Mon, 03 Mar 2025 12:13:26 +0000 [thread overview]
Message-ID: <20250303-pageblock-lockdep-v2-1-3fc0c37e9532@google.com> (raw)
Since the migratetype hygiene patches [0], the locking here is
a bit more formalised.
For other stuff, it's pretty obvious that it would be protected by the
zone lock. But it didn't seem totally self-evident that it should
protect the pageblock type. So it seems particularly helpful to have it
written in the code.
[0] https://lore.kernel.org/lkml/20240320180429.678181-3-hannes@cmpxchg.org/T/
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
Note Vlastimil Acked the first version, I did not carry his ack since
I've changed the diff. Not sure if I'm being overly pedantic there?
Changes in v2:
- Fixed missing in_mem_hotplug() setup for !CONFIG_MEMORY_HOTPLUG
- Expanded commit message to include a bit more rationale
- Link to v1: https://lore.kernel.org/r/20250227-pageblock-lockdep-v1-1-3701efb331bb@google.com
---
include/linux/memory_hotplug.h | 5 +++++
mm/memory_hotplug.c | 5 +++++
mm/page_alloc.c | 4 ++++
3 files changed, 14 insertions(+)
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index eaac5ae8c05c8ee2f2868d5bc1b04d1f68235b3f..508a1d074527a3349c1c9789ecf35d5ab08a5ba6 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -175,6 +175,7 @@ void put_online_mems(void);
void mem_hotplug_begin(void);
void mem_hotplug_done(void);
+bool in_mem_hotplug(void);
/* See kswapd_is_running() */
static inline void pgdat_kswapd_lock(pg_data_t *pgdat)
@@ -223,6 +224,10 @@ static inline void put_online_mems(void) {}
static inline void mem_hotplug_begin(void) {}
static inline void mem_hotplug_done(void) {}
+static inline bool in_mem_hotplug(void)
+{
+ return false;
+}
static inline bool movable_node_is_enabled(void)
{
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index e3655f07dd6e33efb3e811cab07f240649487441..c44c2765b21f1e9e4b2d68abda9ac161fb2869ec 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -267,6 +267,11 @@ void mem_hotplug_done(void)
cpus_read_unlock();
}
+bool in_mem_hotplug(void)
+{
+ return percpu_is_write_locked(&mem_hotplug_lock);
+}
+
u64 max_mem_size = U64_MAX;
/* add this memory to iomem resource */
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 579789600a3c7bfb7b0d847d51af702a9d4b139a..1ed21179676d05c66f77f9dbebf88e36bbe402e9 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -417,6 +417,10 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags,
void set_pageblock_migratetype(struct page *page, int migratetype)
{
+ lockdep_assert_once(system_state == SYSTEM_BOOTING ||
+ in_mem_hotplug() ||
+ lockdep_is_held(&page_zone(page)->lock));
+
if (unlikely(page_group_by_mobility_disabled &&
migratetype < MIGRATE_PCPTYPES))
migratetype = MIGRATE_UNMOVABLE;
---
base-commit: 83c34e70d8dd67525c2547e8c5ee1a4bf37ac06b
change-id: 20250227-pageblock-lockdep-9628c48d7e08
Best regards,
--
Brendan Jackman <jackmanb@google.com>
next reply other threads:[~2025-03-03 12:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-03 12:13 Brendan Jackman [this message]
2025-03-03 13:11 ` David Hildenbrand
2025-03-03 13:48 ` David Hildenbrand
2025-03-03 13:55 ` Brendan Jackman
2025-03-03 14:06 ` David Hildenbrand
2025-03-03 16:00 ` Brendan Jackman
2025-03-03 17:06 ` David Hildenbrand
2025-03-04 12:50 ` Brendan Jackman
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=20250303-pageblock-lockdep-v2-1-3fc0c37e9532@google.com \
--to=jackmanb@google.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=osalvador@suse.de \
--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