From owner-svn-src-head@freebsd.org Thu Aug 15 02:30:45 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 67004C40C1; Thu, 15 Aug 2019 02:30:45 +0000 (UTC) (envelope-from dougm@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4689RT29Scz4JPG; Thu, 15 Aug 2019 02:30:45 +0000 (UTC) (envelope-from dougm@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2C5099915; Thu, 15 Aug 2019 02:30:45 +0000 (UTC) (envelope-from dougm@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x7F2Ujg6088928; Thu, 15 Aug 2019 02:30:45 GMT (envelope-from dougm@FreeBSD.org) Received: (from dougm@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x7F2Ui4Y088925; Thu, 15 Aug 2019 02:30:44 GMT (envelope-from dougm@FreeBSD.org) Message-Id: <201908150230.x7F2Ui4Y088925@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dougm set sender to dougm@FreeBSD.org using -f From: Doug Moore Date: Thu, 15 Aug 2019 02:30:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351064 - in head: sbin/swapon share/man/man5 sys/vm X-SVN-Group: head X-SVN-Commit-Author: dougm X-SVN-Commit-Paths: in head: sbin/swapon share/man/man5 sys/vm X-SVN-Commit-Revision: 351064 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Aug 2019 02:30:45 -0000 Author: dougm Date: Thu Aug 15 02:30:44 2019 New Revision: 351064 URL: https://svnweb.freebsd.org/changeset/base/351064 Log: swap_pager.c reserves 2 blocks for a bsd label. Change that 2 to the expression howmany(BBSIZE, PAGE_SIZE), where BBSIZE is the size of the boot block area. That can be less than 2 if PAGE_SIZE is big. swapon(8) has an option to trim (delete) all the blocks of a device at startup. However, if the first of those blocks is a bsd label, then trimming those blocks is destructive. Change swapon to leave the first BBSIZE bytes untrimmed. Update manual pages to reflect changes in how swapon and how it may be used, espeically in association with savecore. Reviewed by: alc Approved by: markj (mentor) MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D21191 Modified: head/sbin/swapon/swapon.8 head/sbin/swapon/swapon.c head/share/man/man5/fstab.5 head/sys/vm/swap_pager.c Modified: head/sbin/swapon/swapon.8 ============================================================================== --- head/sbin/swapon/swapon.8 Thu Aug 15 02:14:44 2019 (r351063) +++ head/sbin/swapon/swapon.8 Thu Aug 15 02:30:44 2019 (r351064) @@ -90,7 +90,17 @@ The .Fl E option causes each of following devices to receive a .Dv BIO_DELETE -command to mark all blocks as unused. +command. +This command marks the device's blocks as unused, except those that +might store a disk label. +This marking can erase a crash dump. +To delay +.Nm swapon +for a device until after +.Nm savecore +has copied the crash dump to another location, use the +.Dq late +option. .Pp The .Nm swapoff Modified: head/sbin/swapon/swapon.c ============================================================================== --- head/sbin/swapon/swapon.c Thu Aug 15 02:14:44 2019 (r351063) +++ head/sbin/swapon/swapon.c Thu Aug 15 02:30:44 2019 (r351064) @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -761,8 +762,8 @@ swapon_trim(const char *name) } else errx(1, "%s has an invalid file type", name); /* Trim the device. */ - ioarg[0] = 0; - ioarg[1] = sz; + ioarg[0] = BBSIZE; + ioarg[1] = sz - BBSIZE; if (ioctl(fd, DIOCGDELETE, ioarg) != 0) warn("ioctl(DIOCGDELETE)"); Modified: head/share/man/man5/fstab.5 ============================================================================== --- head/share/man/man5/fstab.5 Thu Aug 15 02:14:44 2019 (r351063) +++ head/share/man/man5/fstab.5 Thu Aug 15 02:30:44 2019 (r351064) @@ -246,8 +246,17 @@ For swap devices, the keyword .Dq trimonce triggers the delivery of a .Dv BIO_DELETE -command to the device to mark -all blocks as unused. +command to the device. +This command marks the device's blocks as unused, except those that +might store a disk label. +This marking can erase a crash dump. +To delay +.Nm swapon +for a device until after +.Nm savecore +has copied the crash dump to another location, use the +.Dq late +option. For vnode-backed swap spaces, .Dq file is supported in the Modified: head/sys/vm/swap_pager.c ============================================================================== --- head/sys/vm/swap_pager.c Thu Aug 15 02:14:44 2019 (r351063) +++ head/sys/vm/swap_pager.c Thu Aug 15 02:30:44 2019 (r351064) @@ -79,6 +79,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -2298,10 +2299,11 @@ swaponsomething(struct vnode *vp, void *id, u_long nbl sp->sw_blist = blist_create(nblks, M_WAITOK); /* - * Do not free the first two block in order to avoid overwriting + * Do not free the first blocks in order to avoid overwriting * any bsd label at the front of the partition */ - blist_free(sp->sw_blist, 2, nblks - 2); + blist_free(sp->sw_blist, howmany(BBSIZE, PAGE_SIZE), + nblks - howmany(BBSIZE, PAGE_SIZE)); dvbase = 0; mtx_lock(&sw_dev_mtx); @@ -2319,7 +2321,7 @@ swaponsomething(struct vnode *vp, void *id, u_long nbl sp->sw_end = dvbase + nblks; TAILQ_INSERT_TAIL(&swtailq, sp, sw_list); nswapdev++; - swap_pager_avail += nblks - 2; + swap_pager_avail += nblks - howmany(BBSIZE, PAGE_SIZE); swap_total += nblks; swapon_check_swzone(); swp_sizecheck();