From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (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 F390234DCE6 for ; Fri, 12 Jun 2026 03:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781235680; cv=none; b=aVGvEJxbJQO5nEtIfEX1YCW0f8Au2Qqb/glSCZi/TqpwHKrmdhfcHlwMqmXeZubcxKlgpEZ/MvInpWSaKJXzOEQ0Gg+E5duk7n1S+zuloudhH+bB/iAEAYdziO/UbzPnrdZorFfWX919N4a0fQe47hDtSOJboBh+yb5tpe/MyV4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781235680; c=relaxed/simple; bh=WTK2hxcxZj+XSfa33gRhFEmaxS6KOv45F/EEXKbT97g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rBnUNVAdOWNMStgA3pfU1FTVH8OdbgLE5T6lN5FSqnzJtsTQjpd/HGOAl0I45GN62P0GBSA2qhfhAQf7SSJVCANgc6/Bg+MnLAlncdudcUw3aR6Kv3HD+9CxWiMWFoxbfjuaIofe1NtYjI4o1HAXx1Q7zUKHeOlAXfcUTPLNUek= 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=f6wKqtK1; arc=none smtp.client-ip=91.218.175.181 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="f6wKqtK1" Date: Fri, 12 Jun 2026 11:41:07 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781235676; 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: in-reply-to:in-reply-to:references:references; bh=PJOwCe0Kl8GvUtCfKaSs2MlOZ0Hb5owPZVvPNWzaZCk=; b=f6wKqtK1twAg711k9HqipdHkDjn5F7o/YP5t/eRdU3Oo5pk7f9JEafL029yE0SDngLzMdU RNz26eEOyhZRjz5beMQOBLN24LmHwGaaC6jr87YBi956J3SVw1A3LWpJnNyK5Rns4w0E2b LPC688doy/06UlKnIlQ5rAEDXDuZ4hQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Baoquan He To: "Barry Song (Xiaomi)" Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, chrisl@kernel.org, kasong@tencent.com, shikemeng@huaweicloud.com, nphamcs@gmail.com, youngjun.park@lge.com, jp.kobryn@linux.dev, usama.arif@linux.dev, shakeel.butt@linux.dev Subject: Re: [RFC PATCH 1/3] mm: avoid unnecessary lru drain for wp_can_reuse_anon_folio() Message-ID: References: <20260611105124.98668-1-baohua@kernel.org> <20260611105124.98668-2-baohua@kernel.org> 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: <20260611105124.98668-2-baohua@kernel.org> X-Migadu-Flow: FLOW_OUT On 06/11/26 at 06:51pm, Barry Song (Xiaomi) wrote: > We always unconditionally drain the LRU before retrying anon folio > reuse in wp_can_reuse_anon_folio(). Instead, assume !LRU anon folios > are in lru_cache, and use the refcount to avoid many unnecessary LRU > drains. > > Signed-off-by: Barry Song (Xiaomi) > --- > mm/memory.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 56be920c56d7..487a34377a7b 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -4193,12 +4193,18 @@ static bool wp_can_reuse_anon_folio(struct folio *folio, > */ > if (folio_test_ksm(folio) || folio_ref_count(folio) > 3) > return false; > - if (!folio_test_lru(folio)) > + if (!folio_test_lru(folio)) { > + /* > + * Assume folio is on lru_cache and holds a cache reference. > + */ > + if (folio_ref_count(folio) > 2 + folio_test_swapcache(folio)) > + return false; > /* > * We cannot easily detect+handle references from > * remote LRU caches or references to LRU folios. > */ > lru_add_drain(); > + } > if (folio_ref_count(folio) > 1 + folio_test_swapcache(folio)) > return false; > if (!folio_trylock(folio)) Reviewed-by: Baoquan He > -- > 2.39.3 (Apple Git-146) >