Message ID | 20250318073545.3518707-8-yi.zhang@huaweicloud.com |
---|---|
State | Superseded |
Headers | show |
Series | fallocate: introduce FALLOC_FL_WRITE_ZEROES flag | expand |
On Tue, Mar 18, 2025 at 03:35:42PM +0800, Zhang Yi wrote: > Users can check the disk support of unmap write zeroes command by > querying: > > /sys/block/<disk>/queue/write_zeroes_unmap No, that is not in any way a good user interface. Users need to be able to query this on a per-file basis. > Finally, this flag should not be specified in conjunction with the > FALLOC_FL_KEEP_SIZE since allocating written extents beyond file EOF is > not permitted, and filesystems that always require out-of-place writes > should not support this flag since they still need to allocated new > blocks during subsequent overwrites. Should not or can't? You're returning an error if this happens, so it doesn't look like should is the right word here.
On 2025/4/9 18:50, Christian Brauner wrote: > On Wed, Apr 09, 2025 at 12:35:48PM +0200, Christoph Hellwig wrote: >> On Tue, Mar 18, 2025 at 03:35:42PM +0800, Zhang Yi wrote: >>> Users can check the disk support of unmap write zeroes command by >>> querying: >>> >>> /sys/block/<disk>/queue/write_zeroes_unmap >> >> No, that is not in any way a good user interface. Users need to be >> able to query this on a per-file basis. > > Agreed. This should get a statx attribute most likely. Sorry for the late. Sure, I will add a statx attribute for both bdev and ext4. Thanks, Yi.
diff --git a/fs/open.c b/fs/open.c index bdbf03f799a1..03b30613d7dc 100644 --- a/fs/open.c +++ b/fs/open.c @@ -278,6 +278,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) break; case FALLOC_FL_COLLAPSE_RANGE: case FALLOC_FL_INSERT_RANGE: + case FALLOC_FL_WRITE_ZEROES: if (mode & FALLOC_FL_KEEP_SIZE) return -EOPNOTSUPP; break; diff --git a/include/linux/falloc.h b/include/linux/falloc.h index 3f49f3df6af5..7c38c6b76b60 100644 --- a/include/linux/falloc.h +++ b/include/linux/falloc.h @@ -36,7 +36,8 @@ struct space_resv { FALLOC_FL_COLLAPSE_RANGE | \ FALLOC_FL_ZERO_RANGE | \ FALLOC_FL_INSERT_RANGE | \ - FALLOC_FL_UNSHARE_RANGE) + FALLOC_FL_UNSHARE_RANGE | \ + FALLOC_FL_WRITE_ZEROES) /* on ia32 l_start is on a 32-bit boundary */ #if defined(CONFIG_X86_64) diff --git a/include/uapi/linux/falloc.h b/include/uapi/linux/falloc.h index 5810371ed72b..265aae7ff8c1 100644 --- a/include/uapi/linux/falloc.h +++ b/include/uapi/linux/falloc.h @@ -78,4 +78,22 @@ */ #define FALLOC_FL_UNSHARE_RANGE 0x40 +/* + * FALLOC_FL_WRITE_ZEROES is used to convert a specified range of a file to + * zeros by issuing a zeroing operation. Blocks should be allocated for the + * regions that span holes in the file, and the entire range is converted to + * written extents. This flag is beneficial for subsequent pure overwriting + * within this range, as it can save on block allocation and, consequently, + * significant metadata changes. Therefore, filesystems that always require + * out-of-place writes should not support this flag. + * + * Different filesystems may implement different limitations on the + * granularity of the zeroing operation. Most will preferably be accelerated + * by submitting write zeroes command if the backing storage supports, which + * may not physically write zeros to the media. + * + * This flag cannot be specified in conjunction with the FALLOC_FL_KEEP_SIZE. + */ +#define FALLOC_FL_WRITE_ZEROES 0x80 + #endif /* _UAPI_FALLOC_H_ */