From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796365665; b=yKohFKqF3xoEP7z9gGYvNlqykBAFdwnFBN4vyUUWo0MSheMGF1VSY92By8BsOpn0HRZK TIspihGUn7IUy5P9Tk1bAymgXvbrmoCaTcr+vK+Hz1+RedGN0AwxOq5PFxewMnGhwQ87k 1XfZqU7NbKsWLLmJLaVcRsXgUiwUg8w7cYW9u9lXGgThn8qDrrC7TsNOyRseijWLO+M6t h3dqThKW5HnDipRluZNTL9+1FzAQOJ/MDRV8Mdy4gQFFcVLz8CiEVr1OlzlqPQQNh/3DH plcRzh6NqTC6gwpTYMuyujqBhlS3RmZCrTzimW3V+UxycOaKU+3KKWuwlHw6NywrtFw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796365665; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=8qFNqcJTwEHkylJIn7rUqGyT9CKDi1ggqY4s24xVcBE=; b=mvwaMDa9je2FyGuOgWeKVywalWnR1mKJN7FfgwybbaQmEczhEwTvKh6cNxpAXOtPqCEG T1i6J/Xmtc0vCxEkejj07AMA+OqSBr8hpfDiP7SVaM2TnQ5oCzHvttU6UFh0PgaNlmbFl dF2QEXgNYne0GetgsgJpHAT1mwiKS2/uUYUzjDtMoJAH5tF41owpF0q+hDdGiZ/UIvZMk glS5wHVPonZhUsWsXPxzzFnpFHoXQbgjewvMqDd8NUun0wBNUfXV4AM8sJBOjW0NRxGpo E8kBtmc6UyVDVdVcNO9fjbyQujGk3pEnvqTc67rfkk+aWHIgbwjbFrzSt/diBmRqL0Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=y2kShN6J; arc=none smtp.remote-ip=209.85.210.169 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4412A606A32D for ; Fri, 4 Dec 2026 06:27:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4412A606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=y2kShN6J Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-8a070781f63so324580b3a.1 for ; Thu, 03 Dec 2026 22:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796365664; x=1796970464; darn=lists.linux.dev; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=8qFNqcJTwEHkylJIn7rUqGyT9CKDi1ggqY4s24xVcBE=; b=y2kShN6JOiN8bIsLemAHvPfJDxlnse1MgRT8Rvfs4GNXsjySKPWaADtdWyuG4DAGmh 6BVvgTst1kkVG/BeNQy2g8pVfhSo/fpva1MroL51k0aqAAWcxM2N7eupTDiilFtwyx9l SGRAP1EaN7EiDbsH9eXcvSy9/Cwap0KrjSuaDfP/QAbyiSwYb44PznhEyFMKIZUo9yH+ NKhoB6r/obCNS/S7FW0nPEw7zTvfTo22knQhngXHcAQ0ZGIqFU7AlyZQ1c9qtvTZa6we piFsxaf6JlHnLTfK4IDfyFx9MmsvHdtUBKTbrWcz93uPimHOegee48l545goim/FE7DV I0eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796365664; x=1796970464; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=8qFNqcJTwEHkylJIn7rUqGyT9CKDi1ggqY4s24xVcBE=; b=fwXlWzr1R2b88pha0OhqSxkCTc8z3PNo0Zz946drmYDCMOk+WJW8SXv8oQb0mFJFE9 yYOe+QgzIapRSplRyFfmNVP296yxvK4xyJZU99CZPD903ig2t4YlPTBukQtktPh00TGG 8cui/imXyC1DennEs9KxF7oHQSE7a0/fUQWeKe23sRRT9+sHLgxWSOYOba3zq4KpZDWT GPSNW3IU6w2v0VMr53exgUOZtVpDf5pCCkNToBjtlPt3a+jwL3rNF0/yfw7NkyKTDEfE LT9ZH+2PIlrpPm4Tc206twUmXujLqG6PFoJn6pwiWLRKtC32WaIp7qtYuQ+NesQb6o30 8jUA== X-Forwarded-Encrypted: i=1; AL+hErEsA1XngyaxfundHOHmUlBXKn6jeNgZKHw/SVYZIxoXAzFyefC+Wwr36+fqiscSBDWXHlqJ1w==@lists.linux.dev X-Gm-Message-State: APuU4Z/rOy1l7KnDjfJK7JcQW49uTbQjEYx+G9BkhRNoTfNqdp83YrAj vwcAXxnWMboIH+tyk9Mw6sTx2ldTlRn9RyDBT1FFAwDLxLUKs5/ofZiL X-Gm-Gg: AZFdTZfcX+Rsc1EU52+GZi/fpuG0JfAi63E2TY8AeJQzVx2niLobSJ/Y9KXutci4LfP ywk+bxtRI0kzxQu4giDn4H+iTyMYXjcpVK4L4qpJTtVrGFtObWyVcYmMcAQ3sdq0qh0oZnC7h6A 8klCaMSzJloXofN7XpZX2//luKqL0/A41pvB0sJK7wiOA2S8b8RtS6+/KLcA/iWc/L2HkG+xGSD 8SVOzKBuud1oDwA67GquGhmCSALkon3NCAfwkuPmpU7UdwV9akhrkMlMcP4k6caiclZCIF0QOLF qxaliwMID0LmTVeN8QzLLXvIAxcYqlK/HfcTXHCknsTGShJKyMCdZayRmf+j3tK/uCL49vIBJpp ZIToRHymeS3JfhAmybYiwbYaUxtvovn86YWlBYfeZgccExuSx3U4u+N1ULhG6KY8zWKle2F0iGw hNiIRue+iHGv6d3FXA50Lg6QJxGueka17YcBvY8XaaDZvhHg4woS8iz+OsflzPnzJCr7Cvqpe1X uqqdW+Eh3PznDZgSvsTLIycSawtvooR3tnPPYTk8smFfrVMHayJKlZaiW3fHsB9Rn6OMTQGfhfS JjeArAMKZkuawVr41egSbDMPbOPgIateRsXtO2h//SzQpMGahjAv0k/K+pwG9H5Co6MveDuV+w= = X-Received: by 2002:a17:90b:5628:b0:3a8:59d3:530f with SMTP id 98e67ed59e1d1-3b5e067649bmr884090a91.57.1796365664144; Thu, 03 Dec 2026 22:27:44 -0800 (PST) Received: from KASONG-MC4 ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c7d486efsm7672736a91.9.2026.12.03.22.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 22:27:43 -0800 (PST) Date: Fri, 4 Dec 2026 14:27:31 +0800 From: Kairui Song To: sashiko-reviews@lists.linux.dev Cc: Kairui Song , linux-mm@kvack.org, 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 , "Liam R. Howlett" , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Vlastimil Babka , Suren Baghdasaryan , Nhat Pham , Youngjun Park , Zi Yan , Gregory Price , "Matthew Wilcox (Oracle)" , Baolin Wang , Ryan Roberts , Dev Jain , Lance Yang , Hugh Dickins , SJ Park , David Rientjes , Yu Zhao , Vernon Yang , Zicheng Wang , Tal Zussman , Xiang Liu , Ehab Ababneh , Zhao Zhengzhuo , Lian Wang , Joanne Koong , Kunwu Chan , Hui Zhu , Maxim Muzafarov , Tianyi Chen , Aveline Noir , damon@lists.linux.dev, Ridong Chen , tj@kernel.org, mkoutny@suse.com Subject: Re: [PATCH v8 01/19] mm/memcontrol: allow update of LRU statistic without holding LRU lock Message-ID: References: <20261204-mglru-fg-v8-0-64f81c876c15@tencent.com> <20261204-mglru-fg-v8-1-64f81c876c15@tencent.com> X-Mailing-List: damon@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Dec 03, 2026 at 06:16:32PM +0800, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 3 potential > issues to consider: > - [Medium] mm: lockless LRU counter underflow wraps to ULONG_MAX on > !CONFIG_SMP > - [Low] mm/vmstat: vmstat_refresh() warns on transient negative LRU > stats > - [Low] mm: commit subject prefix mm/memcontrol: mismatches mm_inline.h > diff > -- > > commit a24f6a4c56faf2531e82abb1319104f85ad71220 > Author: Kairui Song > > mm/memcontrol: allow update of LRU statistic without holding LRU lock > > This commit adds __update_lru_size_lockless() in include/linux/mm_inline.h > so callers that do not hold lruvec->lru_lock can update LRU statistics > without relying on the lock disabling IRQs. > > Link: https://lore.kernel.org/20261029204157.117879-1-joannelkoong@gmail.com [1] > Link: https://lore.kernel.org/linux-mm/387237c3-c2f8-4782-9ba6-481f459cf7f2@linux.dev/ > > > mm/memcontrol: allow update of LRU statistic without holding LRU lock > > [Severity: Low] > Should the subject use an mm: or mm/mglru: prefix instead of > mm/memcontrol:? This patch only adds __update_lru_size_lockless() in > include/linux/mm_inline.h and does not touch memcontrol or make > mem_cgroup_update_lru_size() lockless. It's not touching MGLRU code yet, and I think this is really trivial. > > diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h > > index 27c7bba542bce..02a09a2aaf6cd 100644 > > --- a/include/linux/mm_inline.h > > +++ b/include/linux/mm_inline.h > > @@ -55,6 +55,23 @@ static __always_inline void __update_lru_size(struct lruvec *lruvec, > > NR_ZONE_LRU_BASE + lru, nr_pages); > > } > > > > +/* > > + * __update_lru_size() for callers that don't hold lru_lock, so can't rely > > + * on it disabling IRQs. > > + */ > > +static __always_inline void __update_lru_size_lockless(struct lruvec *lruvec, > > + enum lru_list lru, enum zone_type zid, > > + long nr_pages) > > +{ > > + struct pglist_data *pgdat = lruvec_pgdat(lruvec); > > + > > + 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], > > + NR_ZONE_LRU_BASE + lru, nr_pages); > > +} > > [Severity: Medium] > Can temporary LRU counter underflow wrap to values near ULONG_MAX on > !CONFIG_SMP kernels? > > CONFIG_LRU_GEN does not depend on CONFIG_SMP. On a preemptible UP kernel, > a task preempted between updating folio flags and calling > __update_lru_size_lockless() can race with lru_gen_del_folio() and leave an > LRU counter transiently negative. > > The vmstat and memcg stat readers only clamp negative values under > CONFIG_SMP: > > include/linux/vmstat.h:global_node_page_state_pages() { > long x = atomic_long_read(&vm_node_stat[item]); > #ifdef CONFIG_SMP > if (x < 0) > x = 0; > #endif > return x; > } > > zone_page_state(), node_page_state_pages(), and lruvec_page_state() have > the same CONFIG_SMP guard. Besides corrupting reclaim heuristics and > /proc/meminfo, an unclamped negative file LRU count in > global_dirtyable_memory() can make x equal ULONG_MAX so x + 1 wraps to 0. > > That triggers a divide-by-zero in node_dirty_limit() or > domain_dirty_limits() when vm.dirty_bytes or vm.dirty_background_bytes is > non-zero. Should the negative-to-zero clamps in these readers be made > unconditional? Actually, look at it again, this is a pre-existing problem: MGLRU's walk_update_folio() already defers __update_lru_size() until reset_batch_size(), which is a much wider window than folio_inc_lru_refs(). Reparenting may also cause temporary underflow. I'll post a separate fix for this, as it's orthogonal to this series. > > [Severity: Low] > Will transient negative LRU counts trigger spurious pr_warn() messages from > vmstat_refresh()? > > When /proc/sys/vm/stat_refresh is accessed while a lockless LRU update > leaves a global vm_zone_stat[] or vm_node_stat[] entry negative, > vmstat_refresh() logs a warning because it only skips > NR_ZONE_WRITE_PENDING, NR_FREE_CMA_PAGES, and NR_WRITEBACK. > > This can also cause false failures in mm test suites that use stat_refresh > to check for vmstat imbalances. Should the LRU zone and node stat items be > added to vmstat_refresh()'s skip lists? This is really trivial, all mm tests tolerates some degree of delayed counter update, and still we are hardly adding more latency. And same as above, reset_batch_size() already defers __update_lru_size() over a much longer window. A separate fix may help.