From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (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 6E82847A0DC for ; Thu, 11 Jun 2026 18:17:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781201879; cv=none; b=exIWiGXMOGEWa+C1iNKFh8duph15eH1AbhZRMZUa8qaiSUMRAnxvzWEo5ehURqQErjSSa9PSgW1ZwwXEYeAzPwcfXvREQiUt98jwi43Dcd40rh4HczhdbZsMBHROypJEF3l/oVwai8C72Wdc513c2zBY13rlwF/G1c5/q4MuWwI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781201879; c=relaxed/simple; bh=cyxYSwXB/dthoaLBypgguSqQjXfeR1UTsEu7O7DH58s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OScEUe7bORwvpOVKFtopXingrsKZVNr8Ps3OVP3wPVmvcw5lowkWQYfcSNXXDDm2wEA1bT0dwLy+5mM7u+CPmkevD4zs2//10dK6XjZwvoT5KEy4DwIKzftl5iMGdJihOIbFvgJPMVCwJuMlRNxFFzk0f41vI0plVgGptPFGTaM= 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=f707A22u; arc=none smtp.client-ip=95.215.58.182 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="f707A22u" Date: Thu, 11 Jun 2026 11:17:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781201874; 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=kJahH7bi7p54My4ngEqhVqPUzIy3QVfHqPFP00P3Ubc=; b=f707A22u/gqQWW76SSYWqEFLd5gh415tfmwesriF5tQHagCkqWl/hcr5JQQsfG/74tRZdB ca8puMAQwZNDUgjvWsSjduUQguens3Yh1zFacyu8C2VdshUuoN9n04IALTKFSb2zuDHg2y 3FlMhf6eiALduNaNbAUkX+wR0iqkqTo= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt 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, 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=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT On Thu, Jun 11, 2026 at 11:09:43AM -0700, 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? > > I wonder if that data can motivate to introduce lru_add_drain_folio(folio) which > only drains if the given folio is in the local lru_add cache. Actually if we can peek into lru_add cache and folio_ref_count(folio) is exactly equal to (2 + folio_test_swapcache(folio)) and folio is not on LRU then we can just reuse folio if it is in lru_add cache without draining, right? > > > /* > > * 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)) > > -- > > 2.39.3 (Apple Git-146) > >