From nobody Mon Nov 29 16:39:17 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 0989418B194A; Mon, 29 Nov 2021 16:39:18 +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 4J2rfF3sx7z3jd5; Mon, 29 Nov 2021 16:39:17 +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 606F225E17; Mon, 29 Nov 2021 16:39:17 +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 1ATGdHpA033927; Mon, 29 Nov 2021 16:39:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ATGdHva033926; Mon, 29 Nov 2021 16:39:17 GMT (envelope-from git) Date: Mon, 29 Nov 2021 16:39:17 GMT Message-Id: <202111291639.1ATGdHva033926@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 0190c38b9dfa - main - 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/main X-Git-Reftype: branch X-Git-Commit: 0190c38b9dfaa16de1bc61e829b9a1221fed7896 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638203957; 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=1XIxJa0QOc0qy9xGNXLNZB3JDEG2y0BZsbUj1N8iCkc=; b=bbukeDaPU8atifS/QM5B/2lmwyGGYvAXp3vBqtf3Pd8WpEjkzQBDvkmTSZj746A8AB4I8/ uklvszbunlFfWgFGRmSKcM/dlkZeaE0PRmwZBX3XzuFHYW+f6sbTFEqolVqhY37HfkLH9B KixbMdP13YRDcGMLgQ/n6795HxObO5XJkym86QPccy5A1M425qR/bVQ6fQH4MFsJsS7yL/ 5ax+4/Yso6bhRTnFxNHGr1cX+xtY13IqeFxImLI8rs+egnjKGD4Bexynbf4otl5MbzZAeT AIvB4Y924960Rge8eiBOn0gvV5XJZfmRZ0srofDyKOMMO7pw1OHgCsfypnu+Kw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638203957; a=rsa-sha256; cv=none; b=GXN4x1trUNhV4susN0UCrVNizMbM4giaavmglYJTMsy/xQnXXfR2YH/a05UV+jEVP3vgCp cJbQDsvV6iC+i4kv/nyGGsM+1+pu3lGExrzdsxzPtweTX98qSeW2VDRZJBm7uDGsFYg5OI zWZW4bWuk7bO1uoz7AW+4Hh/EzWozX0V1kMbwUKoN1mreUyZ7ar3eQl4t1hhdBhOmGNXL1 6/RLV61auFpL3hff9MIjr1mY19AJxxWmQG4tyReX4/d0gNxZywuLhzEzPqU5V3znNXVOUV BFP+UhwjamQ0kd5M2CLeo/al0i42dLXl4ku/D/uz1MMfj/l8WdD0awClV5oYPA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=0190c38b9dfaa16de1bc61e829b9a1221fed7896 commit 0190c38b9dfaa16de1bc61e829b9a1221fed7896 Author: Konstantin Belousov AuthorDate: 2021-11-26 23:22:27 +0000 Commit: Konstantin Belousov CommitDate: 2021-11-29 16:38:02 +0000 swapoff_one(): only check free pages count manually turning swap off When swap is turned off due to system shutdown or reboot, ignore the check. Problem is that the check is not accurate by any means, free page count can legitimately be low while system still able to page in everything from the swap. Then, we turn swap off if swapping on real file or some non-standard geom provider, and typically panic when system appears to actually need to unavailable page. For syscall, it is better to be safe than sorry. Reported and tested by: peterj Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33147 --- 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 4cfdb3fd2cc8..f313d8b2d014 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 @@ -2523,14 +2524,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 @@ -2552,8 +2553,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); /* @@ -2603,7 +2612,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);