Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794598478; b=Jssd0eJOEFL/VYfjG/gWJMkqXW1r45HDXXcn2XMEf6EH8d/1PBCLQeMpEX/X72y2ceUw 3xedgKDDX+T0NksqeFF279LAgz/uAUJ2r7sW/OW0ekjRlUaDLopzERh6mHxVnXRGiTjLy l3Zy4DM7g58Hr8YpcA9kEOp/oreh9Gbe7+IVT1xSDg26K9pkH4L/D+tF9CJ3uegvxkAVt qAou0NoaTBC9J/J/prcJCdIdqAvvLioNta5GBGAs5Umzp+YjSHiOrn8Lenh+B4dAVQA7d l4IoQK5X6ghv84uSrk8kA99D5906yxGO+aFVSJid/7WO3JrkRWVeK9ukWNshR9Yu5yg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794598478; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=vsymCTo6Nf/eQfky9bIot12Tdu25i9dgp5S/nqhgtaE=; b=rYDhQof9pH9nFzgEARpW2YYLHeQRbrrRi/pS/MbsQepDJneEnSC1mJ7oLq00cR2uVg3r j2vbwXz+wJMoe8cNMA0KYwxUicNzkmw0WH/KCWpL+yygvyzpQTqD+V7FmJ5nNXAn2Sve/ XByDJcTkfdlNLIGUNQxXFl/kUwUiU1t2Ce0Kmhlnv0SHb47dDtq4J1B9VkR5qWCx+JspU E/VqKSpAO6zabkSrnBlj3HJ9V+4LZ09EKsC40aoxC5HaVzFIiddUviMH4yJO+aAgLezzj hoxdEdcO/JQUmPFdPktxkP6QVe96ok+ceG69L61nZ3V4pCEogZ2H7DZEHBPXLX52HWA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=knjoXP6G; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7C24606A327 for ; Fri, 13 Nov 2026 19:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=knjoXP6G Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06D541F000C4; Fri, 13 Nov 2026 19:34:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794598478; bh=vsymCTo6Nf/eQfky9bIot12Tdu25i9dgp5S/nqhgtaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=knjoXP6Gb2JETkgvtyMhsRmnMHo85w+QNOIw+kgBOTBBeqM3u9cbQDeA7+QkPMUew V73hu3t19B/YiOegYCVVt1SsCRHgLMFfaYCCTAtjSpK1xluU9vGyalK9oxxOEVVIkF 2janhX9NBKl33X0IygylrHe0ZKaAv2rbtF61zqN3EZ+qz3iRV4CxMN6RPrWtxiecwa TMSUVwCP0uJqk+YqfcunWTKCubhJOYqBaPMUEchJ7r5ZkpCVCpKedCiNrhLz95o9c7 p3OeewidTLaabjIAtIcWJfvtn1mmJpC4fFmKZXsGLRvu+LGSEizG1tH33zD0nnI9xn V3hWTMsNR2lUw== From: Sasha Levin To: stable@vger.kernel.org Cc: Chris Down , Andrew Morton , "Vineeth Pillai (Google)" , Baolin Wang , Kairui Song , Hugh Dickins , Chris Li , Nhat Pham , Baoquan He , Barry Song , Youngjun Park , Ying Huang , Kelley Nielsen , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.10.y] mm: make swapoff interruptible when unusing mms/shmem Date: Fri, 13 Nov 2026 14:34:36 -0500 Message-ID: <20261113192843.2333244-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261109202656-failed-5.10-740128dd1a3f@kernel.org> References: <20261109202656-failed-5.10-740128dd1a3f@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chris Down [ Upstream commit 740128dd1a3f2bd81a80314d079b6b03c39ba3af ] try_to_unuse() only checks for a pending signal between mms, and shmem_unuse() doesn't check at all. That means that once swapoff gets to a process or a shmem file with a lot swapped out, nothing can interrupt it until every last page of it has been read back in. Just as one example of where this can concretely show up, freezing tasks for suspend or hibernation has to wait for swapoff to notice the freezer's fake signal, and gives up after freeze_timeout_msecs (20 seconds by default). Here's a facetious example where one swaps out 2GiB of one process to a swap file on ext4, starts swapoff, and half a second later tries to freeze with pm_test=freezer. Writing to /sys/power/state then fails with EBUSY and this in dmesg: Freezing user space processes failed after 20.003 seconds (1 tasks refusing to freeze, wq_busy=0): task:swapoff state:D stack:0 pid:3175 tgid:3175 ppid:2955 task_flags:0x400100 flags:0x00000419 Call trace: [...] io_schedule+0x44/0x70 folio_wait_bit_common+0x1ec/0x3d0 __folio_lock+0x24/0x40 unuse_pte_range+0x2d0/0x348 unuse_vma+0x158/0x248 unuse_mm+0xfc/0x150 try_to_unuse+0x104/0x3f8 __do_sys_swapoff+0x220/0x5d8 [...] The same goes for anything else that wants swapoff to stop, like an admin hitting ^C in a panic, of course. Prior to commit b56a2d8af914 ("mm: rid swapoff of quadratic complexity") try_to_unuse() was driven by find_next_to_unuse() which checks for a signal before every entry, so let's restore that behaviour. Just as an example of the improvements, here's how long freezing takes in the same test while swapoff is happening on my computer: before after 400MiB anon 8.925s 0.028s 400MiB shmem 1.639s 0.003s 2GiB anon failed after 20.003s 0.011s Link: https://lore.kernel.org/at9kJwdGkHPsWwgG@chrisdown.name Fixes: b56a2d8af914 ("mm: rid swapoff of quadratic complexity") Signed-off-by: Chris Down Signed-off-by: Andrew Morton Acked-by: Vineeth Pillai (Google) Reviewed-by: Baolin Wang Reviewed-by: Kairui Song Cc: Hugh Dickins Cc: Chris Li Cc: Nhat Pham Cc: Baoquan He Cc: Barry Song Cc: Youngjun Park Cc: Ying Huang Cc: Kelley Nielsen Cc: Rafael J. Wysocki Cc: [ sashal: Adapted folio-batch context to page vectors while preserving frontswap accounting and the shared retval return path. ] Signed-off-by: Sasha Levin --- mm/shmem.c | 4 ++++ mm/swapfile.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 6f2e267aa092f..8858db132090c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1305,6 +1305,10 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type, } } + if (signal_pending(current)) { + ret = -ERESTARTSYS; + break; + } start = indices[pvec.nr - 1]; } while (true); diff --git a/mm/swapfile.c b/mm/swapfile.c index 9c32c0055cbb1..79b3f0d034a42 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2048,6 +2048,8 @@ static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud, pmd = pmd_offset(pud, addr); do { cond_resched(); + if (signal_pending(current)) + return -ERESTARTSYS; next = pmd_addr_end(addr, end); if (pmd_none_or_trans_huge_or_clear_bad(pmd)) continue; @@ -2284,7 +2286,7 @@ int try_to_unuse(unsigned int type, bool frontswap, if (READ_ONCE(si->inuse_pages)) { if (!signal_pending(current)) goto retry; - retval = -EINTR; + retval = -ERESTARTSYS; } out: return (retval == FRONTSWAP_PAGES_UNUSED) ? 0 : retval; -- 2.53.0