btrfs dax support
Subsystems (8)
v3 cover btrfs dax support
This patch set adds support for dax on the BTRFS filesystem. In order to support for CoW for btrfs, there were changes which had to be made to the dax handling. The important one is copying blocks into the same dax device before using them which is performed by iomap type IOMAP_DAX_COW.
Snapshotting and CoW features are supported (including mmap preservation across snapshots).
Git: https://github.com/goldwynr/linux/tree/btrfs-dax
Changes since v2:
- Created a new type IOMAP_DAX_COW as opposed to flag IOMAP_F_COW
- CoW source address is presented in iomap.inline_data
- Split the patches to more elaborate dax/iomap patches
Changes since v1:
- use iomap instead of redoing everything in btrfs
- support for mmap writeprotecting on snapshotting
fs/btrfs/Makefile | 1 fs/btrfs/ctree.h | 38 +++++ fs/btrfs/dax.c | 288 +++++++++++++++++++++++++++++++++++++++++-- fs/btrfs/disk-io.c | 4 fs/btrfs/file.c | 37 ++++- fs/btrfs/inode.c | 114 ++++++++++++----- fs/btrfs/ioctl.c | 29 +++- fs/btrfs/send.c | 4 fs/btrfs/super.c | 30 ++++ fs/dax.c | 152 ++++++++++++++++++++-- fs/iomap.c | 9 - fs/ocfs2/file.c | 2 fs/read_write.c | 10 - fs/xfs/xfs_reflink.c | 2 include/linux/dax.h | 13 + include/linux/fs.h | 7 - include/linux/iomap.h | 7 + include/trace/events/btrfs.h | 56 ++++++++ 18 files changed, 717 insertions(+), 86 deletions(-)
Signature · 7 lines
Goldwyn _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 1/18 btrfs: create a mount option for dax
From: Goldwyn Rodrigues <[email protected]>
This sets S_DAX in inode->i_flags, which can be used with IS_DAX().
The dax option is restricted to non multi-device mounts. dax interacts with the device directly instead of using bio, so all bio-hooks which we use for multi-device cannot be performed here. While regular read/writes could be manipulated with RAID0/1, mmap() is still an issue.
Auto-setting free space tree, because dealing with free space inode (specifically readpages) is a nightmare. Auto-setting nodatasum because we don't get callback for writing checksums after mmap()s.
Deny compression because it does not work with direct I/O.
--- fs/btrfs/ctree.h | 2 ++ fs/btrfs/disk-io.c | 4 ++++ fs/btrfs/ioctl.c | 5 ++++- fs/btrfs/super.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-)
fs/btrfs/ctree.h +2 -0
@@ -1067,6 +1067,7 @@ struct btrfs_fs_info {u32 metadata_ratio;void *bdev_holder; +struct dax_device *dax_dev;/* private scrub information */ struct mutex scrub_lock;
@@ -1442,6 +1443,7 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)#define BTRFS_MOUNT_FREE_SPACE_TREE (1 << 26)#define BTRFS_MOUNT_NOLOGREPLAY (1 << 27)#define BTRFS_MOUNT_REF_VERIFY (1 << 28) +#define BTRFS_MOUNT_DAX (1 << 29)#define BTRFS_DEFAULT_COMMIT_INTERVAL (30)#define BTRFS_DEFAULT_MAX_INLINE (2048)
fs/btrfs/disk-io.c +4 -0
@@ -16,6 +16,7 @@#include <linux/uuid.h> #include <linux/semaphore.h> #include <linux/error-injection.h> +#include <linux/dax.h> #include <linux/crc32c.h> #include <linux/sched/mm.h> #include <asm/unaligned.h>
@@ -2805,6 +2806,8 @@ int open_ctree(struct super_block *sb, goto fail_alloc; } + fs_info->dax_dev =fs_dax_get_by_bdev (fs_devices->latest_bdev); +/* * We want to check superblock checksum, the type is stored inside. * Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k).
@@ -4043,6 +4046,7 @@ void close_ctree(struct btrfs_fs_info *fs_info)#endif btrfs_close_devices (fs_info->fs_devices); +fs_put_dax (fs_info->dax_dev);btrfs_mapping_tree_free (&fs_info->mapping_tree);percpu_counter_destroy (&fs_info->dirty_metadata_bytes);
fs/btrfs/ioctl.c +4 -1
@@ -149,8 +149,11 @@ void btrfs_sync_inode_flags_to_i_flags(struct inode *inode)if (binode->flags &BTRFS_INODE_DIRSYNC ) new_fl |=S_DIRSYNC ; +if ((btrfs_test_opt (btrfs_sb (inode->i_sb),DAX )) &&S_ISREG (inode->i_mode)) + new_fl |=S_DAX ; +set_mask_bits (&inode->i_flags, -S_SYNC |S_APPEND |S_IMMUTABLE |S_NOATIME |S_DIRSYNC , +S_SYNC |S_APPEND |S_IMMUTABLE |S_NOATIME |S_DIRSYNC |S_DAX , new_fl); }
fs/btrfs/super.c +30 -0
@@ -326,6 +326,7 @@ enum { Opt_treelog, Opt_notreelog, Opt_usebackuproot, Opt_user_subvol_rm_allowed, + Opt_dax,/* Deprecated options */ Opt_alloc_start,
@@ -393,6 +394,7 @@ static const match_table_t tokens = { {Opt_notreelog, "notreelog"}, {Opt_usebackuproot, "usebackuproot"}, {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"}, + {Opt_dax, "dax"},/* Deprecated options */ {Opt_alloc_start, "alloc_start=%s"},
@@ -745,6 +747,32 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,case Opt_user_subvol_rm_allowed:btrfs_set_opt (info->mount_opt,USER_SUBVOL_RM_ALLOWED );break ; +case Opt_dax: +#ifdef CONFIG_FS_DAX +if (btrfs_super_num_devices (info->super_copy) >1 ) { +btrfs_info (info, +"dax not supported for multi-device btrfs partition\n" ); + ret = -EOPNOTSUPP ; + goto out; + } +btrfs_set_opt (info->mount_opt,DAX ); +btrfs_warn (info,"DAX enabled. Warning: EXPERIMENTAL, use at your own risk\n" ); +btrfs_set_and_info (info,NODATASUM , +"auto-setting nodatasum (dax)" ); +btrfs_clear_opt (info->mount_opt,SPACE_CACHE ); +btrfs_set_and_info (info,FREE_SPACE_TREE , +"auto-setting free space tree (dax)" ); +if (btrfs_test_opt (info,COMPRESS )) { +btrfs_info (info,"disabling compress (dax)" ); +btrfs_clear_opt (info->mount_opt,COMPRESS ); + } +break ; +#else +btrfs_err (info, +"DAX option not supported\n" ); + ret = -EINVAL ; + goto out; +#endif case Opt_enospc_debug:btrfs_set_opt (info->mount_opt,ENOSPC_DEBUG );break ;
@@ -1335,6 +1363,8 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)seq_puts (seq,",clear_cache" );if (btrfs_test_opt (info,USER_SUBVOL_RM_ALLOWED ))seq_puts (seq,",user_subvol_rm_allowed" ); +if (btrfs_test_opt (info,DAX )) +seq_puts (seq,",dax" );if (btrfs_test_opt (info,ENOSPC_DEBUG ))seq_puts (seq,",enospc_debug" );if (btrfs_test_opt (info,AUTO_DEFRAG ))
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [PATCH 01/18] btrfs: create a mount option for dax
Quoted 12 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
This sets
S_DAXininode->i_flags, which can be used withIS_DAX().The dax option is restricted to non multi-device mounts. dax interacts with the device directly instead of using bio, so all bio-hooks which we use for multi-device cannot be performed here. While regular read/writes could be manipulated with RAID0/1,
mmap()is still an issue.
Quoted 5 lines
Auto-setting free space tree, because dealing with free space inode (specifically readpages) is a nightmare. Auto-setting nodatasum because we don't get callback for writing checksums after mmap()s.
Deny compression because it does not work with direct I/O.
I'd like to consider the dax mount option deprecated and require new implementations to use a dynamic scheme that Darrick and I once discussed where "dax" (or more specifically the MAP_SYNC semantic) is an attribute that can be set on an empty directory and then inherited by all files / directories created in that hierarchy.
Dax mappings are not always a performance win and enabling it for all files in the filesystem is potentially overkill, and I'm of opinion that we should step away from an filesystem-global mount option.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 2/18 btrfs: Carve out btrfs_get_extent_map_write() out of btrfs_get_blocks_write()
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
This makes btrfs_get_extent_map_write() independent of Direct I/O code.
--- fs/btrfs/ctree.h | 2 ++ fs/btrfs/inode.c | 40 +++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-)
fs/btrfs/ctree.h +2 -0
@@ -3277,6 +3277,8 @@ struct inode *btrfs_iget_path(struct super_block *s, struct btrfs_key *location, struct btrfs_path *path);struct inode *btrfs_iget (struct super_block *s,struct btrfs_key *location,struct btrfs_root *root,int *was_new); +int btrfs_get_extent_map_write (struct extent_map **map,struct buffer_head *bh, +struct inode *inode,u64 start,u64 len);struct extent_map *btrfs_get_extent (struct btrfs_inode *inode,struct page *page,size_t pg_offset,u64 start,u64 end,int create);
fs/btrfs/inode.c +27 -13
@@ -7496,11 +7496,10 @@ static int btrfs_get_blocks_direct_read(struct extent_map *em,return 0 ; } -static int btrfs_get_blocks_direct_write (struct extent_map **map, -struct buffer_head *bh_result, -struct inode *inode, -struct btrfs_dio_data *dio_data, -u64 start,u64 len) +int btrfs_get_extent_map_write (struct extent_map **map, +struct buffer_head *bh, +struct inode *inode, +u64 start,u64 len) {struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb);struct extent_map *em = *map;
@@ -7554,22 +7553,38 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,*/ btrfs_free_reserved_data_space_noquota (inode, start, len); - goto skip_cow; +/* skip COW */ + goto out; } }/* this will cow the extent */ - len = bh_result->b_size; +if (bh) + len = bh->b_size;free_extent_map (em); *map = em =btrfs_new_extent_direct (inode, start, len); -if (IS_ERR (em)) { - ret =PTR_ERR (em); - goto out; - } +if (IS_ERR (em)) +return PTR_ERR (em); +out: +return ret; +} +static int btrfs_get_blocks_direct_write (struct extent_map **map, +struct buffer_head *bh_result, +struct inode *inode, +struct btrfs_dio_data *dio_data, +u64 start,u64 len) +{ +int ret =0 ; +struct extent_map *em; + + ret =btrfs_get_extent_map_write (map, bh_result, inode, + start, len); +if (ret <0 ) +return ret; + em = *map; len =min (len, em->len - (start - em->start)); -skip_cow: bh_result->b_blocknr = (em->block_start + (start - em->start)) >> inode->i_blkbits; bh_result->b_size = len;
@@ -7590,7 +7605,6 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map, dio_data->reserve -= len; dio_data->unsubmitted_oe_range_end = start + len; current->journal_info = dio_data; -out:return ret; }
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
RE: [PATCH 02/18] btrfs: Carve out btrfs_get_extent_map_write() out of btrfs_get_blocks_write()
Quoted 4 lines
-----Original Message-----
From: Linux-nvdimm [mailto:[email protected]] On Behalf Of Goldwyn Rodrigues
Sent: Tuesday, April 16, 2019 11:42 AM
Subject: [PATCH 02/18] btrfs: Carve outbtrfs_get_extent_map_write()out ofbtrfs_get_blocks_write()
...
fs/btrfs/inode.c static int btrfs_get_blocks_direct_write(struct extent_map **map, · line 7578
Quoted 7 lines
fs/btrfs/inode.c +7
-0+static int btrfs_get_blocks_direct_write (struct extent_map **map, +struct buffer_head *bh_result, +struct inode *inode, +struct btrfs_dio_data *dio_data, +u64 start,u64 len) +{ +int ret =0 ;
That initialization value is not needed, since ret is always overwritten two lines later.
fs/btrfs/inode.c static int btrfs_get_blocks_direct_write(struct extent_map **map, · line 7585
Quoted 7 lines
fs/btrfs/inode.c +7
-0+struct extent_map *em; + + ret =btrfs_get_extent_map_write (map, bh_result, inode, + start, len); +if (ret <0 ) +return ret; + em = *map;
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 3/18 btrfs: basic dax read
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Perform a basic read using iomap support. The btrfs_iomap_begin() finds the extent at the position and fills the iomap data structure with the values.
--- fs/btrfs/Makefile | 1 + fs/btrfs/ctree.h | 5 +++++ fs/btrfs/dax.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/file.c | 11 ++++++++++- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs/dax.c
fs/btrfs/Makefile +1 -0
@@ -12,6 +12,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ reada.o backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \ uuid-tree.o props.o free-space-tree.o tree-checker.o +btrfs-$(CONFIG_FS_DAX) += dax.o btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o btrfs-$(CONFIG_BTRFS_FS_REF_VERIFY) += ref-verify.o
fs/btrfs/ctree.h +5 -0
@@ -3795,6 +3795,11 @@ int btrfs_reada_wait(void *handle);void btrfs_reada_detach (void *handle);int btree_readahead_hook (struct extent_buffer *eb,int err); +#ifdef CONFIG_FS_DAX +/* dax.c */ +ssize_t btrfs_file_dax_read (struct kiocb *iocb,struct iov_iter *to); +#endif /* CONFIG_FS_DAX */ +static inline int is_fstree (u64 rootid) { if (rootid == BTRFS_FS_TREE_OBJECTID ||
fs/btrfs/dax.c new file +49 -0
49 lines not on this page · raw message
fs/btrfs/file.c +10 -1
@@ -3288,9 +3288,18 @@ static int btrfs_file_open(struct inode *inode, struct file *filp)return generic_file_open (inode, filp); } +static ssize_t btrfs_file_read_iter (struct kiocb *iocb,struct iov_iter *to) +{ +#ifdef CONFIG_FS_DAX +if (IS_DAX (file_inode (iocb->ki_filp))) +return btrfs_file_dax_read (iocb, to); +#endif +return generic_file_read_iter (iocb, to); +} +const struct file_operations btrfs_file_operations = { .llseek = btrfs_file_llseek, - .read_iter = generic_file_read_iter, + .read_iter = btrfs_file_read_iter, .splice_read = generic_file_splice_read, .write_iter = btrfs_file_write_iter, .mmap = btrfs_file_mmap,
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 4/18 dax: Introduce IOMAP_DAX_COW to CoW edges during writes
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
The IOMAP_DAX_COW is a iomap type which performs copy of edges of data while performing a write if start/end are not page aligned. The source address is expected in iomap->inline_data.
dax_copy_edges() is a helper functions performs a copy from one part of the device to another for data not page aligned. If iomap->inline_data is NULL, it memset's the area to zero.
--- fs/dax.c | 41 ++++++++++++++++++++++++++++++++++++++++- include/linux/iomap.h | 1 + 2 files changed, 41 insertions(+), 1 deletion(-)
fs/dax.c +40 -1
@@ -1083,6 +1083,40 @@ int __dax_zero_page_range(struct block_device *bdev, }EXPORT_SYMBOL_GPL (__dax_zero_page_range); +/* +* dax_copy_edges - Copies the part of the pages not included in +* the write, but required for CoW because +* offset/offset+length are not page aligned. +*/ +static void dax_copy_edges (struct inode *inode,loff_t pos,loff_t length, +struct iomap *iomap,void *daddr) +{ +unsigned offset = pos & (PAGE_SIZE -1 ); +loff_t end = pos + length; +loff_t pg_end =round_up (end,PAGE_SIZE ); +void *saddr = iomap->inline_data; +/* +* Copy the first part of the page +* Note: we pass offset as length +*/ +if (offset) { +if (saddr) +memcpy (daddr, saddr, offset); +else +memset (daddr,0 , offset); + } + +/* Copy the last part of the range */ +if (end < pg_end) { +if (saddr) +memcpy (daddr + offset + length, + saddr + offset + length, pg_end - end); +else +memset (daddr + offset + length,0 , + pg_end - end); + } +} +static loff_t dax_iomap_actor (struct inode *inode,loff_t pos,loff_t length,void *data,struct iomap *iomap)
@@ -1104,9 +1138,11 @@ dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data,return iov_iter_zero (min (length, end - pos), iter); } -if (WARN_ON_ONCE (iomap->type !=IOMAP_MAPPED )) +if (WARN_ON_ONCE (iomap->type !=IOMAP_MAPPED + && iomap->type !=IOMAP_DAX_COW ))return -EIO ; +/* * Write can allocate block for an area which has a hole page mapped * into page tables. We have to tear down these mappings so that data
@@ -1143,6 +1179,9 @@ dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data,break ; } +if (iomap->type ==IOMAP_DAX_COW ) +dax_copy_edges (inode, pos, length, iomap, kaddr); + map_len =PFN_PHYS (map_len); kaddr += offset; map_len -= offset;
include/linux/iomap.h +1 -0
@@ -25,6 +25,7 @@ struct vm_fault;#define IOMAP_MAPPED 0x03/* blocks allocated at @addr */ #define IOMAP_UNWRITTEN 0x04/* blocks allocated at @addr in unwritten state */ #define IOMAP_INLINE 0x05/* data inline in the inode */ +#define IOMAP_DAX_COW 0x06/* Copy data pointed by inline_data before write*/ /* * Flags for all iomap mappings:
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [PATCH 04/18] dax: Introduce IOMAP_DAX_COW to CoW edges during writes
Quoted 34 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <rgoldwyn-IBi9RG/[email protected]>
The
IOMAP_DAX_COWis a iomap type which performs copy of edges of data while performing a write if start/end are not page aligned. The source address is expected iniomap->inline_data.
dax_copy_edges()is a helper functions performs a copy from one part of the device to another for data not page aligned. Ifiomap->inline_datais NULL, it memset's the area to zero.Signed-off-by Goldwyn Rodrigues <rgoldwyn-IBi9RG/[email protected]>--- fs/dax.c | 41 ++++++++++++++++++++++++++++++++++++++++- include/linux/iomap.h | 1 + 2 files changed, 41 insertions(+), 1 deletion(-)fs/dax.c +9
-0@@ -1083,6 +1083,40 @@ int __dax_zero_page_range(struct block_device *bdev, }EXPORT_SYMBOL_GPL (__dax_zero_page_range); +/* +* dax_copy_edges - Copies the part of the pages not included in +* the write, but required for CoW because +* offset/offset+length are not page aligned. +*/ +static void dax_copy_edges (struct inode *inode,loff_t pos,loff_t length, +struct iomap *iomap,void *daddr) +{ +unsigned offset = pos & (PAGE_SIZE -1 );
fs/dax.c int __dax_zero_page_range(struct block_device *bdev, · line 1104
Quoted 10 lines
fs/dax.c +10
-0+loff_t end = pos + length; +loff_t pg_end =round_up (end,PAGE_SIZE ); +void *saddr = iomap->inline_data; +/* +* Copy the first part of the page +* Note: we pass offset as length +*/ +if (offset) { +if (saddr) +memcpy (daddr, saddr, offset);
I've been wondering, do we need memcpy_mcsafe here?
fs/dax.c int __dax_zero_page_range(struct block_device *bdev, · line 1106
Quoted 2 lines
fs/dax.c +2
-0+else +memset (daddr,0 , offset);
Or here?
(Or any of the other places we call memcpy/memset in this series...)
Because I think we'd prefer to return EIO on bad pmem over a machine check.
--D
Quoted 17 lines
fs/dax.c +13
-0+ } + +/* Copy the last part of the range */ +if (end < pg_end) { +if (saddr) +memcpy (daddr + offset + length, + saddr + offset + length, pg_end - end); +else +memset (daddr + offset + length,0 , + pg_end - end); + } +} +static loff_t dax_iomap_actor (struct inode *inode,loff_t pos,loff_t length,void *data,struct iomap *iomap)
fs/dax.c dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data, · line 1142
Quoted 6 lines
fs/dax.c +2
-1@@ -1104,9 +1138,11 @@ dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data,return iov_iter_zero (min (length, end - pos), iter); } -if (WARN_ON_ONCE (iomap->type !=IOMAP_MAPPED )) +if (WARN_ON_ONCE (iomap->type !=IOMAP_MAPPED + && iomap->type !=IOMAP_DAX_COW ))
Usually the '&&' goes on the first line, right?
fs/dax.c dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data, · line 1183
Quoted 12 lines
fs/dax.c +3
-0return -EIO ; +/* * Write can allocate block for an area which has a hole page mapped * into page tables. We have to tear down these mappings so that data @@ -1143,6 +1179,9 @@ dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data,break ; } +if (iomap->type ==IOMAP_DAX_COW ) +dax_copy_edges (inode, pos, length, iomap, kaddr);
No return value? So the pmem copy never fails?
--D
Quoted 19 lines
fs/dax.c +1
-0+ map_len =PFN_PHYS (map_len); kaddr += offset; map_len -= offset;include/linux/iomap.h +1
-0@@ -25,6 +25,7 @@ struct vm_fault;#define IOMAP_MAPPED 0x03/* blocks allocated at @addr */ #define IOMAP_UNWRITTEN 0x04/* blocks allocated at @addr in unwritten state */ #define IOMAP_INLINE 0x05/* data inline in the inode */ +#define IOMAP_DAX_COW 0x06/* Copy data pointed by inline_data before write*/ /* * Flags for all iomap mappings: Signature · 1 line
2.16.4
PATCH v3 5/18 btrfs: return whether extent is nocow or not
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
We require this to make sure we return type IOMAP_DAX_COW in iomap structure, in the later patches.
--- fs/btrfs/ctree.h | 2 +- fs/btrfs/inode.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-)
fs/btrfs/ctree.h +1 -1
@@ -3278,7 +3278,7 @@ struct inode *btrfs_iget_path(struct super_block *s, struct btrfs_key *location,struct inode *btrfs_iget (struct super_block *s,struct btrfs_key *location,struct btrfs_root *root,int *was_new);int btrfs_get_extent_map_write (struct extent_map **map,struct buffer_head *bh, -struct inode *inode,u64 start,u64 len); +struct inode *inode,u64 start,u64 len,bool *nocow);struct extent_map *btrfs_get_extent (struct btrfs_inode *inode,struct page *page,size_t pg_offset,u64 start,u64 end,int create);
fs/btrfs/inode.c +7 -2
@@ -7499,12 +7499,15 @@ static int btrfs_get_blocks_direct_read(struct extent_map *em,int btrfs_get_extent_map_write (struct extent_map **map,struct buffer_head *bh,struct inode *inode, -u64 start,u64 len) +u64 start,u64 len,bool *nocow) {struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb);struct extent_map *em = *map;int ret =0 ; +if (nocow) + *nocow = false; +/* * We don't allocate a new extent in the following cases *
@@ -7553,6 +7556,8 @@ int btrfs_get_extent_map_write(struct extent_map **map,*/ btrfs_free_reserved_data_space_noquota (inode, start, len); +if (nocow) + *nocow = true;/* skip COW */ goto out; }
@@ -7579,7 +7584,7 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,struct extent_map *em; ret =btrfs_get_extent_map_write (map, bh_result, inode, - start, len); + start, len,NULL );if (ret <0 )return ret; em = *map;
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 6/18 btrfs: Rename __endio_write_update_ordered() to btrfs_update_ordered_extent()
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Since we will be using it in another part of the code, use a better name to declare it non-static
--- fs/btrfs/ctree.h | 7 +++++-- fs/btrfs/inode.c | 14 +++++--------- 2 files changed, 10 insertions(+), 11 deletions(-)
fs/btrfs/ctree.h +5 -2
@@ -3280,8 +3280,11 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,int btrfs_get_extent_map_write (struct extent_map **map,struct buffer_head *bh,struct inode *inode,u64 start,u64 len,bool *nocow);struct extent_map *btrfs_get_extent (struct btrfs_inode *inode, -struct page *page,size_t pg_offset, -u64 start,u64 end,int create); +struct page *page,size_t pg_offset, +u64 start,u64 end,int create); +void btrfs_update_ordered_extent (struct inode *inode, +const u64 offset,const u64 bytes, +const bool uptodate);int btrfs_update_inode (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct inode *inode);
fs/btrfs/inode.c +5 -9
@@ -98,10 +98,6 @@ static struct extent_map *create_io_em(struct inode *inode, u64 start, u64 len, u64 ram_bytes, int compress_type, int type); -static void __endio_write_update_ordered (struct inode *inode, -const u64 offset,const u64 bytes, -const bool uptodate); -/* * Cleanup all submitted ordered extents in specified range to handle errors * from the btrfs_run_delalloc_range() callback.
@@ -142,7 +138,7 @@ static inline void btrfs_cleanup_ordered_extents(struct inode *inode, bytes -=PAGE_SIZE ; } -return __endio_write_update_ordered (inode, offset, bytes, false); +return btrfs_update_ordered_extent (inode, offset, bytes, false); }static int btrfs_dirty_inode (struct inode *inode);
@@ -8085,7 +8081,7 @@ static void btrfs_endio_direct_read(struct bio *bio)bio_put (bio); } -static void __endio_write_update_ordered (struct inode *inode, +void btrfs_update_ordered_extent (struct inode *inode,const u64 offset,const u64 bytes,const bool uptodate) {
@@ -8138,7 +8134,7 @@ static void btrfs_endio_direct_write(struct bio *bio)struct btrfs_dio_private *dip = bio->bi_private;struct bio *dio_bio = dip->dio_bio; -__endio_write_update_ordered (dip->inode, dip->logical_offset, +btrfs_update_ordered_extent (dip->inode, dip->logical_offset, dip->bytes, !bio->bi_status);kfree (dip);
@@ -8457,7 +8453,7 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode, bio =NULL ; }else {if (write) -__endio_write_update_ordered (inode, +btrfs_update_ordered_extent (inode, file_offset, dio_bio->bi_iter.bi_size, false);
@@ -8597,7 +8593,7 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)*/ if (dio_data.unsubmitted_oe_range_start < dio_data.unsubmitted_oe_range_end) - __endio_write_update_ordered(inode, + btrfs_update_ordered_extent(inode, dio_data.unsubmitted_oe_range_start, dio_data.unsubmitted_oe_range_end - dio_data.unsubmitted_oe_range_start,
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 7/18 btrfs: add dax write support
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
IOMAP_DAX_COW allows to inform the dax code, to first perform a copy which are not page-aligned before performing the write. The responsibility of checking if data edges are page aligned is performed in ->iomap_begin() and the source address is stored in ->inline_data
A new struct btrfs_iomap is passed from iomap_begin() to iomap_end(), which contains all the accounting and locking information for CoW based writes.
For writing to a hole, iomap->inline_data is set to zero.
--- fs/btrfs/ctree.h | 6 ++ fs/btrfs/dax.c | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- fs/btrfs/file.c | 4 +- 3 files changed, 185 insertions(+), 7 deletions(-)
fs/btrfs/ctree.h +6 -0
@@ -3801,6 +3801,12 @@ int btree_readahead_hook(struct extent_buffer *eb, int err);#ifdef CONFIG_FS_DAX /* dax.c */ ssize_t btrfs_file_dax_read (struct kiocb *iocb,struct iov_iter *to); +ssize_t btrfs_file_dax_write (struct kiocb *iocb,struct iov_iter *from); +#else +static inline ssize_t btrfs_file_dax_write (struct kiocb *iocb,struct iov_iter *from) +{ +return 0 ; +}#endif /* CONFIG_FS_DAX */ static inline int is_fstree (u64 rootid)
fs/btrfs/dax.c +176 -6
210 lines not on this page · raw message
fs/btrfs/file.c +3 -1
@@ -1964,7 +1964,9 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb,if (sync)atomic_inc (&BTRFS_I (inode)->sync_writers); -if (iocb->ki_flags &IOCB_DIRECT ) { +if (IS_DAX (inode)) { + num_written =btrfs_file_dax_write (iocb, from); + }else if (iocb->ki_flags &IOCB_DIRECT ) { num_written =__btrfs_direct_write (iocb, from); }else { num_written =btrfs_buffered_write (iocb, from);
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 8/18 dax: memcpy page in case of IOMAP_DAX_COW for mmap faults
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Change dax_iomap_pfn to return the address as well in order to use it for performing a memcpy in case the type is IOMAP_DAX_COW.
Question:
The sequence of bdev_dax_pgoff() and dax_direct_access() is used multiple times to calculate address and pfn's. Would it make sense to call it while calculating address as well to reduce code?
--- fs/dax.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
fs/dax.c +12 -4
@@ -983,7 +983,7 @@ static sector_t dax_iomap_sector(struct iomap *iomap, loff_t pos) }static int dax_iomap_pfn (struct iomap *iomap,loff_t pos,size_t size, -pfn_t *pfnp) +pfn_t *pfnp,void **addr) {const sector_t sector =dax_iomap_sector (iomap, pos);pgoff_t pgoff;
@@ -995,7 +995,7 @@ static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,return rc; id =dax_read_lock (); length =dax_direct_access (iomap->dax_dev, pgoff,PHYS_PFN (size), -NULL , pfnp); + addr, pfnp);if (length <0 ) { rc = length; goto out;
@@ -1280,6 +1280,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,XA_STATE (xas, &mapping->i_pages, vmf->pgoff);struct inode *inode = mapping->host;unsigned long vaddr = vmf->address; +void *addr;loff_t pos = (loff_t )vmf->pgoff <<PAGE_SHIFT ;struct iomap iomap = {0 };unsigned flags =IOMAP_FAULT ;
@@ -1369,16 +1370,23 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, sync =dax_fault_is_synchronous (flags, vma, &iomap);switch (iomap.type) { +case IOMAP_DAX_COW :case IOMAP_MAPPED :if (iomap.flags &IOMAP_F_NEW ) {count_vm_event (PGMAJFAULT );count_memcg_event_mm (vma->vm_mm,PGMAJFAULT ); major =VM_FAULT_MAJOR ; } - error =dax_iomap_pfn (&iomap, pos,PAGE_SIZE , &pfn); + error =dax_iomap_pfn (&iomap, pos,PAGE_SIZE , &pfn, &addr);if (error <0 ) goto error_finish_iomap; +if (iomap.type ==IOMAP_DAX_COW ) { +if (iomap.inline_data) +memcpy (addr, iomap.inline_data,PAGE_SIZE ); +else +memset (addr,0 ,PAGE_SIZE ); + } entry =dax_insert_entry (&xas, mapping, vmf, entry, pfn,0 , write && !sync);
@@ -1577,7 +1585,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,switch (iomap.type) {case IOMAP_MAPPED : - error =dax_iomap_pfn (&iomap, pos,PMD_SIZE , &pfn); + error =dax_iomap_pfn (&iomap, pos,PMD_SIZE , &pfn,NULL );if (error <0 ) goto finish_iomap;
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [PATCH 08/18] dax: memcpy page in case of IOMAP_DAX_COW for mmap faults
Quoted 54 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <rgoldwyn-IBi9RG/[email protected]>
Change
dax_iomap_pfnto return the address as well in order to use it for performing a memcpy in case the type isIOMAP_DAX_COW.Question:
The sequence ofbdev_dax_pgoff()anddax_direct_access()is used multiple times to calculate address and pfn's. Would it make sense to call it while calculating address as well to reduce code?Signed-off-by Goldwyn Rodrigues <rgoldwyn-IBi9RG/[email protected]>--- fs/dax.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)fs/dax.c +4
-2@@ -983,7 +983,7 @@ static sector_t dax_iomap_sector(struct iomap *iomap, loff_t pos) }static int dax_iomap_pfn (struct iomap *iomap,loff_t pos,size_t size, -pfn_t *pfnp) +pfn_t *pfnp,void **addr) {const sector_t sector =dax_iomap_sector (iomap, pos);pgoff_t pgoff;@@ -995,7 +995,7 @@ static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,return rc; id =dax_read_lock (); length =dax_direct_access (iomap->dax_dev, pgoff,PHYS_PFN (size), -NULL , pfnp); + addr, pfnp);if (length <0 ) { rc = length; goto out;@@ -1280,6 +1280,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,XA_STATE (xas, &mapping->i_pages, vmf->pgoff);struct inode *inode = mapping->host;unsigned long vaddr = vmf->address; +void *addr;loff_t pos = (loff_t )vmf->pgoff <<PAGE_SHIFT ;struct iomap iomap = {0 };unsigned flags =IOMAP_FAULT ;@@ -1369,16 +1370,23 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, sync =dax_fault_is_synchronous (flags, vma, &iomap);switch (iomap.type) { +case IOMAP_DAX_COW :case IOMAP_MAPPED :if (iomap.flags &IOMAP_F_NEW ) {count_vm_event (PGMAJFAULT );count_memcg_event_mm (vma->vm_mm,PGMAJFAULT );
fs/dax.c static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, · line 1386
Quoted 10 lines
fs/dax.c +4
-1major =VM_FAULT_MAJOR ; } - error =dax_iomap_pfn (&iomap, pos,PAGE_SIZE , &pfn); + error =dax_iomap_pfn (&iomap, pos,PAGE_SIZE , &pfn, &addr);if (error <0 ) goto error_finish_iomap; +if (iomap.type ==IOMAP_DAX_COW ) { +if (iomap.inline_data) +memcpy (addr, iomap.inline_data,PAGE_SIZE );
Same memcpy_mcsafe question from my reply to patch 4 applies here.
fs/dax.c static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp, · line 1588
Quoted 12 lines
fs/dax.c +4
-1+else +memset (addr,0 ,PAGE_SIZE ); + } entry =dax_insert_entry (&xas, mapping, vmf, entry, pfn,0 , write && !sync);@@ -1577,7 +1585,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,switch (iomap.type) {case IOMAP_MAPPED : - error =dax_iomap_pfn (&iomap, pos,PMD_SIZE , &pfn); + error =dax_iomap_pfn (&iomap, pos,PMD_SIZE , &pfn,NULL );
Same (unanswered) question from the v2 series -- doesn't a PMD fault also require handling IOMAP_DAX_COW?
--D
Quoted 6 lines
fs/dax.c +0
-0if (error <0 ) goto finish_iomap;Signature · 1 line
2.16.4
PATCH v3 9/18 btrfs: Add dax specific address_space_operations
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
--- fs/btrfs/inode.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)
fs/btrfs/inode.c +31 -3
@@ -28,6 +28,7 @@#include <linux/magic.h> #include <linux/iversion.h> #include <linux/swap.h> +#include <linux/dax.h> #include <asm/unaligned.h> #include "ctree.h" #include "disk-io.h"
@@ -65,6 +66,7 @@ static const struct inode_operations btrfs_dir_ro_inode_operations;static const struct inode_operations btrfs_special_inode_operations;static const struct inode_operations btrfs_file_inode_operations;static const struct address_space_operations btrfs_aops; +static const struct address_space_operations btrfs_dax_aops;static const struct file_operations btrfs_dir_file_operations;static const struct extent_io_ops btrfs_extent_io_ops;
@@ -3757,7 +3759,10 @@ static int btrfs_read_locked_inode(struct inode *inode,switch (inode->i_mode &S_IFMT ) {case S_IFREG : - inode->i_mapping->a_ops = &btrfs_aops; +if (btrfs_test_opt (fs_info,DAX )) + inode->i_mapping->a_ops = &btrfs_dax_aops; +else + inode->i_mapping->a_ops = &btrfs_aops;BTRFS_I (inode)->io_tree.ops = &btrfs_extent_io_ops; inode->i_fop = &btrfs_file_operations; inode->i_op = &btrfs_file_inode_operations;
@@ -3778,6 +3783,7 @@ static int btrfs_read_locked_inode(struct inode *inode, }btrfs_sync_inode_flags_to_i_flags (inode); +return 0 ; }
@@ -6538,7 +6544,10 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,*/ inode->i_fop = &btrfs_file_operations; inode->i_op = &btrfs_file_inode_operations; - inode->i_mapping->a_ops = &btrfs_aops; +if (IS_DAX (inode) &&S_ISREG (mode)) + inode->i_mapping->a_ops = &btrfs_dax_aops; +else + inode->i_mapping->a_ops = &btrfs_aops; err =btrfs_init_inode_security (trans, inode, dir, &dentry->d_name);if (err)
@@ -8665,6 +8674,15 @@ static int btrfs_writepages(struct address_space *mapping,return extent_writepages (mapping, wbc); } +static int btrfs_dax_writepages (struct address_space *mapping, +struct writeback_control *wbc) +{ +struct inode *inode = mapping->host; +struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); +return dax_writeback_mapping_range (mapping, fs_info->fs_devices->latest_bdev, + wbc); +} +static int btrfs_readpages (struct file *file,struct address_space *mapping,struct list_head *pages,unsigned nr_pages)
@@ -10436,7 +10454,10 @@ static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) inode->i_fop = &btrfs_file_operations; inode->i_op = &btrfs_file_inode_operations; - inode->i_mapping->a_ops = &btrfs_aops; +if (IS_DAX (inode)) + inode->i_mapping->a_ops = &btrfs_dax_aops; +else + inode->i_mapping->a_ops = &btrfs_aops;BTRFS_I (inode)->io_tree.ops = &btrfs_extent_io_ops; ret =btrfs_init_inode_security (trans, inode, dir,NULL );
@@ -10892,6 +10913,13 @@ static const struct address_space_operations btrfs_aops = { .swap_deactivate = btrfs_swap_deactivate, }; +static const struct address_space_operations btrfs_dax_aops = { + .writepages = btrfs_dax_writepages, + .direct_IO = noop_direct_IO, + .set_page_dirty = noop_set_page_dirty, + .invalidatepage = noop_invalidatepage, +}; +static const struct inode_operations btrfs_file_inode_operations = { .getattr = btrfs_getattr, .setattr = btrfs_setattr,
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 10/18 dax: replace mmap entry in case of CoW
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <rgoldwyn-IBi9RG/[email protected]>
We replace the existing entry to the newly allocated one in case of CoW. Also, we mark the entry as PAGECACHE_TAG_TOWRITE so writeback marks this entry as writeprotected. This helps us snapshots so new write pagefaults after snapshots trigger a CoW.
--- fs/dax.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
fs/dax.c +15 -8
@@ -708,14 +708,15 @@ static int copy_user_dax(struct block_device *bdev, struct dax_device *dax_dev,*/ static void *dax_insert_entry (struct xa_state *xas,struct address_space *mapping,struct vm_fault *vmf, -void *entry,pfn_t pfn,unsigned long flags,bool dirty) +void *entry,pfn_t pfn,unsigned long flags,bool dirty, +bool cow) {void *new_entry =dax_make_entry (pfn, flags);if (dirty)__mark_inode_dirty (mapping->host,I_DIRTY_PAGES ); -if (dax_is_zero_entry (entry) && !(flags &DAX_ZERO_PAGE )) { +if (cow || (dax_is_zero_entry (entry) && !(flags &DAX_ZERO_PAGE ))) {unsigned long index = xas->xa_index;/* we are replacing a zero page with block mapping */ if (dax_is_pmd_entry (entry))
@@ -727,12 +728,12 @@ static void *dax_insert_entry(struct xa_state *xas,xas_reset (xas);xas_lock_irq (xas); -if (dax_entry_size (entry) !=dax_entry_size (new_entry)) { +if (cow || (dax_entry_size (entry) !=dax_entry_size (new_entry))) {dax_disassociate_entry (entry, mapping, false);dax_associate_entry (new_entry, mapping, vmf->vma, vmf->address); } -if (dax_is_zero_entry (entry) ||dax_is_empty_entry (entry)) { +if (cow ||dax_is_zero_entry (entry) ||dax_is_empty_entry (entry)) {/* * Only swap our new entry into the page cache if the current * entry is a zero page or an empty entry. If a normal PTE or
@@ -752,6 +753,9 @@ static void *dax_insert_entry(struct xa_state *xas,if (dirty)xas_set_mark (xas,PAGECACHE_TAG_DIRTY ); +if (cow) +xas_set_mark (xas,PAGECACHE_TAG_TOWRITE ); +xas_unlock_irq (xas);return entry; }
@@ -1031,7 +1035,7 @@ static vm_fault_t dax_load_hole(struct xa_state *xas,vm_fault_t ret; *entry =dax_insert_entry (xas, mapping, vmf, *entry, pfn, -DAX_ZERO_PAGE , false); +DAX_ZERO_PAGE , false, false); ret =vmf_insert_mixed (vmf->vma, vaddr, pfn);trace_dax_load_hole (inode, vmf, ret);
@@ -1388,7 +1392,8 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,memset (addr,0 ,PAGE_SIZE ); } entry =dax_insert_entry (&xas, mapping, vmf, entry, pfn, -0 , write && !sync); +0 , write && !sync, + iomap.type ==IOMAP_DAX_COW );/* * If we are doing synchronous page fault and inode needs fsync,
@@ -1467,7 +1472,8 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state *xas, struct vm_fault *vmf, pfn =page_to_pfn_t (zero_page); *entry =dax_insert_entry (xas, mapping, vmf, *entry, pfn, -DAX_PMD |DAX_ZERO_PAGE , false); +DAX_PMD |DAX_ZERO_PAGE , false, + iomap->type ==IOMAP_DAX_COW ); ptl =pmd_lock (vmf->vma->vm_mm, vmf->pmd);if (!pmd_none (*(vmf->pmd))) {
@@ -1590,7 +1596,8 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp, goto finish_iomap; entry =dax_insert_entry (&xas, mapping, vmf, entry, pfn, -DAX_PMD , write && !sync); +DAX_PMD , write && !sync, + false);/* * If we are doing synchronous page fault and inode needs fsync,
Signature · 1 line
2.16.4
Re: [PATCH 10/18] dax: replace mmap entry in case of CoW
Quoted 18 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <rgoldwyn-IBi9RG/[email protected]>
We replace the existing entry to the newly allocated one in case of CoW. Also, we mark the entry as
PAGECACHE_TAG_TOWRITEso writeback marks this entry as writeprotected. This helps us snapshots so new write pagefaults after snapshots trigger a CoW.Signed-off-by Goldwyn Rodrigues <rgoldwyn-IBi9RG/[email protected]>--- fs/dax.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)fs/dax.c +0
-0
fs/dax.c static int copy_user_dax(struct block_device *bdev, struct dax_device *dax_dev, · line 712
Quoted 6 lines
fs/dax.c +2
-1@@ -708,14 +708,15 @@ static int copy_user_dax(struct block_device *bdev, struct dax_device *dax_dev,*/ static void *dax_insert_entry (struct xa_state *xas,struct address_space *mapping,struct vm_fault *vmf, -void *entry,pfn_t pfn,unsigned long flags,bool dirty) +void *entry,pfn_t pfn,unsigned long flags,bool dirty, +bool cow)
I still wish these were flags instead of double booleans that will be easy to mix up, especially since this is a static function and nobody else has to see the flags...
#define IE_DIRTY (1 << 0) /* mark entry and inode dirty */
#define IE_REPLACE (1 << 1) /* replacing one page with another */
...otoh maybe I'll just defer to the maintainer. :)
fs/dax.c static int copy_user_dax(struct block_device *bdev, struct dax_device *dax_dev, · line 721
Quoted 10 lines
fs/dax.c +1
-1{void *new_entry =dax_make_entry (pfn, flags);if (dirty)__mark_inode_dirty (mapping->host,I_DIRTY_PAGES ); -if (dax_is_zero_entry (entry) && !(flags &DAX_ZERO_PAGE )) { +if (cow || (dax_is_zero_entry (entry) && !(flags &DAX_ZERO_PAGE ))) {unsigned long index = xas->xa_index;/* we are replacing a zero page with block mapping */
These comments need updating.
Otherwise looks good to me...
--D
Quoted 68 lines
fs/dax.c +12
-6if (dax_is_pmd_entry (entry))@@ -727,12 +728,12 @@ static void *dax_insert_entry(struct xa_state *xas,xas_reset (xas);xas_lock_irq (xas); -if (dax_entry_size (entry) !=dax_entry_size (new_entry)) { +if (cow || (dax_entry_size (entry) !=dax_entry_size (new_entry))) {dax_disassociate_entry (entry, mapping, false);dax_associate_entry (new_entry, mapping, vmf->vma, vmf->address); } -if (dax_is_zero_entry (entry) ||dax_is_empty_entry (entry)) { +if (cow ||dax_is_zero_entry (entry) ||dax_is_empty_entry (entry)) {/* * Only swap our new entry into the page cache if the current * entry is a zero page or an empty entry. If a normal PTE or @@ -752,6 +753,9 @@ static void *dax_insert_entry(struct xa_state *xas,if (dirty)xas_set_mark (xas,PAGECACHE_TAG_DIRTY ); +if (cow) +xas_set_mark (xas,PAGECACHE_TAG_TOWRITE ); +xas_unlock_irq (xas);return entry; }@@ -1031,7 +1035,7 @@ static vm_fault_t dax_load_hole(struct xa_state *xas,vm_fault_t ret; *entry =dax_insert_entry (xas, mapping, vmf, *entry, pfn, -DAX_ZERO_PAGE , false); +DAX_ZERO_PAGE , false, false); ret =vmf_insert_mixed (vmf->vma, vaddr, pfn);trace_dax_load_hole (inode, vmf, ret);@@ -1388,7 +1392,8 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,memset (addr,0 ,PAGE_SIZE ); } entry =dax_insert_entry (&xas, mapping, vmf, entry, pfn, -0 , write && !sync); +0 , write && !sync, + iomap.type ==IOMAP_DAX_COW );/* * If we are doing synchronous page fault and inode needs fsync, @@ -1467,7 +1472,8 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state *xas, struct vm_fault *vmf, pfn =page_to_pfn_t (zero_page); *entry =dax_insert_entry (xas, mapping, vmf, *entry, pfn, -DAX_PMD |DAX_ZERO_PAGE , false); +DAX_PMD |DAX_ZERO_PAGE , false, + iomap->type ==IOMAP_DAX_COW ); ptl =pmd_lock (vmf->vma->vm_mm, vmf->pmd);if (!pmd_none (*(vmf->pmd))) {@@ -1590,7 +1596,8 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp, goto finish_iomap; entry =dax_insert_entry (&xas, mapping, vmf, entry, pfn, -DAX_PMD , write && !sync); +DAX_PMD , write && !sync, + false);/* * If we are doing synchronous page fault and inode needs fsync, Signature · 1 line
2.16.4
PATCH v3 11/18 btrfs: add dax mmap support
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Add a new vm_operations struct btrfs_dax_vm_ops
specifically for dax files.
Since we will be removing(nulling) readpages/writepages for dax return ENOEXEC only for non-dax files.
--- fs/btrfs/ctree.h | 1 + fs/btrfs/dax.c | 13 ++++++++++++- fs/btrfs/file.c | 18 ++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-)
fs/btrfs/ctree.h +1 -0
@@ -3802,6 +3802,7 @@ int btree_readahead_hook(struct extent_buffer *eb, int err);/* dax.c */ ssize_t btrfs_file_dax_read (struct kiocb *iocb,struct iov_iter *to);ssize_t btrfs_file_dax_write (struct kiocb *iocb,struct iov_iter *from); +vm_fault_t btrfs_dax_fault (struct vm_fault *vmf);#else static inline ssize_t btrfs_file_dax_write (struct kiocb *iocb,struct iov_iter *from) {
fs/btrfs/dax.c +12 -1
@@ -139,7 +139,7 @@ static int btrfs_iomap_begin(struct inode *inode, loff_t pos, iomap->addr = em->block_start + diff;/* Check if we really need to copy data from old extent */ -if (bi && !bi->nocow && (offset || pos + length < bi->end)) { +if (bi && !bi->nocow && (offset || pos + length < bi->end || flags &IOMAP_FAULT )) { iomap->type =IOMAP_DAX_COW ;if (srcblk) { sector_t sector = (srcblk + (pos & PAGE_MASK) -
@@ -216,4 +216,15 @@ ssize_t btrfs_file_dax_write(struct kiocb *iocb, struct iov_iter *iter) }return ret; } + +vm_fault_t btrfs_dax_fault (struct vm_fault *vmf) +{ +vm_fault_t ret; +pfn_t pfn; + ret =dax_iomap_fault (vmf,PE_SIZE_PTE , &pfn,NULL , &btrfs_iomap_ops); +if (ret &VM_FAULT_NEEDDSYNC ) + ret =dax_finish_sync_fault (vmf,PE_SIZE_PTE , pfn); + +return ret; +}#endif /* CONFIG_FS_DAX */
fs/btrfs/file.c +16 -2
@@ -2214,15 +2214,29 @@ static const struct vm_operations_struct btrfs_file_vm_ops = { .page_mkwrite = btrfs_page_mkwrite, }; +#ifdef CONFIG_FS_DAX +static const struct vm_operations_struct btrfs_dax_vm_ops = { + .fault = btrfs_dax_fault, + .page_mkwrite = btrfs_dax_fault, + .pfn_mkwrite = btrfs_dax_fault, +}; +#else +#define btrfs_dax_vm_ops btrfs_file_vm_ops +#endif +static int btrfs_file_mmap (struct file *filp,struct vm_area_struct *vma) {struct address_space *mapping = filp->f_mapping; +struct inode *inode =file_inode (filp); -if (!mapping->a_ops->readpage) +if (!IS_DAX (inode) && !mapping->a_ops->readpage)return -ENOEXEC ;file_accessed (filp); - vma->vm_ops = &btrfs_file_vm_ops; +if (IS_DAX (inode)) + vma->vm_ops = &btrfs_dax_vm_ops; +else + vma->vm_ops = &btrfs_file_vm_ops;return 0 ; }
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 12/18 btrfs: allow MAP_SYNC mmap
In reply to Goldwyn RodriguesFrom: Adam Borowski <[email protected]>
Used by userspace to detect DAX.
--- fs/btrfs/file.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/btrfs/file.c +4 -0
@@ -16,6 +16,7 @@#include <linux/btrfs.h> #include <linux/uio.h> #include <linux/iversion.h> +#include <linux/mman.h> #include "ctree.h" #include "disk-io.h" #include "transaction.h"
@@ -3319,6 +3320,9 @@ const struct file_operations btrfs_file_operations = { .splice_read = generic_file_splice_read, .write_iter = btrfs_file_write_iter, .mmap = btrfs_file_mmap, +#ifdef CONFIG_FS_DAX + .mmap_supported_flags = MAP_SYNC, +#endif .open = btrfs_file_open, .release = btrfs_release_file, .fsync = btrfs_sync_file,
Signature · 1 line
2.16.4
PATCH v3 13/18 fs: dedup file range to use a compare function
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
With dax we cannot deal with readpage() etc. So, we create a funciton callback to perform the file data comparison and pass it to generic_remap_file_range_prep() so it can use iomap-based functions.
This may not be the best way to solve this. Suggestions welcome.
--- fs/btrfs/ctree.h | 9 ++++++++ fs/btrfs/dax.c | 7 +++++++ fs/btrfs/ioctl.c | 11 ++++++++-- fs/dax.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/file.c | 2 +- fs/read_write.c | 10 ++++----- fs/xfs/xfs_reflink.c | 2 +- include/linux/dax.h | 2 ++ include/linux/fs.h | 7 ++++++- 9 files changed, 98 insertions(+), 10 deletions(-)
fs/btrfs/ctree.h +9 -0
@@ -3803,11 +3803,20 @@ int btree_readahead_hook(struct extent_buffer *eb, int err);ssize_t btrfs_file_dax_read (struct kiocb *iocb,struct iov_iter *to);ssize_t btrfs_file_dax_write (struct kiocb *iocb,struct iov_iter *from);vm_fault_t btrfs_dax_fault (struct vm_fault *vmf); +int btrfs_dax_file_range_compare (struct inode *src,loff_t srcoff, +struct inode *dest,loff_t destoff,loff_t len, +bool *is_same);#else static inline ssize_t btrfs_file_dax_write (struct kiocb *iocb,struct iov_iter *from) {return 0 ; } +static inline int btrfs_dax_file_range_compare (struct inode *src,loff_t srcoff, +struct inode *dest,loff_t destoff,loff_t len, +bool *is_same) +{ +return 0 ; +}#endif /* CONFIG_FS_DAX */ static inline int is_fstree (u64 rootid)
fs/btrfs/dax.c +7 -0
@@ -227,4 +227,11 @@ vm_fault_t btrfs_dax_fault(struct vm_fault *vmf) return ret; } + +int btrfs_dax_file_range_compare (struct inode *src,loff_t srcoff, +struct inode *dest,loff_t destoff,loff_t len, +bool *is_same) +{ +return dax_file_range_compare (src, srcoff, dest, destoff, len, is_same, &btrfs_iomap_ops); +}#endif /* CONFIG_FS_DAX */
fs/btrfs/ioctl.c +9 -2
@@ -4000,8 +4000,15 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in,if (ret <0 ) goto out_unlock; - ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, - len, remap_flags); +if (IS_DAX (file_inode (file_in)) &&IS_DAX (file_inode (file_out))) + ret =generic_remap_file_range_prep (file_in, pos_in, file_out, + pos_out, len, remap_flags, + btrfs_dax_file_range_compare); +else + ret =generic_remap_file_range_prep (file_in, pos_in, file_out, + pos_out, len, remap_flags, + vfs_dedupe_file_range_compare); +if (ret <0 || *len ==0 ) goto out_unlock;
fs/dax.c +58 -0
61 lines not on this page · raw message
fs/ocfs2/file.c +1 -1
@@ -2558,7 +2558,7 @@ static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in, goto out_unlock; ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, - &len, remap_flags); + &len, remap_flags, vfs_dedupe_file_range_compare);if (ret <0 || len ==0 ) goto out_unlock;
fs/read_write.c +5 -5
@@ -1778,7 +1778,7 @@ static struct page *vfs_dedupe_get_page(struct inode *inode, loff_t offset)* Compare extents of two files to see if they are the same. * Caller must have locked both inodes to prevent write races. */ -static int vfs_dedupe_file_range_compare (struct inode *src,loff_t srcoff, +int vfs_dedupe_file_range_compare (struct inode *src,loff_t srcoff,struct inode *dest,loff_t destoff,loff_t len,bool *is_same) {
@@ -1845,6 +1845,7 @@ static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, out_error:return error; } +EXPORT_SYMBOL (vfs_dedupe_file_range_compare);/* * Check that the two inodes are eligible for cloning, the ranges make
@@ -1856,7 +1857,7 @@ static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,*/ int generic_remap_file_range_prep (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -loff_t *len,unsigned int remap_flags) +loff_t *len,unsigned int remap_flags,compare_range_t compare) {struct inode *inode_in =file_inode (file_in);struct inode *inode_out =file_inode (file_out);
@@ -1915,9 +1916,8 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,*/ if (remap_flags &REMAP_FILE_DEDUP ) {bool is_same = false; - - ret =vfs_dedupe_file_range_compare (inode_in, pos_in, - inode_out, pos_out, *len, &is_same); + ret =compare (inode_in, pos_in, + inode_out, pos_out, *len, &is_same);if (ret)return ret;if (!is_same)
fs/xfs/xfs_reflink.c +1 -1
@@ -1350,7 +1350,7 @@ xfs_reflink_remap_prep( goto out_unlock; ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, - len, remap_flags); + len, remap_flags, vfs_dedupe_file_range_compare);if (ret <0 || *len ==0 ) goto out_unlock;
include/linux/dax.h +2 -0
@@ -157,6 +157,8 @@ vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,int dax_delete_mapping_entry (struct address_space *mapping,pgoff_t index);int dax_invalidate_mapping_entry_sync (struct address_space *mapping,pgoff_t index); +int dax_file_range_compare (struct inode *src,loff_t srcoff,struct inode *dest, +loff_t destoff,loff_t len,bool *is_same,const struct iomap_ops *ops);#ifdef CONFIG_FS_DAX int __dax_zero_page_range(struct block_device *bdev,
include/linux/fs.h +6 -1
@@ -1883,10 +1883,15 @@ extern ssize_t vfs_readv(struct file *, const struct iovec __user *, unsigned long, loff_t *, rwf_t);extern ssize_t vfs_copy_file_range (struct file *,loff_t ,struct file *,loff_t ,size_t ,unsigned int ); +extern int vfs_dedupe_file_range_compare (struct inode *src,loff_t srcoff, +struct inode *dest,loff_t destoff, +loff_t len,bool *is_same); +typedef int (compare_range_t )(struct inode *src,loff_t srcpos,struct inode *dest, +loff_t destpos,loff_t len,bool *is_same);extern int generic_remap_file_range_prep (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,loff_t *count, -unsigned int remap_flags); +unsigned int remap_flags,compare_range_t cmp);extern loff_t do_clone_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,loff_t len,unsigned int remap_flags);
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [PATCH 13/18] fs: dedup file range to use a compare function
Quoted 71 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <rgoldwyn-IBi9RG/[email protected]>
With dax we cannot deal with
readpage()etc. So, we create a funciton callback to perform the file data comparison and pass it togeneric_remap_file_range_prep()so it can use iomap-based functions.This may not be the best way to solve this. Suggestions welcome.
Signed-off-by Goldwyn Rodrigues <rgoldwyn-IBi9RG/[email protected]>--- fs/btrfs/ctree.h | 9 ++++++++ fs/btrfs/dax.c | 7 +++++++ fs/btrfs/ioctl.c | 11 ++++++++-- fs/dax.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/file.c | 2 +- fs/read_write.c | 10 ++++----- fs/xfs/xfs_reflink.c | 2 +- include/linux/dax.h | 2 ++ include/linux/fs.h | 7 ++++++- 9 files changed, 98 insertions(+), 10 deletions(-)fs/btrfs/ctree.h +9
-0@@ -3803,11 +3803,20 @@ int btree_readahead_hook(struct extent_buffer *eb, int err);ssize_t btrfs_file_dax_read (struct kiocb *iocb,struct iov_iter *to);ssize_t btrfs_file_dax_write (struct kiocb *iocb,struct iov_iter *from);vm_fault_t btrfs_dax_fault (struct vm_fault *vmf); +int btrfs_dax_file_range_compare (struct inode *src,loff_t srcoff, +struct inode *dest,loff_t destoff,loff_t len, +bool *is_same);#else static inline ssize_t btrfs_file_dax_write (struct kiocb *iocb,struct iov_iter *from) {return 0 ; } +static inline int btrfs_dax_file_range_compare (struct inode *src,loff_t srcoff, +struct inode *dest,loff_t destoff,loff_t len, +bool *is_same) +{ +return 0 ; +}#endif /* CONFIG_FS_DAX */ static inline int is_fstree (u64 rootid)fs/btrfs/dax.c +7
-0@@ -227,4 +227,11 @@ vm_fault_t btrfs_dax_fault(struct vm_fault *vmf) return ret; } + +int btrfs_dax_file_range_compare (struct inode *src,loff_t srcoff, +struct inode *dest,loff_t destoff,loff_t len, +bool *is_same) +{ +return dax_file_range_compare (src, srcoff, dest, destoff, len, is_same, &btrfs_iomap_ops); +}#endif /* CONFIG_FS_DAX */ fs/btrfs/ioctl.c +0
-0@@ -4000,8 +4000,15 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in,if (ret <0 ) goto out_unlock;
fs/btrfs/ioctl.c static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in, · line 4010
Quoted 10 lines
fs/btrfs/ioctl.c +8
-2- ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, - len, remap_flags); +if (IS_DAX (file_inode (file_in)) &&IS_DAX (file_inode (file_out))) + ret =generic_remap_file_range_prep (file_in, pos_in, file_out, + pos_out, len, remap_flags, + btrfs_dax_file_range_compare); +else + ret =generic_remap_file_range_prep (file_in, pos_in, file_out, + pos_out, len, remap_flags, + vfs_dedupe_file_range_compare);
I wonder if you could simply have a compare_range_t variable that you can set to either the vfs and btrfs_dax compare functions, and then only have to maintain a single generic_remap_file_range_prep callsite?
Quoted 40 lines
fs/btrfs/ioctl.c +1
-0+if (ret <0 || *len ==0 ) goto out_unlock;fs/dax.c +28
-0@@ -1759,3 +1759,61 @@ vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,return dax_insert_pfn_mkwrite (vmf, pfn, order); }EXPORT_SYMBOL_GPL (dax_finish_sync_fault); + + +int dax_file_range_compare (struct inode *src,loff_t srcoff,struct inode *dest, +loff_t destoff,loff_t len,bool *is_same,const struct iomap_ops *ops) +{ +void *saddr, *daddr; +struct iomap s_iomap = {0 }; +struct iomap d_iomap = {0 }; +loff_t dstart, sstart; +bool same = true; +loff_t cmp_len, l; +int id, ret =0 ; + + id =dax_read_lock (); +while (len) { + ret = ops->iomap_begin (src, srcoff, len,0 , &s_iomap); +if (ret <0 ) { +if (ops->iomap_end) + ops->iomap_end (src, srcoff, len, ret,0 , &s_iomap); +return ret; + } + cmp_len = len; +if (cmp_len > s_iomap.offset + s_iomap.length - srcoff) + cmp_len = s_iomap.offset + s_iomap.length - srcoff; + + ret = ops->iomap_begin (dest, destoff, cmp_len,0 , &d_iomap); +if (ret <0 ) { +if (ops->iomap_end) {
fs/dax.c vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, · line 1799
Quoted 10 lines
fs/dax.c +10
-0+ ops->iomap_end (src, srcoff, len, ret,0 , &s_iomap); + ops->iomap_end (dest, destoff, len, ret,0 , &d_iomap); + } +return ret; + } +if (cmp_len > d_iomap.offset + d_iomap.length - destoff) + cmp_len = d_iomap.offset + d_iomap.length - destoff; + + + sstart = (get_start_sect (s_iomap.bdev) <<9 ) + s_iomap.addr + (srcoff - s_iomap.offset);
This kinda screams static inline helper function...
fs/dax.c vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, · line 1801
Quoted 2 lines
fs/dax.c +2
-0+ l =dax_direct_access (s_iomap.dax_dev,PHYS_PFN (sstart),PHYS_PFN (cmp_len), &saddr,NULL ); + dstart = (get_start_sect (d_iomap.bdev) <<9 ) + d_iomap.addr + (destoff - d_iomap.offset);
...especially since it happens again here...
fs/dax.c vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, · line 1802
Quoted 1 line
fs/dax.c +1
-0+ l =dax_direct_access (d_iomap.dax_dev,PHYS_PFN (dstart),PHYS_PFN (cmp_len), &daddr,NULL );
...and these lines are too long.
Quoted 44 lines
fs/dax.c +17
-0+ same = !memcmp (saddr, daddr, cmp_len); +if (!same) +break ; + len -= cmp_len; + srcoff += cmp_len; + destoff += cmp_len; + +if (ops->iomap_end) { + ret = ops->iomap_end (src, srcoff, len,0 ,0 , &s_iomap); + ret = ops->iomap_end (dest, destoff, len,0 ,0 , &d_iomap); + } + } +dax_read_unlock (id); + *is_same = same; +return ret; +} +EXPORT_SYMBOL_GPL (dax_file_range_compare);fs/ocfs2/file.c +1
-1@@ -2558,7 +2558,7 @@ static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in, goto out_unlock; ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, - &len, remap_flags); + &len, remap_flags, vfs_dedupe_file_range_compare);if (ret <0 || len ==0 ) goto out_unlock;fs/read_write.c +1
-1@@ -1778,7 +1778,7 @@ static struct page *vfs_dedupe_get_page(struct inode *inode, loff_t offset)* Compare extents of two files to see if they are the same. * Caller must have locked both inodes to prevent write races. */ -static int vfs_dedupe_file_range_compare (struct inode *src,loff_t srcoff, +int vfs_dedupe_file_range_compare (struct inode *src,loff_t srcoff,struct inode *dest,loff_t destoff,loff_t len,bool *is_same) {
fs/read_write.c static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, · line 1848
Quoted 4 lines
fs/read_write.c +1
-0@@ -1845,6 +1845,7 @@ static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, out_error:return error; } +EXPORT_SYMBOL (vfs_dedupe_file_range_compare);
Not EXPORT_SYMBOL_GPL? :D
Quoted 54 lines
fs/read_write.c +3
-4/* * Check that the two inodes are eligible for cloning, the ranges make @@ -1856,7 +1857,7 @@ static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,*/ int generic_remap_file_range_prep (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -loff_t *len,unsigned int remap_flags) +loff_t *len,unsigned int remap_flags,compare_range_t compare) {struct inode *inode_in =file_inode (file_in);struct inode *inode_out =file_inode (file_out);@@ -1915,9 +1916,8 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,*/ if (remap_flags &REMAP_FILE_DEDUP ) {bool is_same = false; - - ret =vfs_dedupe_file_range_compare (inode_in, pos_in, - inode_out, pos_out, *len, &is_same); + ret =compare (inode_in, pos_in, + inode_out, pos_out, *len, &is_same);if (ret)return ret;if (!is_same)fs/xfs/xfs_reflink.c +1
-1@@ -1350,7 +1350,7 @@ xfs_reflink_remap_prep( goto out_unlock; ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, - len, remap_flags); + len, remap_flags, vfs_dedupe_file_range_compare);if (ret <0 || *len ==0 ) goto out_unlock;include/linux/dax.h +2
-0@@ -157,6 +157,8 @@ vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,int dax_delete_mapping_entry (struct address_space *mapping,pgoff_t index);int dax_invalidate_mapping_entry_sync (struct address_space *mapping,pgoff_t index); +int dax_file_range_compare (struct inode *src,loff_t srcoff,struct inode *dest, +loff_t destoff,loff_t len,bool *is_same,const struct iomap_ops *ops);#ifdef CONFIG_FS_DAX int __dax_zero_page_range(struct block_device *bdev,include/linux/fs.h +0
-0
include/linux/fs.h extern ssize_t vfs_readv(struct file *, const struct iovec __user *, · line 1890
Quoted 8 lines
include/linux/fs.h +5
-0@@ -1883,10 +1883,15 @@ extern ssize_t vfs_readv(struct file *, const struct iovec __user *, unsigned long, loff_t *, rwf_t);extern ssize_t vfs_copy_file_range (struct file *,loff_t ,struct file *,loff_t ,size_t ,unsigned int ); +extern int vfs_dedupe_file_range_compare (struct inode *src,loff_t srcoff, +struct inode *dest,loff_t destoff, +loff_t len,bool *is_same); +typedef int (compare_range_t )(struct inode *src,loff_t srcpos,struct inode *dest, +loff_t destpos,loff_t len,bool *is_same);
Might want to call this vfs_compare_range_t to make it clear that this belongs to the generic vfs namespace.
--D
Quoted 11 lines
include/linux/fs.h +1
-1extern int generic_remap_file_range_prep (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,loff_t *count, -unsigned int remap_flags); +unsigned int remap_flags,compare_range_t cmp);extern loff_t do_clone_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,loff_t len,unsigned int remap_flags);Signature · 1 line
2.16.4
PATCH v3 14/18 dax: memcpy before zeroing range
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
However, this needed more iomap fields, so it was easier to pass iomap and compute inside the function rather than passing a log of arguments.
Note, there is subtle difference between iomap_sector and dax_iomap_sector(). Can we replace dax_iomap_sector with iomap_sector()? It would need pos & PAGE_MASK though or else bdev_dax_pgoff() return -EINVAL.
--- fs/dax.c | 14 ++++++++++---- fs/iomap.c | 9 +-------- include/linux/dax.h | 11 +++++------ include/linux/iomap.h | 6 ++++++ 4 files changed, 22 insertions(+), 18 deletions(-)
fs/dax.c +10 -4
@@ -1055,11 +1055,15 @@ static bool dax_range_is_aligned(struct block_device *bdev,return true; } -int __dax_zero_page_range (struct block_device *bdev, -struct dax_device *dax_dev,sector_t sector, -unsigned int offset,unsigned int size) +int __dax_zero_page_range (struct iomap *iomap,loff_t pos, +unsigned int offset,unsigned int size) { -if (dax_range_is_aligned (bdev, offset, size)) { +sector_t sector =dax_iomap_sector (iomap, pos &PAGE_MASK ); +struct block_device *bdev = iomap->bdev; +struct dax_device *dax_dev = iomap->dax_dev; + +if (!(iomap->type ==IOMAP_DAX_COW ) && +dax_range_is_aligned (bdev, offset, size)) {sector_t start_sector = sector + (offset >>9 ); return blkdev_issue_zeroout(bdev, start_sector,
@@ -1079,6 +1083,8 @@ int __dax_zero_page_range(struct block_device *bdev,dax_read_unlock (id);return rc; } +if (iomap->type ==IOMAP_DAX_COW ) +memcpy (iomap->inline_data, kaddr, offset);memset (kaddr + offset,0 , size);dax_flush (dax_dev, kaddr + offset, size);dax_read_unlock (id);
fs/iomap.c +1 -8
@@ -98,12 +98,6 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,return written ? written : ret; } -static sector_t -iomap_sector (struct iomap *iomap,loff_t pos) -{ -return (iomap->addr + pos - iomap->offset) >>SECTOR_SHIFT ; -} -static struct iomap_page *iomap_page_create (struct inode *inode,struct page *page) {
@@ -990,8 +984,7 @@ static int iomap_zero(struct inode *inode, loff_t pos, unsigned offset,static int iomap_dax_zero (loff_t pos,unsigned offset,unsigned bytes,struct iomap *iomap) { -return __dax_zero_page_range (iomap->bdev, iomap->dax_dev, -iomap_sector (iomap, pos &PAGE_MASK ), offset, bytes); +return __dax_zero_page_range (iomap, pos, offset, bytes); } static loff_t
include/linux/dax.h +5 -6
@@ -9,6 +9,7 @@typedef unsigned long dax_entry_t ; +struct iomap ;struct iomap_ops ;struct dax_device ;struct dax_operations {
@@ -161,13 +162,11 @@ int dax_file_range_compare(struct inode *src, loff_t srcoff, struct inode *dest, loff_t destoff, loff_t len, bool *is_same, const struct iomap_ops *ops);#ifdef CONFIG_FS_DAX -int __dax_zero_page_range (struct block_device *bdev, -struct dax_device *dax_dev,sector_t sector, -unsigned int offset,unsigned int length); +int __dax_zero_page_range (struct iomap *iomap,loff_t pos, +unsigned int offset,unsigned int size);#else -static inline int __dax_zero_page_range (struct block_device *bdev, -struct dax_device *dax_dev,sector_t sector, -unsigned int offset,unsigned int length) +static inline int __dax_zero_page_range (struct iomap *iomap,loff_t pos, +unsigned int offset,unsigned int size) {return -ENXIO ; }
include/linux/iomap.h +6 -0
@@ -7,6 +7,7 @@#include <linux/mm.h> #include <linux/types.h> #include <linux/mm_types.h> +#include <linux/blkdev.h> struct address_space ;struct fiemap_extent_info ;
@@ -120,6 +121,11 @@ static inline struct iomap_page *to_iomap_page(struct page *page)return NULL ; } +static inline sector_t iomap_sector (struct iomap *iomap,loff_t pos) +{ +return (iomap->addr + pos - iomap->offset) >>SECTOR_SHIFT ; +} +ssize_t iomap_file_buffered_write (struct kiocb *iocb,struct iov_iter *from,const struct iomap_ops *ops);int iomap_readpage (struct page *page,const struct iomap_ops *ops);
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [PATCH 14/18] dax: memcpy before zeroing range
Quoted 44 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <rgoldwyn-IBi9RG/[email protected]>
However, this needed more iomap fields, so it was easier to pass iomap and compute inside the function rather than passing a log of arguments.
Note, there is subtle difference between
iomap_sectoranddax_iomap_sector(). Can we replacedax_iomap_sectorwithiomap_sector()? It would need pos &PAGE_MASKthough or elsebdev_dax_pgoff()return-EINVAL.Signed-off-by Goldwyn Rodrigues <rgoldwyn-IBi9RG/[email protected]>--- fs/dax.c | 14 ++++++++++---- fs/iomap.c | 9 +-------- include/linux/dax.h | 11 +++++------ include/linux/iomap.h | 6 ++++++ 4 files changed, 22 insertions(+), 18 deletions(-)fs/dax.c +8
-4@@ -1055,11 +1055,15 @@ static bool dax_range_is_aligned(struct block_device *bdev,return true; } -int __dax_zero_page_range (struct block_device *bdev, -struct dax_device *dax_dev,sector_t sector, -unsigned int offset,unsigned int size) +int __dax_zero_page_range (struct iomap *iomap,loff_t pos, +unsigned int offset,unsigned int size) { -if (dax_range_is_aligned (bdev, offset, size)) { +sector_t sector =dax_iomap_sector (iomap, pos &PAGE_MASK ); +struct block_device *bdev = iomap->bdev; +struct dax_device *dax_dev = iomap->dax_dev; + +if (!(iomap->type ==IOMAP_DAX_COW ) && +dax_range_is_aligned (bdev, offset, size)) {sector_t start_sector = sector + (offset >>9 ); return blkdev_issue_zeroout(bdev, start_sector,
fs/dax.c int __dax_zero_page_range(struct block_device *bdev, · line 1087
Quoted 5 lines
fs/dax.c +2
-0@@ -1079,6 +1083,8 @@ int __dax_zero_page_range(struct block_device *bdev,dax_read_unlock (id);return rc; } +if (iomap->type ==IOMAP_DAX_COW ) +memcpy (iomap->inline_data, kaddr, offset);
I'm confused, why are we copying into the source page before zeroing some part of the dax device?
Quoted 73 lines
fs/dax.c +0
-0memset (kaddr + offset,0 , size);dax_flush (dax_dev, kaddr + offset, size);dax_read_unlock (id);fs/iomap.c +1
-8@@ -98,12 +98,6 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,return written ? written : ret; } -static sector_t -iomap_sector (struct iomap *iomap,loff_t pos) -{ -return (iomap->addr + pos - iomap->offset) >>SECTOR_SHIFT ; -} -static struct iomap_page *iomap_page_create (struct inode *inode,struct page *page) {@@ -990,8 +984,7 @@ static int iomap_zero(struct inode *inode, loff_t pos, unsigned offset,static int iomap_dax_zero (loff_t pos,unsigned offset,unsigned bytes,struct iomap *iomap) { -return __dax_zero_page_range (iomap->bdev, iomap->dax_dev, -iomap_sector (iomap, pos &PAGE_MASK ), offset, bytes); +return __dax_zero_page_range (iomap, pos, offset, bytes); } static loff_tinclude/linux/dax.h +5
-6@@ -9,6 +9,7 @@typedef unsigned long dax_entry_t ; +struct iomap ;struct iomap_ops ;struct dax_device ;struct dax_operations {@@ -161,13 +162,11 @@ int dax_file_range_compare(struct inode *src, loff_t srcoff, struct inode *dest, loff_t destoff, loff_t len, bool *is_same, const struct iomap_ops *ops);#ifdef CONFIG_FS_DAX -int __dax_zero_page_range (struct block_device *bdev, -struct dax_device *dax_dev,sector_t sector, -unsigned int offset,unsigned int length); +int __dax_zero_page_range (struct iomap *iomap,loff_t pos, +unsigned int offset,unsigned int size);#else -static inline int __dax_zero_page_range (struct block_device *bdev, -struct dax_device *dax_dev,sector_t sector, -unsigned int offset,unsigned int length) +static inline int __dax_zero_page_range (struct iomap *iomap,loff_t pos, +unsigned int offset,unsigned int size) {return -ENXIO ; }include/linux/iomap.h +1
-0@@ -7,6 +7,7 @@#include <linux/mm.h> #include <linux/types.h> #include <linux/mm_types.h> +#include <linux/blkdev.h> struct address_space ;struct fiemap_extent_info ;
include/linux/iomap.h static inline struct iomap_page *to_iomap_page(struct page *page) · line 126
Quoted 6 lines
include/linux/iomap.h +3
-0@@ -120,6 +121,11 @@ static inline struct iomap_page *to_iomap_page(struct page *page)return NULL ; } +static inline sector_t iomap_sector (struct iomap *iomap,loff_t pos) +{ +return (iomap->addr + pos - iomap->offset) >>SECTOR_SHIFT ;
Why the double indent?
--D
Quoted 8 lines
include/linux/iomap.h +2
-0+} +ssize_t iomap_file_buffered_write (struct kiocb *iocb,struct iov_iter *from,const struct iomap_ops *ops);int iomap_readpage (struct page *page,const struct iomap_ops *ops);Signature · 1 line
2.16.4
Re: [PATCH 14/18] dax: memcpy before zeroing range
Quoted 43 lines · Darrick J. Wong
Quoted 42 lines · Goldwyn Rodrigues
From: Goldwyn Rodrigues <[email protected]>
However, this needed more iomap fields, so it was easier to pass iomap and compute inside the function rather than passing a log of arguments.
Note, there is subtle difference between
iomap_sectoranddax_iomap_sector(). Can we replacedax_iomap_sectorwithiomap_sector()? It would need pos &PAGE_MASKthough or elsebdev_dax_pgoff()return-EINVAL.Signed-off-by Goldwyn Rodrigues <[email protected]>--- fs/dax.c | 14 ++++++++++---- fs/iomap.c | 9 +-------- include/linux/dax.h | 11 +++++------ include/linux/iomap.h | 6 ++++++ 4 files changed, 22 insertions(+), 18 deletions(-)fs/dax.c +8
-4@@ -1055,11 +1055,15 @@ static bool dax_range_is_aligned(struct block_device *bdev,return true; } -int __dax_zero_page_range (struct block_device *bdev, -struct dax_device *dax_dev,sector_t sector, -unsigned int offset,unsigned int size) +int __dax_zero_page_range (struct iomap *iomap,loff_t pos, +unsigned int offset,unsigned int size) { -if (dax_range_is_aligned (bdev, offset, size)) { +sector_t sector =dax_iomap_sector (iomap, pos &PAGE_MASK ); +struct block_device *bdev = iomap->bdev; +struct dax_device *dax_dev = iomap->dax_dev; + +if (!(iomap->type ==IOMAP_DAX_COW ) && +dax_range_is_aligned (bdev, offset, size)) {sector_t start_sector = sector + (offset >>9 );
Quoted 10 lines
fs/dax.c int __dax_zero_page_range(struct block_device *bdev, · line 1087
Quoted 7 lines
fs/dax.c +2
-0return blkdev_issue_zeroout(bdev, start_sector,@@ -1079,6 +1083,8 @@ int __dax_zero_page_range(struct block_device *bdev,dax_read_unlock (id);return rc; } +if (iomap->type ==IOMAP_DAX_COW ) +memcpy (iomap->inline_data, kaddr, offset);I'm confused, why are we copying into the source page before zeroing some part of the dax device?
Clearly my testing was not good enough. This should be - memcpy(kaddr, iomap->inline_data, offset);
We copy the part which is not zeroed to new location.
Quoted 77 lines
Quoted 77 lines
fs/dax.c +0
-0memset (kaddr + offset,0 , size);dax_flush (dax_dev, kaddr + offset, size);dax_read_unlock (id);fs/iomap.c +1
-8@@ -98,12 +98,6 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,return written ? written : ret; } -static sector_t -iomap_sector (struct iomap *iomap,loff_t pos) -{ -return (iomap->addr + pos - iomap->offset) >>SECTOR_SHIFT ; -} -static struct iomap_page *iomap_page_create (struct inode *inode,struct page *page) {@@ -990,8 +984,7 @@ static int iomap_zero(struct inode *inode, loff_t pos, unsigned offset,static int iomap_dax_zero (loff_t pos,unsigned offset,unsigned bytes,struct iomap *iomap) { -return __dax_zero_page_range (iomap->bdev, iomap->dax_dev, -iomap_sector (iomap, pos &PAGE_MASK ), offset, bytes); +return __dax_zero_page_range (iomap, pos, offset, bytes); } static loff_tinclude/linux/dax.h +5
-6@@ -9,6 +9,7 @@typedef unsigned long dax_entry_t ; +struct iomap ;struct iomap_ops ;struct dax_device ;struct dax_operations {@@ -161,13 +162,11 @@ int dax_file_range_compare(struct inode *src, loff_t srcoff, struct inode *dest, loff_t destoff, loff_t len, bool *is_same, const struct iomap_ops *ops);#ifdef CONFIG_FS_DAX -int __dax_zero_page_range (struct block_device *bdev, -struct dax_device *dax_dev,sector_t sector, -unsigned int offset,unsigned int length); +int __dax_zero_page_range (struct iomap *iomap,loff_t pos, +unsigned int offset,unsigned int size);#else -static inline int __dax_zero_page_range (struct block_device *bdev, -struct dax_device *dax_dev,sector_t sector, -unsigned int offset,unsigned int length) +static inline int __dax_zero_page_range (struct iomap *iomap,loff_t pos, +unsigned int offset,unsigned int size) {return -ENXIO ; }include/linux/iomap.h +1
-0@@ -7,6 +7,7 @@#include <linux/mm.h> #include <linux/types.h> #include <linux/mm_types.h> +#include <linux/blkdev.h> struct address_space ;struct fiemap_extent_info ;@@ -120,6 +121,11 @@ static inline struct iomap_page *to_iomap_page(struct page *page)return NULL ; }
Quoted 5 lines
include/linux/iomap.h static inline struct iomap_page *to_iomap_page(struct page *page) · line 126
Quoted 3 lines
include/linux/iomap.h +3
-0+static inline sector_t iomap_sector (struct iomap *iomap,loff_t pos) +{ +return (iomap->addr + pos - iomap->offset) >>SECTOR_SHIFT ;Why the double indent?
Ahh.. I will fix this.
Quoted 12 lines
--D
Quoted 8 lines
include/linux/iomap.h +2
-0+} +ssize_t iomap_file_buffered_write (struct kiocb *iocb,struct iov_iter *from,const struct iomap_ops *ops);int iomap_readpage (struct page *page,const struct iomap_ops *ops);Signature · 1 line
2.16.4
Signature · 1 line
Goldwyn
PATCH v3 15/18 btrfs: handle dax page zeroing
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
btrfs_dax_zero_block() zeros part of the page, either from the front or the regular rest of the block.
--- fs/btrfs/ctree.h | 1 + fs/btrfs/dax.c | 27 ++++++++++++++++++++++++++- fs/btrfs/inode.c | 4 ++++ 3 files changed, 31 insertions(+), 1 deletion(-)
fs/btrfs/ctree.h +1 -0
@@ -3806,6 +3806,7 @@ vm_fault_t btrfs_dax_fault(struct vm_fault *vmf);int btrfs_dax_file_range_compare (struct inode *src,loff_t srcoff,struct inode *dest,loff_t destoff,loff_t len,bool *is_same); +int btrfs_dax_zero_block (struct inode *inode,loff_t from,loff_t len,bool front);#else static inline ssize_t btrfs_file_dax_write (struct kiocb *iocb,struct iov_iter *from) {
fs/btrfs/dax.c +26 -1
@@ -132,7 +132,8 @@ static int btrfs_iomap_begin(struct inode *inode, loff_t pos,* This will be true for reads only since we have already * allocated em */ -if (em->block_start ==EXTENT_MAP_HOLE ) { +if (em->block_start ==EXTENT_MAP_HOLE || + em->flags ==EXTENT_FLAG_FILLING ) { iomap->type =IOMAP_HOLE ;return 0 ; }
@@ -234,4 +235,28 @@ int btrfs_dax_file_range_compare(struct inode *src, loff_t srcoff, {return dax_file_range_compare (src, srcoff, dest, destoff, len, is_same, &btrfs_iomap_ops); } + +/* +* zero a part of the page only. This should CoW (via iomap_begin) if required +*/ +int btrfs_dax_zero_block (struct inode *inode,loff_t from,loff_t len,bool front) +{ +loff_t start =round_down (from,PAGE_SIZE ); +loff_t end =round_up (from,PAGE_SIZE ); +loff_t offset = from; +int ret =0 ; + +if (front) { + len = from - start; + offset = start; + }else { +if (!len) + len = end - from; + } + +if (len) + ret =iomap_zero_range (inode, offset, len,NULL , &btrfs_iomap_ops); + +return (ret <0 ) ? ret :0 ; +}#endif /* CONFIG_FS_DAX */
fs/btrfs/inode.c +4 -0
@@ -4833,6 +4833,10 @@ int btrfs_truncate_block(struct inode *inode, loff_t from, loff_t len, (!len || IS_ALIGNED(len, blocksize))) goto out; +#ifdef CONFIG_FS_DAX +if (IS_DAX (inode)) +return btrfs_dax_zero_block (inode, from, len, front); +#endif block_start =round_down (from, blocksize); block_end = block_start + blocksize -1 ;
Signature · 1 line
2.16.4
PATCH v3 16/18 btrfs: Writeprotect mmap pages on snapshot
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
Inorder to make sure mmap'd files don't change after snapshot, writeprotect the mmap pages on snapshot. This is done by performing a data writeback on the pages (which simply mark the pages are wrprotected). This way if the user process tries to access the memory we will get another fault and we can perform a CoW.
In order to accomplish this, we tag all CoW pages as PAGECACHE_TAG_TOWRITE, and add the mmapd inode in delalloc_inodes. During snapshot, it starts writeback of all delalloc'd inodes and here we perform a data writeback. We don't want to keep the inodes in delalloc_inodes until it umount (WARN_ON), so we remove it during inode evictions.
--- fs/btrfs/ctree.h | 3 ++- fs/btrfs/dax.c | 7 +++++++ fs/btrfs/inode.c | 13 ++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-)
fs/btrfs/ctree.h +2 -1
@@ -3252,7 +3252,8 @@ int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,struct btrfs_root *new_root, struct btrfs_root *parent_root, u64 new_dirid); -void btrfs_set_delalloc_extent (struct inode *inode,struct extent_state *state, +void btrfs_add_delalloc_inodes (struct btrfs_root *root,struct inode *inode); +void btrfs_set_delalloc_extent (struct inode *inode,struct extent_state *state,unsigned *bits);void btrfs_clear_delalloc_extent (struct inode *inode,struct extent_state *state,unsigned *bits);
fs/btrfs/dax.c +7 -0
@@ -222,10 +222,17 @@ vm_fault_t btrfs_dax_fault(struct vm_fault *vmf) {vm_fault_t ret;pfn_t pfn; +struct inode *inode =file_inode (vmf->vma->vm_file); +struct btrfs_inode *binode =BTRFS_I (inode); ret =dax_iomap_fault (vmf,PE_SIZE_PTE , &pfn,NULL , &btrfs_iomap_ops);if (ret &VM_FAULT_NEEDDSYNC ) ret =dax_finish_sync_fault (vmf,PE_SIZE_PTE , pfn); +/* Insert into delalloc so we get writeback calls on snapshots */ +if (vmf->flags &FAULT_FLAG_WRITE && + !test_bit (BTRFS_INODE_IN_DELALLOC_LIST , &binode->runtime_flags)) +btrfs_add_delalloc_inodes (binode->root, inode); +return ret; }
fs/btrfs/inode.c +12 -1
@@ -1713,7 +1713,7 @@ void btrfs_merge_delalloc_extent(struct inode *inode, struct extent_state *new,spin_unlock (&BTRFS_I (inode)->lock); } -static void btrfs_add_delalloc_inodes (struct btrfs_root *root, +void btrfs_add_delalloc_inodes (struct btrfs_root *root,struct inode *inode) {struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb);
@@ -5358,12 +5358,17 @@ void btrfs_evict_inode(struct inode *inode) {struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb);struct btrfs_trans_handle *trans; +struct btrfs_inode *binode =BTRFS_I (inode);struct btrfs_root *root =BTRFS_I (inode)->root;struct btrfs_block_rsv *rsv;int ret;trace_btrfs_inode_evict (inode); +if (IS_DAX (inode) + &&test_bit (BTRFS_INODE_IN_DELALLOC_LIST , &binode->runtime_flags)) +btrfs_del_delalloc_inode (root, binode); +if (!root) {clear_inode (inode);return ;
@@ -8683,6 +8688,10 @@ static int btrfs_dax_writepages(struct address_space *mapping, {struct inode *inode = mapping->host;struct btrfs_fs_info *fs_info =btrfs_sb (inode->i_sb); +struct btrfs_inode *binode =BTRFS_I (inode); +if ((wbc->sync_mode ==WB_SYNC_ALL ) && +test_bit (BTRFS_INODE_IN_DELALLOC_LIST , &binode->runtime_flags)) +btrfs_del_delalloc_inode (binode->root, binode);return dax_writeback_mapping_range (mapping, fs_info->fs_devices->latest_bdev, wbc); }
@@ -9981,6 +9990,8 @@ static void btrfs_run_delalloc_work(struct btrfs_work *work) delalloc_work = container_of(work, struct btrfs_delalloc_work, work); inode = delalloc_work->inode; +if (IS_DAX (inode)) +filemap_fdatawrite (inode->i_mapping);filemap_flush (inode->i_mapping);if (test_bit (BTRFS_INODE_HAS_ASYNC_EXTENT , &BTRFS_I (inode)->runtime_flags))
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 17/18 btrfs: Disable dax-based defrag and send
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
This is temporary, and a TODO.
--- fs/btrfs/ioctl.c | 13 +++++++++++++ fs/btrfs/send.c | 4 ++++ 2 files changed, 17 insertions(+)
fs/btrfs/ioctl.c +13 -0
@@ -2990,6 +2990,12 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) goto out; } +if (IS_DAX (inode)) { +btrfs_warn (root->fs_info,"File defrag is not supported with DAX" ); + ret = -EOPNOTSUPP ; + goto out; + } +if (argp) {if (copy_from_user (range, argp,sizeof (*range))) {
@@ -4653,6 +4659,10 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)if (!capable (CAP_SYS_ADMIN ))return -EPERM ; +/* send can be on a directory, so check super block instead */ +if (btrfs_test_opt (fs_info,DAX )) +return -EOPNOTSUPP ; + ret =mnt_want_write_file (file);if (ret)return ret;
@@ -5505,6 +5515,9 @@ static int _btrfs_ioctl_send(struct file *file, void __user *argp, bool compat)struct btrfs_ioctl_send_args *arg;int ret; +if (IS_DAX (file_inode (file))) +return -EOPNOTSUPP ; +if (compat) {#if defined(CONFIG_64BIT ) && defined(CONFIG_COMPAT )struct btrfs_ioctl_send_args_32 args32;
fs/btrfs/send.c +4 -0
@@ -6609,6 +6609,10 @@ long btrfs_ioctl_send(struct file *mnt_file, struct btrfs_ioctl_send_args *arg)int sort_clone_roots =0 ;int index; +/* send can be on a directory, so check super block instead */ +if (btrfs_test_opt (fs_info,DAX )) +return -EOPNOTSUPP ; +if (!capable (CAP_SYS_ADMIN ))return -EPERM ;
Signature · 6 lines
2.16.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 18/18 btrfs: trace functions for btrfs_iomap_begin/end
In reply to Goldwyn RodriguesFrom: Goldwyn Rodrigues <[email protected]>
This is for debug purposes only and can be skipped.
--- fs/btrfs/dax.c | 3 +++ include/trace/events/btrfs.h | 56 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)
fs/btrfs/dax.c +3 -0
@@ -104,6 +104,8 @@ static int btrfs_iomap_begin(struct inode *inode, loff_t pos,u64 srcblk =0 ;loff_t diff; +trace_btrfs_iomap_begin (inode, pos, length, flags); + em =btrfs_get_extent (BTRFS_I (inode),NULL ,0 , pos, length,0 ); iomap->type =IOMAP_MAPPED ;
@@ -164,6 +166,7 @@ static int btrfs_iomap_end(struct inode *inode, loff_t pos, {struct btrfs_iomap *bi = iomap->private;u64 wend; +trace_btrfs_iomap_end (inode, pos, length, written, flags);if (!bi)return 0 ;
include/trace/events/btrfs.h +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.16.4
Quoted 5 lines · Goldwyn Rodrigues
This patch set adds support for dax on the BTRFS filesystem. In order to support for CoW for btrfs, there were changes which had to be made to the dax handling. The important one is copying blocks into the same dax device before using them which is performed by iomap type
IOMAP_DAX_COW.
I'm afraid that PMDK's testsuite nearly instantly makes this patchset explode in different ways.
It'd probably be a waste of your time to require a round-trip to report such fails and re-test. As PMDK is probably the biggest userspace component, and exercises DAX paths in interesting ways, I guess it'd be best if you ran its testsuite locally until it no longer kills the kernel.
Quick start:
git clone https://github.com/pmem/pmdk
deps: libndctl-dev[el], libdaxctl-dev[el]; rest are mostly optional (full deps for Fedora:
https://github.com/pmem/pmdk/blob/master/utils/docker/images/Dockerfile.fedora-28
SuSE's should be similar)
cp src/test/testconfig.sh{.example,}
-- then edit, you'd want:
PMEM_FS_DIR=/mnt/pmem # where you have the dax filesystem on
KEEP_GOING=y # to see more than one broken test
make
make test # to build tests
make check # to build and run all tests
cd src/test && ./RUNTESTS a_single_test
Obviously, PMDK's tests may fail due to some difference of behaviour between ext4, xfs, and your btrfs implementation -- that'll require some cooperation. But crashing the kernel is something where the blame is quite obvious.
Meow!
Signature · 4 lines
⢀⣴⠾⠻⢶⣦⠀ ⣾⠁⢠⠒⠀⣿⡁ A dumb species has no way to open a tuna can. ⢿⡄⠘⠷⠚⠋⠀ A smart species invents a can opener. ⠈⠳⣄⠀⠀⠀⠀ A master species delegates.