From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 1BFF338E12B for ; Mon, 20 Jul 2026 06:03:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784527434; cv=none; b=LglgJP5hIr6g/1siKwF0N1aceLlzksRpuGH8xbZnluYUmph7KeKP+bxVJ+CvuANVLl75TjaN9zZJsZQ8k2plO/415TBIA3Fc/ZtLJEOZn/+37JGJs46loyInRBvxH2B7t0OMl+yLa/Wm/4Piy4VGtDroAuIIzVOvLBjSjLfX2tk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784527434; c=relaxed/simple; bh=S55BSc4p8MUnGdGYJ2TyVRqkS85l9bZdN7cfODQJcoQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Wjyc7RkIaudshMi5rVtR7IGKvmB4llvedyDLAS2MgrCPmTmd3Lo27vECSwpArEH8frQ05hhCG+BKCj8pl3A0nLRQlyY2xyKSK+1CFQsa9Bqnp4W2AcRNFxHLoKAM0o36lSCikeIhxWY4MihIKcwBAV2/ERrG23WvBelfWDBUP1Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=P2d2KH1z; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="P2d2KH1z" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784527421; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EOa2sTI0h7gbpAoJrm7HoBQ8Xn3bVAsybwlbAeYP1CM=; b=P2d2KH1zoFc6CCaHQHoU8kOPKNHeAvz9g/bVcgWvG/bw3S1HxPQ2RSo2VN937qAZdANCte 2KUtW9JMpWaQVpUU8jryQ2SwqH/midwu37hzmQBll6FFLCGOytcNjEKb67I3ljNAHhNCYz 2g/mIfmjrb9xtmY7nJp0gAlyuoWOYuc= Date: Mon, 20 Jul 2026 14:03:32 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v2 4/4] mm/mglru: fix anon-only reclaim evicting file pages when swappiness=max To: Qi Zheng , Barry Song Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, david@kernel.org, mhocko@kernel.org, shakeel.butt@linux.dev, ljs@kernel.org, kasong@tencent.com, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, hezhongkun.hzk@bytedance.com, muchun.song@linux.dev, dave@stgolabs.net, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ridong Chen References: <20260718095251.82937-1-ridong.chen@linux.dev> <20260718095251.82937-5-ridong.chen@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Ridong Chen In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 7/20/2026 10:48 AM, Qi Zheng wrote: > > > On 7/18/26 9:43 PM, Barry Song wrote: >> On Sat, Jul 18, 2026 at 5:54 PM Ridong Chen >> wrote: >>> >>> From: Ridong Chen >>> >>> The previous patch fixes this issue for the traditional LRU, which also >>> exists in MGLRU [1]. Fix this by checking whether swappiness is >>> SWAPPINESS_ANON_ONLY in get_swappiness() first, and returning 0 from >>> get_nr_to_scan() when swappiness is SWAPPINESS_ANON_ONLY and anon pages >>> cannot be reclaimed, to avoid useless work. >> >> Is this intended to avoid unnecessary work, or to prevent file folios >> from being reclaimed incorrectly? > > Based on the test results below, it seems primarily intended to prevent > file pages from being mistakenly reclaimed. Also, bailing out early in > the SWAPPINESS_ANON_ONLY + !can_reclaim_anon_pages case is to avoid > unnecessary work. > > Hi Ridong, perhaps the commit message could be clearer. ;) > Thanks for the feedback. Let me clarify: When SWAPPINESS_ANON_ONLY is set, get_swappiness() returns the swappiness value, and get_type_to_scan() can always return LRU_GEN_ANON. So if anonymous pages cannot be reclaimed, we bail out early to avoid unnecessary work. In that case, get_nr_to_scan() just returns 0. If we do not return early in get_nr_to_scan() under the SWAPPINESS_ANON_ONLY + !can_reclaim_anon_pages condition, then in isolate_folios(), it may fall back to scanning file pages, but this only happens when scanned = 0, which is not the usual case. ``` shrink_one try_to_shrink_lruvec get_swappiness // return SWAPPINESS_ANON_ONLY if swappiness=max get_nr_to_scan // return 0 if anon can't be reclaimed, skip evict_folios isolate_folios // !scanned falling back to anyther type if !scanned ``` I'll update the commit message to make this clearer in the next version. >> >>> >>> The test result: >>> Before fix: >>> >>>    # cat /sys/kernel/mm/lru_gen/enabled >>>    0x0007 >>>    # cat memory.stat >>>    anon 204800 >>>    file 67108864 >>>    ... >>>    pgsteal_proactive 0 >>>    pgscan_proactive 0 >>> >>>    # echo "64M swappiness=max" > memory.reclaim >>>    # cat memory.stat >>>    anon 208896 >>>    file 0 >>>    ... >>>    pgsteal_proactive 16384 >>>    pgscan_proactive 16384 >>> >>> After fix: >>> >>>    # cat memory.stat >>>    anon 188416 >>>    file 67215360 >>>    kernel 1970176 >>>    ... >>>    pgsteal_proactive 0 >>>    pgscan_proactive 0 >>> >>>    # echo "64M swappiness=max" > memory.reclaim >>>    -bash: echo: write error: Resource temporarily unavailable >>>    # cat memory.stat >>>    anon 204800 >>>    file 67215360 >>>    ... >>>    pgsteal_proactive 0 >>>    pgscan_proactive 0 >>> >>> [1] https://sashiko.dev/#/patchset/20260717113300.214717-1- >>> ridong.chen@linux.dev >>> >>> Fixes: 68a1436bde00 ("mm: add swappiness=max arg to memory.reclaim >>> for only anon reclaim") >>> Signed-off-by: Ridong Chen >>> --- >>>   mm/vmscan.c | 14 +++++++++++++- >>>   1 file changed, 13 insertions(+), 1 deletion(-) >>> > > Overall, this looks good to me. > > Acked-by: Qi Zheng > > Thanks, > Qi > > -- Best regards Ridong