From nobody Mon Dec 06 00:30:08 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id D3D1318C25F0; Mon, 6 Dec 2021 00:30:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J6kpm6Yl8z4ZXK; Mon, 6 Dec 2021 00:30:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AD5D4219D2; Mon, 6 Dec 2021 00:30:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1B60U862088317; Mon, 6 Dec 2021 00:30:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B60U8cp088315; Mon, 6 Dec 2021 00:30:08 GMT (envelope-from git) Date: Mon, 6 Dec 2021 00:30:08 GMT Message-Id: <202112060030.1B60U8cp088315@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 08d995ca8f6f - stable/13 - swapoff_one(): only check free pages count manually turning swap off List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 08d995ca8f6f1008a10e4bf4d924824c040f842a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638750609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EbhKtsj/iuH8nZmAaMcL3Z+JBH0yMKXYF3lDShjhWaU=; b=vPAPYm5vlyOEATIssZ8H0zwOtkfGW6I6+1ntaPw4kRx+a2sgGmm9fXXVbHNqYYUNGv65gM vjL3xDHdT1UZph8pvkXgm4EWv7BELiCjdo359Dsku2L5TAXoDBVfG3B1yFhhtYgVpkBGho j7pphY6JQ9mjoaMDGCBDVYntEraY4QqVLrAdKmIQdPRzj07Yz6ZZNdc686dVgNNe1aai67 tHX93pyYmh8AEgO/RmBTN2UtuCotbxlwrQYvdQYQxabjqfxBhHRJMXRcYvGycCzlbKANKj XfDT0n5vX+QIPHR7ALqvYL+HQSv2hAEBhhpkI1xw3G68coGQYJkFtFZE1DgiFA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638750609; a=rsa-sha256; cv=none; b=Xw6j4W4CefNe5VwcMd6ccU46aT3Vkdje/5aAwdL/xrcwv2fZ+tM7LlcAzJyGUC4WKPsZPM qjdmXUJ6C7Twzus31SBEgyGKT05A/2Che6cN9jemYoCi2x/NqFc+az4nim1TWbZhrp/4OP Bu34dQeh9nzuXRGyF4AnpOas46MBkRUXwg0Q6cgco+FjL2Pg/hVoUoXfL5thl4uQCX3F+D ANIFeQJDMa5NiOiG1PNH68J+5rNl5tuhKyNrPTYb7LO9wTGteUoFfBzhu0b/rRmedyAGUG MMOAXg43CJziPikgB9Pa/kp+5tog8UN7FYCoPB/id7Qqz8ANb2oRggbCTxCp3Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=08d995ca8f6f1008a10e4bf4d924824c040f842a commit 08d995ca8f6f1008a10e4bf4d924824c040f842a Author: Konstantin Belousov AuthorDate: 2021-11-26 23:22:27 +0000 Commit: Konstantin Belousov CommitDate: 2021-12-06 00:29:43 +0000 swapoff_one(): only check free pages count manually turning swap off (cherry picked from commit 0190c38b9dfaa16de1bc61e829b9a1221fed7896) --- sys/vm/swap_pager.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c index 78533c9fb5e6..473d950dafbf 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -469,7 +469,8 @@ static bool swp_pager_swblk_empty(struct swblk *sb, int start, int limit); static void swp_pager_free_empty_swblk(vm_object_t, struct swblk *sb); static int swapongeom(struct vnode *); static int swaponvp(struct thread *, struct vnode *, u_long); -static int swapoff_one(struct swdevt *sp, struct ucred *cred); +static int swapoff_one(struct swdevt *sp, struct ucred *cred, + bool ignore_check); /* * Swap bitmap functions @@ -2518,14 +2519,14 @@ sys_swapoff(struct thread *td, struct swapoff_args *uap) error = EINVAL; goto done; } - error = swapoff_one(sp, td->td_ucred); + error = swapoff_one(sp, td->td_ucred, false); done: sx_xunlock(&swdev_syscall_lock); return (error); } static int -swapoff_one(struct swdevt *sp, struct ucred *cred) +swapoff_one(struct swdevt *sp, struct ucred *cred, bool ignore_check) { u_long nblks; #ifdef MAC @@ -2547,8 +2548,16 @@ swapoff_one(struct swdevt *sp, struct ucred *cred) * available virtual memory in the system will fit the amount * of data we will have to page back in, plus an epsilon so * the system doesn't become critically low on swap space. + * The vm_free_count() part does not account e.g. for clean + * pages that can be immediately reclaimed without paging, so + * this is a very rough estimation. + * + * On the other hand, not turning swap off on swapoff_all() + * means that we can lose swap data when filesystems go away, + * which is arguably worse. */ - if (vm_free_count() + swap_pager_avail < nblks + nswap_lowat) + if (!ignore_check && + vm_free_count() + swap_pager_avail < nblks + nswap_lowat) return (ENOMEM); /* @@ -2598,7 +2607,7 @@ swapoff_all(void) devname = devtoname(sp->sw_vp->v_rdev); else devname = "[file]"; - error = swapoff_one(sp, thread0.td_ucred); + error = swapoff_one(sp, thread0.td_ucred, true); if (error != 0) { printf("Cannot remove swap device %s (error=%d), " "skipping.\n", devname, error);