enable cached zone report v4
Enable cached zone report to speed up mkfs and repair on a zoned block device (e.g. an SMR disk). Cached zone report support was introduced in the kernel with version 6.19-rc1.
Note: I've taken this series over from Damien as he's busy and it need it as a base for further work.
Changes from v3:
- reorder includes to not need the forward declaration in xfs_zones.h
- use the libfrog/ for #include statements
- fix the include guard in libfrog/zones.h
- fix up i18n string mess
- hide the new ioctl definition in libfrog/zones.c
- don't add userspace includes to libxfs/xfs_zones.h
- reuse the buffer for multiple report zone calls
Changes from v2:
- Complete rework of the series to make the zone reporting code common in libfrog
- Added patch 1 and 2 as small cleanups/improvements.
Changes from v1:
- Fix erroneous handling of ioctl(BLKREPORTZONEV2) error to correctly fallback to the regular ioctl(BLKREPORTZONE) if the kernel does not support BLKREPORTZONEV2.
PATCH 1/4 xfs: use blkdev_report_zones_cached()
From: Damien Le Moal <[email protected]>
Source kernel commit: e04ccfc28252f181ea8d469d834b48e7dece65b2
Modify xfs_mount_zones() to replace the call to blkdev_report_zones() with blkdev_report_zones_cached() to speed-up mount operations. Since this causes xfs_zone_validate_seq() to see zones with the BLK_ZONE_COND_ACTIVE condition, this function is also modified to acept this condition as valid.
With this change, mounting a freshly formatted large capacity (30 TB) SMR HDD completes under 2s compared to over 4.7s before.
--- include/platform_defs.h | 4 ++++ libxfs/xfs_zones.c | 1 + 2 files changed, 5 insertions(+)
include/platform_defs.h +4 -0
@@ -307,4 +307,8 @@ struct kvec { size_t iov_len; }; +#ifndef BLK_ZONE_COND_ACTIVE /* added in Linux 6.19 */ +#define BLK_ZONE_COND_ACTIVE 0xff +#endif +#endif /* __XFS_PLATFORM_DEFS_H__ */
libxfs/xfs_zones.c +1 -0
@@ -97,6 +97,7 @@ xfs_zone_validate_seq(case BLK_ZONE_COND_IMP_OPEN :case BLK_ZONE_COND_EXP_OPEN :case BLK_ZONE_COND_CLOSED : +case BLK_ZONE_COND_ACTIVE :return xfs_zone_validate_wp (zone, rtg, write_pointer);case BLK_ZONE_COND_FULL :return xfs_zone_validate_full (zone, rtg, write_pointer);
Signature · 1 line
2.47.3
Re: [PATCH 1/4] xfs: use blkdev_report_zones_cached()
Quoted 27 lines · Christoph Hellwig
From: Damien Le Moal <[email protected]>
Source kernel commit:
e04ccfc28252f181ea8d469d834b48e7dece65b2Modify
xfs_mount_zones()to replace the call toblkdev_report_zones()withblkdev_report_zones_cached()to speed-up mount operations. Since this causesxfs_zone_validate_seq()to see zones with theBLK_ZONE_COND_ACTIVEcondition, this function is also modified to acept this condition as valid.With this change, mounting a freshly formatted large capacity (30 TB) SMR HDD completes under 2s compared to over 4.7s before.
Signed-off-by Damien Le Moal <[email protected]>Reviewed-by Martin K. Petersen <[email protected]>Signed-off-by Jens Axboe <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>--- include/platform_defs.h | 4 ++++ libxfs/xfs_zones.c | 1 + 2 files changed, 5 insertions(+)include/platform_defs.h +0
-0
include/platform_defs.h struct kvec { · line 311
Quoted 5 lines
include/platform_defs.h +2
-0@@ -307,4 +307,8 @@ struct kvec {size_t iov_len; }; +#ifndef BLK_ZONE_COND_ACTIVE /* added in Linux 6.19 */ +#define BLK_ZONE_COND_ACTIVE 0xff
hmm I think #ifndef doesn't work for enum member. Compiling against linux 6.19-rc6:
../include/platform_defs.h:311:33: error: expected identifier before numeric constant
311 | #define BLK_ZONE_COND_ACTIVE 0xff
| ^~~~
/linux-headers-v6.19-rc6/include/linux/blkzoned.h:84:9: note: in expansion of macro ‘BLK_ZONE_COND_ACTIVE’
84 | BLK_ZONE_COND_ACTIVE = 0xFF,
| ^~~~~~~~~~~~~~~~~~~~Signature · 1 line
- Andrey
Re: [PATCH 1/4] xfs: use blkdev_report_zones_cached()
Quoted 37 lines · Andrey Albershteyn
Quoted 27 lines · Christoph Hellwig
From: Damien Le Moal <[email protected]>
Source kernel commit:
e04ccfc28252f181ea8d469d834b48e7dece65b2Modify
xfs_mount_zones()to replace the call toblkdev_report_zones()withblkdev_report_zones_cached()to speed-up mount operations. Since this causesxfs_zone_validate_seq()to see zones with theBLK_ZONE_COND_ACTIVEcondition, this function is also modified to acept this condition as valid.With this change, mounting a freshly formatted large capacity (30 TB) SMR HDD completes under 2s compared to over 4.7s before.
Signed-off-by Damien Le Moal <[email protected]>Reviewed-by Martin K. Petersen <[email protected]>Signed-off-by Jens Axboe <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>--- include/platform_defs.h | 4 ++++ libxfs/xfs_zones.c | 1 + 2 files changed, 5 insertions(+)include/platform_defs.h +0
-0include/platform_defs.h struct kvec { · line 311
Quoted 5 lines
include/platform_defs.h +2
-0@@ -307,4 +307,8 @@ struct kvec {size_t iov_len; }; +#ifndef BLK_ZONE_COND_ACTIVE /* added in Linux 6.19 */ +#define BLK_ZONE_COND_ACTIVE 0xffhmm I think #ifndef doesn't work for enum member. Compiling against linux 6.19-rc6:
Quoted 6 lines
../include/platform_defs.h:311:33: error: expected identifier before numeric constant311 | #define BLK_ZONE_COND_ACTIVE 0xff | ^~~~ /linux-headers-v6.19-rc6/include/linux/blkzoned.h:84:9: note: in expansion of macro ‘BLK_ZONE_COND_ACTIVE’ 84 | BLK_ZONE_COND_ACTIVE = 0xFF, | ^~~~~~~~~~~~~~~~~~~~
I hacked around this very crudely:
https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfsprogs-dev.git/commit/?h=djwong-wtf&id=d5d9b4bd2da95c7b9429112f1c1098a62f155270
Though I think one of hch's fix patches fixed that. I cannot post a lore link because the #@!%)*&!%!!! anubis b@%#%!!! is completely broken and will not let me in. But we did the review for the kernel-side fixes within the last couple of weeks.
--D
Quoted 5 lines
Signature · 2 lines
-- - Andrey
Re: [PATCH 1/4] xfs: use blkdev_report_zones_cached()
Quoted 13 lines · Darrick J. Wong
Quoted 6 lines
include/platform_defs.h struct kvec { · line 311
Quoted 2 lines
include/platform_defs.h +2
-0+#ifndef BLK_ZONE_COND_ACTIVE /* added in Linux 6.19 */ +#define BLK_ZONE_COND_ACTIVE 0xffhmm I think #ifndef doesn't work for enum member. Compiling against linux 6.19-rc6:
Quoted 6 lines
../include/platform_defs.h:311:33: error: expected identifier before numeric constant311 | #define BLK_ZONE_COND_ACTIVE 0xff | ^~~~ /linux-headers-v6.19-rc6/include/linux/blkzoned.h:84:9: note: in expansion of macro ‘BLK_ZONE_COND_ACTIVE’ 84 | BLK_ZONE_COND_ACTIVE = 0xFF, | ^~~~~~~~~~~~~~~~~~~~
Quoted 2 lines
I hacked around this very crudely:
https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfsprogs-dev.git/commit/?h=djwong-wtf&id=d5d9b4bd2da95c7b9429112f1c1098a62f155270
Urgg. That's why we should not use enums in uapi headers..
Damien, I guess we could do a:
#define BLK_ZONE_COND_ACTIVE BLK_ZONE_COND_ACTIVE
as the usual trick to fix that in the blkzoned.h header, and given that 6.19 hasn't been released still get it to Linus in time.
Quoted 4 lines
Though I think one of hch's fix patches fixed that. I cannot post a lore link because the #@!%)*&!%!!! anubis b@%#%!!! is completely broken and will not let me in. But we did the review for the kernel-side fixes within the last couple of weeks.
I don't think I fixed it. Not intentionally, and not unintentionally in a way I'd actually understand at least :)
PATCH 1/1 libfrog: adjust header order for BLK_ZONE_COND_ACTIVE #ifndef check
Even after kernel fix via defining BLK_ZONE_COND_ACTIVE the compiler is still failing on this with:
In file included from zones.c:5:../include/platform_defs.h:311:33: error: expected identifier before numeric constant
311 | #define BLK_ZONE_COND_ACTIVE 0xff
| ^~~~
/linux-headers-v6.19-rc7/include/linux/blkzoned.h:84:9: note: in expansion of macro ‘BLK_ZONE_COND_ACTIVE’
84 | BLK_ZONE_COND_ACTIVE = 0xFF, /* added in Linux 6.19 */
| ^~~~~~~~~~~~~~~~~~~~
In file included from ../libfrog/zones.h:8,
from zones.c:7:
/linux-headers-v6.19-rc7/include/linux/blkzoned.h:85:9: warning: ‘BLK_ZONE_COND_ACTIVE’ redefined
85 | #define BLK_ZONE_COND_ACTIVE BLK_ZONE_COND_ACTIVE
| ^~~~~~~~~~~~~~~~~~~~
../include/platform_defs.h:311:9: note: this is the location of the previous definition
311 | #define BLK_ZONE_COND_ACTIVE 0xff
| ^~~~~~~~~~~~~~~~~~~~This is because of the order of #ifndef (in platform_defs.h) and #define (in blkzoned.h). The platform_defs.h defines BLK_ZONE_COND_ACTIVE first and this causes enum to fail and macro being redefined. Fix this by including libfrog/zones.h first, which includes blkzoned.h. Add stdint.h for uint64_t in xfrog_report_zones().
--- libfrog/zones.c | 2 +- libfrog/zones.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
libfrog/zones.c +1 -1
@@ -2,9 +2,9 @@/* * Copyright (c) 2025, Western Digital Corporation or its affiliates. */ +#include "libfrog/zones.h" #include "platform_defs.h" #include "atomic.h" -#include "libfrog/zones.h" #include <sys/ioctl.h> /*
libfrog/zones.h +1 -0
@@ -6,6 +6,7 @@#define __LIBFROG_ZONES_H__#include <linux/blkzoned.h> +#include <stdint.h> struct xfrog_zone_report {struct blk_zone_report rep;
Signature · 1 line
2.51.2
Re: [PATCH] libfrog: adjust header order for BLK_ZONE_COND_ACTIVE #ifndef check
Quoted 5 lines · Andrey Albershteyn
This is because of the order of #ifndef (in
platform_defs.h) and #define (inblkzoned.h). Theplatform_defs.hdefinesBLK_ZONE_COND_ACTIVEfirst and this causes enum to fail and macro being redefined. Fix this by includinglibfrog/zones.hfirst, which includesblkzoned.h. Addstdint.hforuint64_tinxfrog_report_zones().
Thanks, this looks good:
please order this before the cached zone reporting series, or fold it in to preserve bisectability. Or should I resend the series with this change included?
Re: [PATCH] libfrog: adjust header order for BLK_ZONE_COND_ACTIVE #ifndef check
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Andrey Albershteyn
This is because of the order of #ifndef (in
platform_defs.h) and #define (inblkzoned.h). Theplatform_defs.hdefinesBLK_ZONE_COND_ACTIVEfirst and this causes enum to fail and macro being redefined. Fix this by includinglibfrog/zones.hfirst, which includesblkzoned.h. Addstdint.hforuint64_tinxfrog_report_zones().Thanks, this looks good:
Reviewed-by Christoph Hellwig <[email protected]>
Thanks!
Quoted 2 lines
please order this before the cached zone reporting series, or fold it in
I will apply it first
Signature · 1 line
- Andrey
Re: [PATCH] libfrog: adjust header order for BLK_ZONE_COND_ACTIVE #ifndef check
Quoted 10 lines · Andrey Albershteyn
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Andrey Albershteyn
This is because of the order of #ifndef (in
platform_defs.h) and #define (inblkzoned.h). Theplatform_defs.hdefinesBLK_ZONE_COND_ACTIVEfirst and this causes enum to fail and macro being redefined. Fix this by includinglibfrog/zones.hfirst, which includesblkzoned.h. Addstdint.hforuint64_tinxfrog_report_zones().Thanks, this looks good:
Quoted 8 lines
Quoted 1 line
Reviewed-by Christoph Hellwig <[email protected]>Thanks!
Quoted 2 lines
please order this before the cached zone reporting series, or fold it in
I will apply it first
hmm, actually there's no this header to apply fix to, can you resend it with this fix applied?
Signature · 1 line
- Andrey
Re: [PATCH] libfrog: adjust header order for BLK_ZONE_COND_ACTIVE #ifndef check
Quoted 4 lines · Andrey Albershteyn
Quoted 1 line
I will apply it first
hmm, actually there's no this header to apply fix to, can you resend it with this fix applied?
Sure.
PATCH 2/4 mkfs: remove unnecessary return value affectation
In reply to Christoph HellwigFrom: Damien Le Moal <[email protected]>
The function report_zones() in mkfs/xfs_mkfs.c is a void function. So there is no need to set the variable ret to -EIO before returning if fstat() fails.
--- mkfs/xfs_mkfs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
mkfs/xfs_mkfs.c +1 -3
@@ -2587,10 +2587,8 @@ report_zones(exit (1 ); } -if (fstat (fd, &st) <0 ) { - ret = -EIO ; +if (fstat (fd, &st) <0 ) goto out_close; - }if (!S_ISBLK (st.st_mode)) goto out_close;
Signature · 1 line
2.47.3
PATCH 3/4 libfrog: lift common zone reporting code from mkfs and repair
In reply to Christoph HellwigFrom: Damien Le Moal <[email protected]>
Define the new helper function xfrog_report_zones() to report zones of a zoned block device. This function is implemented in the new file libfrog/zones.c and defined in the header file libfrog/zones.h and use it from mkfs and repair instead of the previous open coded versions.
xfrog_report_zones() allocates and returns a struct blk_zone_report structure, which can be be reused by subsequent invocations. It is the responsibility of the caller to free this structure after use.
--- libfrog/Makefile | 6 ++++-- libfrog/zones.c | 39 +++++++++++++++++++++++++++++++++++++++ libfrog/zones.h | 18 ++++++++++++++++++ mkfs/xfs_mkfs.c | 41 ++++++++++++----------------------------- repair/zoned.c | 35 +++++++++++------------------------ 5 files changed, 84 insertions(+), 55 deletions(-) create mode 100644 libfrog/zones.c create mode 100644 libfrog/zones.h
libfrog/Makefile +4 -2
@@ -35,7 +35,8 @@ radix-tree.c \ randbytes.c \ scrub.c \ util.c \ -workqueue.c +workqueue.c \ +zones.c HFILES = \ avl64.h \
@@ -65,7 +66,8 @@ radix-tree.h \ randbytes.h \ scrub.h \ statx.h \ -workqueue.h +workqueue.h \ +zones.h GETTEXT_PY = \ gettext.py
libfrog/zones.c new file +39 -0
@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2025, Western Digital Corporation or its affiliates. +*/ +#include "platform_defs.h" +#include "libfrog/zones.h" +#include <sys/ioctl.h> + +/* random size that allows efficient processing */ +#define ZONES_PER_REPORT 16384 + +struct xfrog_zone_report * +xfrog_report_zones ( +int fd, +uint64_t sector, +struct xfrog_zone_report *rep) +{ +if (!rep) { + rep =calloc (1 ,struct_size (rep, zones,ZONES_PER_REPORT )); +if (!rep) { +fprintf (stderr,"%s\n" , +_ ("Failed to allocate memory for reporting zones." )); +return NULL ; + } + } + + rep->rep.sector = sector; + rep->rep.nr_zones =ZONES_PER_REPORT ; + +if (ioctl (fd,BLKREPORTZONE , &rep->rep)) { +fprintf (stderr,"%s %s\n" , +_ ("ioctl(BLKREPORTZONE) failed:\n" ), +strerror (-errno)); +free (rep); +return NULL ; + } + +return rep; +}
libfrog/zones.h new file +18 -0
@@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2025, Western Digital Corporation or its affiliates. +*/ +#ifndef __LIBFROG_ZONES_H__ +#define __LIBFROG_ZONES_H__ + +#include <linux/blkzoned.h> + +struct xfrog_zone_report { +struct blk_zone_report rep; +struct blk_zone zones[]; +}; + +struct xfrog_zone_report * +xfrog_report_zones (int fd,uint64_t sector,struct xfrog_zone_report *rep); + +#endif /* __LIBFROG_ZONES_H__ */
mkfs/xfs_mkfs.c +12 -29
79 lines not on this page · raw message
repair/zoned.c +11 -24
@@ -7,6 +7,7 @@#include "libxfs_priv.h" #include "libxfs.h" #include "xfs_zones.h" +#include "libfrog/zones.h" #include "err_protos.h" #include "zoned.h"
@@ -51,8 +52,7 @@ check_zones(uint64_t sector =XFS_FSB_TO_BB (mp, mp->m_sb.sb_rtstart);unsigned int zone_size, zone_capacity;uint64_t device_size; -size_t rep_size; -struct blk_zone_report *rep; +struct xfrog_zone_report *rep =NULL ;unsigned int i, n =0 ;if (ioctl (fd,BLKGETSIZE64 , &device_size))
@@ -67,31 +67,18 @@ check_zones(return ; } - rep_size =sizeof (struct blk_zone_report ) + -sizeof (struct blk_zone ) *ZONES_PER_IOCTL ; - rep =malloc (rep_size); -if (!rep) { -do_warn (_ ("malloc failed for zone report\n" )); -return ; - } -while (n < mp->m_sb.sb_rgcount) { -struct blk_zone *zones = (struct blk_zone *)(rep +1 ); -int ret; +struct blk_zone *zones; -memset (rep,0 , rep_size); - rep->sector = sector; - rep->nr_zones =ZONES_PER_IOCTL ; + rep =xfrog_report_zones (fd, sector, rep); +if (!rep) +return ; - ret =ioctl (fd,BLKREPORTZONE , rep); -if (ret) { -do_error (_ ("ioctl(BLKREPORTZONE) failed: %d!\n" ), ret); - goto out_free; - } -if (!rep->nr_zones) +if (!rep->rep.nr_zones)break ; -for (i =0 ; i < rep->nr_zones; i++) { + zones = rep->zones; +for (i =0 ; i < rep->rep.nr_zones; i++) {if (n >= mp->m_sb.sb_rgcount)break ;
@@ -130,8 +117,8 @@ _("Inconsistent zone capacity!\n"));report_zones_cb (mp, &zones[i]); n++; } - sector = zones[rep->nr_zones -1 ].start + - zones[rep->nr_zones -1 ].len; + sector = zones[rep->rep.nr_zones -1 ].start + + zones[rep->rep.nr_zones -1 ].len; } out_free:
Signature · 1 line
2.47.3
Re: [PATCH 3/4] libfrog: lift common zone reporting code from mkfs and repair
Quoted 7 lines · Christoph Hellwig
From: Damien Le Moal <[email protected]>
Define the new helper function
xfrog_report_zones()to report zones of a zoned block device. This function is implemented in the new filelibfrog/zones.cand defined in the header filelibfrog/zones.hand use it from mkfs and repair instead of the previous open coded versions.
Quoted 7 lines
xfrog_report_zones()allocates and returns a structblk_zone_reportstructure, which can be be reused by subsequent invocations. It is the responsibility of the caller to free this structure after use.Signed-off-by Damien Le Moal <[email protected]>[hch: refactored to allow buffer reuse]Signed-off-by Christoph Hellwig <[email protected]>
Looks good now, thanx for avoiding the buffer reallocations
--D
Quoted 267 lines
--- libfrog/Makefile | 6 ++++-- libfrog/zones.c | 39 +++++++++++++++++++++++++++++++++++++++ libfrog/zones.h | 18 ++++++++++++++++++ mkfs/xfs_mkfs.c | 41 ++++++++++++----------------------------- repair/zoned.c | 35 +++++++++++------------------------ 5 files changed, 84 insertions(+), 55 deletions(-) create mode 100644 libfrog/zones.c create mode 100644 libfrog/zones.hlibfrog/Makefile +4
-2@@ -35,7 +35,8 @@ radix-tree.c \ randbytes.c \ scrub.c \ util.c \ -workqueue.c +workqueue.c \ +zones.c HFILES = \ avl64.h \@@ -65,7 +66,8 @@ radix-tree.h \ randbytes.h \ scrub.h \ statx.h \ -workqueue.h +workqueue.h \ +zones.h GETTEXT_PY = \ gettext.pylibfrog/zones.c new file +39
-0@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2025, Western Digital Corporation or its affiliates. +*/ +#include "platform_defs.h" +#include "libfrog/zones.h" +#include <sys/ioctl.h> + +/* random size that allows efficient processing */ +#define ZONES_PER_REPORT 16384 + +struct xfrog_zone_report * +xfrog_report_zones ( +int fd, +uint64_t sector, +struct xfrog_zone_report *rep) +{ +if (!rep) { + rep =calloc (1 ,struct_size (rep, zones,ZONES_PER_REPORT )); +if (!rep) { +fprintf (stderr,"%s\n" , +_ ("Failed to allocate memory for reporting zones." )); +return NULL ; + } + } + + rep->rep.sector = sector; + rep->rep.nr_zones =ZONES_PER_REPORT ; + +if (ioctl (fd,BLKREPORTZONE , &rep->rep)) { +fprintf (stderr,"%s %s\n" , +_ ("ioctl(BLKREPORTZONE) failed:\n" ), +strerror (-errno)); +free (rep); +return NULL ; + } + +return rep; +}libfrog/zones.h new file +18
-0@@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2025, Western Digital Corporation or its affiliates. +*/ +#ifndef __LIBFROG_ZONES_H__ +#define __LIBFROG_ZONES_H__ + +#include <linux/blkzoned.h> + +struct xfrog_zone_report { +struct blk_zone_report rep; +struct blk_zone zones[]; +}; + +struct xfrog_zone_report * +xfrog_report_zones (int fd,uint64_t sector,struct xfrog_zone_report *rep); + +#endif /* __LIBFROG_ZONES_H__ */ mkfs/xfs_mkfs.c +12
-29@@ -15,6 +15,7 @@#include "libfrog/crc32cselftest.h" #include "libfrog/dahashselftest.h" #include "libfrog/fsproperties.h" +#include "libfrog/zones.h" #include "proto.h" #include <ini.h> @@ -2542,9 +2543,6 @@ struct zone_topology {struct zone_info log; }; -/* random size that allows efficient processing */ -#define ZONES_PER_IOCTL 16384 - static void zone_validate_capacity( struct zone_info *zi,@@ -2572,12 +2570,11 @@ report_zones(const char *name, struct zone_info *zi) { - struct blk_zone_report *rep; + struct xfrog_zone_report *rep = NULL;bool found_seq = false; -int fd, ret =0 ; +int fd;uint64_t device_size;uint64_t sector =0 ; -size_t rep_size;unsigned int i, n =0 ;struct stat st;@@ -2604,32 +2601,18 @@ report_zones( zi->nr_zones = device_size / zi->zone_size; zi->nr_conv_zones =0 ; - rep_size =sizeof (struct blk_zone_report ) + -sizeof (struct blk_zone ) *ZONES_PER_IOCTL ; - rep =malloc (rep_size); -if (!rep) { -fprintf (stderr, -_ ("Failed to allocate memory for zone reporting.\n" )); -exit (1 ); - } -while (n < zi->nr_zones) { -struct blk_zone *zones = (struct blk_zone *)(rep +1 ); +struct blk_zone *zones; -memset (rep,0 , rep_size); - rep->sector = sector; - rep->nr_zones =ZONES_PER_IOCTL ; - - ret =ioctl (fd,BLKREPORTZONE , rep); -if (ret) { -fprintf (stderr, -_ ("ioctl(BLKREPORTZONE) failed: %d!\n" ), -errno); + rep =xfrog_report_zones (fd, sector, rep); +if (!rep)exit (1 ); - } -if (!rep->nr_zones) + +if (!rep->rep.nr_zones)break ; -for (i =0 ; i < rep->nr_zones; i++) { + zones = rep->zones; +for (i =0 ; i < rep->rep.nr_zones; i++) {if (n >= zi->nr_zones)break ;@@ -2676,8 +2659,8 @@ _("Unknown zone type (0x%x) found.\n"), zones[i].type); n++; } - sector = zones[rep->nr_zones -1 ].start + - zones[rep->nr_zones -1 ].len; + sector = zones[rep->rep.nr_zones -1 ].start + + zones[rep->rep.nr_zones -1 ].len; }free (rep);repair/zoned.c +11
-24@@ -7,6 +7,7 @@#include "libxfs_priv.h" #include "libxfs.h" #include "xfs_zones.h" +#include "libfrog/zones.h" #include "err_protos.h" #include "zoned.h" @@ -51,8 +52,7 @@ check_zones(uint64_t sector =XFS_FSB_TO_BB (mp, mp->m_sb.sb_rtstart);unsigned int zone_size, zone_capacity;uint64_t device_size; -size_t rep_size; -struct blk_zone_report *rep; +struct xfrog_zone_report *rep =NULL ;unsigned int i, n =0 ;if (ioctl (fd,BLKGETSIZE64 , &device_size))@@ -67,31 +67,18 @@ check_zones(return ; } - rep_size =sizeof (struct blk_zone_report ) + -sizeof (struct blk_zone ) *ZONES_PER_IOCTL ; - rep =malloc (rep_size); -if (!rep) { -do_warn (_ ("malloc failed for zone report\n" )); -return ; - } -while (n < mp->m_sb.sb_rgcount) { -struct blk_zone *zones = (struct blk_zone *)(rep +1 ); -int ret; +struct blk_zone *zones; -memset (rep,0 , rep_size); - rep->sector = sector; - rep->nr_zones =ZONES_PER_IOCTL ; + rep =xfrog_report_zones (fd, sector, rep); +if (!rep) +return ; - ret =ioctl (fd,BLKREPORTZONE , rep); -if (ret) { -do_error (_ ("ioctl(BLKREPORTZONE) failed: %d!\n" ), ret); - goto out_free; - } -if (!rep->nr_zones) +if (!rep->rep.nr_zones)break ; -for (i =0 ; i < rep->nr_zones; i++) { + zones = rep->zones; +for (i =0 ; i < rep->rep.nr_zones; i++) {if (n >= mp->m_sb.sb_rgcount)break ;@@ -130,8 +117,8 @@ _("Inconsistent zone capacity!\n"));report_zones_cb (mp, &zones[i]); n++; } - sector = zones[rep->nr_zones -1 ].start + - zones[rep->nr_zones -1 ].len; + sector = zones[rep->rep.nr_zones -1 ].start + + zones[rep->rep.nr_zones -1 ].len; } out_free:Signature · 1 line
2.47.3
PATCH 4/4 libfrog: enable cached report zones
In reply to Christoph HellwigFrom: Damien Le Moal <[email protected]>
Modify the function xfrog_report_zones() to default to always trying first a cached report zones using the BLKREPORTZONEV2 ioctl. If the kernel does not support BLKREPORTZONEV2, fall back to the (slower) regular report zones BLKREPORTZONE ioctl.
TO enable this feature even if xfsprogs is compiled on a system where linux/blkzoned.h does not define BLKREPORTZONEV2, this ioctl is defined in libfrog/zones.h, together with the BLK_ZONE_REP_CACHED flag and the BLK_ZONE_COND_ACTIVE zone condition.
Since a cached report zone always return the condition BLK_ZONE_COND_ACTIVE for any zone that is implicitly open, explicitly open or closed, the function xfs_zone_validate_seq() is modified to handle this new condition as being equivalent to the implicit open, explicit open or closed conditions.
--- libfrog/zones.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
libfrog/zones.c +30 -1
@@ -3,12 +3,24 @@* Copyright (c) 2025, Western Digital Corporation or its affiliates. */ #include "platform_defs.h" +#include "atomic.h" #include "libfrog/zones.h" #include <sys/ioctl.h> +/* +* Cached report ioctl (/usr/include/linux/blkzoned.h). +* Add in Linux 6.19. +*/ +#ifndef BLKREPORTZONEV2 +#define BLKREPORTZONEV2 _IOWR(0x12, 142, struct blk_zone_report) +#define BLK_ZONE_REP_CACHED (1U << 31) +#endif /* BLKREPORTZONEV2 */ +/* random size that allows efficient processing */ #define ZONES_PER_REPORT 16384 +static atomic_t cached_reporting_disabled; +struct xfrog_zone_report * xfrog_report_zones( int fd,
@@ -24,10 +36,27 @@ _("Failed to allocate memory for reporting zones.")); } } +/* +* Try cached report zones first. If this fails, fallback to the regular +* (slower) report zones. +*/ rep->rep.sector = sector; rep->rep.nr_zones =ZONES_PER_REPORT ; -if (ioctl (fd,BLKREPORTZONE , &rep->rep)) { +if (atomic_read (&cached_reporting_disabled)) + goto uncached; + + rep->rep.flags =BLK_ZONE_REP_CACHED ; +if (ioctl (fd,BLKREPORTZONEV2 , &rep->rep)) { +atomic_inc (&cached_reporting_disabled); + goto uncached; + } + +return rep; + +uncached: + rep->rep.flags =0 ; +if (ioctl (fd,BLKREPORTZONE , rep)) {fprintf (stderr,"%s %s\n" ,_ ("ioctl(BLKREPORTZONE) failed:\n" ),strerror (-errno));
Signature · 1 line
2.47.3
Re: [PATCH 4/4] libfrog: enable cached report zones
Quoted 18 lines · Christoph Hellwig
From: Damien Le Moal <[email protected]>
Modify the function
xfrog_report_zones()to default to always trying first a cached report zones using the BLKREPORTZONEV2 ioctl. If the kernel does not support BLKREPORTZONEV2, fall back to the (slower) regular report zones BLKREPORTZONE ioctl.TO enable this feature even if xfsprogs is compiled on a system where
linux/blkzoned.hdoes not define BLKREPORTZONEV2, this ioctl is defined inlibfrog/zones.h, together with theBLK_ZONE_REP_CACHEDflag and theBLK_ZONE_COND_ACTIVEzone condition.Since a cached report zone always return the condition
BLK_ZONE_COND_ACTIVEfor any zone that is implicitly open, explicitly open or closed, the functionxfs_zone_validate_seq()is modified to handle this new condition as being equivalent to the implicit open, explicit open or closed conditions.
Quoted 3 lines
Signed-off-by Damien Le Moal <[email protected]>[hch: don't try cached reporting again if not supported]Signed-off-by Christoph Hellwig <[email protected]>
That's an amusing use of atomic_t :)
--D
Quoted 66 lines
--- libfrog/zones.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)libfrog/zones.c +30
-1@@ -3,12 +3,24 @@* Copyright (c) 2025, Western Digital Corporation or its affiliates. */ #include "platform_defs.h" +#include "atomic.h" #include "libfrog/zones.h" #include <sys/ioctl.h> +/* +* Cached report ioctl (/usr/include/linux/blkzoned.h). +* Add in Linux 6.19. +*/ +#ifndef BLKREPORTZONEV2 +#define BLKREPORTZONEV2 _IOWR(0x12, 142, struct blk_zone_report) +#define BLK_ZONE_REP_CACHED (1U << 31) +#endif /* BLKREPORTZONEV2 */ +/* random size that allows efficient processing */ #define ZONES_PER_REPORT 16384 +static atomic_t cached_reporting_disabled; +struct xfrog_zone_report * xfrog_report_zones( int fd,@@ -24,10 +36,27 @@ _("Failed to allocate memory for reporting zones.")); } } +/* +* Try cached report zones first. If this fails, fallback to the regular +* (slower) report zones. +*/ rep->rep.sector = sector; rep->rep.nr_zones =ZONES_PER_REPORT ; -if (ioctl (fd,BLKREPORTZONE , &rep->rep)) { +if (atomic_read (&cached_reporting_disabled)) + goto uncached; + + rep->rep.flags =BLK_ZONE_REP_CACHED ; +if (ioctl (fd,BLKREPORTZONEV2 , &rep->rep)) { +atomic_inc (&cached_reporting_disabled); + goto uncached; + } + +return rep; + +uncached: + rep->rep.flags =0 ; +if (ioctl (fd,BLKREPORTZONE , rep)) {fprintf (stderr,"%s %s\n" ,_ ("ioctl(BLKREPORTZONE) failed:\n" ),strerror (-errno));Signature · 1 line
2.47.3
Quoted 6 lines · Christoph Hellwig
Enable cached zone report to speed up mkfs and repair on a zoned block device (e.g. an SMR disk). Cached zone report support was introduced in the kernel with version 6.19-rc1.
Note: I've taken this series over from Damien as he's busy and it need it as a base for further work.
Thanks for doing this !
Quoted 21 lines
Changes from v3:
- reorder includes to not need the forward declaration inxfs_zones.h
- use the libfrog/ for #include statements
- fix the include guard inlibfrog/zones.h
- fix up i18n string mess
- hide the new ioctl definition inlibfrog/zones.c
- don't add userspace includes tolibxfs/xfs_zones.h
- reuse the buffer for multiple report zone callsChanges from v2:
- Complete rework of the series to make the zone reporting code common in libfrog
- Added patch 1 and 2 as small cleanups/improvements.Changes from v1:
- Fix erroneous handling of ioctl(BLKREPORTZONEV2) error to correctly fallback to the regular ioctl(BLKREPORTZONE) if the kernel does not support BLKREPORTZONEV2.
Signature · 2 lines
Damien Le Moal Western Digital Research