HomeFreeBSD

swap_pager: cleanup swapoff_object

Description

swap_pager: cleanup swapoff_object

Function swap_pager_swapoff_object calls vm_pager_unswapped (via
swp_pager_force_dirty) for every page that must be unswapped. That
means that there's an unneeded check for lock ownership (the caller
always owns it), a needless PCTRIE_LOOKUP (the caller has already
found it), a call to free one page of swap space only, and a check to
see if all blocks are empty, when the caller usually knows that the
check is useless.

Isolate the essential part, needed however swap_pager_unswapped is
invoked, into a smaller function swap_pager_unswapped_acct. From
swapoff_object, invoke swp_pager_update_freerange for each appropriate
page, so that there are potentially fewer calls to
swp_pager_freeswapspace. Consider freeing a set of blocks (a struct
swblk) only after having invalidated all those blocks.

Replace the doubly-nested loops with a single loop, and refetch and
rescan a swblk only when the object write lock has been released and
reacquired.

After getting a page from swap, dirty it immediately to address a race
condition observed by @kib.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D45668

Details

Provenance
dougmAuthored on Jun 27 2024, 7:06 PM
Reviewer
kib
Differential Revision
D45668: swap_pager: aggregate freeswapspace calls in swapoff_object
Parents
rG14fee5324a9b: tcp: improve failure handling in tcp_newtcpcb()
Branches
Unknown
Tags
Unknown