linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/page_alloc: Add lockdep assertion for pageblock type change
@ 2025-02-27 16:15 Brendan Jackman
  2025-02-27 22:33 ` Andrew Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Brendan Jackman @ 2025-02-27 16:15 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Oscar Salvador
  Cc: Johannes Weiner, Vlastimil Babka, linux-mm, linux-kernel,
	Brendan Jackman

Since the migratetype hygiene patches [0], the locking here is
a bit more formalised, so write it down with an assert.

[0] https://lore.kernel.org/lkml/20240320180429.678181-3-hannes@cmpxchg.org/T/

Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
 include/linux/memory_hotplug.h | 1 +
 mm/memory_hotplug.c            | 5 +++++
 mm/page_alloc.c                | 4 ++++
 3 files changed, 10 insertions(+)

diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index eaac5ae8c05c8ee2f2868d5bc1b04d1f68235b3f..ff9511d9b9e6f775feeb4f897754878ac4c8cdb0 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)
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 16cf9e17077e359b98a69dc4bca48f4575b9a28c..2b9d1a6267c0872c433fafe8684dd4e2aa821f5f 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 299c9f10bbcd2aa1d35ac6eb5131a2471da825d5..e0516d70835e20e54ff8e43f3aa884c7e36d929a 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: d58172d128acbafa2295aa17cc96e28260da9a86
change-id: 20250227-pageblock-lockdep-9628c48d7e08

Best regards,
-- 
Brendan Jackman <jackmanb@google.com>



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-03-04 10:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-27 16:15 [PATCH] mm/page_alloc: Add lockdep assertion for pageblock type change Brendan Jackman
2025-02-27 22:33 ` Andrew Morton
2025-02-28  9:20   ` Brendan Jackman
2025-02-28 10:12     ` Vlastimil Babka
2025-02-28 17:31 ` kernel test robot
2025-02-28 18:28   ` Johannes Weiner
2025-03-03 11:18     ` Andy Shevchenko
2025-03-03 23:13       ` Stephen Rothwell
2025-03-04 10:18         ` Brendan Jackman
2025-03-04 10:31           ` David Hildenbrand
2025-02-28 23:42 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox