* Perform the work of the laundry thread: periodically wake up and determine * whether any pages need to be laundered. If so, determine the number of pages * that need to be laundered, and launder them. */
| 987 | * that need to be laundered, and launder them. |
| 988 | */ |
| 989 | static void |
| 990 | vm_pageout_laundry_worker(void *arg) |
| 991 | { |
| 992 | struct vm_domain *vmd; |
| 993 | struct vm_pagequeue *pq; |
| 994 | uint64_t nclean, ndirty, nfreed; |
| 995 | int domain, last_target, launder, shortfall, shortfall_cycle, target; |
| 996 | bool in_shortfall; |
| 997 | |
| 998 | domain = (uintptr_t)arg; |
| 999 | vmd = VM_DOMAIN(domain); |
| 1000 | pq = &vmd->vmd_pagequeues[PQ_LAUNDRY]; |
| 1001 | KASSERT(vmd->vmd_segs != 0, ("domain without segments")); |
| 1002 | |
| 1003 | shortfall = 0; |
| 1004 | in_shortfall = false; |
| 1005 | shortfall_cycle = 0; |
| 1006 | last_target = target = 0; |
| 1007 | nfreed = 0; |
| 1008 | |
| 1009 | /* |
| 1010 | * Calls to these handlers are serialized by the swap syscall lock. |
| 1011 | */ |
| 1012 | (void)EVENTHANDLER_REGISTER(swapon, vm_pageout_swapon, vmd, |
| 1013 | EVENTHANDLER_PRI_ANY); |
| 1014 | (void)EVENTHANDLER_REGISTER(swapoff, vm_pageout_swapoff, vmd, |
| 1015 | EVENTHANDLER_PRI_ANY); |
| 1016 | |
| 1017 | /* |
| 1018 | * The pageout laundry worker is never done, so loop forever. |
| 1019 | */ |
| 1020 | for (;;) { |
| 1021 | KASSERT(target >= 0, ("negative target %d", target)); |
| 1022 | KASSERT(shortfall_cycle >= 0, |
| 1023 | ("negative cycle %d", shortfall_cycle)); |
| 1024 | launder = 0; |
| 1025 | |
| 1026 | /* |
| 1027 | * First determine whether we need to launder pages to meet a |
| 1028 | * shortage of free pages. |
| 1029 | */ |
| 1030 | if (shortfall > 0) { |
| 1031 | in_shortfall = true; |
| 1032 | shortfall_cycle = VM_LAUNDER_RATE / VM_INACT_SCAN_RATE; |
| 1033 | target = shortfall; |
| 1034 | } else if (!in_shortfall) |
| 1035 | goto trybackground; |
| 1036 | else if (shortfall_cycle == 0 || vm_laundry_target(vmd) <= 0) { |
| 1037 | /* |
| 1038 | * We recently entered shortfall and began laundering |
| 1039 | * pages. If we have completed that laundering run |
| 1040 | * (and we are no longer in shortfall) or we have met |
| 1041 | * our laundry target through other activity, then we |
| 1042 | * can stop laundering pages. |
| 1043 | */ |
| 1044 | in_shortfall = false; |
| 1045 | target = 0; |
| 1046 | goto trybackground; |
nothing calls this directly
no test coverage detected