Page MenuHomeFreeBSD

D16610.id46518.diff
No OneTemporary

D16610.id46518.diff

Index: sys/vm/vm_swapout.c
===================================================================
--- sys/vm/vm_swapout.c
+++ sys/vm/vm_swapout.c
@@ -159,6 +159,8 @@
MTX_SYSINIT(vm_daemon, &vm_daemon_mtx, "vm daemon", MTX_DEF);
static int swapped_cnt;
+static int swap_inprogress; /* Pending swap-ins done outside swapper. */
+static int last_swapin;
static void swapclear(struct proc *);
static int swapout(struct proc *);
@@ -634,6 +636,8 @@
sx_xlock(&allproc_lock);
MPASS(swapped_cnt > 0);
swapped_cnt--;
+ if (curthread != &thread0)
+ swap_inprogress++;
sx_xunlock(&allproc_lock);
/*
@@ -644,6 +648,13 @@
FOREACH_THREAD_IN_PROC(p, td)
vm_thread_swapin(td, oom_alloc);
+ if (curthread != &thread0) {
+ sx_xlock(&allproc_lock);
+ MPASS(swap_inprogress > 0);
+ swap_inprogress--;
+ last_swapin = ticks;
+ sx_xunlock(&allproc_lock);
+ }
PROC_LOCK(p);
swapclear(p);
p->p_swtick = ticks;
@@ -661,18 +672,17 @@
*/
static struct proc *
-swapper_selector(void)
+swapper_selector(bool wkilled_only)
{
struct proc *p, *res;
struct thread *td;
- int min_flag, ppri, pri, slptime, swtime;
+ int ppri, pri, slptime, swtime;
sx_assert(&allproc_lock, SA_SLOCKED);
if (swapped_cnt == 0)
return (NULL);
res = NULL;
ppri = INT_MIN;
- min_flag = vm_page_count_min();
FOREACH_PROC_IN_SYSTEM(p) {
PROC_LOCK(p);
if (p->p_state == PRS_NEW || (p->p_flag & (P_SWAPPINGOUT |
@@ -690,7 +700,7 @@
*/
return (p);
}
- if (min_flag) {
+ if (wkilled_only) {
PROC_UNLOCK(p);
continue;
}
@@ -721,11 +731,29 @@
}
PROC_UNLOCK(p);
}
+
if (res != NULL)
PROC_LOCK(res);
return (res);
}
+#define SWAPIN_INTERVAL (MAXSLP * hz / 2)
+
+/*
+ * Limit swapper to swap in one non-WKILLED process in MAXSLP/2
+ * interval, assuming that there is:
+ * - no memory shortage;
+ * - no parallel swap-ins;
+ * - no other swap-ins in the current SWAPIN_INTERVAL.
+ */
+static bool
+swapper_wkilled_only(void)
+{
+
+ return (vm_page_count_min() || swap_inprogress > 0 ||
+ (u_int)(ticks - last_swapin) < SWAPIN_INTERVAL);
+}
+
void
swapper(void)
{
@@ -733,11 +761,11 @@
for (;;) {
sx_slock(&allproc_lock);
- p = swapper_selector();
+ p = swapper_selector(swapper_wkilled_only());
sx_sunlock(&allproc_lock);
if (p == NULL) {
- tsleep(&proc0, PVM, "swapin", MAXSLP * hz / 2);
+ tsleep(&proc0, PVM, "swapin", SWAPIN_INTERVAL);
} else {
PROC_LOCK_ASSERT(p, MA_OWNED);

File Metadata

Mime Type
text/plain
Expires
Mon, Feb 9, 3:10 AM (12 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28529458
Default Alt Text
D16610.id46518.diff (2 KB)

Event Timeline