From nobody Sun Jun 02 12:27:59 2024 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 4VsbjW1wqmz5MhND; Sun, 02 Jun 2024 12:27:59 +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 4VsbjW1MDDz570D; Sun, 2 Jun 2024 12:27:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717331279; 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=X+OnCZ2Ttibxa6hZpf4CknuUWkpROCUq912a+wjSlH0=; b=FeVRVvTJu7Q9+yb76RgzCfHxUbUBFDmiPssd+OGUG4tiaSDvSlT7DIECOYCpiD5M7Nx3hp FhTGZLVAJrHB2xHrR/qydWcpOQ2qjSCs4/QBJs4llxBJfGl7XnnpSZ7U6xI+vhW4bE1ySr 9V7tQ1CZoo5Xsb8yF13AtkqJmWl9JOHVd6muHatv6Zfdq6S3vT1qwboPV1LXL+IsCpOKMF CFovc5eEUOEk9UjL3jBzgGJn+xnZvbuyEGw9LT4S0JjDXN8jfn6i0IoeD+W9pmSKwxpE1x +Ii8/ys/bvJ0Tb48yOl8Su894QlKxVTlkIbrNBZfBA5GvysevTmjX3qZZGRkjA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717331279; a=rsa-sha256; cv=none; b=X6zP8KuA0zhLEFUmQYDHEXgIxY2/PfaCTEh5wr3D+iASXOZiXeIp0rDpAxoQkErDGtP87z /3R+fMK3Sy/7pm99aLhi7L+WVc8YN/u6LsFDAWZhuI7MG9bKEjz14g9+VDVxUwCcEQtKIa uiPWHiAfgSyG0gi4h4HEZGB09Yjl6v7bAQfCgOWWqPSZJKqthf3HLJ6lgFF4nF3EQcEwUK bQFNfe7FO9fMG2iMhIZuZ77fWjlqchNTlyU0PApBlEF1mIiAIeVb7Vyl4KajOQF48Tq9Pa 2b9jtexRd/BS5qoFeqXxa4M+HCkmKgTXiD7HaCgcRdjKlU52CVbyogUfqeTIow== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717331279; 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=X+OnCZ2Ttibxa6hZpf4CknuUWkpROCUq912a+wjSlH0=; b=XIEdm3bsXANjQbrrRXm/6W0CUL034qILewoWh7N+RmjVjdI1W1dJ9jmf0tUrsFmqlM2p/5 b9cbT/zBzGLRSX/8dJfe/a8P7bNLNvbm38vMycevbS35kTHw3NnaHL9ypc2YFl2MOpcE0z yGdSf6lg3gMSODkPagkQFaIyzKsPIOMmusZRCvUKkfNE9jjyxrBfBaNkuDFksjcFFJcH14 42VFeOyTaTrr9fMhLfHcyERJMpQSyPGOUNWzbkIFJN16JNv/oAW1k7niXwEDYxrH1qmxqr Y14gzKrbykWQ905Wb+9i0VyuoqxfmKN2Necg58w7nJpoanGPlOT7gd+k5+//wg== 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 4VsbjW0yWyzrZg; Sun, 2 Jun 2024 12:27:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 452CRx7r007473; Sun, 2 Jun 2024 12:27:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 452CRx8I007470; Sun, 2 Jun 2024 12:27:59 GMT (envelope-from git) Date: Sun, 2 Jun 2024 12:27:59 GMT Message-Id: <202406021227.452CRx8I007470@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Stefan =?utf-8?Q?E=C3=9Fer?= Subject: git: 077f757d72e5 - main - newfs_msdos: align data area to VM page boundary by default 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: se X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 077f757d72e561eb84193d8e58f63e96e69b8096 Auto-Submitted: auto-generated The branch main has been updated by se: URL: https://cgit.FreeBSD.org/src/commit/?id=077f757d72e561eb84193d8e58f63e96e69b8096 commit 077f757d72e561eb84193d8e58f63e96e69b8096 Author: Stefan Eßer AuthorDate: 2024-06-02 12:07:52 +0000 Commit: Stefan Eßer CommitDate: 2024-06-02 12:07:52 +0000 newfs_msdos: align data area to VM page boundary by default Without alignment, the data area will not be aligned with the buffer cache, leading to overhead, higher write multiplication on SSD devices and issues with very large cluster sizes (see PR 277414). The -A option used to align the start of the root directory to a multiple of the cluster size, which happens to align the start of the data area with a buffer page boundary in case of large clusters and the default number of directory entries (512 entries requiring 16 KB for FAT12 or FAT16, FAT32 puts the root directory into the data area). This commit aligns the start of the data area with the page size, if neither -A nor -r is used. It changes -A to align the start of the data area (end of the root directory) to a multiple of the cluster size, since this is the alignment that prevents write multiplication due to clusters crossing erase block boundaries of a SSD device. The -r option is unchanged and will prevent any automatic alignment from occuring. Approved by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D45436 --- sbin/newfs_msdos/mkfs_msdos.c | 26 ++++++++++++++++++-------- sbin/newfs_msdos/newfs_msdos.8 | 16 ++++++++++++++-- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/sbin/newfs_msdos/mkfs_msdos.c b/sbin/newfs_msdos/mkfs_msdos.c index 065e3c5f4192..423fbbcadcc5 100644 --- a/sbin/newfs_msdos/mkfs_msdos.c +++ b/sbin/newfs_msdos/mkfs_msdos.c @@ -249,7 +249,7 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op) ssize_t n; time_t now; u_int fat, bss, rds, cls, dir, lsn, x, x1, x2; - u_int extra_res, alignment, saved_x, attempts=0; + u_int extra_res, alignment, alignto, saved_x, attempts=0; bool set_res, set_spf, set_spc; int fd, fd1, rv; struct msdos_options o = *op; @@ -412,8 +412,12 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op) } bpb.bpbFATs = o.num_FAT; } - if (o.directory_entries) - bpb.bpbRootDirEnts = o.directory_entries; + if (o.directory_entries) { + bpb.bpbRootDirEnts = roundup(o.directory_entries, + bpb.bpbBytesPerSec / sizeof(struct de)); + if (bpb.bpbBytesPerSec == 0 || o.directory_entries >= MAXU16) + bpb.bpbRootDirEnts = MAXU16; + } if (o.media_descriptor_set) { if (o.media_descriptor < 0xf0) { warnx("illegal media descriptor (%#x)", o.media_descriptor); @@ -564,14 +568,20 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op) x1 += (bpb.bpbBigFATsecs - 1) * bpb.bpbFATs; } if (set_res) { - /* attempt to align root directory */ - alignment = (bpb.bpbResSectors + bpb.bpbBigFATsecs * bpb.bpbFATs) % - bpb.bpbSecPerClust; if (o.align) - extra_res += bpb.bpbSecPerClust - alignment; + alignto = bpb.bpbSecPerClust; + else + alignto = PAGE_SIZE / bpb.bpbBytesPerSec; + if (alignto > 1) { + /* align data clusters */ + alignment = (bpb.bpbResSectors + bpb.bpbBigFATsecs * bpb.bpbFATs + rds) % + alignto; + if (alignment != 0) + extra_res += alignto - alignment; + } } attempts++; - } while (o.align && alignment != 0 && attempts < 2); + } while (alignment != 0 && attempts < 2); if (o.align && alignment != 0) warnx("warning: Alignment failed."); diff --git a/sbin/newfs_msdos/newfs_msdos.8 b/sbin/newfs_msdos/newfs_msdos.8 index efa69c058453..816b5fc867b4 100644 --- a/sbin/newfs_msdos/newfs_msdos.8 +++ b/sbin/newfs_msdos/newfs_msdos.8 @@ -23,7 +23,7 @@ .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd January 12, 2024 +.Dd June 2, 2024 .Dt NEWFS_MSDOS 8 .Os .Sh NAME @@ -91,7 +91,13 @@ A suffix s, k, m, g (lower or upper case) appended to the offset specifies that the number is in sectors, kilobytes, megabytes or gigabytes, respectively. .It Fl A -Attempt to cluster align root directory, useful for SD card. +Attempt to cluster align the data area, useful for SD card. +If neither the +.Fl A +nor +.Fl r +option is used, the number of reserved sectors is set to a value that aligns +the start of the data area to a multiple of the page size of the host. .It Fl B Ar boot Get bootstrap from file. .It Fl C Ar create-size @@ -167,6 +173,12 @@ is 2. Number of hidden sectors. .It Fl r Ar reserved Number of reserved sectors. +If neither the +.Fl A +nor +.Fl r +option is used, the number of reserved sectors is set to a value that aligns +the start of the data area to a multiple of the page size of the host. .It Fl s Ar total File system size. .It Fl u Ar track-size