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 941463E8695 for ; Wed, 12 Aug 2026 12:18:28 +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=1786537109; cv=none; b=t3G1g5edPQ7SETXhgky6oIAayeIAC+TWdPjYRoy/xJ6DOtVWdzZYsAaC8SYKg78REZD+Z2D0HKAiUw0xDPw8Tte8GAvQtbysKkwfqRd547D1axJsXwZGNejigUfFJzir/EHiHlwOUIwNOaBzp7a0ZxB4PKTzv0XhoTAaFsFc80o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786537109; c=relaxed/simple; bh=bjTlo5q4inqWpZchLdWAj07VC2VV4wp6sZQCGMSy6hU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RPZgSOTKlt5l6iA5/sVvC2G/IAlzLy2AhZZyX10kq4LJ5u/zmkYBHK6un2ks+Vfj/nEscK1SCMiraDmkDWLVI4EQL5qlaTxmwm6H20hshFFqzA3WtQ3ssPl65a8LostU3cbZ9t1l9zCTcONNOLUWt9uaWFLCS+D0KBOL+MdAy7I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hlfLM8xQ; 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="hlfLM8xQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B1E41F000E9; Wed, 12 Aug 2026 12:18:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786537108; bh=//ieBRIhh4nll3qPbLkaxIxKpZguGkr7hzBbi75fbu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hlfLM8xQi8KQaXw+J7ZyMU+xzBNGMgaQJ38nanoZDFLF92B7RFmSJxOSjC6btYMfB jNcHmL0DSGsLmeaLjaNVO7gk9eIy7/f2tvDXVxVJ/H/4sdMLRpaip0ODjNNxmnR1gi p6KKiBiOnd1Jmvq0r/4MEIKAcNNvRQ30kd6uaalEdXvoArBlDGcWhQRHbszHeHRDui PBwcUJc2MXMKyi4PURpglOsBz5RTBqtC+n3MctaQz5nXJxclzkk9631VKhIsK9vb/c RcN8AYZqgMq3arGkjouIxZQ5CGb1rC46IlLuAUjVMR8qyF+BpOUW3DLDDj/R4p2g0F SHz7g8ARwdt5Q== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: axelrasmussen@google.com, 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, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, "Barry Song (Xiaomi)" Subject: [RFC PATCH v4 06/16] mm/mglru: batch update lrugen->protected in inc_min_seq() Date: Wed, 12 Aug 2026 20:16:48 +0800 Message-Id: <20260812121658.69965-7-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260812121658.69965-1-baohua@kernel.org> References: <20260812121658.69965-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 c6e3b92c8cae..10f690389f5d 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3930,7 +3930,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); @@ -3952,8 +3952,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) @@ -3963,6 +3962,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