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=1795037664; b=UO4mGV0ciYKRyD8qlcI6F+1V4yHZh0Fb4Z0wXqRVflN4bz5OgqKnOHBQSVqTTAlmj2nl bULB4y4CmA3Z15Lq6V0R6GR1O87QF1X0hMzSu5LbHoBA6pAlgaCvI0G7cPjH4rbfzysBv 72lXi5JuVPU4LTO6VpKXiUa96zM4C5XSMtLBO7LtvAci/g5po4D2SlwlvNRk/QH/Z/cMu yCarzvhPxhOR6rM1SSC5ngwN2A80/LQ2MnRhW1+KfQbaukrwJlY/HUCzIqmt/0y6gSFLh bXpporQVtVdk7lj+5/iQmqUapzekIjf3kdEkw5DkVn61po+ZNarZy9WjBUWLtBx2ISQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795037664; 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=d25R9RMxkO2MmmbCsNCqmX8xYyM3OMmcErbHMWqcaZY=; b=3Y9L/FQgQPpvSPrSuPJ5rUJDZrFq0iD3Aip5cIZ4VmtmfG84Zf2YOzsA8pqf+C9S596I rhp9ZZUPaVbr4rUw0zrYD1wuDjYtjNo4JHUriaxYN8AuDaHq1hBGir9PWNgk0dcU2NBvf mAzFEXR6gT2yQpCdx/aWtpT4HKPufJuSmwofvX4nddv+DRZTIdAMIEIM5e8eMlOIlUUtL 9VyJjQ1I/3TesX9eV5Vm8etkw/5uAM6lOKBAT90KNd6HyZlrGS3I7d3U59uCvDi3+zzbT mqsnjlCAnLJEi1Ptc1ZPnJHg+mPQIritnxx8ArzpGGenR//IMgCjEyARr7VrhEZ9ZUw== 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=qYdeIBVc; 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 126D9606A31C; Wed, 18 Nov 2026 21:34:24 +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=qYdeIBVc Received: by smtp.kernel.org (Postfix) with ESMTPSA id 466781F000C4; Wed, 18 Nov 2026 21:34:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795037663; bh=d25R9RMxkO2MmmbCsNCqmX8xYyM3OMmcErbHMWqcaZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qYdeIBVcUT7XTTPxRVYfsq2b9/kSM6NkE5QJ+5eIa+q2433VTjla9Ek5rNxmlZyVQ ASoBevcld5kAY9z+ECBoyjCdEPQsW3f/gnREDj3JRT1FLHDUX0vWYVcn33igVCyp4W waqeLg+uE0Q7GaT+qckUKbj4RCVmZMbz3zJg2d68= 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.6 1477/3318] mm: make swapoff interruptible when unusing mms/shmem Date: Wed, 18 Nov 2026 15:34:59 +0100 Message-ID: <20261118150405.213632707@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-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 3a6192f5cc7d6..e6b39b49caec7 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1405,6 +1405,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 d4a4b2fb172aa..170f0d45a0758 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1926,6 +1926,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) @@ -2136,7 +2138,7 @@ static int try_to_unuse(unsigned int type) if (READ_ONCE(si->inuse_pages)) { if (!signal_pending(current)) goto retry; - return -EINTR; + return -ERESTARTSYS; } return 0; -- 2.53.0