From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6125F409275 for ; Mon, 24 Aug 2026 11:09:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787569777; cv=none; b=SI2KiK0X3gYo2STNV7Fs/qhbbQdWmlTGuL0L2iJxHQEksCTrssbBF0BSo2Y6NDytJmXo9zU66+cMBx+gLBUPb2sNabEQxe8cvQzwGbP8ereK0X/kcz9kQl+hE0Tb7TgROMJqbJ6QCtnCgX15QOsuuYf8bqUJU0kE5xl7zEy4vt8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787569777; c=relaxed/simple; bh=jMKl6ZV8VKQYwnIufmRflu12OH18KYtDSa975PPqrLE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HzX/fmz0UVofWuupKhNn2/8Brgk0c9x8e8imURXdb6mXGp9qDcanQ9H2zRvr7761md9TeZEGvMl9dR/D+dhiKso224dP1PrFQbfXlxWsoOlsTY6EMP/9Wm2Q3wkWWc3HkjXNUi2ciIv7OIrhU0ov9DTzurN6V7WCIuZ6uG0JbO8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QJU2yX5J; arc=none smtp.client-ip=209.85.210.176 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.b="QJU2yX5J" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-84e84a6c4bfso2856798b3a.1 for ; Mon, 24 Aug 2026 04:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787569776; x=1788174576; darn=vger.kernel.org; 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=FqwXbXyfUlH6nF/dcWjMtptrPqoYpuG4oKFrsn7psr0=; b=QJU2yX5JKzA7Xy7F251AC6hYb79nxMHmN1rYMxgOC5Z510tQqt2Ll8XDozvIGE8icl TKi3lSuBn0ztGZ/j0iR1VFP+h1/Q2Gty8MHEmB+Miz5p+G65wWNSB2s0tAKWDK9HAFDi BB8cZnzpCjst3ydcneXmfcT2ALX+Nj+Gj3xapLZmAkJpBCEyr7SHz7xHAfYldjKoXch9 RjC3EV9N+99wTUiXKxCndTWU9wMGuOhHFAdMn8kY7hX2lCefONrh0Hggbi01FJKnJabD KfRm65pVs1b9ZAUaBcVzFvTdMIZF2oF+mDS8XD1rZ/LWPGaK0MsTiQkr2HdtkviVs+6u zofg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787569776; x=1788174576; 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=FqwXbXyfUlH6nF/dcWjMtptrPqoYpuG4oKFrsn7psr0=; b=bsyNB+gXfVcOS40BbjQo3aWH+YS2MJu2hs3I1pajYTpav8rs8TbaZ7iY7Dfu96aDVT fBMSPWwQhnXE+19wkawIMYszYcMnBSmsslAe3a3ge5+goOHOwmbpVnO+0BZ15ATlUlRS q+6qmzSTzUWSeyV/5wdV9ql0VTAW+j7zQRJNwQfgw1E0ukLs9rg9x35X+OwrGAzFWjKU ymoGm5Y2tOTQOtt+yMenRUnjJoUomVNi7Ug7PiBQ2U2PpN/GZ1gXETy81hDpe8hT35fJ 0K2YSwk4K6q1skGonW5sMPLwL7JpfvhfqbmmBFXKBNzatzAale7bzy1Smj3Zj3Aw+Hr3 qiPg== X-Forwarded-Encrypted: i=1; AHgh+RqXJBGDfdL5yT2kIZ7MYRNehxEuq+FOIxSrUsllIJ0x2ktwyotHWPXHcdlezfBEeuP2I//e2+EU/zNrPHw=@vger.kernel.org X-Gm-Message-State: AFuF++kNiFz/K8ZZ+ZH3tClMn9Pb2H8mEkPiIxzF1ruTOwo4z6izRmPg hE31qB2kfAl9a0YGbv5b0iSM9SD6Mhmzc0HZvyhg6zHhHY5RSCxpADaI X-Gm-Gg: AR+sD10697iskEub5oDXiKCUU5j/qYSgYcws8HCgZAVHiVfkZSC6vDQj7F8x0W4YAVx s1jf2pSQW/8xd80QE++316yFxB68/bDNSQiD7RcxG6Ye3QTxB9R+pXM1nqOXfOo7JFfERo6qtbD qQrAxxg0WLRUL6j1YlY7hN3kjlxQA0VP3R/dlBaco44kNwiqJabe9VmvbRFfRs+Kd32js7c5c8B h++PEdCeHsrONUZe8lIPG7tjCy4y6YcFmLvgZZ6st5R6xOFLu2nba2QBdbuCGHKNZEDGJC+63RJ CYINfgZlkGKpevS6ivtbchRyZPM8tiQBDzXO9jBK6BgnHlaI1XEDguaJ0INDGYJAIVvksOL7GUs HXUJS0i9Zjzp8xT7oFU+rb6xJNmHhvJlVT3/PkvxyWJia5Sno54ZmGRQA2NjUTQIC3sADWbVmtF wMRks94fi1sLtzztjIyZdCfTB+DKBSHKoFnVJjE3C/5RTr4xXZAqWj7DbLksqq0ziP9Icxxhh7R MACtSSHreqq/X1gvyYBHXOU X-Received: by 2002:a05:6a00:2d04:b0:84b:9a69:156d with SMTP id d2e1a72fcca58-851f9a2c87amr22297176b3a.0.1787569775691; Mon, 24 Aug 2026 04:09:35 -0700 (PDT) Received: from KASONG-MC4 ([114.246.239.71]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8520ef26df4sm1790900b3a.21.2026.08.24.04.09.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 04:09:35 -0700 (PDT) Date: Mon, 24 Aug 2026 19:09:24 +0800 From: Kairui Song To: Ridong Chen Cc: kasong@tencent.com, linux-mm@kvack.org, Andrew Morton , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Shakeel Butt , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Chris Li , Baolin Wang , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Yu Zhao , Zi Yan , Qi Zheng , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/7] mm/mglru: introduce helpers for manipulating gen and refs flags Message-ID: References: <20260818-mglru-flags-cleanup-v1-0-8dbbdac0d28c@tencent.com> <20260818-mglru-flags-cleanup-v1-2-8dbbdac0d28c@tencent.com> 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=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Aug 20, 2026 at 09:43:38AM +0800, Ridong Chen wrote: > > > On 8/18/2026 1:38 PM, Kairui Song via B4 Relay wrote: > > From: Kairui Song > > > > Instead of doing bit ops on folio->flags.f, introduce helpers for > > adjusting folio's refs and gen info, make the code easier to debug and > > understand. > > > > No functional change is intended: some combined atomic operations are > > split into two, which only creates harmless transient states. > > > > Signed-off-by: Kairui Song > > --- > > include/linux/mm_inline.h | 79 +++++++++++++++++++++++++++++++++++++++++------ > > include/linux/mmzone.h | 2 ++ > > mm/folio.c | 19 +++++++----- > > mm/vmscan.c | 61 ++++++++++++++++++++---------------- > > 4 files changed, 117 insertions(+), 44 deletions(-) > > > > diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h > > index 621c8653d8f7..93bf3fa221f8 100644 > > --- a/include/linux/mm_inline.h > > +++ b/include/linux/mm_inline.h > > @@ -142,10 +142,43 @@ static inline int lru_tier_from_refs(int refs, bool workingset) > > return workingset ? MAX_NR_TIERS - 1 : order_base_2(refs); > > } > > -static inline int folio_lru_refs(const struct folio *folio) > > +/** > > + * lru_gen_from_flags - Return the LRU generation number from folio flags. > > + * @flags: folio flags > > + * > > + * Returns: A number between 0 and LRU_GEN_MAX, inclusive. Returns -1 if the > > + * flags indicate the folio is off the list (e.g., isolated). > > + */ > > +static inline int lru_gen_from_flags(unsigned long flags) > > +{ > > + int gen = ((flags & LRU_GEN_MASK) >> LRU_GEN_PGOFF); > > + > > + BUILD_BUG_ON(LRU_GEN_MASK & LRU_REFS_MASK); > > + gen -= 1; > > + VM_WARN_ON_ONCE(gen != -1 && gen > LRU_GEN_MAX); > > Perhaps we could define a macro such as GEN_OFF = -1 to make the code more > self-explanatory, I found this warning a bit confusing at first glance. > > LRU_GEN_MAX already bears some resemblance to MAX_NR_GENS, so introducing > yet another macro may add some clutter. > > Just my two cents. > Thanks for the review. Let me just simplify the sanity check then, I think using MAX_NR_GENS are good engough.