From owner-svn-src-all@freebsd.org Mon Aug 27 09:39:35 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A31F61081F7E; Mon, 27 Aug 2018 09:39:35 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 598188673C; Mon, 27 Aug 2018 09:39:35 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 22A1C1BD72; Mon, 27 Aug 2018 09:39:35 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7R9dYvD073644; Mon, 27 Aug 2018 09:39:34 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7R9dYJb073643; Mon, 27 Aug 2018 09:39:34 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201808270939.w7R9dYJb073643@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 27 Aug 2018 09:39:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r338335 - stable/11/sys/vm X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/vm X-SVN-Commit-Revision: 338335 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Aug 2018 09:39:35 -0000 Author: kib Date: Mon Aug 27 09:39:34 2018 New Revision: 338335 URL: https://svnweb.freebsd.org/changeset/base/338335 Log: MFC r337714: Prevent some parallel swap-ins, rate-limit swapper swap-ins. Modified: stable/11/sys/vm/vm_swapout.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/vm/vm_swapout.c ============================================================================== --- stable/11/sys/vm/vm_swapout.c Mon Aug 27 07:32:41 2018 (r338334) +++ stable/11/sys/vm/vm_swapout.c Mon Aug 27 09:39:34 2018 (r338335) @@ -157,6 +157,8 @@ static struct mtx vm_daemon_mtx; 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 *); @@ -625,6 +627,8 @@ faultin(struct proc *p) sx_xlock(&allproc_lock); MPASS(swapped_cnt > 0); swapped_cnt--; + if (curthread != &thread0) + swap_inprogress++; sx_xunlock(&allproc_lock); /* @@ -635,6 +639,13 @@ faultin(struct proc *p) 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; @@ -652,18 +663,17 @@ faultin(struct proc *p) */ 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 | @@ -681,7 +691,7 @@ swapper_selector(void) */ return (p); } - if (min_flag) { + if (wkilled_only) { PROC_UNLOCK(p); continue; } @@ -712,11 +722,29 @@ swapper_selector(void) } 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) { @@ -724,11 +752,11 @@ swapper(void) 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);