* [PATCH 0/2] mm: replace custom ratelimiting logic
@ 2026-08-11 17:21 Pedro Falcato
2026-08-11 17:21 ` [PATCH 1/2] mm: replace custom bad page map " Pedro Falcato
2026-08-11 17:21 ` [PATCH 2/2] mm/page_alloc: replace custom bad page " Pedro Falcato
0 siblings, 2 replies; 7+ messages in thread
From: Pedro Falcato @ 2026-08-11 17:21 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Pedro Falcato, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, linux-mm, linux-kernel
The kernel has a perfectly cromulent and mostly-equivalent variant in
lib/ratelimit.c that can be used.
To: Andrew Morton <akpm@linux-foundation.org>
To: David Hildenbrand <david@kernel.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: "Liam R. Howlett" <liam@infradead.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Brendan Jackman <brendan.jackman@linux.dev>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Zi Yan <ziy@nvidia.com>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Pedro Falcato (2):
mm: replace custom bad page map ratelimiting logic
mm/page_alloc: replace custom bad page ratelimiting logic
mm/memory.c | 30 +++---------------------------
mm/page_alloc.c | 28 +++++-----------------------
2 files changed, 8 insertions(+), 50 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] mm: replace custom bad page map ratelimiting logic
2026-08-11 17:21 [PATCH 0/2] mm: replace custom ratelimiting logic Pedro Falcato
@ 2026-08-11 17:21 ` Pedro Falcato
2026-08-11 19:13 ` Johannes Weiner
2026-08-11 19:37 ` Zi Yan
2026-08-11 17:21 ` [PATCH 2/2] mm/page_alloc: replace custom bad page " Pedro Falcato
1 sibling, 2 replies; 7+ messages in thread
From: Pedro Falcato @ 2026-08-11 17:21 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Pedro Falcato, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, linux-mm, linux-kernel
The current logic (allow up to $BURST prints per minute) can be entirely
replaced by the generic version in lib/ratelimit.c, used around the kernel.
Do so. The only functional difference should be that the new logs will
read something like:
KERN_WARNING "print_bad_page_map: %d callbacks suppressed\n", ...
But that should be fine enough.
Signed-off-by: Pedro Falcato <pfalcato@suse.de>
---
mm/memory.c | 30 +++---------------------------
1 file changed, 3 insertions(+), 27 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index 4134ac607ee0..b4be57b590ce 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -492,32 +492,8 @@ static inline void add_mm_rss_vec(struct mm_struct *mm, int *rss)
add_mm_counter(mm, i, rss[i]);
}
-static bool is_bad_page_map_ratelimited(void)
-{
- static unsigned long resume;
- static unsigned long nr_shown;
- static unsigned long nr_unshown;
-
- /*
- * Allow a burst of 60 reports, then keep quiet for that minute;
- * or allow a steady drip of one report per second.
- */
- if (nr_shown == 60) {
- if (time_before(jiffies, resume)) {
- nr_unshown++;
- return true;
- }
- if (nr_unshown) {
- pr_alert("BUG: Bad page map: %lu messages suppressed\n",
- nr_unshown);
- nr_unshown = 0;
- }
- nr_shown = 0;
- }
- if (nr_shown++ == 0)
- resume = jiffies + 60 * HZ;
- return false;
-}
+/* Allow a burst of 60 bad page map reports per minute. */
+static DEFINE_RATELIMIT_STATE(bad_page_map_ratelimit, 60 * HZ, 60);
static void ptval_bytes_to_hex_str(char *buf, size_t buf_size, const void *entry, size_t entry_size)
{
@@ -633,7 +609,7 @@ static void print_bad_page_map(struct vm_area_struct *vma,
char entry_str[PTVAL_STR_MAX];
pgoff_t index, anon_index;
- if (is_bad_page_map_ratelimited())
+ if (!__ratelimit(&bad_page_map_ratelimit))
return;
mapping = vma->vm_file ? vma->vm_file->f_mapping : NULL;
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] mm/page_alloc: replace custom bad page ratelimiting logic
2026-08-11 17:21 [PATCH 0/2] mm: replace custom ratelimiting logic Pedro Falcato
2026-08-11 17:21 ` [PATCH 1/2] mm: replace custom bad page map " Pedro Falcato
@ 2026-08-11 17:21 ` Pedro Falcato
2026-08-11 19:13 ` Johannes Weiner
2026-08-11 19:39 ` Zi Yan
1 sibling, 2 replies; 7+ messages in thread
From: Pedro Falcato @ 2026-08-11 17:21 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Pedro Falcato, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, linux-mm, linux-kernel
The current logic (allow up to $BURST prints per minute) can be entirely
replaced by the generic version in lib/ratelimit.c, used around the kernel.
Do so. The only functional difference should be that the new logs will
read something like:
KERN_WARNING "bad_page: %d callbacks suppressed\n", ...
But that should be fine enough.
Signed-off-by: Pedro Falcato <pfalcato@suse.de>
---
mm/page_alloc.c | 28 +++++-----------------------
1 file changed, 5 insertions(+), 23 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 12fac9084c48..9ccfd87bc273 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -613,31 +613,13 @@ static inline bool __maybe_unused bad_range(struct zone *zone, struct page *page
}
#endif
+/* Allow a burst of 60 reports per minute */
+static DEFINE_RATELIMIT_STATE(bad_page_ratelimit, 60 * HZ, 60);
+
static void bad_page(struct page *page, const char *reason)
{
- static unsigned long resume;
- static unsigned long nr_shown;
- static unsigned long nr_unshown;
-
- /*
- * Allow a burst of 60 reports, then keep quiet for that minute;
- * or allow a steady drip of one report per second.
- */
- if (nr_shown == 60) {
- if (time_before(jiffies, resume)) {
- nr_unshown++;
- goto out;
- }
- if (nr_unshown) {
- pr_alert(
- "BUG: Bad page state: %lu messages suppressed\n",
- nr_unshown);
- nr_unshown = 0;
- }
- nr_shown = 0;
- }
- if (nr_shown++ == 0)
- resume = jiffies + 60 * HZ;
+ if (!__ratelimit(&bad_page_ratelimit))
+ goto out;
pr_alert("BUG: Bad page state in process %s pfn:%05lx\n",
current->comm, page_to_pfn(page));
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] mm: replace custom bad page map ratelimiting logic
2026-08-11 17:21 ` [PATCH 1/2] mm: replace custom bad page map " Pedro Falcato
@ 2026-08-11 19:13 ` Johannes Weiner
2026-08-11 19:37 ` Zi Yan
1 sibling, 0 replies; 7+ messages in thread
From: Johannes Weiner @ 2026-08-11 19:13 UTC (permalink / raw)
To: Pedro Falcato
Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan,
linux-mm, linux-kernel
On Tue, Aug 11, 2026 at 06:21:55PM +0100, Pedro Falcato wrote:
> The current logic (allow up to $BURST prints per minute) can be entirely
> replaced by the generic version in lib/ratelimit.c, used around the kernel.
>
> Do so. The only functional difference should be that the new logs will
> read something like:
>
> KERN_WARNING "print_bad_page_map: %d callbacks suppressed\n", ...
>
> But that should be fine enough.
>
> Signed-off-by: Pedro Falcato <pfalcato@suse.de>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] mm/page_alloc: replace custom bad page ratelimiting logic
2026-08-11 17:21 ` [PATCH 2/2] mm/page_alloc: replace custom bad page " Pedro Falcato
@ 2026-08-11 19:13 ` Johannes Weiner
2026-08-11 19:39 ` Zi Yan
1 sibling, 0 replies; 7+ messages in thread
From: Johannes Weiner @ 2026-08-11 19:13 UTC (permalink / raw)
To: Pedro Falcato
Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan,
linux-mm, linux-kernel
On Tue, Aug 11, 2026 at 06:21:56PM +0100, Pedro Falcato wrote:
> The current logic (allow up to $BURST prints per minute) can be entirely
> replaced by the generic version in lib/ratelimit.c, used around the kernel.
>
> Do so. The only functional difference should be that the new logs will
> read something like:
>
> KERN_WARNING "bad_page: %d callbacks suppressed\n", ...
>
> But that should be fine enough.
>
> Signed-off-by: Pedro Falcato <pfalcato@suse.de>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] mm: replace custom bad page map ratelimiting logic
2026-08-11 17:21 ` [PATCH 1/2] mm: replace custom bad page map " Pedro Falcato
2026-08-11 19:13 ` Johannes Weiner
@ 2026-08-11 19:37 ` Zi Yan
1 sibling, 0 replies; 7+ messages in thread
From: Zi Yan @ 2026-08-11 19:37 UTC (permalink / raw)
To: Pedro Falcato, Andrew Morton, David Hildenbrand
Cc: Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, linux-mm, linux-kernel
On Tue Aug 11, 2026 at 1:21 PM EDT, Pedro Falcato wrote:
> The current logic (allow up to $BURST prints per minute) can be entirely
> replaced by the generic version in lib/ratelimit.c, used around the kernel.
>
> Do so. The only functional difference should be that the new logs will
> read something like:
>
> KERN_WARNING "print_bad_page_map: %d callbacks suppressed\n", ...
>
> But that should be fine enough.
>
> Signed-off-by: Pedro Falcato <pfalcato@suse.de>
> ---
> mm/memory.c | 30 +++---------------------------
> 1 file changed, 3 insertions(+), 27 deletions(-)
>
Great!
Acked-by: Zi Yan <ziy@nvidia.com>
--
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] mm/page_alloc: replace custom bad page ratelimiting logic
2026-08-11 17:21 ` [PATCH 2/2] mm/page_alloc: replace custom bad page " Pedro Falcato
2026-08-11 19:13 ` Johannes Weiner
@ 2026-08-11 19:39 ` Zi Yan
1 sibling, 0 replies; 7+ messages in thread
From: Zi Yan @ 2026-08-11 19:39 UTC (permalink / raw)
To: Pedro Falcato, Andrew Morton, David Hildenbrand
Cc: Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, linux-mm, linux-kernel
On Tue Aug 11, 2026 at 1:21 PM EDT, Pedro Falcato wrote:
> The current logic (allow up to $BURST prints per minute) can be entirely
> replaced by the generic version in lib/ratelimit.c, used around the kernel.
>
> Do so. The only functional difference should be that the new logs will
> read something like:
>
> KERN_WARNING "bad_page: %d callbacks suppressed\n", ...
>
> But that should be fine enough.
>
> Signed-off-by: Pedro Falcato <pfalcato@suse.de>
> ---
> mm/page_alloc.c | 28 +++++-----------------------
> 1 file changed, 5 insertions(+), 23 deletions(-)
>
LGTM.
Acked-by: Zi Yan <ziy@nvidia.com>
--
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-08-11 19:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-11 17:21 [PATCH 0/2] mm: replace custom ratelimiting logic Pedro Falcato
2026-08-11 17:21 ` [PATCH 1/2] mm: replace custom bad page map " Pedro Falcato
2026-08-11 19:13 ` Johannes Weiner
2026-08-11 19:37 ` Zi Yan
2026-08-11 17:21 ` [PATCH 2/2] mm/page_alloc: replace custom bad page " Pedro Falcato
2026-08-11 19:13 ` Johannes Weiner
2026-08-11 19:39 ` Zi Yan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox