Re: [PATCH 1/2] mm: replace custom bad page map ratelimiting logic

"Lorenzo Stoakes (ARM)" <[email protected]>
Newsgroups org.kvack.linux-mm,org.kernel.vger.linux-kernel
Message-ID <an2juJMHR8r09q5u@lucifer>
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 <[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:

Reviewed-by: Lorenzo Stoakes (ARM) <[email protected]>

> ---
>  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
>

--
Cheers, Lorenzo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.