From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796404258; b=MwGrsrVBXSgAEH+mjkEYwcPPdB2W9mwg3/rQCytHlZqmVM3eUOTvd9GelR3qwTiTjaLk VWCg9dhZJxzNXHAE8v7U/zMN9eSHDQFpujwUh8jjth6cCEa+HjcCu5JXj02SNS6EFZbAk X/J70n7ei/J4E+W/9qklP/wm6/lSUFYUL2tqLtwBo5V/eHkNcbYtTmdcnxrnyFzuKjYof flzNnI5am2BBJnbVOutizGuu/vuvq54Ny2LQb6bH+ALIJyKO3ufS+Mtf5y4LEfkjGzsVF 7c3GcpB8750QMk2ixxoeKjRmv2nUyFpGhUWp9zRw1ztE3dM1ct68osX2sVD628DYNFw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796404258; 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=IlCzhrtA/6cAK+QyFKjDBcXpOoqznDWejXQH4pKKVQQ=; b=h5RSNFZ55lfXZuPxL4iqXu0vJVZvgRMSyJRSCW1KAOlPTX2nw15OVlcLxTaeSA7gsimi X5jO591fQeZxHd8RhKjaBOkmhbbf04WGt+W1utqaR7nN6js6Iu9zn5Ne6mOW8kzaMa5Uk oGMriax5unqhr5777uVJcUDaR1lRRC6rGru73u/zo2Bs5NJlFgH3FEMThwelLc/47hg4L uAllMrfbaUkq7yLPxK5aYfSIg6tO15P+n8AVENMtXTornbisW1MVDxGFLdo3tZABdlWMw hAQaEWAi2cvtfOYT4vFCnOlUoXu8vp4eFf46m7ZyT0ng/4/z/6JSl+9ptMrvfa4X+ng== 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=HzebKOEI; arc=none smtp.remote-ip=209.85.210.170 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 17667606A698 for ; Fri, 4 Dec 2026 17:10:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 17667606A698 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=HzebKOEI Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-8b3577deeb0so618513b3a.3 for ; Fri, 04 Dec 2026 09:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796404253; x=1797009053; 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=IlCzhrtA/6cAK+QyFKjDBcXpOoqznDWejXQH4pKKVQQ=; b=HzebKOEIivQyR1hBWbPDGU9aoPrfsRN5CU0ssM6JDxD48O0H6Ya4iIVr21ZZAFMo1+ crDfwAgfwBbCxXptprjq6czCLoqKV4djy+4ltMM6/K3aux9LbpHcrT49VevXqWgtDFsG eJOJbDWKG58sUHBk2qbcGfiuRzwXv1GaLItDCfZavXeWDaGeOGvJ1MgtDpcGiN2M9cR3 3uvPNUj43ris1LEdpllSUbLaSiRizNsxbp5T2jPzy09rtBjU7R1mtLcTo92rK74tlMPb Shb4+oV6ITG8egtcG4/BuRX2zR5ZzqMBoDWzd47KmaCXENrW5+1j8Nb4dj7wqodSQ6Yr o8YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796404253; x=1797009053; 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=IlCzhrtA/6cAK+QyFKjDBcXpOoqznDWejXQH4pKKVQQ=; b=q6vodlEIfu+RivmMJ3y4WhIGreG80ICJGeVpb4IqG3sxs9i/0F0LekX7Rmazwd6sYp 5MBZo7kFU/nDiZ2D8t64JT/KO6bzfkIdl4dQuGuaEjxjov9uOzBOypx956+iL+1+q2IQ vtPWyoe09ckaaNF6druwpFhJ9mBaM2Wxj9J1NH0n0ve8CEmHxROMYlmCcRjZ8YwzRkaH N+f+V5oiBFiq/4Fm8tQHIbXtByDu5yXk0dDzniPbla9zKoyRITZCekTZhRuTlacNyo5F CyYVzELK4/XefCt1HJK5R0keHo1m2XG1VhtNsyZDNteTPJEPgh0BM31NSSMJdDnwmdGS UKcA== X-Forwarded-Encrypted: i=1; AL+hErGJISTWlmWvcj4ZDtEuSU9vmC1RfIbyHBqapZpvRrFX08r203Ag4DnmGPlYs8XWR5PQZ+g8UQ==@lists.linux.dev X-Gm-Message-State: APuU4Z9Vn40K/hll9jjwhBDzNQSv53XxuQY5uUzgTkSfWgY2xda+UYj9 XsheiDM+5yNW7xeMPOx5KV8ATziAgx8cgn8Ee2kMQvQ32Ml+XKNQ9Xzu X-Gm-Gg: AZFdTZfIFuQnL2LA6Wir3oxtXqtEP3cH3qD2yKtXxUFPZNxE/OIOLDO/QUVWMyUSfNQ DUoS+9Vg7n7Br9Mxukuu34jwxuzdAuq9V8SEKa+5sS+XhtlD/grgdS+lHr1sD9JJRtinFO2UBNE w+5LBaS9ZIQNIGMyDGPVKLlJ2S4pNLatjnxpwKq3moXlannO9p6zmaptDWAz5qBRQLbfTaKIB9x eM4AG3ZznkooYpAKP4hVN0jrLstdq4lEhoTZFcEe2Ps5OfNOBT82OelhrOyHUsBK6reWGeujVnm C03jSL5N3UVsnWFAt/qdlAv45lHH5fqNFhJvwtJgCk4Zijo8mwfzCfcxNFviiyJgnKxAYfC7k+T i3dxtu6JzGSAMqm8NA9aeWzrA8dTffube019dSHnlzO4Qf0PoS+cbYmf66SQANB4Q9Y/E/7vH/u 2HUe3g0v4wbVd1mx3FkBJwD8BXMh9RY9Pm3o1fBs0X2cOubbzLG0Aro8HCSti0nUUAaD20yQcNj CkUAMzR23MBHLzvn7bRcUe+VgL+WpK2ajTpZRhuYertKNJRoAU9wsKEdOVA6WdRmOv5cBe95mE/ kdjLk2u/DzvfKAz10fESerB1lQq27RetfSdBkaistsce9z8o5HQMl5CONSx40uljVwER X-Received: by 2002:a05:6a00:2906:b0:89e:9560:fc7a with SMTP id d2e1a72fcca58-8de2db0b726mr2333630b3a.29.1796404253192; Fri, 04 Dec 2026 09:10:53 -0800 (PST) Received: from KASONG-MC4 ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8de130a27a6sm1944846b3a.41.2026.12.04.09.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 09:10:52 -0800 (PST) Date: Sat, 5 Dec 2026 01:10:39 +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 19/19] mm/mglru: make folio_inc_lru_refs lruvec lockless Message-ID: References: <20261204-mglru-fg-v8-0-64f81c876c15@tencent.com> <20261204-mglru-fg-v8-19-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 10:39:12PM +0800, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 1 potential > issue to consider: > - [Medium] mm/mglru: unnecessary lruvec/RCU work on first read in > folio_inc_lru_refs() > -- > > commit 7de20732c529ae133ce4e3d556fee78af099121c > Author: Kairui Song > > mm/mglru: make folio_inc_lru_refs lruvec lockless > > This commit drops lruvec->lru_lock from folio_inc_lru_refs(), using RCU > via folio_lruvec_live_get()/folio_lruvec_live_put() and lockless LRU > size updates, and retries with LRU_REF_FORCE if concurrent aging moves > max_seq. > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > index f30c80c738ca3..8d365f80f43ea 100644 > > --- a/mm/vmscan.c > > +++ b/mm/vmscan.c > > @@ -876,38 +876,35 @@ void folio_inc_lru_refs(struct folio *folio, unsigned int flags) > > long nr_pages = folio_nr_pages(folio); > > struct lru_gen_folio *lrugen; > > struct lruvec *lruvec = NULL; > > + bool aged = false; > > > > +retry: > > old_flags = READ_ONCE(*folio_flags(folio, 0)); > > do { > > new_flags = old_flags; > > old_gen = lru_get_gen_flags(old_flags); > > old_refs = lru_get_refs_flags(old_flags); > > - file = folio_flags_is_file_lru(&old_flags); > > refs = old_refs + 1; > > gen = old_gen; > > + file = folio_flags_is_file_lru(&old_flags); > > if (old_gen < 0) > > goto out; > > - /* > > - * Lock the lruvec if the folio is on-list. We are already > > - * doing lazy promotion so in theory we don't need this, > > - * but for now, concurrent aging would still corrupt the > > - * size counters. This is a temporary limitation and > > - * will be lifted very soon, so the lock here is not a > > - * performance concern. > > - */ > > if (!lruvec) { > > lruvec = folio_lruvec_live_get(folio); > > - spin_lock_irq(&lruvec->lru_lock); > > lrugen = &lruvec->lrugen; > > } > > + /* > > + * Read the flags before max_seq, paired with the store of a > > + * gen, which samples max_seq first. > > + */ > > + smp_rmb(); > > max_seq = READ_ONCE(lrugen->max_seq); > > [Severity: Medium] > Can folio_inc_lru_refs() skip the lruvec lookup, smp_rmb(), and max_seq > read when !flags && !old_refs? > > On every first-access streaming read, filemap_read() -> > folio_mark_accessed() calls folio_inc_lru_refs(folio, 0) with > old_refs == 0. Since refs becomes 1, neither gen nor active/inactive > accounting can change, regressing the old lru_gen_inc_refs() fast path. > > In the else-if branch below, lru_gen_is_old(lruvec, file, old_gen) is > also evaluated before lru_refs_is_workingset(refs), forcing a > READ_ONCE(lruvec->lrugen.min_seq[file]) load even when refs == 1. > > Jumping to out when old_gen < 0 || (!flags && !old_refs) and checking > lru_refs_is_workingset(refs) before lru_gen_is_old() avoids this > hot-path overhead while remaining safe if try_cmpxchg() retries with a > newer old_refs. OK, this seems a pretty nice mirco optimization indeed, can include it.