From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEF7040F723 for ; Thu, 13 Aug 2026 11:30:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786620613; cv=none; b=eeMdtKCBzzJGwZ7BK/++vlOoCK8stR+5/YOUDRWXitI7ROh6Oxkm/mkZ87Lb2/APjnYrIpqfTp/cy/GAxj1Lbl5cGR+ZZvJs3JsW3xquORCQ4hcRxpoddXD+i5iQxTZWW6jf3+ToWSiZLYmFEaZwRLP5HGegyrdlC2Gv8L5OghA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786620613; c=relaxed/simple; bh=RIafp6cXjvZPhjP8tZX1xiMyQWb76KeM2wLsec6g/Q0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=H/kWvG1siCql6Fl2Gsfc6E9m7fMpC4kMsXdzA10UQhQJhrAWQ18Y8h6zPoB7EDIc1T3+efRKC4nJi/9B5cLOBA826X8bk0jzUSC+qvJi3szoc5uv96EFUUMLrQUQLT8kHpj4qK48aZiVST6BBkmGLXFCsaVPBXGGIm2dOez1usY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bIIYvDgu; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bIIYvDgu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 515911F000E9; Thu, 13 Aug 2026 11:30:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786620610; bh=l9aopBS7WCREPco4Au3BJaWnHNfNUNrAPzSVqlHVLHo=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=bIIYvDgubqyEPdnlOWTu+Ja15dC+1f7Tr2+yhC4Y5fv7Nej555T05u/p0Wyfm9C43 GM3rOb8V+MA094qoew/BBBOo0wyXDOc3DKe3Y+yV28mZ1L1Anv8grTI7pGOfMrpDPG zE15h/BoP7UPMsxQGHg7KNO596rp+ufNqFnKkFGu75mTM1gO38FneofbDbyWoM5Zby x2EB1SxvmPhDdae9aXThdHuADsUzEHeYzNaZEgJK+G+x59zQL4YmHMoj0kyai1Ej1B I2aDuWT5tOB8uf+cEf6hDBVNqApz/4QtYzmJkzqRC9pxpnGItt4uJu+UREOF1tVUUH UkTdVZT0+d62A== Date: Thu, 13 Aug 2026 12:29:50 +0100 From: "Lorenzo Stoakes (ARM)" To: Pedro Falcato Cc: Andrew Morton , David Hildenbrand , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] mm: replace custom bad page map ratelimiting logic Message-ID: References: <20260811172156.356053-1-pfalcato@suse.de> <20260811172156.356053-2-pfalcato@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260811172156.356053-2-pfalcato@suse.de> 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 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) > --- > 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