[PATCH v6 14/14] mm, swap: skip the overcommit probe when removing xswap

From: Baoquan He

Date: Sun Nov 22 2026 - 07:48:55 EST


From: Baoquan He <hebaoquan@xxxxxxxxxx>

swap_info_remove() probes whether Committed_AS still fits under the
commit limit left after the device's pages are subtracted. An xswap
device's pages are its address space, not backing storage, but they
raised the commit limit at creation. A workload can commit into that
headroom, after which the probe refuses to destroy the device.

Skip the probe for xswap until the overcommit accounting for it is
settled. Real swap devices keep the existing protection.

Signed-off-by: Baoquan He <hebaoquan@xxxxxxxxxx>
---
mm/swapfile.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 90f17edce1d0..a65afd35c7d9 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3644,10 +3644,17 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
*/
static int swap_info_remove(struct swap_info_struct *p)
{
- if (!security_vm_enough_memory_mm(current->mm, p->pages))
- vm_unacct_memory(p->pages);
- else
- return -ENOMEM;
+ /*
+ * The device's pages are its address space, not backing storage.
+ * The commit limit it added may have been committed against, so
+ * skip the probe until the limit stops counting that space.
+ */
+ if (!(p->flags & SWP_XSWAP)) {
+ if (!security_vm_enough_memory_mm(current->mm, p->pages))
+ vm_unacct_memory(p->pages);
+ else
+ return -ENOMEM;
+ }

spin_lock(&p->lock);
del_from_avail_list(p, true);
--
2.54.0