From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (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 7457A44E052 for ; Thu, 11 Jun 2026 18:10:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781201422; cv=none; b=dNPuNq1hUEDbi+G5/YB2scq67558271aeBL0SsjaKjpIaOwprqjElG1Lv1lyYBW96xqZcbBDzxIm3caOw1kzuLR3nbIT7BzLsOUO8ANMMEuau1Cr3S5uEsbpS3UGbHvtcC3SxoqpAMcQYpspBX0ZKo2y2opPFUlcUJGVXdYUlbY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781201422; c=relaxed/simple; bh=S1/pStSNe/+rF8CoNbiN104TZezIeenjtWSfyCCG0go=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Wq3ix/wb/VuUOQmFnRVu8gStqB7Z25+0Hc9Q3usO4YJs2Pti+JBDxkyGG+yI386X+H3p3NB/k1qfRHI1IopkOY6UnLDRHOae7g41ZYbHZq3Q4QdgFEDFlYFbma6Rt3U8ctpEUa3iLdeJNgiLTNVv/qBzG8m9BxqQUpx1Yywl2oM= 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=WfTJfI5r; arc=none smtp.client-ip=95.215.58.189 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="WfTJfI5r" Date: Thu, 11 Jun 2026 11:09:43 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781201417; 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=fPdQHZvmvzHMhqv9JGT9CD5ktNpQerM+IV8idlHzHvk=; b=WfTJfI5rZZC34ooadd63p++rPupbf2SfNROjlhgO8bl2cNrn925GYSeWmECP96zFIlNPxy u1fIb820RrYOYHU99Map7AYr040HWsrVuEotmMO2chgxxybzeVd5G2CRHCxg6LKpVU+aHZ Ul4k1fDpRb6gtJs5vscyOuMaWW40eP4= 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: <20260611105124.98668-2-baohua@kernel.org> X-Migadu-Flow: FLOW_OUT 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. > /* > * 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) >