[PATCH] mm/debug: optimize once judgment with clang
From: Xie Yuanbin
Date: Mon Mar 09 2026 - 11:41:55 EST
commit 242b872239f6a7deacbc ("include/linux/once_lite.h: fix judgment in
WARN_ONCE with clang") helps optimize performance and size under the
clang compiler, but the modification is not complete.
Port the modification to VM_WARN_ON_ONCE_PAGE(), VM_WARN_ON_ONCE_FOLIO(),
VM_WARN_ON_ONCE_MM() and VM_WARN_ON_ONCE_VMA().
Cc: Mike Rapoport <rppt@xxxxxxxxxx>
Cc: David Laight <david.laight.linux@xxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Xie Yuanbin <qq570070308@xxxxxxxxx>
---
include/linux/mmdebug.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/linux/mmdebug.h b/include/linux/mmdebug.h
index ab60ffba08f5..a167c5aa525e 100644
--- a/include/linux/mmdebug.h
+++ b/include/linux/mmdebug.h
@@ -60,7 +60,7 @@ void vma_iter_dump_tree(const struct vma_iterator *vmi);
static bool __section(".data..once") __warned; \
int __ret_warn_once = !!(cond); \
\
- if (unlikely(__ret_warn_once && !__warned)) { \
+ if (unlikely(__ret_warn_once) && unlikely(!__warned)) { \
dump_page(page, "VM_WARN_ON_ONCE_PAGE(" __stringify(cond)")");\
__warned = true; \
WARN_ON(1); \
@@ -80,7 +80,7 @@ void vma_iter_dump_tree(const struct vma_iterator *vmi);
static bool __section(".data..once") __warned; \
int __ret_warn_once = !!(cond); \
\
- if (unlikely(__ret_warn_once && !__warned)) { \
+ if (unlikely(__ret_warn_once) && unlikely(!__warned)) { \
dump_page(&folio->page, "VM_WARN_ON_ONCE_FOLIO(" __stringify(cond)")");\
__warned = true; \
WARN_ON(1); \
@@ -91,7 +91,7 @@ void vma_iter_dump_tree(const struct vma_iterator *vmi);
static bool __section(".data..once") __warned; \
int __ret_warn_once = !!(cond); \
\
- if (unlikely(__ret_warn_once && !__warned)) { \
+ if (unlikely(__ret_warn_once) && unlikely(!__warned)) { \
dump_mm(mm); \
__warned = true; \
WARN_ON(1); \
@@ -102,7 +102,7 @@ void vma_iter_dump_tree(const struct vma_iterator *vmi);
static bool __section(".data..once") __warned; \
int __ret_warn_once = !!(cond); \
\
- if (unlikely(__ret_warn_once && !__warned)) { \
+ if (unlikely(__ret_warn_once) && unlikely(!__warned)) { \
dump_vma(vma); \
__warned = true; \
WARN_ON(1); \
--
2.53.0