From nobody Sat Dec 04 22:21:08 2021 X-Original-To: dev-commits-src-main@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 0853E189D1A3; Sat, 4 Dec 2021 22:21:10 +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 4J640P0dn3z3tSY; Sat, 4 Dec 2021 22:21: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 B38A84826; Sat, 4 Dec 2021 22:21: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 1B4ML8gI002176; Sat, 4 Dec 2021 22:21:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B4ML8qj002175; Sat, 4 Dec 2021 22:21:08 GMT (envelope-from git) Date: Sat, 4 Dec 2021 22:21:08 GMT Message-Id: <202112042221.1B4ML8qj002175@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: e8dc2ba29c62 - main - swapoff(2): add a SWAPOFF_FORCE flag List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: e8dc2ba29c62f3be2bdeb1a09321d73644a84475 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638656469; 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=aVOuFnswMy+x+vhgHMU+HdgICcdrG5/nvPiY7+osI1g=; b=cnyA0C7yc1lCaE1Q91N13817AJM6Zx1VRyFCsbOwsrdotmL+FcJooajyLfx7KS2UIPWzFp e8nfG6xeDeHXZ/2CdEzyg6sAGTkv9AsbYvZyMJpIejbCQrV04AEmmmbu8L9HacWBdSlQ/u W93opBRqGZNMoFJYbskbseextBheticrs1BqgP/RORWAOSATTSmlTyfc51wdTslSme6ao4 ksPhFmaaur0xVSmrI2jutHN0wN1SOWIzqmTm+Z0Xc8immt+Lr4m8RcFglBb9jRrC8yVwxY RJDBSbXgJEClKWQQ5IvThlBtr8O+HeupMY3WiYl9SoGoM7Y3K2OaRnbubtIjHw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638656469; a=rsa-sha256; cv=none; b=VIgwwj3bbNSEgOuupoa6CmvsACUHCH1j0krLl2CK6BBeI7UTjcxzlW8n7/iXb8oeTDoWw4 41YhU/Ez/D/4GtfZKbOjAcEDIOF/yYKbI+jyHSR8ApOeIazCUJDvP+m0+S0ZmKv4nf2odR 9Ky2Y8G4saGCPqEb6pTV2ITs9cUouSwJHIe4CoSveokeXsCHan42qxopNvirHQKoqQ7dgD VSy1tJgNyzbW7HqBtLTOaHJbMGpUbFbiNvY+IksqD7jwkx92cp59LkgYU1qvDOIIL2VHb+ VHo/rNRnTvFcbmK5gpEADY92QZfNZj2+b6bGEnFTl8G4k4RGy4pRO/Vlv81D9Q== 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=e8dc2ba29c62f3be2bdeb1a09321d73644a84475 commit e8dc2ba29c62f3be2bdeb1a09321d73644a84475 Author: Konstantin Belousov AuthorDate: 2021-11-29 16:28:19 +0000 Commit: Konstantin Belousov CommitDate: 2021-12-04 22:20:58 +0000 swapoff(2): add a SWAPOFF_FORCE flag The flag requests skipping the heuristic which tries to avoid leaving system with more allocated memory than available from RAM and remanining swap. Reviewed by: markj Discussed with: alc Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33165 --- 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 dc1df79f4fcd..99addb2c8e53 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 @@ -2511,7 +2511,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: @@ -2539,14 +2539,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 @@ -2576,7 +2576,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); @@ -2627,7 +2627,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 469de3e8eaf4..59322d49cbc9 100644 --- a/sys/vm/swap_pager.h +++ b/sys/vm/swap_pager.h @@ -77,6 +77,8 @@ struct swapoff_new_args { uintptr_t pad1[8]; }; +#define SWAPOFF_FORCE 0x00000001 + #ifdef _KERNEL extern int swap_pager_avail;