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 EB5A037D131 for ; Fri, 21 Aug 2026 10:26:27 +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=1787307994; cv=none; b=c9OYUgUMXyXxiH9ex08VaFE4XQ7HdrTIH7Xxrn3gEQ02BuATMeB1rM2FMuRiC4/kun4lXF0KerA2S37NsghKwu5+Oe9qwNY24lRSEEHo0FmiA8y/At2kQ70+ordGGvfcFXPCgdbuCFNqHpotihKKxlfkW1K/Z5aJey/DPcmt4V4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787307994; c=relaxed/simple; bh=9RQZ2saCVCXg+gV6puYyA4G+l5ZtffcHSGbbMakqqzg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rU/dnXV9wt87MmAUpQrW1M4bgwFC6IrvoDRsw4Gm982LRthV80uzApA8SkZCT6o04FTXDhxjAxzUx22v48Nmms8EkvKf7+1k5eaAbOqt7ItnkRvCAosETMKaUnBMVpB1kago9IBgzLxQc6elsGBGZX3fmXtGSEkarDU3unHPVZQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iF+sSeP3; 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="iF+sSeP3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A11C61F00A3D; Fri, 21 Aug 2026 10:26:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787307986; bh=xaIllxSu2Y9u0+sAmWxSLKA+YkGfX6Fr0GdsHrBYVUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iF+sSeP3VoDwF86my97C70bwVVWVkjD5QSlZlwlruiEgMQBn/wy4kKdvZxjcR0zf3 A7I6SU/Zc44/mWsYmI1/wNYCD+kqtBjXd8SV+Gt+1qcvjl+0so/AZyoLkULtlkc4i+ Va6Shven2L5OX538x0k7mskcxIQIel19UF43jFTDu/ka1e635+7jped0IeMdt7zC7r ES32xrFLVvOKt8/Gn1G8HlYjR4bFLp3qFI8hXJ3MpEj4MG5eITovty9B6ksi+FEu1g 1R4t7tARNjrks8gs45n5MDZFwGQgQGvpwQFmgRrVCNEAomavSljfze0nWzH1V4np0U jOoythJbV4TXQ== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: axelrasmussen@google.com, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, chenridong@xiaomi.com, david@kernel.org, hannes@cmpxchg.org, kasong@tencent.com, lianux.mm@gmail.com, linux-kernel@vger.kernel.org, ljs@kernel.org, lyugaofei@xiaomi.com, mhocko@kernel.org, qi.zheng@linux.dev, shakeel.butt@linux.dev, stevensd@chromium.org, wangzicheng@honor.com, weixugc@google.com, yuanchu@google.com, zhangbo56@xiaomi.com, "Barry Song (Xiaomi)" Subject: [PATCH 2/6] mm/mglru: batch update lrugen->protected in inc_min_seq() Date: Fri, 21 Aug 2026 18:25:34 +0800 Message-Id: <20260821102538.22642-3-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260821102538.22642-1-baohua@kernel.org> References: <20260821102538.22642-1-baohua@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Avoid updating lrugen->protected with WRITE_ONCE() for each folio, which may prevent potential compiler optimizations. Accumulate the updates locally and apply them in a batch instead. Signed-off-by: Barry Song (Xiaomi) --- mm/vmscan.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 0d74fc00abd3..99ee3c833d54 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3931,7 +3931,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) /* prevent cold/hot inversion if the type is evictable */ for (zone = 0; zone < MAX_NR_ZONES; zone++) { struct list_head *head = &lrugen->folios[old_gen][type][zone]; - unsigned long delta = 0; + unsigned long protected[MAX_NR_TIERS] = {}, delta = 0; while (!list_empty(head)) { struct folio *folio = lru_to_folio(head); @@ -3953,8 +3953,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) if (refs + workingset != BIT(LRU_REFS_WIDTH) + 1) { int tier = lru_tier_from_refs(refs, workingset); - WRITE_ONCE(lrugen->protected[hist][type][tier], - lrugen->protected[hist][type][tier] + nr_pages); + protected[tier] += nr_pages; } if (!--remaining) @@ -3964,6 +3963,9 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) lrugen->nr_pages[old_gen][type][zone] - delta); WRITE_ONCE(lrugen->nr_pages[target_gen][type][zone], lrugen->nr_pages[target_gen][type][zone] + delta); + for (int tier = 0; tier < MAX_NR_TIERS; tier++) + WRITE_ONCE(lrugen->protected[hist][type][tier], + lrugen->protected[hist][type][tier] + protected[tier]); if (!remaining) return false; } -- 2.34.1