From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=156.147.23.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796359935; b=XMq/NNHiqSVbdx3U+jGwfGjbmbuKjIamWTcDOShGTSdW65ZDMMP3lg0aBmcrBdhNflGm PQzJMKObOcaTimQyoi1dXgLgRrGBkrGV9aeOiOY7NVy7qy+OfjFN3QznP6sEx6FA4ZgOW kEsNrOnS+/Nry6GvSSGyAjJI/UVXiga1xENgAtHQawssZ7XUTqW3H+InduPZ2DFD85LjQ uGSJNHB0vHGpWSCuHI7gaZoVZrifN7jePJiQo+fPirSSeoKTlJvBkefcCyT11iL9Ec+j2 Oqz+zUGNk+COrHR39EiY7NnRyZPkxZWANGz7fFZXmkTDHMU7xwZGXaApRV2NE9RYOSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796359935; h=DMARC-Filter:Received:X-Original-SENDERIP:X-Original-MAILFROM: Received:X-Original-SENDERIP:X-Original-MAILFROM:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=6UrzbndPOXNwFLlOaxVVsxhQPQF+PRGfe1v5pVGpqhE=; b=jFehusJM3mW0W33TKCMt/AgxpnFhK3q58HWAauubv83nV7D2t+zaSXWG6shn8xppTA0o wGpLggFXZJqI3fXHNu7I2nJCHiaRdPumTDq2s5jYuB/mZPrhJ9h6fh/jG4f/UCcHRyOqA rwYNmEiBZLr4id0gITuRzvW3LrkSEQCzOp1s553noVLHGMIYgVk5r+M1YQQjA6+m/QnL5 o7j9J0QRjRedMoqEb4f2ICiPFSr1oQOSu4ao4i7NjqriSom/g1f5s0Y+iMvqtVDx5qkId JKPmkpOqs6Wov0xV1+Ss3TAqGOES65tt+T+XXNr27HdpIaOeeomWm+EclHwMeZypDvw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.remote-ip=156.147.23.51 Received: from lgeamrelo11.lge.com (lgeamrelo11.lge.com [156.147.23.51]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EF4E606A322 for ; Fri, 4 Dec 2026 04:52:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8EF4E606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO lgeamrelo01.lge.com) (156.147.1.125) by 156.147.23.51 with ESMTP; 4 Dec 2026 13:52:06 +0900 X-Original-SENDERIP: 156.147.1.125 X-Original-MAILFROM: youngjun.park@lge.com Received: from unknown (HELO yjaykim-PowerEdge-T330) (10.177.112.156) by 156.147.1.125 with ESMTP; 4 Dec 2026 13:52:06 +0900 X-Original-SENDERIP: 10.177.112.156 X-Original-MAILFROM: youngjun.park@lge.com Date: Fri, 4 Dec 2026 13:52:06 +0900 From: Youngjun Park To: albin_yang@163.com Cc: akpm@linux-foundation.org, chrisl@kernel.org, kasong@tencent.com, nphamcs@gmail.com, baoquan.he@linux.dev, baohua@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, albinwyang@tencent.com, stable@vger.kernel.org Subject: Re: [PATCH v2] mm/swap: skip devices without SWP_PAGE_DISCARD in swap_sync_discard() Message-ID: References: <20261204024446.3612318-1-albin_yang@163.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261204024446.3612318-1-albin_yang@163.com> On Fri, Dec 04, 2026 at 10:44:46AM +0800, albin_yang@163.com wrote: > From: Wei Yang Hi Wei > Measured on v7.4-rc4, strictly paired on the same machine (26 x 256MB > swap devices, 16 concurrent workers, 512MB MADV_PAGEOUT chunks, swap > 100% full), unpatched vs patched: > > folio_alloc_swap avg 32.745 us -> 1.505 us (21.8x) > allocations in 30s 916,734 -> 6,216,609 (6.8x) > per-page 30.2 us -> 4.0 us (7.6x) > spinlock slowpath/alloc 27.1 -> 1.87 (14.5x lower) > > The per-allocation cost used to grow linearly with the device count > and is now independent of it. > > Semantics are unchanged: swap stayed 100% full in both runs, so > allocation outcomes were identical, and swap_do_scheduled_discard() > had 0 hits. A separate test with 25 no-flag devices plus one enabled > with --discard=pages confirmed that flag-bearing devices still take > the original path: swap_do_scheduled_discard() was called once per > folio_alloc_swap() call, with no hung tasks or regression. Looking at your use case, there seems to be no discard device at all. What about counting SWP_PAGE_DISCARD devices like nr_rotate_swap, so we can skip the walk (and swap_lock) entirely when it's zero? Might be a bit local, but swap on discard devices isn't that common. It is just opinion for curios about your thought. no serious consideration plz :) > Fixes: f9e82f99b377 ("mm/swapfile: fix list iteration when next node is removed during discard") > Cc: stable@vger.kernel.org > Signed-off-by: Wei Yang > --- > Changes in v2: > - Point Fixes at f9e82f99b377 (Kairui Song) > - Add Cc: stable (Kairui Song) > > v1: https://lore.kernel.org/r/20261128134810.3203203-1-albin_yang@163.com > > mm/swapfile.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 226230dda0aa..e553bd2c20a7 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -1509,6 +1509,8 @@ static bool swap_sync_discard(void) > spin_lock(&swap_lock); > start_over: > plist_for_each_entry_safe(si, next, &swap_active_head, list) { > + if (!(si->flags & SWP_PAGE_DISCARD)) > + continue; > spin_unlock(&swap_lock); > if (get_swap_device_info(si)) { > if (si->flags & SWP_PAGE_DISCARD) This inner check should be redundant now, right? Can we drop it? Thanks, Youngjun