From nobody Fri Apr 17 22:01:03 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9018B194A60 for ; Fri, 13 Feb 2026 12:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770986349; cv=none; b=ic6hf3D8HV7Wl9xghiaa3+yPRX5M0ZJv3iH1deaxrH95y8s0VZhnXLI1Bli8msLdv1EQwvW3IcL0vPwjPzGHhbffOp/ZHn+2eVB1Kwj9XR3NkQ52K40Dg/RGbOYdCrF488fteg3k7yGufMjdkMmHuKdCWpFclBDaJiJcvNhfQ6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770986349; c=relaxed/simple; bh=laNa4BER7QFZASdIZfUnttS00mWIh/fuYeeHXj7xcO8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=KJVdFWZoMOrEBXjGcGnqQDoZasHJJaEsez9sEEgUG0U+Kwktxz8vmDtYX1wDR1gW+ndbRdpSl1SgCW+b+f+nt5ErU2/65iRR1s8Y58plnyROiv6B0ZW4Y6KizRTzOQYWk6PY6dHWSzdd5EQQDT7bXI2cx0cTaaDU+gflmf23a34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Iewffj1a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Iewffj1a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AB84C116C6; Fri, 13 Feb 2026 12:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770986349; bh=laNa4BER7QFZASdIZfUnttS00mWIh/fuYeeHXj7xcO8=; h=From:To:Cc:Subject:Date:From; b=Iewffj1ahTP1mCqpsfnFwRscoWq4f6h5zfMRcqNOVSONn+gTfwlnwGuhiYXlz++qa +DtjTZweVklZpK3ft/cdvh6pakHSzWFkzSgtYuU9Ctw92Sd5l6RGVwIGwPMr3iGnFU Usn+yK9GIY3TanxCi/JhSD0zkWWFgfnJ3TTCvk6PCbBprZbUbU94gwR5J8TrlKUEuk JBTGpe7KTlkXWpqttzm386ehH3l9WeVbAuPmar1cFIo25pKKxax3Ga40BkODaHY5Gf T0afnStlLIbfxsxasvATv1gj+575CtIWCDNS2TtLRBU2JKIaiHjgTQxdyy3iXO9ZOY QCLHQ50IPkNcg== From: Arnd Bergmann To: Andrew Morton , Johannes Weiner , Axel Rasmussen , Yuanchu Xie Cc: Arnd Bergmann , Wei Xu , David Hildenbrand , Michal Hocko , Qi Zheng , Shakeel Butt , Lorenzo Stoakes , Baolin Wang , Kairui Song , Davidlohr Bueso , Koichiro Den , Jiayuan Chen , Bertrand Wlodarczyk , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/vmscan: avoid false-positive -Wuninitialized warning Date: Fri, 13 Feb 2026 13:38:56 +0100 Message-Id: <20260213123902.3466040-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnd Bergmann When the -fsanitize=3Dbounds sanitizer is enabled, gcc-16 sometimes runs into a corner case in the read_ctrl_pos() pos function, where it sees possible undefined behavior from the 'tier' index overflowing, presumably in the case that this was called with a negative tier: In function 'get_tier_idx', inlined from 'isolate_folios' at mm/vmscan.c:4671:14: mm/vmscan.c: In function 'isolate_folios': mm/vmscan.c:4645:29: error: 'pv.refaulted' is used uninitialized [-Werror= =3Duninitialized] Part of the problem seems to be that read_ctrl_pos() has unusual calling conventions since commit 37a260870f2c ("mm/mglru: rework type selection") where passing MAX_NR_TIERS makes it accumulate all tiers but passing a smaller positive number makes it read a single tier instead. Avoid this case by splitting read_ctrl_pos() into two separate helpers that each only do one of the two cases. This avoids the warning as far as I can tell, and seems a bit easier to understand to me. Signed-off-by: Arnd Bergmann --- This is currently the only such warning I get from gcc-16.0.1, and none from any other version. I'm not overly happy about having to work around it with a random code chance, but hopefully the version I ended up with makes sense regardless. --- mm/vmscan.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index eaf795c1cfb3..602c955d1f30 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3159,20 +3159,15 @@ struct ctrl_pos { static void read_ctrl_pos(struct lruvec *lruvec, int type, int tier, int g= ain, struct ctrl_pos *pos) { - int i; struct lru_gen_folio *lrugen =3D &lruvec->lrugen; int hist =3D lru_hist_from_seq(lrugen->min_seq[type]); =20 pos->gain =3D gain; - pos->refaulted =3D pos->total =3D 0; - - for (i =3D tier % MAX_NR_TIERS; i <=3D min(tier, MAX_NR_TIERS - 1); i++) { - pos->refaulted +=3D lrugen->avg_refaulted[type][i] + - atomic_long_read(&lrugen->refaulted[hist][type][i]); - pos->total +=3D lrugen->avg_total[type][i] + - lrugen->protected[hist][type][i] + - atomic_long_read(&lrugen->evicted[hist][type][i]); - } + pos->refaulted =3D lrugen->avg_refaulted[type][tier] + + atomic_long_read(&lrugen->refaulted[hist][type][tier]); + pos->total =3D lrugen->avg_total[type][tier] + + lrugen->protected[hist][type][tier] + + atomic_long_read(&lrugen->evicted[hist][type][tier]); } =20 static void reset_ctrl_pos(struct lruvec *lruvec, int type, bool carryover) @@ -4640,6 +4635,24 @@ static int get_tier_idx(struct lruvec *lruvec, int t= ype) return tier - 1; } =20 +static void aggregate_ctrl_pos(struct lruvec *lruvec, int type, int gain, + struct ctrl_pos *pos) +{ + struct lru_gen_folio *lrugen =3D &lruvec->lrugen; + int hist =3D lru_hist_from_seq(lrugen->min_seq[type]); + + pos->gain =3D gain; + pos->refaulted =3D pos->total =3D 0; + + for (int i =3D 0; i < MAX_NR_TIERS; i++) { + pos->refaulted +=3D lrugen->avg_refaulted[type][i] + + atomic_long_read(&lrugen->refaulted[hist][type][i]); + pos->total +=3D lrugen->avg_total[type][i] + + lrugen->protected[hist][type][i] + + atomic_long_read(&lrugen->evicted[hist][type][i]); + } +} + static int get_type_to_scan(struct lruvec *lruvec, int swappiness) { struct ctrl_pos sp, pv; @@ -4653,8 +4666,8 @@ static int get_type_to_scan(struct lruvec *lruvec, in= t swappiness) * Compare the sum of all tiers of anon with that of file to determine * which type to scan. */ - read_ctrl_pos(lruvec, LRU_GEN_ANON, MAX_NR_TIERS, swappiness, &sp); - read_ctrl_pos(lruvec, LRU_GEN_FILE, MAX_NR_TIERS, MAX_SWAPPINESS - swappi= ness, &pv); + aggregate_ctrl_pos(lruvec, LRU_GEN_ANON, swappiness, &sp); + aggregate_ctrl_pos(lruvec, LRU_GEN_FILE, MAX_SWAPPINESS - swappiness, &pv= ); =20 return positive_ctrl_err(&sp, &pv); } --=20 2.39.5