From: "Darrick J. Wong" <djwong@kernel.org>
To: aalbersh@kernel.org, djwong@kernel.org
Cc: john.g.garry@oracle.com, catherine.hoang@oracle.com,
john.g.garry@oracle.com, linux-xfs@vger.kernel.org
Subject: [PATCH 6/7] mkfs: try to align AG size based on atomic write capabilities
Date: Mon, 14 Jul 2025 22:19:30 -0700 [thread overview]
Message-ID: <175255652564.1831001.14293121870201939425.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <175255652424.1831001.9800800142745344742.stgit@frogsfrogsfrogs>
From: Darrick J. Wong <djwong@kernel.org>
Try to align the AG size to the maximum hardware atomic write unit so
that we can give users maximum flexibility in choosing an RWF_ATOMIC
write size.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: John Garry <john.g.garry@oracle.com>
---
libxfs/topology.h | 6 ++++--
libxfs/topology.c | 36 ++++++++++++++++++++++++++++++++++++
mkfs/xfs_mkfs.c | 48 +++++++++++++++++++++++++++++++++++++++++++-----
3 files changed, 83 insertions(+), 7 deletions(-)
diff --git a/libxfs/topology.h b/libxfs/topology.h
index 207a8a7f150556..f0ca65f3576e92 100644
--- a/libxfs/topology.h
+++ b/libxfs/topology.h
@@ -13,8 +13,10 @@
struct device_topology {
int logical_sector_size; /* logical sector size */
int physical_sector_size; /* physical sector size */
- int sunit; /* stripe unit */
- int swidth; /* stripe width */
+ int sunit; /* stripe unit */
+ int swidth; /* stripe width */
+ int awu_min; /* min atomic write unit in bbcounts */
+ int awu_max; /* max atomic write unit in bbcounts */
};
struct fs_topology {
diff --git a/libxfs/topology.c b/libxfs/topology.c
index 96ee74b61b30f5..7764687beac000 100644
--- a/libxfs/topology.c
+++ b/libxfs/topology.c
@@ -4,11 +4,18 @@
* All Rights Reserved.
*/
+#ifdef OVERRIDE_SYSTEM_STATX
+#define statx sys_statx
+#endif
+#include <fcntl.h>
+#include <sys/stat.h>
+
#include "libxfs_priv.h"
#include "libxcmd.h"
#include <blkid/blkid.h>
#include "xfs_multidisk.h"
#include "libfrog/platform.h"
+#include "libfrog/statx.h"
#define TERABYTES(count, blog) ((uint64_t)(count) << (40 - (blog)))
#define GIGABYTES(count, blog) ((uint64_t)(count) << (30 - (blog)))
@@ -278,6 +285,34 @@ blkid_get_topology(
device);
}
+static void
+get_hw_atomic_writes_topology(
+ struct libxfs_dev *dev,
+ struct device_topology *dt)
+{
+ struct statx sx;
+ int fd;
+ int ret;
+
+ fd = open(dev->name, O_RDONLY);
+ if (fd < 0)
+ return;
+
+ ret = statx(fd, "", AT_EMPTY_PATH, STATX_WRITE_ATOMIC, &sx);
+ if (ret)
+ goto out_close;
+
+ if (!(sx.stx_mask & STATX_WRITE_ATOMIC))
+ goto out_close;
+
+ dt->awu_min = sx.stx_atomic_write_unit_min >> 9;
+ dt->awu_max = max(sx.stx_atomic_write_unit_max_opt,
+ sx.stx_atomic_write_unit_max) >> 9;
+
+out_close:
+ close(fd);
+}
+
static void
get_device_topology(
struct libxfs_dev *dev,
@@ -316,6 +351,7 @@ get_device_topology(
}
} else {
blkid_get_topology(dev->name, dt, force_overwrite);
+ get_hw_atomic_writes_topology(dev, dt);
}
ASSERT(dt->logical_sector_size);
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index b6de13cebc93ed..d2080804a21470 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3379,6 +3379,32 @@ _("illegal CoW extent size hint %lld, must be less than %u and a multiple of %u.
}
}
+static void
+validate_device_awu(
+ struct mkfs_params *cfg,
+ struct device_topology *dt)
+{
+ /* Ignore hw atomic write capability if it can't do even 1 fsblock */
+ if (BBTOB(dt->awu_min) > cfg->blocksize ||
+ BBTOB(dt->awu_max) < cfg->blocksize) {
+ dt->awu_min = 0;
+ dt->awu_max = 0;
+ }
+}
+
+static void
+validate_hw_atomic_writes(
+ struct mkfs_params *cfg,
+ struct cli_params *cli,
+ struct fs_topology *ft)
+{
+ validate_device_awu(cfg, &ft->data);
+ if (cli->xi->log.name)
+ validate_device_awu(cfg, &ft->log);
+ if (cli->xi->rt.name)
+ validate_device_awu(cfg, &ft->rt);
+}
+
/* Complain if this filesystem is not a supported configuration. */
static void
validate_supported(
@@ -4052,10 +4078,20 @@ _("agsize (%s) not a multiple of fs blk size (%d)\n"),
*/
static void
align_ag_geometry(
- struct mkfs_params *cfg)
+ struct mkfs_params *cfg,
+ struct fs_topology *ft)
{
- uint64_t tmp_agsize;
- int dsunit = cfg->dsunit;
+ uint64_t tmp_agsize;
+ int dsunit = cfg->dsunit;
+
+ /*
+ * We've already validated (or discarded) the hardware atomic write
+ * geometry. Try to align the agsize to the maximum atomic write unit
+ * to give users maximum flexibility in choosing atomic write sizes.
+ */
+ if (ft->data.awu_max > 0)
+ dsunit = max(DTOBT(ft->data.awu_max, cfg->blocklog),
+ dsunit);
if (!dsunit)
goto validate;
@@ -4111,7 +4147,8 @@ _("agsize rounded to %lld, sunit = %d\n"),
(long long)cfg->agsize, dsunit);
}
- if ((cfg->agsize % cfg->dswidth) == 0 &&
+ if (cfg->dswidth > 0 &&
+ (cfg->agsize % cfg->dswidth) == 0 &&
cfg->dswidth != cfg->dsunit &&
cfg->agcount > 1) {
@@ -5875,6 +5912,7 @@ main(
cfg.rtblocks = calc_dev_size(cli.rtsize, &cfg, &ropts, R_SIZE, "rt");
validate_rtextsize(&cfg, &cli, &ft);
+ validate_hw_atomic_writes(&cfg, &cli, &ft);
/*
* Open and validate the device configurations
@@ -5893,7 +5931,7 @@ main(
* aligns to device geometry correctly.
*/
calculate_initial_ag_geometry(&cfg, &cli, &xi);
- align_ag_geometry(&cfg);
+ align_ag_geometry(&cfg, &ft);
if (cfg.sb_feat.zoned)
calculate_zone_geometry(&cfg, &cli, &xi, &zt);
else
next prev parent reply other threads:[~2025-07-15 5:19 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-15 5:13 [PATCHBOMB v2] xfsprogs: ports and new code for 6.16 Darrick J. Wong
2025-07-15 5:15 ` [PATCHSET 1/3] xfsprogs: new libxfs code from kernel 6.16 Darrick J. Wong
2025-07-15 5:16 ` [PATCH 1/6] xfs: add helpers to compute transaction reservation for finishing intent items Darrick J. Wong
2025-07-15 5:16 ` [PATCH 2/6] xfs: allow block allocator to take an alignment hint Darrick J. Wong
2025-07-15 5:17 ` [PATCH 3/6] xfs: commit CoW-based atomic writes atomically Darrick J. Wong
2025-07-15 5:17 ` [PATCH 4/6] libxfs: add helpers to compute log item overhead Darrick J. Wong
2025-07-18 14:03 ` Andrey Albershteyn
2025-07-15 5:17 ` [PATCH 5/6] xfs: add xfs_calc_atomic_write_unit_max() Darrick J. Wong
2025-07-15 5:17 ` [PATCH 6/6] xfs: allow sysadmins to specify a maximum atomic write limit at mount time Darrick J. Wong
2025-07-15 5:16 ` [PATCHSET 2/3] xfsprogs: atomic writes Darrick J. Wong
2025-07-15 5:18 ` [PATCH 1/7] libfrog: move statx.h from io/ to libfrog/ Darrick J. Wong
2025-07-15 5:18 ` [PATCH 2/7] xfs_db: create an untorn_max subcommand Darrick J. Wong
2025-07-15 5:18 ` [PATCH 3/7] xfs_io: dump new atomic_write_unit_max_opt statx field Darrick J. Wong
2025-07-15 5:18 ` [PATCH 4/7] mkfs: don't complain about overly large auto-detected log stripe units Darrick J. Wong
2025-07-15 5:19 ` [PATCH 5/7] mkfs: autodetect log stripe unit for external log devices Darrick J. Wong
2025-07-15 5:19 ` Darrick J. Wong [this message]
2025-07-15 5:19 ` [PATCH 7/7] mkfs: allow users to configure the desired maximum atomic write size Darrick J. Wong
2025-07-15 5:16 ` [PATCHSET 3/3] xfs_scrub: drop EXPERIMENTAL warning Darrick J. Wong
2025-07-15 5:20 ` [PATCH 1/1] xfs_scrub: remove EXPERIMENTAL warnings Darrick J. Wong
-- strict thread matches above, loose matches on Subject: below --
2025-07-01 18:05 [PATCHSET 2/3] xfsprogs: atomic writes Darrick J. Wong
2025-07-01 18:08 ` [PATCH 6/7] mkfs: try to align AG size based on atomic write capabilities Darrick J. Wong
2025-07-02 9:03 ` John Garry
2025-07-02 19:00 ` Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=175255652564.1831001.14293121870201939425.stgit@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=aalbersh@kernel.org \
--cc=catherine.hoang@oracle.com \
--cc=john.g.garry@oracle.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox