[PATCH] mkfs: use stx_blksize for dev block size by default

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Daniel Gomez <da.gomez@xxxxxxxxxxx>

In patch [1] ("bdev: use bdev_io_min() for statx block size"), block
devices will now report their preferred minimum I/O size for optimal
performance in the stx_blksize field of the statx data structure. This
change updates the current default 4 KiB block size for all devices
reporting a minimum I/O larger than 4 KiB, opting instead to query for
its advertised minimum I/O value in the statx data struct.

[1]:
https://lore.kernel.org/all/20250204231209.429356-9-mcgrof@xxxxxxxxxx/

Signed-off-by: Daniel Gomez <da.gomez@xxxxxxxxxxx>
---
Set MIN-IO from statx as the default filesystem fundamental block size.
This ensures that, for devices reporting values within the supported
XFS block size range, we do not incur in RMW. If the MIN-IO reported
value is lower than the current default of 4 KiB, then 4 KiB will be
used instead.
---
 mkfs/xfs_mkfs.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index bbd0dbb6c80ab63ebf9edbe0a9a304149770f89d..e17389622682bc23f9b20c207db7e22181e2fe6f 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -2178,6 +2178,26 @@ _("block size %d cannot be smaller than sector size %d\n"),
 	}
 }
 
+void
+get_dev_blocksize(
+	struct cli_params	*cli,
+	struct mkfs_default_params *dft)
+{
+	struct statx stx;
+	int ret;
+
+	if (!cli->xi->data.name)
+		return;
+
+	ret = statx(AT_FDCWD, cli->xi->data.name,
+		    AT_STATX_DONT_SYNC | AT_NO_AUTOMOUNT,
+		    STATX_DIOALIGN | STATX_TYPE | STATX_MODE | STATX_INO, &stx);
+	if (!ret)
+		dft->blocksize =
+			min(max(1 << XFS_DFL_BLOCKSIZE_LOG, stx.stx_blksize),
+			    XFS_MAX_BLOCKSIZE);
+}
+
 static void
 validate_blocksize(
 	struct mkfs_params	*cfg,
@@ -2189,6 +2209,7 @@ validate_blocksize(
 	 * For RAID4/5/6 we want to align sector size and block size,
 	 * so we need to start with the device geometry extraction too.
 	 */
+	get_dev_blocksize(cli, dft);
 	if (!cli->blocksize)
 		cfg->blocksize = dft->blocksize;
 	else

---
base-commit: 90d6da68ee54e6d4ef99eca4a82cac6036a34b00
change-id: 20250206-min-io-default-blocksize-13334f54899e

Best regards,
-- 
Daniel Gomez <da.gomez@xxxxxxxxxxx>





[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux