From mboxrd@z Thu Jan 1 00:00:00 1970 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 CB9BC3A5452; Mon, 3 Aug 2026 19:47:22 +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=1785786442; cv=none; b=Oh/fO5e5HSWIC7/Bv3VLBFcy1MQBu1fv2AZv7JouYwRTzkRSvYenqsJPoi/AuLotx5J6h2k2ayjWXjNr/CrdmP6jN7LU0YC/5P93S+ymAGndDQBnJvK6g6ggJKxm+L56dF5lxksbXNE+0LO8QmaodCLoyGFDnayvewH9dTKgXrE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785786442; c=relaxed/simple; bh=TjoR3Q+A/75X5CmlKSstBL+V/RoGE3aGMjE+kfk6FR0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M8DZq+TXAdlkNTuPRjFlZ/4EXlsncDOx+h6PLkoO2HrCaLVp12Pg/+++2VNFXok84S6M9AtollNrCOfXRzA/o6RJC3+d1werCsSDJmFeVr932fouJ76uWy49wjz2NUyH2T7KYy0M+w2H9nr8WP0uCDa/5x55qPNqlcFUjF4vDEg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R7P1axca; 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="R7P1axca" Received: by smtp.kernel.org (Postfix) with ESMTPS id 60311C2BCFA; Mon, 3 Aug 2026 19:47:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1785786442; bh=TjoR3Q+A/75X5CmlKSstBL+V/RoGE3aGMjE+kfk6FR0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=R7P1axcakJNma1d6DuaGGoEgfK2OzXAzNi+Mv/cg47QiL1r1DdF7o44v9HsRZtfSj GcAjs7OZPa+Dyp7aWJVjrQrwO/lD0mKmSNLayy+yI5cdGOfeL8H7nKWhSWR+qYFesJ nCd94i7xeq3HnPzNX6ystfYRy2auErIRpTW5YebkMSlmQZgmVxeWVP5GOxnwJHzLwT Nx7gdGo6citbgBfA04y+d4jcCKf9uaKOQS5u2ql5cshdJHeRrF1tZA+bdq7hBfw1FT QPSsF68Z7AZ9nYAZbu6b5EnXX8NrVQWkhXpaMV7w1uDLoSV712syYsX6r4YcmJBu4f tRvI3jtpwT10g== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EDDEC55822; Mon, 3 Aug 2026 19:47:22 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 04 Aug 2026 03:46:58 +0800 Subject: [PATCH RFC 02/15] mm/memcontrol: allow update of LRU statistic without holding LRU lock 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260804-mglru-fg-v1-2-4d8dad39dad6@tencent.com> References: <20260804-mglru-fg-v1-0-4d8dad39dad6@tencent.com> In-Reply-To: <20260804-mglru-fg-v1-0-4d8dad39dad6@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Johannes Weiner , Muchun Song , Qi Zheng , Ying Huang , Chris Li , Baoquan He , Nico Pache , Usama Arif , Michal Hocko , Roman Gushchin , Shakeel Butt , David Hildenbrand , Lorenzo Stoakes , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Vlastimil Babka , Suren Baghdasaryan , Kemeng Shi , Nhat Pham , Youngjun Park , Zi Yan , Gregory Price , "Matthew Wilcox (Oracle)" , Baolin Wang , Ryan Roberts , Dev Jain , Lance Yang , Hugh Dickins , SeongJae Park , David Rientjes , Yu Zhao , Vernon Yang , Zicheng Wang , Chen Ridong , Tal Zussman , Kairui Song , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Kairui Song , Baoquan He , Nico Pache X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1785786439; l=2443; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=5ef1JMmzTBWQNcW2bqr39zuDrTRlv1xJUE0rVPZJ1C4=; b=UvqFhP7b4fq/TB0tz3nC3HBptpJwoGpzzJy32pvAzSQ2v9hQM5SwhY+4eceXnqcf0tEbwa++W fjNuHNjeJheAat9Cj1uzPEjUbiHDcOtF8tc1fq2VEat9TX/fYD3goID X-Developer-Key: i=kasong@tencent.com; a=ed25519; pk=kCdoBuwrYph+KrkJnrr7Sm1pwwhGDdZKcKrqiK8Y1mI= X-Endpoint-Received: by B4 Relay for kasong@tencent.com/kasong-sign-tencent with auth_id=562 X-Original-From: Kairui Song Reply-To: kasong@tencent.com From: Kairui Song To enable moving file pages in folio_mark_accessed directly and lazily for MGLRU, allow updating the LRU statistic atomically without holding a lock. It may cause temporary counter underflow, which should be fine as we still follow final consistency of the counter, and it only serves as a factor for calculating the reclaim budget in vmscan. A little inaccuracy has no visible effect. Signed-off-by: Kairui Song --- include/linux/memcontrol.h | 2 +- include/linux/mm_inline.h | 3 +-- mm/memcontrol.c | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index b13e3f056319..68f363000d7f 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -902,7 +902,7 @@ unsigned long mem_cgroup_get_zone_lru_size(struct lruvec *lruvec, mz = container_of(lruvec, struct mem_cgroup_per_node, lruvec); val = atomic_long_read(&mz->lru_zone_size[zone_idx][lru]); - if (WARN_ON_ONCE(val < 0)) + if (val < 0) return 0; return val; diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index 621c8653d8f7..3ad1619ce8ca 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -36,11 +36,10 @@ static __always_inline void __update_lru_size(struct lruvec *lruvec, { struct pglist_data *pgdat = lruvec_pgdat(lruvec); - lockdep_assert_held(&lruvec->lru_lock); WARN_ON_ONCE(nr_pages != (int)nr_pages); mod_lruvec_state(lruvec, NR_LRU_BASE + lru, nr_pages); - __mod_zone_page_state(&pgdat->node_zones[zid], + mod_zone_page_state(&pgdat->node_zones[zid], NR_ZONE_LRU_BASE + lru, nr_pages); } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7511773b3491..3fbd7a6f6650 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1522,8 +1522,8 @@ struct lruvec *folio_lruvec_lock_irqsave(struct folio *folio, * @zid: zone id of the accounted pages * @nr_pages: positive when adding or negative when removing * - * This function must be called under lru_lock, just before a page is added - * to or just after a page is removed from an lru list. + * This function must be called when a page is added to or removed from + * an lru list. Caller need to protect the lruvec from being freed. */ void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru, int zid, long nr_pages) -- 2.55.0