Index: vm_glue.c =================================================================== --- vm_glue.c +++ vm_glue.c @@ -842,6 +842,15 @@ SYSCTL_INT(_vm, OID_AUTO, swap_idle_threshold2, CTLFLAG_RW, &swap_idle_threshold2, 0, "Time before a process will be swapped out"); +/* Long before Unix supported paging, it used process swapping. + * While this was ok with the PDP-11/20's 64kB address spaces, it does not work as well today + * when address spaces can easily be hundreds of GB.*/ + +static u_long proc_swapout_max = 65536 ; +SYSCTL_LONG(_vm, OID_AUTO, proc_swapout_max, CTLFLAG_RW, &proc_swapout_max, 0, + "Allows to limit the swapout of whole processes which max resident size (in bytes) is equal or less than value"); + + /* * First, if any processes have been sleeping or stopped for at least * "swap_idle_threshold1" seconds, they are swapped out. If, however, @@ -982,11 +991,14 @@ /* * If the pageout daemon didn't free enough pages, * or if this process is idle and the system is - * configured to swap proactively, swap it out. + * configured to swap proactively, and if the process resident count + * is less that vm.proc_swapout_max swap it out. */ - if ((action & VM_SWAP_NORMAL) || + if (((vmspace_resident_count(p->p_vmspace) * PAGE_SIZE) + <= proc_swapout_max ) && + ((action & VM_SWAP_NORMAL) || ((action & VM_SWAP_IDLE) && - (minslptime > swap_idle_threshold2))) { + (minslptime > swap_idle_threshold2)))) { _PRELE(p); if (swapout(p) == 0) didswap++; @@ -994,7 +1006,8 @@ vm_map_unlock(&vm->vm_map); vmspace_free(vm); goto retry; - } + } + } nextproc: PROC_UNLOCK(p); @@ -1044,6 +1057,8 @@ p->p_flag |= P_INMEM; } + + static int swapout(p) struct proc *p;