From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (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 1951630CDAF for ; Thu, 23 Apr 2026 18:46:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776969989; cv=none; b=aJYpJHyYhg4y8OFo1HFgsDdvx/Fc3Ko/6g0sY68VYU6ojSypoeOjJQ0tgnMeS3BwkwnNsulNFvTJ99DvBzgBWFJS5FE/GZb6Nw6FpMxPFouCXghDPaewsr4FqA+/T6j6ZWlgYhqpIjX0YThOSB4R27Mu/ut9SNRgdDchmKEG2zc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776969989; c=relaxed/simple; bh=C1e/38sep4rWPxNu/GrIIxSHqA0+nYKgO3P1cKGf14s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YnqOJ1KJGzstVK5sqaCXUDrIFGXCRvcodOHQxa+Af2SU4ynaayitVblFoNe69OH8sEavCy8inI1EogvcFNIwab3aIMdcVu5t5IBkekOGD08+m8keLpWV4mNDGzQ3IAx1QD2AxvO9RMw+35+lNGnBqm3a0wdC2SdUGbV5/toI43Q= 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=teKKL1k3; arc=none smtp.client-ip=95.215.58.173 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="teKKL1k3" Date: Thu, 23 Apr 2026 11:46:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776969986; 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=jB6W6hyPcyKqmQvUS+I0KZ5W2s9baEJl33kMKvENrVo=; b=teKKL1k3n/NP7oWJm4s62DMoOONCrRIv3rQeBFiJ2MKJoSeoIqbA1xxLAG8eFswl8e8rOh ZPpSI8TEAFWP0zDc/KVczsP5DAHWPKZt5M+XsXut3sqgxCNYTebY/mAHfxHcOUhZB8iFaD PvEp2BC1to6UFnzjKYLC1LZ8fsRRj0o= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: "JP Kobryn (Meta)" Cc: linux-mm@kvack.org, akpm@linux-foundation.org, vbabka@kernel.org, mhocko@suse.com, willy@infradead.org, hannes@cmpxchg.org, riel@surriel.com, chrisl@kernel.org, kasong@tencent.com, shikemeng@huaweicloud.com, nphamcs@gmail.com, bhe@redhat.com, baohua@kernel.org, youngjun.park@lge.com, qi.zheng@linux.dev, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH] mm/lruvec: preemptively free dead folios during lru_add drain Message-ID: References: <20260423164307.29805-1-jp.kobryn@linux.dev> 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: <20260423164307.29805-1-jp.kobryn@linux.dev> X-Migadu-Flow: FLOW_OUT On Thu, Apr 23, 2026 at 09:43:07AM -0700, JP Kobryn (Meta) wrote: > Of all observable lruvec lock contention in our fleet, we find that ~24% > occurs when dead folios are present in lru_add batches at drain time. So, when they were added to the percpu lru cache, they were alive but during their stay in lru cache, they were freed (last non-lrucache ref dropped) or somehow we are adding folio where the caller drops the reference just after adding to percpu lru cache e.g. folio_putback_lru() ? > This > is wasteful in the sense that the folio is added to the LRU just to be > immediately removed via folios_put_refs(), incurring two unnecessary lock > acquisitions. > > Eliminate this overhead by preemptively cleaning up dead folios before they > make it into the LRU. Use folio_ref_freeze() to filter folios whose only > remaining refcount is the batch ref. When dead folios are found, move them > off the add batch and onto a temporary batch to be freed. > > During A/B testing on one of our prod instagram workloads (high-frequency > short-lived requests), the patch intercepted almost all dead folios before > they entered the LRU. Data collected using the mm_lru_insertion tracepoint > shows the effectiveness of the patch: > > Per-host LRU add averages at 95% CPU load > (60 hosts each side, 3 x 60s intervals) > > dead folios/min total folios/min dead % > unpatched: 1,297,785 19,341,986 6.7097% > patched: 14 19,039,996 0.0001% > > Within this workload, we save ~2.6M lock acquisitions per minute per host > as a result. > > System-wide memory stats improved on the patched side also at 95% CPU load: > - direct reclaim scanning reduced 7% > - allocation stalls reduced 5.2% > - compaction stalls reduced 12.3% > - page frees reduced 4.9% > > No regressions were observed in requests served per second or request tail > latency (p99). Both metrics showed directional improvement at higher CPU > utilization (comparing 85% to 95%). > > Signed-off-by: JP Kobryn (Meta) Overall the code looks good but I do wonder if we can add something similar to folio_add_lru() and if that would be enough.