From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) (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 498ED757EA for ; Mon, 24 Aug 2026 06:47:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787554082; cv=none; b=nE03c5aLovji/iYTDwq2i2O0pk9Tn4Fi+F9AY2kK/7VGHVru4emiWVOU1mXXJGdCw8SRYI7Gyt9FzyUKO0YWDepGU0iy7ynO5TTzONy0X4ilcdaR6NvFMWIyHsCDUB5TGC77a3aS00+yCqRQSQ5qeGTDTWJQ2ztQpCJKojfYpe0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787554082; c=relaxed/simple; bh=On7a4jMsd6wNdcB7Rck8s3wPD4WXyeCNGrXgypSACKI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Uzf4chc6hn5d342GPJOrZ2iMTjYWVXTpqAV46w7PVUpi19hf9vk6dQOG93cHjr4MnuKj/2BVb5PVHmWbTio6bYci3BsDc5Ua0srnxAuU8If8lZCm0i0biJuxbR7TR5AGJ2nHcLaacIVD0qwlaYsiU9cIbvb+eadKOzSSjV1n90M= 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=kcDSvdS1; arc=none smtp.client-ip=115.124.30.124 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="kcDSvdS1" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1787554068; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=GK/MIea32e4NUGMWanxCuajUxRGuMhSI8qj69sbXJ1U=; b=kcDSvdS1BUAvR3NVBR/HVo68CH+4w6gWiqLUIzXJRW0ZLKKsuZoM7P8tByPV1U6pr8uV6vL6OFF/ZR2NTjOTT61+70bwucfb8buaUD7ytEXmbZg7Py53mzw9ycQlPr2fQzW5z9VY7149mvuUZjeB2+laGkTWDzqc282fJ+Eu7As= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037026112;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=20;SR=0;TI=SMTPD_---0X9U.yEG_1787554065; Received: from 30.74.144.121(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X9U.yEG_1787554065 cluster:ay36) by smtp.aliyun-inc.com; Mon, 24 Aug 2026 14:47:46 +0800 Message-ID: <5e0b17f1-a9db-4317-aa4f-924c6c767ee1@linux.alibaba.com> Date: Mon, 24 Aug 2026 14:47:45 +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: [PATCH 2/3] mm/mglru: improve scan_folios() exhaustion detection To: "Barry Song (Xiaomi)" , akpm@linux-foundation.org, linux-mm@kvack.org Cc: axelrasmussen@google.com, baoquan.he@linux.dev, chenridong@xiaomi.com, david@kernel.org, hannes@cmpxchg.org, kasong@tencent.com, lianux.mm@gmail.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, wangzicheng@honor.com, weixugc@google.com, yuanchu@google.com References: <20260820045603.68809-1-baohua@kernel.org> <20260820045603.68809-3-baohua@kernel.org> From: Baolin Wang In-Reply-To: <20260820045603.68809-3-baohua@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 8/20/26 12:56 PM, Barry Song (Xiaomi) wrote: > Commit 16b475d2ac3c ("mm/mglru: avoid reclaim type fall back when > isolation makes no progress") uses scanned == 0 to determine > whether scan_folios() has exhausted a reclaim type. However, > this is not always sufficient. It is possible for scanned > 0, > while the oldest reclaimable generation is exhausted after the > first scan_folios() call. > > We detect early_stop in scan_folios(). If we stop early for any reason, > it means the current reclaim type is not exhausted yet. If early_stop is > never reached, it means we have exhausted the current oldest generation > without hitting any scanning limit. > > Another issue is that if the lruvec has 4 generations, we might have > exhausted the oldest generation while the second oldest generation is > still reclaimable. In that case, this type is not exhausted yet. > > Add an exhausted output argument to scan_folios() so it can > explicitly report whether the reclaimable lists for the current > type have been exhausted. > > Signed-off-by: Barry Song (Xiaomi) > --- LGTM. One nit below. Reviewed-by: Baolin Wang > mm/vmscan.c | 28 ++++++++++++++++++++++------ > 1 file changed, 22 insertions(+), 6 deletions(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index d5cc30b667ad..1f2e574b0061 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -4721,7 +4721,8 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct sca > > static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, > struct scan_control *sc, int type, int tier, > - struct list_head *list, int *isolatedp) > + struct list_head *list, int *isolatedp, > + bool *exhausted) > { > int i; > int gen; > @@ -4732,12 +4733,15 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, > int skipped = 0; > unsigned long remaining = nr_to_scan; > struct lru_gen_folio *lrugen = &lruvec->lrugen; > + bool early_stop = false; > > VM_WARN_ON_ONCE(nr_to_scan > MAX_LRU_BATCH); > VM_WARN_ON_ONCE(!list_empty(list)); > > - if (get_nr_gens(lruvec, type) == MIN_NR_GENS) > + if (get_nr_gens(lruvec, type) == MIN_NR_GENS) { > + *exhausted = true; > return 0; > + } > > gen = lru_gen_from_seq(lrugen->min_seq[type]); > > @@ -4768,8 +4772,10 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, > skipped_zone += delta; > } > > - if (!--remaining || max(isolated, skipped_zone) >= MIN_LRU_BATCH) > + if (!--remaining || max(isolated, skipped_zone) >= MIN_LRU_BATCH) { > + early_stop = true; > break; > + } > } > > if (skipped_zone) { > @@ -4778,8 +4784,10 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, > skipped += skipped_zone; > } > > - if (!remaining || isolated >= MIN_LRU_BATCH) > + if (!remaining || isolated >= MIN_LRU_BATCH) { > + early_stop = true; > break; > + } > } > > item = PGSCAN_KSWAPD + reclaimer_offset(sc); > @@ -4790,6 +4798,13 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, > scanned, skipped, isolated, > type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON); > > + /* > + * If we didn't stop early, all reclaimable folios in the current > + * generation have been scanned. We are exhausted if this is the last > + * reclaimable generation. > + */ > + *exhausted = !early_stop && > + lrugen->min_seq[type] + MIN_NR_GENS == lrugen->max_seq; Nit: using get_nr_gens() looks more readable to me: *exhausted = !early_stop && get_nr_gens(lruvec, type) == MIN_NR_GENS + 1;