From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796318128; b=R4N92R8Z4NtuzaSDH8Pl7bv5Tdlr9PmBrSuQ9LZlWq/3LvdMSjvXfXXLOSD23xU56g2s VASbAJBzWQLWG4A9Q03z55NZvka7TW8RY9EC5DRRqG71rLgtl7VxP2QOK0O/gbnwywVQ5 XNUel3T0kf/IS00G7EG/UP+NjSkoLgtwuHyEbRM+YYu4CqmcrZjKbDwZVRHBk+emdWvo9 4X8xyU7d6TQnvLRwZMELLO/C5N1I5iasotxFLu+fPZDpO8atZCgC3zjjr3rJMwKzN5H81 I3fGXFUgwPkrV7IccIEjh+orV6ff+fvOzETmDEVVYSBODo6EBiyAnuKNjO9WmiMGDCg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796318128; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=YCG5AQ8Q/tat/81YSzQlFG3GH3ia5w50MF+7Gub9C44=; b=Vq9mPBUOSVNc4e0ndt7pxPxcylGERx5v8DpA7C5pRJvf/2oB1oLHC/2G4jIlxqcR4S43 E+eNNND6vRw2IKKpCkfhb5wtKa+Og625Ce88cxo5rmuLEm5XOwR+uCwvtOxELCHpDCV8b 1LNfjdotS6k8ehozAyqaXujlTbAEW+5Yn1ASfBwL9CBtWEr3I5/rmz1OHNK2g+dhSgZXT Le53aIa5pwiSP1GpQxqUa57c6onoC3SGQBeaYXTq0u3OepWNeb064hRDl3P5Hn20m+Qfc gYOW2dqw7ptgCPKE8t8+AxIJwKEtAaMiaqPgvEb0UIKUVYseniMndW61kFB/BwK5oGA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ZSJazqvu; arc=none smtp.remote-ip=74.125.82.173 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB752606A333 for ; Thu, 3 Dec 2026 17:15:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EB752606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ZSJazqvu Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-38747f42472so1239770eec.0 for ; Thu, 03 Dec 2026 09:15:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796318127; x=1796922927; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=YCG5AQ8Q/tat/81YSzQlFG3GH3ia5w50MF+7Gub9C44=; b=ZSJazqvu7X9ORx8q29aHzbicxKL6T86JqtSFjXMh8VzT2eB3+XjhgqIGE3o+5J1GGi nKTmPZNdgnATkNzKDgtXXGyU9x2hyRwp+5/ZJSix2Hq4HZ1SnJIeLmtxtJRQhDMVbUK7 D5XD45VvvTX7v/1GzR0fPEl66A0AZ+ezD1KGuESDQ8qF1OC6mb/NG0UXVyBPKVmzjoY3 Aynphu8snWOoYmf30hKTEV21fOBJYvh2co5QXe+38U+6E0NunU9yrPt0jwmIsWc+j8/k EULINBQrYoZ6rpjuoKmTTNVvBh3oLPYHub2AypOPh/7wF4tVNPsKZKo8gtVU1+fi9bpQ 2n0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796318127; x=1796922927; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=YCG5AQ8Q/tat/81YSzQlFG3GH3ia5w50MF+7Gub9C44=; b=jdMKOolxtF1sZjHy+n9LfXYzliW0lDOVBM6gszTR+/+5PShHK+soBHO6D2gUfbqScW hp0y1WKUT4Qt0OtWlxPgDpl9Hlb+Z1mPIRUOQfESHAbeM5eHZXFIvmasdpF3iW25/bP+ vjJU/JhOTWQG2DWOqY0skbzGjnmVk0JOfGhIqSfMZHwTG5d+/cC1Fo6/onX/sKmZCPZm mMNE8I7KhhniP9wK6MnsMFEfmyPK1Fmpx589iuCIiQJoUAOVrZUIWFt8aZRTcRv5r5R5 Zry0fOk7gcjRdemW3hsOy2Ez4EpcMWwjjrRlqOsDmIpK+l1QIHGfVMGbtokDXFUTTPpB eQnw== X-Forwarded-Encrypted: i=1; AL+hErEv5Ge/zxObU+iRO43SNPNvtjcPejvh7gRB7oIjB6xKo0omyUtv7tzoQ0TSR6QeYXsQlVKkC3uc6oxDyXg=@vger.kernel.org X-Gm-Message-State: APuU4Z9uUCLf5w9GJopZri9oVR5/r/TUrHLxRyzueoVGYPtmGAudO1Cl 7QJW0SNUbkvyoKJonB6MvArGldZaXOPopNdFA4g3QXX3CjVTWUzKsb31 X-Gm-Gg: AZFdTZdZdOAzts6x0zQYQYkBRK1EIlI6YpYi6bxgJslfU3OUaVaDcuM4+FMlS98zjGS uAMMnqEuZRhoE9jb4zuNduXogCK8WVkoiWcSRxfTzm7GFX6Svmkq+D6arS0cQoY+4LAVTuUb9/5 4CsG8HiWK/NmVxYigJqC5XGlzEaclaftrB+fGH4SLGLJyD891HB1VSDqYL3INd6N70a3j4mvZNm c7yzwxg4KSkFSnm45lfZQBAZ43rGbtxQizb/f5hXUkrLh0xZFOZHT4JD4ptzODdmMPgaDEdab24 KAao6I4WLMXgVmsJ0ZCICXORd1o66br+Viu2lMOO09IOqfRS1wPXagQLZfZv1UDQ4k6o1o80kIY 7Wdnc94LepTKSGPHfVTX4d3a/iFOiQF4dSJTxnoekFd7I+boMQy8GXuoElRYBGdaSokA67ZQlqy 7F5lNsAdIRnDj1VwGuf2YCNQDF3ba7M506vgCLXZ1tvP3qskl4rwYMaYbVZRVHxdq96toxAkTg0 bFuiv7Se9cRIYfdcdUQ0ilEGAXCXk2LAQjOBc+3IPPPach2KArs8MQ0nRBx69iprAcJyGeeHRzQ 6RcfdSxHvRXI/2C+hBuMGsI3aorIu8HojlC8QSKEpvuzHP0CnNV3TE1OrmKT4L/sCGDYPA== X-Received: by 2002:a05:7300:fb97:b0:381:6ac8:ef2e with SMTP id 5a478bee46e88-3856ff5db0bmr59803792eec.25.1796318126750; Thu, 03 Dec 2026 09:15:26 -0800 (PST) Received: from KASONG-MC4 ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385c6830815sm118373373eec.20.2026.12.03.09.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 09:15:26 -0800 (PST) Date: Fri, 4 Dec 2026 01:15:20 +0800 From: Kairui Song To: albin_yang@163.com Cc: akpm@linux-foundation.org, chrisl@kernel.org, kasong@tencent.com, nphamcs@gmail.com, shikemeng@huaweicloud.com, baoquan.he@linux.dev, baohua@kernel.org, youngjun.park@lge.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, albinwyang@tencent.com Subject: Re: [PATCH] mm/swap: skip devices without SWP_PAGE_DISCARD in swap_sync_discard() Message-ID: References: <20261128134810.3203203-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: <20261128134810.3203203-1-albin_yang@163.com> On Sat, Nov 28, 2026 at 09:48:10PM +0800, albin_yang@163.com wrote: > From: Wei Yang > > swap_sync_discard() walks swap_active_head and, for every device, drops > and re-takes the global swap_lock and does a get/put_swap_device() > round trip. A device without SWP_PAGE_DISCARD can never make this > function return true, because swap_do_scheduled_discard() is only > reached under that flag. For such devices all of that work is pure > overhead. > > Skip them without dropping swap_lock. A skipped device cannot affect > ret or any global state, so folio_alloc_swap() behaves identically. > Holding the lock keeps 'next' on the list (plist_del() takes the same > lock), so the plist_node_empty() re-check below is unnecessary here; > visited devices still unlock/relock and re-validate as before. > SWP_PAGE_DISCARD is only set or cleared at swapon/swapoff time. > > We backported the upstream swap sync-discard changes into our 6.6-based > kernel. LTP/stress-ng swap stress testing then drove swap 100% full > and triggered a hung_task panic: the vmcore showed 17 of 256 CPUs > spinning on swap_lock here, with 25 active devices and none carrying > SWP_PAGE_DISCARD, while the mmap_read_lock holder starved on block > tags. > > With swap full, each failed folio_alloc_swap() on an order-0, > non-swapcache folio walks all N devices, costing 1+N+N+1 global > swap_lock operations plus N get/put round trips. The walk is over > swap_active_head, so an empty avail list no longer lets it exit early. > The same code is present in current mainline. > > 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. > > Fixes: 9fb749cd1507 ("mm, swap: do not perform synchronous discard during allocation") Hi, Thanks for the report and fix! Maybe should be f9e82f99b377? The per-device lock churn came from 9fb749cd1507, but that version walked swap_avail_head, and full devices are removed from it, so with swap 100% full it iterated zero times. The reported hang needs the start_over/plist_node_empty() restart that f9e82f99b377 added IIUC. And maybe need Cc stable?