[Bug 286152] do not swap in while shutting down

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 17 Apr 2025 10:13:59 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=286152

            Bug ID: 286152
           Summary: do not swap in while shutting down
           Product: Base System
           Version: 15.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: avg@FreeBSD.org

The code to turn off swap during shutdown is the same code that is used to turn
swap during normal system operation, e.g., with swapoff command.
It makes total sense that during normal operation we swap in all pages on a
swap devcie being turned off.
But in the case of shutdown that does not seem to make much sense.
The userland should already be dead or, worst case, dying anyway.
And there should not be anything that kernel depends on in pageable memory at
that late of the shutdown.  That should definitely be true since we disabled
swapping for kernel stacks.

Not only such swapping in is unnecessary and can slow down shutdown process, it
can also cause a shutdown hang if the swapped memory size is large than the
free memory size.

Here is a stack trace demonstrating the problem:
sched_switch+0x8c1 mi_switch+0xc1 _sleep+0x1f9 vm_wait_doms+0xe3
vm_wait_domain+0x47 vm_page_alloc_domain_after+0x228 vm_page_alloc+0x74
swapoff_one+0x33b swapoff_all+0x64 bufshutdown+0x2f8 kern_reboot+0x1a2
sys_reboot+0x336 amd64_syscall+0xed fast_syscall_common+0xf8

Messages seen on console:
Waiting (max 60 seconds) for system process `vnlru' to stop... done
Waiting (max 60 seconds) for system process `syncer' to stop... 
Syncing disks, vnodes remaining... 0 0 0 0 0 done
All buffers synced.
swp_pager_getswapspace(32): failed

-- 
You are receiving this mail because:
You are the assignee for the bug.