From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) (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 DE4E134D4E2 for ; Mon, 3 Aug 2026 03:22:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.111 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785727337; cv=none; b=Zu9PldiOCy9GGFZsAEPkjWEKR9HgyknxPTZw6Kbn+wE7fkAWGstxpr7iyQyg5ojtv9s9wYaXn7iH3nO/EbPir54e6DbJPG0aiWQrQ8gLfvoOAMX/2KwRJ7FvSUMTpzFIjdF9Qkd324wIydrmw8spcqjNAq1wl425yftnY6op/2U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785727337; c=relaxed/simple; bh=tYTqEfsmglXradPReCySuL+eOH+hcY3anyvIHClUN9M=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=iosJ8gnyNwn6kKusW7hkZqqE16T28/Ejlg/mKLwMPNxShabIvXrMFFxtqP3hq8x6kDgNBJRQmBHOhgIQuf85NYE8Uddgu0znNfe9+du5BdAXlrcri340MJmy63rs9AU0/inHRHUjS0Q3nJHxooiPoKqadhdTRPf8xsY9LEJBXXM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=T9A5HPRG; arc=none smtp.client-ip=115.124.30.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="T9A5HPRG" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1785727331; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=u3z7jErvysYS7pNJ/uLaA0r4Xt2Aj3qRn93q+F1nN8Y=; b=T9A5HPRGiIUKWyV9CmfyIRED+P/7Dil6FGsfGm+blbtb06UpYSxaKlWnZ8oLXqRo31yy7pddkDwgMHQr/HpxtfBxT/K+ibzFzF4cE6r5rJVbOdZVtLW744rn4jcqqOny0RtaqU9K0uqY5rBKmR8N1q0gpGfk6fYLeK45F7CUCdQ= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045133197;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=20;SR=0;TI=SMTPD_---0X8DqCxp_1785727328; Received: from 30.74.144.148(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X8DqCxp_1785727328 cluster:ay36) by smtp.aliyun-inc.com; Mon, 03 Aug 2026 11:22:08 +0800 Message-ID: <9692264d-74a0-4a69-9d57-49a8c90cf41d@linux.alibaba.com> Date: Mon, 3 Aug 2026 11:22:06 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v3 3/6] mm/mglru: improve readability of isolate_folios() To: "Barry Song (Xiaomi)" , akpm@linux-foundation.org, linux-mm@kvack.org Cc: axelrasmussen@google.com, david@kernel.org, hannes@cmpxchg.org, kasong@tencent.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, weixugc@google.com, yuanchu@google.com, chenridong@xiaomi.com, zhangbo56@xiaomi.com, wangzicheng@honor.com, lianux.mm@gmail.com References: <20260731083843.37811-1-baohua@kernel.org> <20260731083843.37811-4-baohua@kernel.org> From: Baolin Wang In-Reply-To: <20260731083843.37811-4-baohua@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 7/31/26 4:38 PM, Barry Song (Xiaomi) wrote: > From: Ridong Chen > > The for_each_evictable_type() loop in isolate_folios() > is misleading: it does not actually iterate over each > evictable type. Instead, get_type_to_scan() selects the > type to scan, while the iterator `i` merely bounds the > number of attempts. > > Signed-off-by: Ridong Chen > Co-developed-by: Barry Song (Xiaomi) > Signed-off-by: Barry Song (Xiaomi) > --- Good cleanup. Some comments below. > mm/vmscan.c | 47 +++++++++++++++++++++++++++-------------------- > 1 file changed, 27 insertions(+), 20 deletions(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 31947fa60f18..0038f33aa318 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -4828,35 +4828,42 @@ static int get_type_to_scan(struct lruvec *lruvec, int swappiness) > return positive_ctrl_err(&sp, &pv); > } > > +static inline bool is_single_type_reclaim(int swappiness) > +{ > + return swappiness == MIN_SWAPPINESS || > + swappiness == SWAPPINESS_ANON_ONLY; > +} > + > static int isolate_folios(unsigned long nr_to_scan, struct lruvec *lruvec, > struct scan_control *sc, int swappiness, > struct list_head *list, int *isolated, > int *isolate_type, int *isolate_scanned) > { > - int i; > - int total_scanned = 0; > + bool single_type = is_single_type_reclaim(swappiness); > int type = get_type_to_scan(lruvec, swappiness); > + int total_scanned = 0, scanned, tier; > + bool tried = false; The tried' is a bit confusing. How about 'type_fallback_allowed'? Or other more readable variable name? In addition, the 'single_type' variable can be removed, and just initialize 'type_fallback_allowed' directly: bool type_fallback_allowed = !is_single_type_reclaim(swappiness); > - for_each_evictable_type(i, swappiness) { > - int scanned; > - int tier = get_tier_idx(lruvec, type); > +retry: > + tier = get_tier_idx(lruvec, type); > + scanned = scan_folios(nr_to_scan, lruvec, sc, > + type, tier, list, isolated); > > - scanned = scan_folios(nr_to_scan, lruvec, sc, > - type, tier, list, isolated); > + total_scanned += scanned; > + if (*isolated) { > + *isolate_type = type; > + *isolate_scanned = scanned; > + return total_scanned; > + } > > - total_scanned += scanned; > - if (*isolated) { > - *isolate_type = type; > - *isolate_scanned = scanned; > - break; > - } > - /* > - * If scanned > 0 and isolated == 0, avoid falling back to the > - * other type, as this type remains sufficient. Falling back > - * too readily can disrupt the positive_ctrl_err() bias. > - */ > - if (!scanned) > - type = !type; > + /* > + * We are running out of the current reclaim type. Fall back to > + * the other type if allowed. > + */ > + if (!tried && !scanned && !single_type) { > + type = !type; > + tried = true; > + goto retry; > } > > return total_scanned;