From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (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 A631232FA14 for ; Mon, 8 Jun 2026 16:07:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780934824; cv=none; b=mbaltjmDB28wwQ6Eakum8BFwhj3DsBoCkBRKmyMRV5WQ0rEDRTPVG6HXnjOw3GLuO8n1PZQq9X7ZfYVGhnpaJB+UY9tGBVsdDlNAU6daayQup54ecmmQ4i9i8ATGrhNanFvN2W88oAUOiM0blY48RgSKmp+k05868ZEiyFZt0BQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780934824; c=relaxed/simple; bh=fd6QOYjZILN8t9s/0OoY5MC+2bDAnDVlAXjXfBBhSLo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=R1pSHyMQWvy7toKukamtWCtWQycg9o4ISRl7tdkZJm5ZDDO7lnxwdNfCFpcdCW4OVsaDaTnnEO4WaRdttkafTZWcFOZn15MynczLvAbXe2Dn77y5DOsb026ucMYnIeyzcztqCA4nFL4aypjLL/ZMvAIvMrl8wQdsWnpNzjNrRrQ= 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=xQbe/Ssd; arc=none smtp.client-ip=91.218.175.177 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="xQbe/Ssd" Date: Mon, 8 Jun 2026 09:06:48 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780934820; 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=rXQzeZbKTFVTTpfiVd3SFhRp8gvKbhszT3P2b4EaKwU=; b=xQbe/SsdERdt9owUyf4KPyXwbqz6rpEZgWeG0I/KJNrxxyDSUd+TdL7gfeXgLxvkLhYOS8 VFS6kN9WBpN3STneGSq/QSVIKCSNbDC2yUuzXkDF9Zlj4DmS8N0rM9R55tnDBsVo1uhO1h J4Nq53n2wTeCK6YHqzsjOovKkot5I3k= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Usama Arif Cc: Andrew Morton , riel@surriel.com, david@kernel.org, baohua@kernel.org, baoquan.he@linux.dev, chrisl@kernel.org, kasong@tencent.com, linux-mm@kvack.org, hannes@cmpxchg.org, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, linux-kernel@vger.kernel.org, kernel-team@meta.com, inwardvessel@gmail.com Subject: Re: [PATCH] mm/swap_state: remove unnecessary lru_add_drain() from readahead Message-ID: References: <20260608143242.2869392-1-usama.arif@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: <20260608143242.2869392-1-usama.arif@linux.dev> X-Migadu-Flow: FLOW_OUT On Mon, Jun 08, 2026 at 07:32:42AM -0700, Usama Arif wrote: > swap_cluster_readahead() and swap_vma_readahead() end the readahead > loop with an explicit lru_add_drain() call. That drain is a leftover > from 2.6.12 era code and serves no functional purpose for the callers: > > - do_swap_page() ignores LRU residency for the readahead folios; > it only needs the target folio it called swapin_readahead() for, > and if the write-fault path needs the target folio on the LRU to count > references accurately, it runs its own lru_add_drain() at the > wp_can_reuse_anon_folio() and do_swap_page() sites. > > - shmem_swapin_cluster() immediately locks the returned folio, waits > for writeback, then operates on it - LRU residency of either the target > or the readahead folios is irrelevant. > > - try_to_unuse() likewise locks the folio and calls unuse_pte() without > depending on LRU presence. > > Folios newly added to the swap cache by the readahead loop sit in > the per-CPU LRU folio_batch and will be drained naturally as the > batch fills (FOLIO_BATCH_SIZE),by the next reclaim/compaction > lru_add_drain_all() and so on. The unconditional drain only > synchronously flushes a partial batch and forces contention on > lruvec_lock. > > On a 176-CPU production host running a memory-pressured workload, this > path was observed to call folio_batch_move_lru() from > swap_cluster_readahead() ~28K/min, a very large source of LRU lock > traffic. > > This is a direct continuation of the cleanup started in commit > 1aa43598c03b ("mm: remove unnecessary calls to lru_add_drain") which > removed the equivalent drain from free_pages_and_swap_cache() with > the same rationale. A detailed reasoning for this is present in [1]. > > Remove both drains. > > [1] https://lore.kernel.org/all/dca2824e8e88e826c6b260a831d79089b5b9c79d.camel@surriel.com/T/#u > > Signed-off-by: Usama Arif Acked-by: Shakeel Butt Thanks for pushing this. JP was also looking into LRU lock contention sources. Particularly we lack visibiluty into the lru_add_drain_all() callers. The idea was to add tracepoints to tracks such callers. (Just nudging you towards it :P)