From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (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 E9078478842 for ; Wed, 17 Jun 2026 15:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781708926; cv=none; b=FkUKzM4Nb7nCsbPxeam5noZpvucEYKMKIRd8TqdN6cvY8koGWL6bV6hBSI3mTJdHzJtM0d6FIYuDPERAJBTokUmXtdREQ50+sP0mfqW4hFC5uBL/s/K3VQwjKR2aQYLRIDLAC0UVhmJ/eyDkn8mjeVT17SHEXTd84eOzz1yLKdA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781708926; c=relaxed/simple; bh=hV+wXOu8JTreqm9ffstpN8rbvjUac/ZqhYO9cQ73FXQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UnagP+mGlJDSPy1LLC1eanweOs6/cIv09Z//71DknvVGITrOsrXVwXsBlfg7QZ2HPTfYoBB28QlHCflkQITeBgC6rsWRv2KO2KMZjTtBBxQrdMXX2GT1v08bu/7DrlQ3vraH7xUPJDqD1TFXeIkTQMCJjyH81IhP19z0rovCENA= 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=H5w89jvj; arc=none smtp.client-ip=91.218.175.186 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="H5w89jvj" Date: Wed, 17 Jun 2026 08:08:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781708922; 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=KmNoOt2xhXhUdVUypMM4EgODu463lMUf0qQnokW3yA4=; b=H5w89jvjIl9L+nV8GNPt+jiKO3stjNwlMcQTQfT6QUXnYd4W8l4YZukHOKyaIWnSY63+yv s4KpIx92Idi1rcmvtlmN1qed4GPPYv/h/M+IY77RlBqSXSspXt0xDhmbE4HpODIdd6XwS2 Tw2x8417z7hXyOHKlEuwhzSvz3thqYs= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Barry Song 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, baoquan.he@linux.dev, youngjun.park@lge.com, jp.kobryn@linux.dev, usama.arif@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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT On Fri, Jun 12, 2026 at 12:48:19PM +0800, Barry Song wrote: > On Fri, Jun 12, 2026 at 2:10 AM Shakeel Butt wrote: > > > > On Thu, Jun 11, 2026 at 06:51:22PM +0800, 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; > > > > In your experiments, how much amount of drains were reduced due to this specific > > check? > > This is a very good question. I booted the system into Ubuntu, and after > boot completed I observed: > > wp_reuse_skipped_drain: 5542 > do_swap_skipped_drain: 0 > > Then I built the kernel in a 1GB memcg using zRAM swap, and observed: > > wp_reuse_skipped_drain: 25017 > do_swap_skipped_drain: 43595 > > So in summary, even without swap-in we can save a significant number of > drains in wp_can_reuse_anon_folio(). With heavy swap-in workloads, most > of the savings come from avoiding drains in do_swap_page(), while we > still see a substantial number of skipped drains in wp_can_reuse_anon_folio(). Thanks and this is very good info. Add this in the commit message when you send the non-RFC version.