From nobody Sat Dec 04 22:21:10 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 5E5CB189D511; Sat, 4 Dec 2021 22:21:12 +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 4J640R3h9hz3tb5; Sat, 4 Dec 2021 22:21:11 +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 061984897; Sat, 4 Dec 2021 22:21:11 +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 1B4MLAWh002224; Sat, 4 Dec 2021 22:21:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B4MLApj002223; Sat, 4 Dec 2021 22:21:10 GMT (envelope-from git) Date: Sat, 4 Dec 2021 22:21:10 GMT Message-Id: <202112042221.1B4MLApj002223@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: 1aa249c93588 - main - swapoff(8): add -f 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: 1aa249c935884d4c0c096c00facbb22f214128cc Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638656471; 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=V9Jn+kfIL8XdLexygbcd6QtTot+sPRdYea62V3MZIY8=; b=IBlJAdAupBjHilJoKEyXDeWnPNi57ArPvKPTJLAmJ68JbN7EzTRFS0249tukO8v4rslZYH K392IHucvG06yYxTF2LRKXjwUJnBlqLHeCfOlSkQSTwDbZNRRgEZaGzcj48CQeFnYGhx+S Vl1gPeDYaSmuX5ezbK89xGJBT+2s7S8tcw8nVmj0+r6XBGEiErvQjSAE4UwM9aGx2vdcr5 /xOIZ8KUfs2podEIaOXlaL2ooTwUlA94lms8Lm6HjwKk8/hzs9gJVxgJAbALDw3gf/RzYc uC95RdZtfg9BPttmMf5zy4+2uv2EA+gQqwGz11wXky7Txjsm/eh6QLh8qrxsDA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638656471; a=rsa-sha256; cv=none; b=icHyIxvEq7JlGp8Qy+mZYP/fJhe/qle2r5MdTkWUvMZ+SOabdpJv53YHCfGW1SXMTFAGEc eocMLdFaXHPfAwUmxU1ykOSsy3US8dhsKE8+a+aLSP6xcoQFdgxZwhq/uLGQ4RLuc8YwFn wHaRQ1TwAm9ELUyNo/X5R+mbxHiPQga27na4SGdIerUQ9Mxaqfx1OsbORAZd5zistybVgz OgjfgW8ncJomYwkFQr8ZZnCwuOxYSi9lzVxbSJzZB66oYCiv3aRmzKzD67+W43DLhISDB0 PzXpP0pPnwGjufXbSPS7x+7cTQsEtkzF/uqH7lS/G9oxGD692w9LB+nEmtXYKA== 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=1aa249c935884d4c0c096c00facbb22f214128cc commit 1aa249c935884d4c0c096c00facbb22f214128cc Author: Konstantin Belousov AuthorDate: 2021-11-29 16:30:09 +0000 Commit: Konstantin Belousov CommitDate: 2021-12-04 22:20:58 +0000 swapoff(8): add -f flag to force swapout by ignoring the heuristic that calculates amount of allocated memory against total of RAM plus remaining swap. Reviewed by: markj Discussed with: alc Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33165 --- sbin/swapon/swapon.8 | 16 +++++++++++----- sbin/swapon/swapon.c | 23 ++++++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/sbin/swapon/swapon.8 b/sbin/swapon/swapon.8 index 7ae28031dc1e..0146a7750e12 100644 --- a/sbin/swapon/swapon.8 +++ b/sbin/swapon/swapon.8 @@ -28,7 +28,7 @@ .\" @(#)swapon.8 8.1 (Berkeley) 6/5/93 .\" $FreeBSD$ .\" -.Dd May 19, 2020 +.Dd November 29, 2021 .Dt SWAPON 8 .Os .Sh NAME @@ -42,9 +42,9 @@ .Nm swapoff .Oo Fl F Ar fstab .Oc -.Fl aLq | Ar +.Fl afLq | Ar .Nm swapctl -.Op Fl AghklmsU +.Op Fl AfghklmsU .Oo .Fl a Ar | @@ -125,8 +125,14 @@ informational messages will not be written to standard output when a swap device is removed. Note that .Nm swapoff -will fail and refuse to remove a swap device if there is insufficient -VM (memory + remaining swap devices) to run the system. +will fail and refuse to remove a swap device if a very conservative +check does not conclude that there is sufficient VM (memory + +remaining swap devices) to run the system. +The +.Fl f +option turns off this check, which could deadlock the system +if there is insufficient swap space remaining. +.Pp The .Nm swapoff utility diff --git a/sbin/swapon/swapon.c b/sbin/swapon/swapon.c index 5adc870adf59..d644d99e7913 100644 --- a/sbin/swapon/swapon.c +++ b/sbin/swapon/swapon.c @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -78,7 +79,7 @@ static int run_cmd(int *, const char *, ...) __printflike(2, 3); static enum { SWAPON, SWAPOFF, SWAPCTL } orig_prog, which_prog = SWAPCTL; -static int Eflag, qflag; +static int Eflag, fflag, qflag; int main(int argc, char **argv) @@ -101,7 +102,7 @@ main(int argc, char **argv) doall = 0; etc_fstab = NULL; - while ((ch = getopt(argc, argv, "AadEghklLmqsUF:")) != -1) { + while ((ch = getopt(argc, argv, "AadEfghklLmqsUF:")) != -1) { switch(ch) { case 'A': if (which_prog == SWAPCTL) { @@ -128,6 +129,12 @@ main(int argc, char **argv) else usage(); break; + case 'f': + if (which_prog == SWAPOFF) + fflag = 1; + else + usage(); + break; case 'g': hflag = 'G'; break; @@ -782,12 +789,18 @@ swapon_trim(const char *name) static const char * swap_on_off_sfile(const char *name, int doingall) { + struct swapoff_new_args sa; int error; if (which_prog == SWAPON) error = Eflag ? swapon_trim(name) : swapon(name); - else /* SWAPOFF */ - error = swapoff(name); + else { /* SWAPOFF */ + bzero(&sa, sizeof(sa)); + sa.name = name; + if (fflag) + sa.flags |= SWAPOFF_FORCE; + error = swapoff((const char *)&sa); + } if (error == -1) { switch (errno) { @@ -820,7 +833,7 @@ usage(void) fprintf(stderr, "[-F fstab] -aLq | [-E] file ...\n"); break; case SWAPOFF: - fprintf(stderr, "[-F fstab] -aLq | file ...\n"); + fprintf(stderr, "[-F fstab] -afLq | file ...\n"); break; case SWAPCTL: fprintf(stderr, "[-AghklmsU] [-a file ... | -d file ...]\n");