From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (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 0226830E821 for ; Mon, 3 Aug 2026 05:33:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785735238; cv=none; b=BdkTfMaK5zPsFfTLzSnAWKuPiPgc3jJnJiAvkrd5uWo1vc70OhsJfS4yq9I46N5Z+7SIpKlt4BMg4IPQRzW13WtXeP6JEVOasEA9TSHX6yQGJfadJwiTrOJaJDOkbElBTACpY83lant4p1/F37ghFjCS39P1aiZyrRo3QbUcWzE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785735238; c=relaxed/simple; bh=6Td1rWuRNhwR5hG824MT8G8jk6qeOb+lS0WyYcGyOJc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jGq3Gm4tXfk+bYiJg4NoouUst4/uZm9mjx+DCwCVT52+xpQQzPBwUIDj62CVjNxzHkAHgOnP8c/eTVQXDcP/O1gx3Z6Ae7w9CO26dSWC6HokQ21Fp2yRZ7h1vWsSDwJ0WY8Jt1UTsRUItmg8eiZFilTCX7TUyIr3wjQZo4fuPSk= 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=bUaz5LgE; arc=none smtp.client-ip=115.124.30.130 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="bUaz5LgE" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1785735227; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=MuLECA5wEc+VuT7fskiCgEgJaLOrznwzNQPZMRxjVd4=; b=bUaz5LgE//bVKlBxQ2ks+Ju2tLXNl+0IwXCP+oXSi4Rdm4wpR3IwMtuTP3Lwlno5+Fvb6Kt3OiFD+YBEA0GvU5hOExZqFed5AN6AAJ9D5tV0WHT2GExBoqTCIN5kZl+lZsfUvFvuihOX9KMXvOCSmlXdwrNBe3ZeBmYWeZevny8= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R361e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037033178;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=20;SR=0;TI=SMTPD_---0X8FRsN3_1785735224; Received: from 30.74.144.148(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X8FRsN3_1785735224 cluster:ay36) by smtp.aliyun-inc.com; Mon, 03 Aug 2026 13:33:45 +0800 Message-ID: Date: Mon, 3 Aug 2026 13:33:44 +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 Cc: akpm@linux-foundation.org, linux-mm@kvack.org, 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> <9692264d-74a0-4a69-9d57-49a8c90cf41d@linux.alibaba.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 8/3/26 12:46 PM, Barry Song wrote: > On Mon, Aug 3, 2026 at 11:22 AM Baolin Wang > wrote: >> >> >> >> 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); > > > Yep. It seems we can simply use type_fallback_allowed and drop > tried entirely: Thanks. That's what I meant:) > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 1ffd96c87bc2..358388b49a70 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -4840,10 +4840,9 @@ static int isolate_folios(unsigned long > nr_to_scan, struct lruvec *lruvec, > struct list_head *list, int *isolated, > int *isolate_type, int *isolate_scanned) > { > - bool single_type = is_single_type_reclaim(swappiness); > + bool type_fallback_allowed = !is_single_type_reclaim(swappiness); > int type = get_type_to_scan(lruvec, swappiness); > int total_scanned = 0, scanned, tier; > - bool tried = false; > > retry: > tier = get_tier_idx(lruvec, type); > @@ -4861,9 +4860,9 @@ static int isolate_folios(unsigned long > nr_to_scan, struct lruvec *lruvec, > * We are running out of the current reclaim type. Fall back to > * the other type if allowed. > */ > - if (!tried && !scanned && !single_type) { > + if (type_fallback_allowed && !scanned) { > type = !type; > - tried = true; > + type_fallback_allowed = false; > goto retry; > }