From mboxrd@z Thu Jan 1 00:00:00 1970 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=1794590339; b=aUkVEH1M8a7dY4+ZxrXmviTeGSxfaXy7fOohOHvLIpWJDujBpkGXL1oIZAXtqiUPHsR0 K0Txk8XE7vlC3vi4hqWjl4W4D6DZToJz1UgEj5X2Tia5EEbfgCLPGmAnuwpVbNp0Tq2d6 zwoKIue2uNHfkCU8gnpnmt9i0K0IU3vOXyD0lKxpuF1vYpMp4uk/oGB5snEkDpEnvqFW6 2f/DGIW93Bn7h2WK8eOzg1LUaDoq3m7QJp83IxoDBYVfM4bkM2ANxmbjnkJ8pycGJhdBv FwBOTOmYFA72ZHLO4IukoUC84FMoWWmO5p9r9wk4F7P0SdCpGyr3DDjJ9aYx3PHFWrw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794590339; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=b8vISMcq+YC+s9bYg9/ffwTEHMrM+zXxfoxX12zwPn8=; b=w8ht9/IhA/L6f8HLWcgnpO1UkZSs5lsOpMa/xgx2/ezcVvuwUdUrsWlxQzxx09YgCblC C78OSsOTHSnxjTPGXDRlhfj6F13g5WhNIZEhUvPTd2qTN+7FAak6RWkWVKpmC/nbQzcBI PGd8lJjYUC6CPmxMKgi3ILsIeonNdz4UxfZp3UffjworD9ecYuHOJ9KnTVAL2ORkVKnhd JHQtElM/V9Gllm7GpJRjVESelsC6QozPB8CWMCinRhTv0mgs0TmH7G8OO1HnyZ2X/YeHS Q+8TqC+Ogv1NAZoD/hqitgdWrGFqPWsSq9MS+olsUPnvvTSih/DPwGcd1BSbs3WZ38g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=oLSQwRPs; 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 2F6EA606D4A6; Fri, 13 Nov 2026 17:18:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=oLSQwRPs Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB8B31F000C6; Fri, 13 Nov 2026 17:18:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794590339; bh=b8vISMcq+YC+s9bYg9/ffwTEHMrM+zXxfoxX12zwPn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oLSQwRPs+BuGVazx7qR5ITv0bGB6ud2JCxha3Bz5jpjG4vJLFvja4sFXg4UG7Lv0n TnDdeDk04ssxtwg2b4W6rROrylMqgkbOasUtY2BLiWj0yYpAPuaMeC+G8d2i49ZU9l 560qliRuEAR7yfX6jz/AC/VjMW8zLJKu3uNrnbPs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, 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 6.18 316/686] mm: make swapoff interruptible when unusing mms/shmem Date: Fri, 13 Nov 2026 10:47:29 -0500 Message-ID: <20261113153831.649012079@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153820.902362109@linuxfoundation.org> References: <20261113153820.902362109@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ 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: 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 da043ca0c2e22..5efde9fcc3057 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1519,6 +1519,10 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type) if (ret < 0) break; + if (signal_pending(current)) { + ret = -ERESTARTSYS; + break; + } start = indices[folio_batch_count(&fbatch) - 1]; } while (true); diff --git a/mm/swapfile.c b/mm/swapfile.c index 3ffa258de79ec..3a786446dacbe 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2349,6 +2349,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); ret = unuse_pte_range(vma, pmd, addr, next, type); if (ret) @@ -2562,7 +2564,7 @@ static int try_to_unuse(unsigned int type) if (swap_usage_in_pages(si)) { if (!signal_pending(current)) goto retry; - return -EINTR; + return -ERESTARTSYS; } success: -- 2.53.0