mm: replace custom ratelimiting logic
Subsystems (3)
cover mm: replace custom ratelimiting logic
The kernel has a perfectly cromulent and mostly-equivalent variant in lib/ratelimit.c that can be used.
To: Andrew Morton <[email protected]>
To: David Hildenbrand <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: "Liam R. Howlett" <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Mike Rapoport <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Brendan Jackman <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Zi Yan <[email protected]>
Cc: [email protected]
Cc: [email protected]
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(-)
Signature · 1 line
2.55.0
PATCH 1/2 mm: replace custom bad page map ratelimiting logic
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.
--- mm/memory.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-)
mm/memory.c +3 -27
@@ -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 ;
Signature · 1 line
2.55.0
Re: [PATCH 1/2] mm: replace custom bad page map ratelimiting logic
Quoted 11 lines · Pedro Falcato
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 <[email protected]>
Re: [PATCH 1/2] mm: replace custom bad page map ratelimiting logic
In reply to Pedro FalcatoQuoted 6 lines · Pedro Falcato
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:
Quoted 9 lines
KERN_WARNING"print_bad_page_map: %d callbacks suppressed\n", ...But that should be fine enough.
Signed-off-by Pedro Falcato <[email protected]>--- mm/memory.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-)
Great!
Signature · 2 lines
Best Regards, Yan, Zi
Re: [PATCH 1/2] mm: replace custom bad page map ratelimiting logic
In reply to Pedro FalcatoQuoted 9 lines · On Tue, 11 Aug 2026 18:21:55 +0100 Pedro Falcato <[email protected]> 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.
Nice cleanup, thank you! I also agree the change on the log message should be fine.
Quoted 2 lines
Signed-off-by Pedro Falcato <[email protected]>
Thanks,
SJ
[...]
Re: [PATCH 1/2] mm: replace custom bad page map ratelimiting logic
In reply to Pedro FalcatoQuoted 6 lines · Pedro Falcato
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:
Quoted 6 lines
KERN_WARNING"print_bad_page_map: %d callbacks suppressed\n", ...But that should be fine enough.
Signed-off-by Pedro Falcato <[email protected]>---
Well that's nice!
Signature · 3 lines
Cheers, David
Re: [PATCH 1/2] mm: replace custom bad page map ratelimiting logic
In reply to Pedro FalcatoQuoted 11 lines · Pedro Falcato
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 <[email protected]>
Oh I love this :) seems __ratelimited() uses a try-lock on a spinlock internally but I don't think that's an issue, a spurious not-rate-limted output on any contention isn't really a big problem.
So LGTM and:
Quoted 53 lines
--- mm/memory.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-)mm/memory.c +3
-28@@ -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 ; --
Quoted 2 lines
2.55.0
--
Cheers, Lorenzo
PATCH 2/2 mm/page_alloc: replace custom bad page ratelimiting logic
In reply to Pedro FalcatoThe 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.
--- mm/page_alloc.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-)
mm/page_alloc.c +5 -23
@@ -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));
Signature · 1 line
2.55.0
Re: [PATCH 2/2] mm/page_alloc: replace custom bad page ratelimiting logic
Quoted 11 lines · Pedro Falcato
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 <[email protected]>
Re: [PATCH 2/2] mm/page_alloc: replace custom bad page ratelimiting logic
In reply to Pedro FalcatoQuoted 6 lines · Pedro Falcato
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:
Quoted 9 lines
KERN_WARNING"bad_page: %d callbacks suppressed\n", ...But that should be fine enough.
Signed-off-by Pedro Falcato <[email protected]>--- mm/page_alloc.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-)
LGTM.
Signature · 2 lines
Best Regards, Yan, Zi
Re: [PATCH 2/2] mm/page_alloc: replace custom bad page ratelimiting logic
In reply to Pedro FalcatoQuoted 9 lines · On Tue, 11 Aug 2026 18:21:56 +0100 Pedro Falcato <[email protected]> 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.
I agree that should be fine. This looks good cleanup to me.
Quoted 2 lines
Signed-off-by Pedro Falcato <[email protected]>
Thanks,
SJ
[...]
Re: [PATCH 2/2] mm/page_alloc: replace custom bad page ratelimiting logic
In reply to Pedro FalcatoQuoted 6 lines · Pedro Falcato
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:
Quoted 6 lines
KERN_WARNING"bad_page: %d callbacks suppressed\n", ...But that should be fine enough.
Signed-off-by Pedro Falcato <[email protected]>---
Nice :)
Signature · 3 lines
Cheers, David
Re: [PATCH 2/2] mm/page_alloc: replace custom bad page ratelimiting logic
In reply to Pedro FalcatoQuoted 11 lines · Pedro Falcato
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 <[email protected]>
LGTM so:
Quoted 46 lines
--- mm/page_alloc.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-)mm/page_alloc.c +5
-24@@ -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)); --
Quoted 2 lines
2.55.0
--
Cheers, Lorenzo
Quoted 17 lines · Pedro Falcato
The kernel has a perfectly cromulent and mostly-equivalent variant in
lib/ratelimit.cthat can be used.To: Andrew Morton <[email protected]>
To: David Hildenbrand <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: "Liam R. Howlett" <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Mike Rapoport <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Brendan Jackman <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Zi Yan <[email protected]>
Cc: [email protected]
Cc: [email protected]
Quoted 3 lines
Pedro Falcato (2):
mm: replace custom bad page map ratelimiting logicmm/page_alloc: replace custom bad page ratelimiting logic
For the series:
Quoted 7 lines
mm/memory.c | 30 +++--------------------------- mm/page_alloc.c | 28 +++++----------------------- 2 files changed, 8 insertions(+), 50 deletions(-)Signature · 1 line
2.55.0
Signature · 2 lines
Sincerely yours, Mike.
Quoted 17 lines · Pedro Falcato
The kernel has a perfectly cromulent and mostly-equivalent variant in
lib/ratelimit.cthat can be used.To: Andrew Morton <[email protected]>
To: David Hildenbrand <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: "Liam R. Howlett" <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Mike Rapoport <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Brendan Jackman <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Zi Yan <[email protected]>
Cc: [email protected]
Cc: [email protected]
Quoted 3 lines
Pedro Falcato (2):
mm: replace custom bad page map ratelimiting logicmm/page_alloc: replace custom bad page ratelimiting logic
Cool!
Quoted 5 lines
mm/memory.c | 30 +++--------------------------- mm/page_alloc.c | 28 +++++----------------------- 2 files changed, 8 insertions(+), 50 deletions(-)