From nobody Mon Dec 20 00:38:07 2021 X-Original-To: dev-commits-src-branches@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 C551F18F0152; Mon, 20 Dec 2021 00:38:07 +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 4JHLKW37kkz3rQx; Mon, 20 Dec 2021 00:38:07 +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 425F94A04; Mon, 20 Dec 2021 00:38:07 +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 1BK0c7R4059877; Mon, 20 Dec 2021 00:38:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BK0c7ba059876; Mon, 20 Dec 2021 00:38:07 GMT (envelope-from git) Date: Mon, 20 Dec 2021 00:38:07 GMT Message-Id: <202112200038.1BK0c7ba059876@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: 45786883b076 - stable/13 - swapoff(2): add a SWAPOFF_FORCE flag List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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: 45786883b0761dcd13495be67d3e7959b0657609 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639960687; 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=Z0wB/OLMSkFAhKqr0jPnnOc6u+9Lgq/zpp7f/QoKuPs=; b=QSYRC7BpDlnYKFos8D7X1rFpbid7U6G4g6/Lz+MrtfIsN4VFqzPjxNSvduPLaIDiYPyYeY /Lt0zqOFJUTEQOpT5XtcU1p//z6/8GaDeNwPL3LD+VOt5HckPNUyYIe521PC1na32GVpo4 DwMDdKUFz/FGnA6TFFCASiPPJ+70rbHwxDST2/rtL4vWMEnT+w3f52XfeUqo0NxI9xbKPQ Cd0BqaNtgpFKTcSgMFpEbmYTWL8lzlchyoxRYvfxq+wMbw7Q+GPw3zh53HLw5VMzrxEUTl mEYgmTR9Dn6bJruyxrk8O5cLux0O2GXsFKLVunZjM8yi/1n8gHrr/NgMfT/Utw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639960687; a=rsa-sha256; cv=none; b=ORjdq54daI64heeBETSeN2MgPU9HJ1xD8tJJ4M/n5Hx1r6UFB6uB5JPG4WLx7Hm2XeeRr/ ZCTaCCLYCY1Lo/hdbNhV60tDBcFw7MQKZgkX7k8foOxSjodWrw4NSMdiNCf8PgIhHAFwId NDaH5ILAssafqWhwfCncVJav5i5u/NyHCPm1+9f+q/pwo4l9FwN67Mgmvs63peiLuJStrf 7CoM7aswM7Nnah7ZhzacKIuZhuI0pbxeJQq05ikCxJK7yZ4wIa24nMOjN1GOybOplbf4Vg 0efkQNhdpGywVXXJrngz7UxqKDeaoF5DiY/3CaTMDQRWVB+xcClPTzHtS+56cw== 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=45786883b0761dcd13495be67d3e7959b0657609 commit 45786883b0761dcd13495be67d3e7959b0657609 Author: Konstantin Belousov AuthorDate: 2021-11-29 16:28:19 +0000 Commit: Konstantin Belousov CommitDate: 2021-12-20 00:29:11 +0000 swapoff(2): add a SWAPOFF_FORCE flag (cherry picked from commit e8dc2ba29c62f3be2bdeb1a09321d73644a84475) --- sys/vm/swap_pager.c | 12 ++++++------ sys/vm/swap_pager.h | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c index 17722f314650..9238ecd5645d 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -470,7 +470,7 @@ 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, - bool ignore_check); + u_int flags); /* * Swap bitmap functions @@ -2505,7 +2505,7 @@ sys_swapoff(struct thread *td, struct swapoff_args *uap) error = copyin(uap->name, &sa, sizeof(sa)); if (error != 0) return (error); - if (sa.flags != 0) + if ((sa.flags & ~(SWAPOFF_FORCE)) != 0) return (EINVAL); break; default: @@ -2534,14 +2534,14 @@ sys_swapoff(struct thread *td, struct swapoff_args *uap) error = EINVAL; goto done; } - error = swapoff_one(sp, td->td_ucred, false); + error = swapoff_one(sp, td->td_ucred, sa.flags); done: sx_xunlock(&swdev_syscall_lock); return (error); } static int -swapoff_one(struct swdevt *sp, struct ucred *cred, bool ignore_check) +swapoff_one(struct swdevt *sp, struct ucred *cred, u_int flags) { u_long nblks; #ifdef MAC @@ -2571,7 +2571,7 @@ swapoff_one(struct swdevt *sp, struct ucred *cred, bool ignore_check) * means that we can lose swap data when filesystems go away, * which is arguably worse. */ - if (!ignore_check && + if ((flags & SWAPOFF_FORCE) == 0 && vm_free_count() + swap_pager_avail < nblks + nswap_lowat) return (ENOMEM); @@ -2622,7 +2622,7 @@ swapoff_all(void) devname = devtoname(sp->sw_vp->v_rdev); else devname = "[file]"; - error = swapoff_one(sp, thread0.td_ucred, true); + error = swapoff_one(sp, thread0.td_ucred, SWAPOFF_FORCE); if (error != 0) { printf("Cannot remove swap device %s (error=%d), " "skipping.\n", devname, error); diff --git a/sys/vm/swap_pager.h b/sys/vm/swap_pager.h index ed0abdee7d3f..b78ac6a7c698 100644 --- a/sys/vm/swap_pager.h +++ b/sys/vm/swap_pager.h @@ -76,6 +76,8 @@ struct swapoff_new_args { uintptr_t pad1[8]; }; +#define SWAPOFF_FORCE 0x00000001 + #ifdef _KERNEL extern int swap_pager_avail;