fsdax: introduce fs query to support reflink
Subsystems (10)
v11 cover fsdax: introduce fs query to support reflink
This patchset is aimed to support shared pages tracking for fsdax.
Changes since V10:
- Use cmpxchg() to prevent concurrent registration/unregistration
- Use phys_addr_t for ->memory_failure()
- Add dax_entry_lock() for dax_lock_mapping_entry()
- Fix offset and length calculation at the boundary of a filesystem
This patchset moves owner tracking from dax_assocaite_entry() to pmem device driver, by introducing an interface ->memory_failure() for struct pagemap. This interface is called by memory_failure() in mm, and implemented by pmem device.
Then call holder operations to find the filesystem which the corrupted data located in, and call filesystem handler to track files or metadata associated with this page.
Finally we are able to try to fix the corrupted data in filesystem and do other necessary processing, such as killing processes who are using the files affected.
The call trace is like this:memory_failure()
|* fsdax case |------------ |pgmap->ops->memory_failure() => pmem_pgmap_memory_failure() | dax_holder_notify_failure() => | dax_device->holder_ops->notify_failure() => | - xfs_dax_notify_failure() | |* xfs_dax_notify_failure() | |-------------------------- | | xfs_rmap_query_range() | | xfs_dax_failure_fn() | | * corrupted on metadata | | try to recover data, call xfs_force_shutdown() | | * corrupted on file data | | try to recover data, call mf_dax_kill_procs() |* normal case |------------- |mf_generic_kill_procs()
==
Shiyang Ruan (8):
dax: Introduce holder for dax_device
mm: factor helpers for memory_failure_dev_pagemap pagemap,pmem: Introduce ->memory_failure()
fsdax: Introduce dax_lock_mapping_entry()
mm: move pgoff_address() to vma_pgoff_address()
mm: Introduce mf_dax_kill_procs() for fsdax case
xfs: Implement ->notify_failure() for XFS
fsdax: set a CoW flag when associate reflink mappings
drivers/dax/super.c | 89 +++++++++++++ drivers/nvdimm/pmem.c | 16 +++ fs/dax.c | 140 ++++++++++++++++++--- fs/xfs/Makefile | 1 + fs/xfs/xfs_buf.c | 12 ++ fs/xfs/xfs_fsops.c | 3 + fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_notify_failure.c | 235 +++++++++++++++++++++++++++++++++++ fs/xfs/xfs_notify_failure.h | 10 ++ fs/xfs/xfs_super.c | 6 + include/linux/dax.h | 47 +++++++ include/linux/memremap.h | 12 ++ include/linux/mm.h | 17 +++ include/linux/page-flags.h | 6 + mm/memory-failure.c | 240 ++++++++++++++++++++++++++---------- 15 files changed, 747 insertions(+), 88 deletions(-) create mode 100644 fs/xfs/xfs_notify_failure.c create mode 100644 fs/xfs/xfs_notify_failure.h
Signature · 1 line
2.35.1
PATCH v11 1/8 dax: Introduce holder for dax_device
To easily track filesystem from a pmem device, we introduce a holder for dax_device structure, and also its operation. This holder is used to remember who is using this dax_device:
- When it is the backend of a filesystem, the holder will be the instance of this filesystem.
- When this pmem device is one of the targets in a mapped device, the holder will be this mapped device. In this case, the mapped device has its own dax_device and it will follow the first rule. So that we can finally track to the filesystem we needed.
The holder and holder_ops will be set when filesystem is being mounted, or an target device is being activated.
--- drivers/dax/super.c | 89 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/dax.h | 32 ++++++++++++++++ 2 files changed, 121 insertions(+)
drivers/dax/super.c +89 -0
@@ -21,6 +21,9 @@* @cdev: optional character interface for "device dax" * @private: dax driver private data * @flags: state and boolean properties +* @ops: operations for dax_device +* @holder_data: holder of a dax_device: could be filesystem or mapped device +* @holder_ops: operations for the inner holder */ struct dax_device {struct inode inode;
@@ -28,6 +31,8 @@ struct dax_device {void *private;unsigned long flags;const struct dax_operations *ops; +void *holder_data; +const struct dax_holder_operations *holder_ops; };static dev_t dax_devt;
@@ -193,6 +198,29 @@ int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, }EXPORT_SYMBOL_GPL (dax_zero_page_range); +int dax_holder_notify_failure (struct dax_device *dax_dev,u64 off, +u64 len,int mf_flags) +{ +int rc, id; + + id =dax_read_lock (); +if (!dax_alive (dax_dev)) { + rc = -ENXIO ; + goto out; + } + +if (!dax_dev->holder_ops) { + rc = -EOPNOTSUPP ; + goto out; + } + + rc = dax_dev->holder_ops->notify_failure (dax_dev, off, len, mf_flags); +out: +dax_read_unlock (id); +return rc; +} +EXPORT_SYMBOL_GPL (dax_holder_notify_failure); +#ifdef CONFIG_ARCH_HAS_PMEM_API void arch_wb_cache_pmem (void *addr,size_t size);void dax_flush (struct dax_device *dax_dev,void *addr,size_t size)
@@ -268,6 +296,10 @@ void kill_dax(struct dax_device *dax_dev)clear_bit (DAXDEV_ALIVE , &dax_dev->flags);synchronize_srcu (&dax_srcu); + +/* clear holder data */ + dax_dev->holder_ops =NULL ; + dax_dev->holder_data =NULL ; }EXPORT_SYMBOL_GPL (kill_dax);
@@ -409,6 +441,63 @@ void put_dax(struct dax_device *dax_dev) }EXPORT_SYMBOL_GPL (put_dax); +/** +* dax_holder() - obtain the holder of a dax device +* @dax_dev: a dax_device instance + +* Return: the holder's data which represents the holder if registered, +* otherwize NULL. +*/ +void *dax_holder (struct dax_device *dax_dev) +{ +if (!dax_alive (dax_dev)) +return NULL ; + +return dax_dev->holder_data; +} +EXPORT_SYMBOL_GPL (dax_holder); + +/** +* dax_register_holder() - register a holder to a dax device +* @dax_dev: a dax_device instance +* @holder: a pointer to a holder's data which represents the holder +* @ops: operations of this holder + +* Return: negative errno if an error occurs, otherwise 0. +*/ +int dax_register_holder (struct dax_device *dax_dev,void *holder, +const struct dax_holder_operations *ops) +{ +if (!dax_alive (dax_dev)) +return -ENXIO ; + +if (cmpxchg (&dax_dev->holder_data,NULL , holder)) +return -EBUSY ; + + dax_dev->holder_ops = ops; +return 0 ; +} +EXPORT_SYMBOL_GPL (dax_register_holder); + +/** +* dax_unregister_holder() - unregister the holder for a dax device +* @dax_dev: a dax_device instance +* @holder: the holder to be unregistered +* +* Return: negative errno if an error occurs, otherwise 0. +*/ +int dax_unregister_holder (struct dax_device *dax_dev,void *holder) +{ +if (!dax_alive (dax_dev)) +return -ENXIO ; + +if (cmpxchg (&dax_dev->holder_data, holder,NULL ) != holder) +return -EBUSY ; + dax_dev->holder_ops =NULL ; +return 0 ; +} +EXPORT_SYMBOL_GPL (dax_unregister_holder); +/** * inode_dax: convert a public inode into its dax_dev * @inode: An inode with i_cdev pointing to a dax_dev
include/linux/dax.h +32 -0
@@ -32,8 +32,24 @@ struct dax_operations {int (*zero_page_range)(struct dax_device *,pgoff_t ,size_t ); }; +struct dax_holder_operations { +/* +* notify_failure - notify memory failure into inner holder device +* @dax_dev: the dax device which contains the holder +* @offset: offset on this dax device where memory failure occurs +* @len: length of this memory failure event +* @flags: action flags for memory failure handler +*/ +int (*notify_failure)(struct dax_device *dax_dev,u64 offset, +u64 len,int mf_flags); +}; +#if IS_ENABLED (CONFIG_DAX )struct dax_device *alloc_dax (void *private,const struct dax_operations *ops); +int dax_register_holder (struct dax_device *dax_dev,void *holder, +const struct dax_holder_operations *ops); +int dax_unregister_holder (struct dax_device *dax_dev,void *holder); +void *dax_holder (struct dax_device *dax_dev);void put_dax (struct dax_device *dax_dev);void kill_dax (struct dax_device *dax_dev);void dax_write_cache (struct dax_device *dax_dev,bool wc);
@@ -53,6 +69,20 @@ static inline bool daxdev_mapping_supported(struct vm_area_struct *vma, return dax_synchronous(dax_dev); }#else +static inline int dax_register_holder (struct dax_device *dax_dev,void *holder, +const struct dax_holder_operations *ops) +{ +return 0 ; +} +static inline int dax_unregister_holder (struct dax_device *dax_dev, +void *holder) +{ +return 0 ; +} +static inline void *dax_holder (struct dax_device *dax_dev) +{ +return NULL ; +}static inline struct dax_device *alloc_dax (void *private,const struct dax_operations *ops) {
@@ -185,6 +215,8 @@ size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i);int dax_zero_page_range (struct dax_device *dax_dev,pgoff_t pgoff,size_t nr_pages); +int dax_holder_notify_failure (struct dax_device *dax_dev,u64 off,u64 len, +int mf_flags);void dax_flush (struct dax_device *dax_dev,void *addr,size_t size); ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
Signature · 1 line
2.35.1
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
Quoted 50 lines · Shiyang Ruan
To easily track filesystem from a pmem device, we introduce a holder for
dax_devicestructure, and also its operation. This holder is used to remember who is using thisdax_device:
- When it is the backend of a filesystem, the holder will be the instance of this filesystem.
- When this pmem device is one of the targets in a mapped device, the holder will be this mapped device. In this case, the mapped device has its owndax_deviceand it will follow the first rule. So that we can finally track to the filesystem we needed.The holder and
holder_opswill be set when filesystem is being mounted, or an target device is being activated.Signed-off-by Shiyang Ruan <[email protected]>--- drivers/dax/super.c | 89 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/dax.h | 32 ++++++++++++++++ 2 files changed, 121 insertions(+)drivers/dax/super.c +8
-0@@ -21,6 +21,9 @@* @cdev: optional character interface for "device dax" * @private: dax driver private data * @flags: state and boolean properties +* @ops: operations for dax_device +* @holder_data: holder of a dax_device: could be filesystem or mapped device +* @holder_ops: operations for the inner holder */ struct dax_device {struct inode inode;@@ -28,6 +31,8 @@ struct dax_device {void *private;unsigned long flags;const struct dax_operations *ops; +void *holder_data; +const struct dax_holder_operations *holder_ops; };static dev_t dax_devt;@@ -193,6 +198,29 @@ int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, }EXPORT_SYMBOL_GPL (dax_zero_page_range); +int dax_holder_notify_failure (struct dax_device *dax_dev,u64 off, +u64 len,int mf_flags) +{
drivers/dax/super.c int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, · line 213
Quoted 10 lines
drivers/dax/super.c +10
-0+int rc, id; + + id =dax_read_lock (); +if (!dax_alive (dax_dev)) { + rc = -ENXIO ; + goto out; + } + +if (!dax_dev->holder_ops) { + rc = -EOPNOTSUPP ;
I think it is ok to return success (0) for this case. All the caller of dax_holder_notify_failure() wants to know is if the notification was successfully delivered to the holder. If there is no holder present then there is nothing to report. This is minor enough for me to fix up locally if nothing else needs to be changed.
Quoted 14 lines
drivers/dax/super.c +10
-0+ goto out; + } + + rc = dax_dev->holder_ops->notify_failure (dax_dev, off, len, mf_flags); +out: +dax_read_unlock (id); +return rc; +} +EXPORT_SYMBOL_GPL (dax_holder_notify_failure); +#ifdef CONFIG_ARCH_HAS_PMEM_API void arch_wb_cache_pmem (void *addr,size_t size);void dax_flush (struct dax_device *dax_dev,void *addr,size_t size)
drivers/dax/super.c void kill_dax(struct dax_device *dax_dev) · line 302
Quoted 7 lines
drivers/dax/super.c +4
-0@@ -268,6 +296,10 @@ void kill_dax(struct dax_device *dax_dev)clear_bit (DAXDEV_ALIVE , &dax_dev->flags);synchronize_srcu (&dax_srcu); + +/* clear holder data */ + dax_dev->holder_ops =NULL ; + dax_dev->holder_data =NULL ;
Isn't this another failure scenario? If kill_dax() is called while a holder is still holding the dax_device that seems to be another ->notify_failure scenario to tell the holder that the device is going away and the holder has not released the device yet.
Quoted 8 lines
drivers/dax/super.c +1
-0}EXPORT_SYMBOL_GPL (kill_dax);@@ -409,6 +441,63 @@ void put_dax(struct dax_device *dax_dev) }EXPORT_SYMBOL_GPL (put_dax); +/**
drivers/dax/super.c void put_dax(struct dax_device *dax_dev) · line 454
Quoted 10 lines
drivers/dax/super.c +10
-0+* dax_holder() - obtain the holder of a dax device +* @dax_dev: a dax_device instance + +* Return: the holder's data which represents the holder if registered, +* otherwize NULL. +*/ +void *dax_holder (struct dax_device *dax_dev) +{ +if (!dax_alive (dax_dev)) +return NULL ;
It's safe for the holder to assume that it can de-reference ->holder_data freely in its notify_handler callback because dax_holder_notify_failure() arranges for the callback to run in dax_read_lock() context.
This is another minor detail that I can fixup locally.
Quoted 54 lines
drivers/dax/super.c +46
-0+ +return dax_dev->holder_data; +} +EXPORT_SYMBOL_GPL (dax_holder); + +/** +* dax_register_holder() - register a holder to a dax device +* @dax_dev: a dax_device instance +* @holder: a pointer to a holder's data which represents the holder +* @ops: operations of this holder + +* Return: negative errno if an error occurs, otherwise 0. +*/ +int dax_register_holder (struct dax_device *dax_dev,void *holder, +const struct dax_holder_operations *ops) +{ +if (!dax_alive (dax_dev)) +return -ENXIO ; + +if (cmpxchg (&dax_dev->holder_data,NULL , holder)) +return -EBUSY ; + + dax_dev->holder_ops = ops; +return 0 ; +} +EXPORT_SYMBOL_GPL (dax_register_holder); + +/** +* dax_unregister_holder() - unregister the holder for a dax device +* @dax_dev: a dax_device instance +* @holder: the holder to be unregistered +* +* Return: negative errno if an error occurs, otherwise 0. +*/ +int dax_unregister_holder (struct dax_device *dax_dev,void *holder) +{ +if (!dax_alive (dax_dev)) +return -ENXIO ; + +if (cmpxchg (&dax_dev->holder_data, holder,NULL ) != holder) +return -EBUSY ; + dax_dev->holder_ops =NULL ; +return 0 ; +} +EXPORT_SYMBOL_GPL (dax_unregister_holder); +/** * inode_dax: convert a public inode into its dax_dev * @inode: An inode with i_cdev pointing to a dax_dev include/linux/dax.h +0
-0
include/linux/dax.h struct dax_operations { · line 40
Quoted 9 lines
include/linux/dax.h +6
-0@@ -32,8 +32,24 @@ struct dax_operations {int (*zero_page_range)(struct dax_device *,pgoff_t ,size_t ); }; +struct dax_holder_operations { +/* +* notify_failure - notify memory failure into inner holder device +* @dax_dev: the dax device which contains the holder +* @offset: offset on this dax device where memory failure occurs +* @len: length of this memory failure event
Forgive me if this has been discussed before, but since dax_operations are in terms of pgoff and nr pages and memory_failure() is in terms of pfns what was the rationale for making the function signature byte based?
I want to get this series merged into linux-next shortly after v5.18-rc1. Then we can start working on incremental fixups rather resending the full series with these long reply cycles.
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
Quoted 59 lines · Dan Williams
Quoted 58 lines · Shiyang Ruan
To easily track filesystem from a pmem device, we introduce a holder for
dax_devicestructure, and also its operation. This holder is used to remember who is using thisdax_device:
- When it is the backend of a filesystem, the holder will be the instance of this filesystem.
- When this pmem device is one of the targets in a mapped device, the holder will be this mapped device. In this case, the mapped device has its owndax_deviceand it will follow the first rule. So that we can finally track to the filesystem we needed.The holder and
holder_opswill be set when filesystem is being mounted, or an target device is being activated.Signed-off-by Shiyang Ruan <[email protected]>--- drivers/dax/super.c | 89 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/dax.h | 32 ++++++++++++++++ 2 files changed, 121 insertions(+)drivers/dax/super.c +16
-0@@ -21,6 +21,9 @@* @cdev: optional character interface for "device dax" * @private: dax driver private data * @flags: state and boolean properties +* @ops: operations for dax_device +* @holder_data: holder of a dax_device: could be filesystem or mapped device +* @holder_ops: operations for the inner holder */ struct dax_device {struct inode inode;@@ -28,6 +31,8 @@ struct dax_device {void *private;unsigned long flags;const struct dax_operations *ops; +void *holder_data; +const struct dax_holder_operations *holder_ops; };static dev_t dax_devt;@@ -193,6 +198,29 @@ int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, }EXPORT_SYMBOL_GPL (dax_zero_page_range); +int dax_holder_notify_failure (struct dax_device *dax_dev,u64 off, +u64 len,int mf_flags) +{ +int rc, id; + + id =dax_read_lock (); +if (!dax_alive (dax_dev)) { + rc = -ENXIO ; + goto out; + } +
Quoted 8 lines
drivers/dax/super.c int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, · line 213
Quoted 2 lines
drivers/dax/super.c +2
-0+if (!dax_dev->holder_ops) { + rc = -EOPNOTSUPP ;I think it is ok to return success (0) for this case. All the caller of
dax_holder_notify_failure()wants to know is if the notification was successfully delivered to the holder. If there is no holder present then there is nothing to report. This is minor enough for me to fix up locally if nothing else needs to be changed.
I thought it could fall back to generic memory failure handler: mf_generic_kill_procs(), if holder_ops not exists.
Quoted 16 lines
Quoted 16 lines
drivers/dax/super.c +10
-0+ goto out; + } + + rc = dax_dev->holder_ops->notify_failure (dax_dev, off, len, mf_flags); +out: +dax_read_unlock (id); +return rc; +} +EXPORT_SYMBOL_GPL (dax_holder_notify_failure); +#ifdef CONFIG_ARCH_HAS_PMEM_API void arch_wb_cache_pmem (void *addr,size_t size);void dax_flush (struct dax_device *dax_dev,void *addr,size_t size)@@ -268,6 +296,10 @@ void kill_dax(struct dax_device *dax_dev)
Quoted 11 lines
drivers/dax/super.c void kill_dax(struct dax_device *dax_dev) · line 302
Quoted 6 lines
drivers/dax/super.c +4
-0clear_bit (DAXDEV_ALIVE , &dax_dev->flags);synchronize_srcu (&dax_srcu); + +/* clear holder data */ + dax_dev->holder_ops =NULL ; + dax_dev->holder_data =NULL ;Isn't this another failure scenario? If
kill_dax()is called while a holder is still holding thedax_devicethat seems to be another ->notify_failure scenario to tell the holder that the device is going away and the holder has not released the device yet.
Yes. I should call dax_holder_notify_failure() and then unregister the holder.
Quoted 84 lines
Quoted 9 lines
drivers/dax/super.c +1
-0}EXPORT_SYMBOL_GPL (kill_dax);@@ -409,6 +441,63 @@ void put_dax(struct dax_device *dax_dev) }EXPORT_SYMBOL_GPL (put_dax); +/** drivers/dax/super.c void put_dax(struct dax_device *dax_dev) · line 454
Quoted 10 lines
drivers/dax/super.c +10
-0+* dax_holder() - obtain the holder of a dax device +* @dax_dev: a dax_device instance + +* Return: the holder's data which represents the holder if registered, +* otherwize NULL. +*/ +void *dax_holder (struct dax_device *dax_dev) +{ +if (!dax_alive (dax_dev)) +return NULL ;It's safe for the holder to assume that it can de-reference ->holder_data freely in its
notify_handlercallback becausedax_holder_notify_failure()arranges for the callback to run indax_read_lock()context.This is another minor detail that I can fixup locally.
Quoted 57 lines
drivers/dax/super.c +46
-0+ +return dax_dev->holder_data; +} +EXPORT_SYMBOL_GPL (dax_holder); + +/** +* dax_register_holder() - register a holder to a dax device +* @dax_dev: a dax_device instance +* @holder: a pointer to a holder's data which represents the holder +* @ops: operations of this holder + +* Return: negative errno if an error occurs, otherwise 0. +*/ +int dax_register_holder (struct dax_device *dax_dev,void *holder, +const struct dax_holder_operations *ops) +{ +if (!dax_alive (dax_dev)) +return -ENXIO ; + +if (cmpxchg (&dax_dev->holder_data,NULL , holder)) +return -EBUSY ; + + dax_dev->holder_ops = ops; +return 0 ; +} +EXPORT_SYMBOL_GPL (dax_register_holder); + +/** +* dax_unregister_holder() - unregister the holder for a dax device +* @dax_dev: a dax_device instance +* @holder: the holder to be unregistered +* +* Return: negative errno if an error occurs, otherwise 0. +*/ +int dax_unregister_holder (struct dax_device *dax_dev,void *holder) +{ +if (!dax_alive (dax_dev)) +return -ENXIO ; + +if (cmpxchg (&dax_dev->holder_data, holder,NULL ) != holder) +return -EBUSY ; + dax_dev->holder_ops =NULL ; +return 0 ; +} +EXPORT_SYMBOL_GPL (dax_unregister_holder); +/** * inode_dax: convert a public inode into its dax_dev * @inode: An inode with i_cdev pointing to a dax_dev include/linux/dax.h +0
-0@@ -32,8 +32,24 @@ struct dax_operations {int (*zero_page_range)(struct dax_device *,pgoff_t ,size_t ); };
Quoted 11 lines
include/linux/dax.h struct dax_operations { · line 40
Quoted 6 lines
include/linux/dax.h +6
-0+struct dax_holder_operations { +/* +* notify_failure - notify memory failure into inner holder device +* @dax_dev: the dax device which contains the holder +* @offset: offset on this dax device where memory failure occurs +* @len: length of this memory failure event Forgive me if this has been discussed before, but since
dax_operationsare in terms of pgoff and nr pages andmemory_failure()is in terms of pfns what was the rationale for making the function signature byte based?
Maybe I didn't describe it clearly... The @offset and @len here are byte-based. And so is ->memory_failure().
You can find the implementation of ->memory_failure() in 3rd patch:
+static int pmem_pagemap_memory_failure(struct dev_pagemap *pgmap,
+ phys_addr_t addr, u64 len, int mf_flags)
+{
+ struct pmem_device *pmem =
+ container_of(pgmap, struct pmem_device, pgmap);
+ u64 offset = addr - pmem->phys_addr - pmem->data_offset;
+
+ return dax_holder_notify_failure(pmem->dax_dev, offset, len, mf_flags);
+}
Quoted 4 lines
I want to get this series merged into linux-next shortly after v5.18-rc1. Then we can start working on incremental fixups rather resending the full series with these long reply cycles.
Thanks. That really helps.
--
Ruan.
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
Quoted 7 lines · Shiyang Ruan
Quoted 4 lines
Forgive me if this has been discussed before, but since
dax_operationsare in terms of pgoff and nr pages andmemory_failure()is in terms of pfns what was the rationale for making the function signature byte based?Maybe I didn't describe it clearly... The @offset and @len here are byte-based. And so is ->memory_failure().
Yes, but is there a good reason for that when the rest of the DAX code tends to work in page chunks?
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
Quoted 11 lines · Christoph Hellwig
Quoted 7 lines · Shiyang Ruan
Quoted 4 lines
Forgive me if this has been discussed before, but since
dax_operationsare in terms of pgoff and nr pages andmemory_failure()is in terms of pfns what was the rationale for making the function signature byte based?Maybe I didn't describe it clearly... The @offset and @len here are byte-based. And so is ->memory_failure().
Yes, but is there a good reason for that when the rest of the DAX code tends to work in page chunks?
Because I am not sure if the offset between each layer is page aligned.
For example, when pmem dirver handles ->memory_failure(), it should
subtract its ->data_offset when it calls dax_holder_notify_failure().
The implementation of ->memory_failure() by pmem driver:
+static int pmem_pagemap_memory_failure(struct dev_pagemap *pgmap,
+ phys_addr_t addr, u64 len, int mf_flags)
+{
+ struct pmem_device *pmem =
+ container_of(pgmap, struct pmem_device, pgmap);
+ u64 offset = addr - pmem->phys_addr - pmem->data_offset;
+
+ return dax_holder_notify_failure(pmem->dax_dev, offset, len, mf_flags);
+}
So, I choose u64 as the type of @len. And for consistency, the @addr is using byte-based type as well.
Quoted 5 lines
memory_failure()|* fsdax case |------------ |pgmap->ops->memory_failure() => pmem_pgmap_memory_failure() | dax_holder_notify_failure() =>
the offset from 'pmem driver' to 'dax holder'
Quoted 5 lines
| dax_device->holder_ops->notify_failure() => | - xfs_dax_notify_failure() | |* xfs_dax_notify_failure() | |-------------------------- | | xfs_rmap_query_range()
Quoted 8 lines
| | xfs_dax_failure_fn() | | * corrupted on metadata | | try to recover data, call xfs_force_shutdown() | | * corrupted on file data | | try to recover data, call mf_dax_kill_procs() |* normal case |------------- |mf_generic_kill_procs()
--
Thanks,
Ruan.
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
Quoted 4 lines · Shiyang Ruan
Because I am not sure if the offset between each layer is page aligned. For example, when pmem dirver handles ->memory_failure(), it should subtract its ->data_offset when it calls
dax_holder_notify_failure().
If they aren't, none of the DAX machinery would work.
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
Quoted 7 lines · Christoph Hellwig
Quoted 4 lines · Shiyang Ruan
Because I am not sure if the offset between each layer is page aligned. For example, when pmem dirver handles ->memory_failure(), it should subtract its ->data_offset when it calls
dax_holder_notify_failure().If they aren't, none of the DAX machinery would work.
OK. Got it.
So, use page-based function signature for ->memory_failure():
int (*memory_failure)(struct dev_pagemap *pgmap, unsigned long pfn,
unsigned long nr_pfns, int flags);
As the code I pasted before, pmem driver will subtract its ->data_offset, which is byte-based. And the filesystem who implements ->notify_failure() will calculate the offset in unit of byte again.
So, leave its function signature byte-based, to avoid repeated conversions.
int (*notify_failure)(struct dax_device *dax_dev, u64 offset,
u64 len, int mf_flags);
What do you think?
--
Thanks,
Ruan.
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
Quoted 5 lines · Shiyang Ruan
As the code I pasted before, pmem driver will subtract its ->data_offset, which is byte-based. And the filesystem who implements ->notify_failure() will calculate the offset in unit of byte again.
So, leave its function signature byte-based, to avoid repeated conversions.
I'm actually fine either way, so I'll wait for Dan to comment.
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Shiyang Ruan
As the code I pasted before, pmem driver will subtract its ->data_offset, which is byte-based. And the filesystem who implements ->notify_failure() will calculate the offset in unit of byte again.
So, leave its function signature byte-based, to avoid repeated conversions.
I'm actually fine either way, so I'll wait for Dan to comment.
FWIW I'd convinced myself that the reason for using byte units is to make it possible to reduce the pmem failure blast radius to subpage units... but then I've also been distracted for months. :/
--D
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Shiyang Ruan
As the code I pasted before, pmem driver will subtract its ->data_offset, which is byte-based. And the filesystem who implements ->notify_failure() will calculate the offset in unit of byte again.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
So, leave its function signature byte-based, to avoid repeated conversions.
I'm actually fine either way, so I'll wait for Dan to comment.
FWIW I'd convinced myself that the reason for using byte units is to make it possible to reduce the pmem failure blast radius to subpage units... but then I've also been distracted for months. :/
Yes, thanks Darrick! I recall that.
Maybe just add a comment about why byte unit is used?
thanks!
-jane
Quoted 1 line
--D
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
Quoted 12 lines · Jane Chu
Quoted 10 lines · Darrick J. Wong
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Shiyang Ruan
As the code I pasted before, pmem driver will subtract its ->data_offset, which is byte-based. And the filesystem who implements ->notify_failure() will calculate the offset in unit of byte again.
So, leave its function signature byte-based, to avoid repeated conversions.
I'm actually fine either way, so I'll wait for Dan to comment.
Quoted 7 lines
Quoted 4 lines
FWIW I'd convinced myself that the reason for using byte units is to make it possible to reduce the pmem failure blast radius to subpage units... but then I've also been distracted for months. :/
Yes, thanks Darrick! I recall that.
Maybe just add a comment about why byte unit is used?
I think we start with page failure notification and then figure out how to get finer grained through the dax interface in follow-on changes. Otherwise, for finer grained error handling support, memory_failure() would also need to be converted to stop upcasting cache-line granularity to page granularity failures. The native MCE notification communicates a 'struct mce' that can be in terms of sub-page bytes, but the memory management implications are all page based. I assume the FS implications are all FS-block-size based?
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
Quoted 21 lines · Dan Williams
Quoted 12 lines · Jane Chu
Quoted 10 lines · Darrick J. Wong
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Shiyang Ruan
As the code I pasted before, pmem driver will subtract its ->data_offset, which is byte-based. And the filesystem who implements ->notify_failure() will calculate the offset in unit of byte again.
So, leave its function signature byte-based, to avoid repeated conversions.
I'm actually fine either way, so I'll wait for Dan to comment.
Quoted 7 lines
Quoted 4 lines
FWIW I'd convinced myself that the reason for using byte units is to make it possible to reduce the pmem failure blast radius to subpage units... but then I've also been distracted for months. :/
Yes, thanks Darrick! I recall that.
Maybe just add a comment about why byte unit is used?
Quoted 8 lines
I think we start with page failure notification and then figure out how to get finer grained through the dax interface in follow-on changes. Otherwise, for finer grained error handling support,
memory_failure()would also need to be converted to stop upcasting cache-line granularity to page granularity failures. The native MCE notification communicates a 'struct mce' that can be in terms of sub-page bytes, but the memory management implications are all page based. I assume the FS implications are all FS-block-size based?
I wouldn't necessarily make that assumption -- for regular files, the user program is in a better position to figure out how to reset the file contents.
For fs metadata, it really depends. In principle, if (say) we could get byte granularity poison info, we could look up the space usage within the block to decide if the poisoned part was actually free space, in which case we can correct the problem by (re)zeroing the affected bytes to clear the poison.
Obviously, if the blast radius hits the internal space info or something that was storing useful data, then you'd have to rebuild the whole block (or the whole data structure), but that's not necessarily a given.
--D
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
[ add Mauro and Tony for RAS discussion ]
Quoted 42 lines · Darrick J. Wong
Quoted 21 lines · Dan Williams
Quoted 12 lines · Jane Chu
Quoted 10 lines · Darrick J. Wong
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Shiyang Ruan
As the code I pasted before, pmem driver will subtract its ->data_offset, which is byte-based. And the filesystem who implements ->notify_failure() will calculate the offset in unit of byte again.
So, leave its function signature byte-based, to avoid repeated conversions.
I'm actually fine either way, so I'll wait for Dan to comment.
Quoted 7 lines
Quoted 4 lines
FWIW I'd convinced myself that the reason for using byte units is to make it possible to reduce the pmem failure blast radius to subpage units... but then I've also been distracted for months. :/
Yes, thanks Darrick! I recall that.
Maybe just add a comment about why byte unit is used?Quoted 8 lines
I think we start with page failure notification and then figure out how to get finer grained through the dax interface in follow-on changes. Otherwise, for finer grained error handling support,
memory_failure()would also need to be converted to stop upcasting cache-line granularity to page granularity failures. The native MCE notification communicates a 'struct mce' that can be in terms of sub-page bytes, but the memory management implications are all page based. I assume the FS implications are all FS-block-size based?I wouldn't necessarily make that assumption -- for regular files, the user program is in a better position to figure out how to reset the file contents.
For fs metadata, it really depends. In principle, if (say) we could get byte granularity poison info, we could look up the space usage within the block to decide if the poisoned part was actually free space, in which case we can correct the problem by (re)zeroing the affected bytes to clear the poison.
Quoted 3 lines
Obviously, if the blast radius hits the internal space info or something that was storing useful data, then you'd have to rebuild the whole block (or the whole data structure), but that's not necessarily a given.
tl;dr: dax_holder_notify_failure() != fs->notify_failure()
So I think I see some confusion between what DAX->notify_failure() needs, memory_failure() needs, the raw information provided by the hardware, and the failure granularity the filesystem can make use of.
DAX and memory_failure() need to make immediate page granularity decisions. They both need to map out whole pages (in the direct map and userspace respectively) to prevent future poison consumption, at least until the poison is repaired.
The event that leads to a page being failed can be triggered by a hardware error as small as an individual cacheline. While that is interesting to a filesystem it isn't information that memory_failure() and DAX can utilize.
The reason DAX needs to have a callback into filesystem code is to map the page failure back to all the processes that might have that page mapped because reflink means that page->mapping is not sufficient to find all the affected 'struct address_space' instances. So it's more of an address-translation / "help me kill processes" service than a general failure notification service.
Currently when raw hardware event happens there are mechanisms like arch-specific notifier chains, like powerpc::mce_register_notifier() and x86::mce_register_decode_chain(), or other platform firmware code like ghes_edac_report_mem_error() that uplevel the error to a coarse page granularity failure, while emitting the fine granularity error event to userspace.
All of this to say that the interface to ask the fs to do the bottom half of memory_failure() (walking affected 'struct address_space' instances and killing processes (mf_dax_kill_procs())) is different than the general interface to tell the filesystem that memory has gone bad relative to a device. So if the only caller of fs->notify_failure() handler is this code:
+ if (pgmap->ops->memory_failure) {
+ rc = pgmap->ops->memory_failure(pgmap, PFN_PHYS(pfn), PAGE_SIZE,
+ flags);
...then you'll never get fine-grained reports. So, I still think the DAX, pgmap and memory_failure() interface should be pfn based. The interface to the *filesystem* ->notify_failure() can still be byte-based, but the trigger for that byte based interface will likely need to be something driven by another agent. Perhaps like rasdaemon in userspace translating all the arch specific physical address events back into device-relative offsets and then calling a new ABI that is serviced by fs->notify_failure() on the backend.
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
Quoted 90 lines · Dan Williams
[ add Mauro and Tony for RAS discussion ]
Quoted 42 lines · Darrick J. Wong
Quoted 21 lines · Dan Williams
Quoted 12 lines · Jane Chu
Quoted 10 lines · Darrick J. Wong
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Shiyang Ruan
As the code I pasted before, pmem driver will subtract its ->data_offset, which is byte-based. And the filesystem who implements ->notify_failure() will calculate the offset in unit of byte again.
So, leave its function signature byte-based, to avoid repeated conversions.
I'm actually fine either way, so I'll wait for Dan to comment.
Quoted 7 lines
Quoted 4 lines
FWIW I'd convinced myself that the reason for using byte units is to make it possible to reduce the pmem failure blast radius to subpage units... but then I've also been distracted for months. :/
Yes, thanks Darrick! I recall that.
Maybe just add a comment about why byte unit is used?Quoted 8 lines
I think we start with page failure notification and then figure out how to get finer grained through the dax interface in follow-on changes. Otherwise, for finer grained error handling support,
memory_failure()would also need to be converted to stop upcasting cache-line granularity to page granularity failures. The native MCE notification communicates a 'struct mce' that can be in terms of sub-page bytes, but the memory management implications are all page based. I assume the FS implications are all FS-block-size based?I wouldn't necessarily make that assumption -- for regular files, the user program is in a better position to figure out how to reset the file contents.
For fs metadata, it really depends. In principle, if (say) we could get byte granularity poison info, we could look up the space usage within the block to decide if the poisoned part was actually free space, in which case we can correct the problem by (re)zeroing the affected bytes to clear the poison.
Quoted 3 lines
Obviously, if the blast radius hits the internal space info or something that was storing useful data, then you'd have to rebuild the whole block (or the whole data structure), but that's not necessarily a given.
tl;dr:
dax_holder_notify_failure()!=fs->notify_failure()So I think I see some confusion between what
DAX->notify_failure()needs,memory_failure()needs, the raw information provided by the hardware, and the failure granularity the filesystem can make use of.DAX and
memory_failure()need to make immediate page granularity decisions. They both need to map out whole pages (in the direct map and userspace respectively) to prevent future poison consumption, at least until the poison is repaired.The event that leads to a page being failed can be triggered by a hardware error as small as an individual cacheline. While that is interesting to a filesystem it isn't information that
memory_failure()and DAX can utilize.The reason DAX needs to have a callback into filesystem code is to map the page failure back to all the processes that might have that page mapped because reflink means that
page->mappingis not sufficient to find all the affected 'structaddress_space' instances. So it's more of an address-translation / "help me kill processes" service than a general failure notification service.Currently when raw hardware event happens there are mechanisms like arch-specific notifier chains, like
powerpc::mce_register_notifier()andx86::mce_register_decode_chain(), or other platform firmware code likeghes_edac_report_mem_error()that uplevel the error to a coarse page granularity failure, while emitting the fine granularity error event to userspace.All of this to say that the interface to ask the fs to do the bottom half of
memory_failure()(walking affected 'structaddress_space' instances and killing processes (mf_dax_kill_procs())) is different than the general interface to tell the filesystem that memory has gone bad relative to a device. So if the only caller offs->notify_failure()handler is this code:(quoted diff) +3
-0+ if (pgmap->ops->memory_failure) { + rc = pgmap->ops->memory_failure(pgmap, PFN_PHYS(pfn), PAGE_SIZE, + flags);
Quoted 8 lines
...then you'll never get fine-grained reports. So, I still think the DAX, pgmap and
memory_failure()interface should be pfn based. The interface to the *filesystem* ->notify_failure() can still be byte-based, but the trigger for that byte based interface will likely need to be something driven by another agent. Perhaps like rasdaemon in userspace translating all the arch specific physical address events back into device-relative offsets and then calling a new ABI that is serviced byfs->notify_failure()on the backend.
Understood. I'll do as your advise. Thanks!
--
Ruan.
Re: [PATCH v11 1/8] dax: Introduce holder for dax_device
In reply to Dan WilliamsQuoted 8 lines · Dan Williams
drivers/dax/super.c int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, · line 213
Quoted 2 lines
drivers/dax/super.c +2
-0+if (!dax_dev->holder_ops) { + rc = -EOPNOTSUPP ;I think it is ok to return success (0) for this case. All the caller of
dax_holder_notify_failure()wants to know is if the notification was successfully delivered to the holder. If there is no holder present then there is nothing to report. This is minor enough for me to fix up locally if nothing else needs to be changed.
The caller needs to know there are no holder ops to fall back to different path.
Quoted 4 lines
Isn't this another failure scenario? If
kill_dax()is called while a holder is still holding thedax_devicethat seems to be another ->notify_failure scenario to tell the holder that the device is going away and the holder has not released the device yet.
Yes.
PATCH v11 2/8 mm: factor helpers for memory_failure_dev_pagemap
In reply to Shiyang Ruanmemory_failure_dev_pagemap code is a bit complex before introduce RMAP feature for fsdax. So it is needed to factor some helper functions to simplify these code.
--- mm/memory-failure.c | 141 ++++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 64 deletions(-)
mm/memory-failure.c +77 -64
@@ -1500,6 +1500,80 @@ static int try_to_split_thp_page(struct page *page, const char *msg)return 0 ; } +static void unmap_and_kill (struct list_head *to_kill,unsigned long pfn, +struct address_space *mapping,pgoff_t index,int flags) +{ +struct to_kill *tk; +unsigned long size =0 ; + +list_for_each_entry (tk, to_kill, nd) +if (tk->size_shift) + size =max (size,1UL << tk->size_shift); + +if (size) { +/* +* Unmap the largest mapping to avoid breaking up device-dax +* mappings which are constant size. The actual size of the +* mapping being torn down is communicated in siginfo, see +* kill_proc() +*/ +loff_t start = (index <<PAGE_SHIFT ) & ~(size -1 ); + +unmap_mapping_range (mapping, start, size,0 ); + } + +kill_procs (to_kill, flags &MF_MUST_KILL , false, pfn, flags); +} + +static int mf_generic_kill_procs (unsigned long long pfn,int flags, +struct dev_pagemap *pgmap) +{ +struct page *page =pfn_to_page (pfn); +LIST_HEAD (to_kill); +dax_entry_t cookie; + +/* +* Prevent the inode from being freed while we are interrogating +* the address_space, typically this would be handled by +* lock_page(), but dax pages do not use the page lock. This +* also prevents changes to the mapping of this pfn until +* poison signaling is complete. +*/ + cookie =dax_lock_page (page); +if (!cookie) +return -EBUSY ; + +if (hwpoison_filter (page)) +return 0 ; + +if (pgmap->type ==MEMORY_DEVICE_PRIVATE ) { +/* +* TODO: Handle HMM pages which may need coordination +* with device-side memory. +*/ +return -EBUSY ; + } + +/* +* Use this flag as an indication that the dax page has been +* remapped UC to prevent speculative consumption of poison. +*/ +SetPageHWPoison (page); + +/* +* Unlike System-RAM there is no possibility to swap in a +* different physical page at a given virtual address, so all +* userspace consumption of ZONE_DEVICE memory necessitates +* SIGBUS (i.e. MF_MUST_KILL) +*/ + flags |=MF_ACTION_REQUIRED |MF_MUST_KILL ; +collect_procs (page, &to_kill, true); + +unmap_and_kill (&to_kill, pfn, page->mapping, page->index, flags); +dax_unlock_page (page, cookie); +return 0 ; +} +static int memory_failure_hugetlb (unsigned long pfn,int flags) {struct page *p =pfn_to_page (pfn);
@@ -1576,12 +1650,8 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, struct dev_pagemap *pgmap) {struct page *page =pfn_to_page (pfn); -unsigned long size =0 ; -struct to_kill *tk;LIST_HEAD (tokill); -int rc = -EBUSY ; -loff_t start; -dax_entry_t cookie; +int rc = -ENXIO ;if (flags &MF_COUNT_INCREASED )/*
@@ -1590,67 +1660,10 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags,put_page (page);/* device metadata space is not recoverable */ -if (!pgmap_pfn_valid (pgmap, pfn)) { - rc = -ENXIO ; - goto out; - } - -/* -* Prevent the inode from being freed while we are interrogating -* the address_space, typically this would be handled by -* lock_page(), but dax pages do not use the page lock. This -* also prevents changes to the mapping of this pfn until -* poison signaling is complete. -*/ - cookie =dax_lock_page (page); -if (!cookie) +if (!pgmap_pfn_valid (pgmap, pfn)) goto out; -if (hwpoison_filter (page)) { - rc =0 ; - goto unlock; - } - -if (pgmap->type ==MEMORY_DEVICE_PRIVATE ) { -/* -* TODO: Handle HMM pages which may need coordination -* with device-side memory. -*/ - goto unlock; - } - -/* -* Use this flag as an indication that the dax page has been -* remapped UC to prevent speculative consumption of poison. -*/ -SetPageHWPoison (page); - -/* -* Unlike System-RAM there is no possibility to swap in a -* different physical page at a given virtual address, so all -* userspace consumption of ZONE_DEVICE memory necessitates -* SIGBUS (i.e. MF_MUST_KILL) -*/ - flags |=MF_ACTION_REQUIRED |MF_MUST_KILL ; -collect_procs (page, &tokill, flags &MF_ACTION_REQUIRED ); - -list_for_each_entry (tk, &tokill, nd) -if (tk->size_shift) - size =max (size,1UL << tk->size_shift); -if (size) { -/* -* Unmap the largest mapping to avoid breaking up -* device-dax mappings which are constant size. The -* actual size of the mapping being torn down is -* communicated in siginfo, see kill_proc() -*/ - start = (page->index <<PAGE_SHIFT ) & ~(size -1 ); -unmap_mapping_range (page->mapping, start, size,0 ); - } -kill_procs (&tokill, flags &MF_MUST_KILL , false, pfn, flags); - rc =0 ; -unlock: -dax_unlock_page (page, cookie); + rc =mf_generic_kill_procs (pfn, flags, pgmap); out:/* drop pgmap ref acquired in caller */ put_dev_pagemap (pgmap);
Signature · 1 line
2.35.1
PATCH v11 3/8 pagemap,pmem: Introduce ->memory_failure()
In reply to Shiyang RuanWhen memory-failure occurs, we call this function which is implemented by each kind of devices. For the fsdax case, pmem device driver implements it. Pmem device driver will find out the filesystem in which the corrupted page located in.
With dax_holder notify support, we are able to notify the memory failure from pmem driver to upper layers. If there is something not support in the notify routine, memory_failure will fall back to the generic hanlder.
--- drivers/nvdimm/pmem.c | 16 ++++++++++++++++ include/linux/memremap.h | 12 ++++++++++++ mm/memory-failure.c | 15 +++++++++++++++ 3 files changed, 43 insertions(+)
drivers/nvdimm/pmem.c +16 -0
@@ -366,6 +366,20 @@ static void pmem_release_disk(void *__pmem)blk_cleanup_disk (pmem->disk); } +static int pmem_pagemap_memory_failure (struct dev_pagemap *pgmap, +phys_addr_t addr,u64 len,int mf_flags) +{ +struct pmem_device *pmem = + container_of(pgmap, struct pmem_device, pgmap); +u64 offset = addr - pmem->phys_addr - pmem->data_offset; + +return dax_holder_notify_failure (pmem->dax_dev, offset, len, mf_flags); +} + +static const struct dev_pagemap_ops fsdax_pagemap_ops = { + .memory_failure = pmem_pagemap_memory_failure, +}; +static int pmem_attach_disk (struct device *dev,struct nd_namespace_common *ndns) {
@@ -427,6 +441,7 @@ static int pmem_attach_disk(struct device *dev, pmem->pfn_flags =PFN_DEV ;if (is_nd_pfn (dev)) { pmem->pgmap.type =MEMORY_DEVICE_FS_DAX ; + pmem->pgmap.ops = &fsdax_pagemap_ops; addr =devm_memremap_pages (dev, &pmem->pgmap); pfn_sb = nd_pfn->pfn_sb; pmem->data_offset =le64_to_cpu (pfn_sb->dataoff);
@@ -440,6 +455,7 @@ static int pmem_attach_disk(struct device *dev, pmem->pgmap.range.end = res->end; pmem->pgmap.nr_range =1 ; pmem->pgmap.type =MEMORY_DEVICE_FS_DAX ; + pmem->pgmap.ops = &fsdax_pagemap_ops; addr =devm_memremap_pages (dev, &pmem->pgmap); pmem->pfn_flags |=PFN_MAP ; bb_range = pmem->pgmap.range;
include/linux/memremap.h +12 -0
@@ -77,6 +77,18 @@ struct dev_pagemap_ops {* the page back to a CPU accessible page. */ vm_fault_t (*migrate_to_ram)(struct vm_fault *vmf); + +/* +* Handle the memory failure happens on a range of pfns. Notify the +* processes who are using these pfns, and try to recover the data on +* them if necessary. The mf_flags is finally passed to the recover +* function through the whole notify routine. +* +* When this is not implemented, or it returns -EOPNOTSUPP, the caller +* will fall back to a common handler called mf_generic_kill_procs(). +*/ +int (*memory_failure)(struct dev_pagemap *pgmap,phys_addr_t addr, +u64 len,int mf_flags); };#define PGMAP_ALTMAP_VALID (1 << 0)
mm/memory-failure.c +15 -0
@@ -1663,6 +1663,21 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags,if (!pgmap_pfn_valid (pgmap, pfn)) goto out; +/* +* Call driver's implementation to handle the memory failure, otherwise +* fall back to generic handler. +*/ +if (pgmap->ops->memory_failure) { + rc = pgmap->ops->memory_failure (pgmap,PFN_PHYS (pfn),PAGE_SIZE , + flags); +/* +* Fall back to generic handler too if operation is not +* supported inside the driver/device/filesystem. +*/ +if (rc != -EOPNOTSUPP ) + goto out; + } + rc =mf_generic_kill_procs (pfn, flags, pgmap); out:/* drop pgmap ref acquired in caller */
Signature · 1 line
2.35.1
PATCH v11 4/8 fsdax: Introduce dax_lock_mapping_entry()
In reply to Shiyang RuanThe current dax_lock_page() locks dax entry by obtaining mapping and index in page. To support 1-to-N RMAP in NVDIMM, we need a new function to lock a specific dax entry corresponding to this file's mapping,index. And output the page corresponding to the specific dax entry for caller use.
--- fs/dax.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/dax.h | 15 +++++++++++ 2 files changed, 78 insertions(+)
fs/dax.c +63 -0
@@ -455,6 +455,69 @@ void dax_unlock_page(struct page *page, dax_entry_t cookie)dax_unlock_entry (&xas, (void *)cookie); } +/* +* dax_lock_mapping_entry - Lock the DAX entry corresponding to a mapping +* @mapping: the file's mapping whose entry we want to lock +* @index: the offset within this file +* @page: output the dax page corresponding to this dax entry +* +* Return: A cookie to pass to dax_unlock_mapping_entry() or 0 if the entry +* could not be locked. +*/ +dax_entry_t dax_lock_mapping_entry (struct address_space *mapping,pgoff_t index, +struct page **page) +{ +XA_STATE (xas,NULL ,0 ); +void *entry; + +rcu_read_lock (); +for (;;) { + entry =NULL ; +if (!dax_mapping (mapping)) +break ; + + xas.xa = &mapping->i_pages; +xas_lock_irq (&xas); +xas_set (&xas, index); + entry =xas_load (&xas); +if (dax_is_locked (entry)) { +rcu_read_unlock (); +wait_entry_unlocked (&xas, entry); +rcu_read_lock (); +continue ; + } +if (!entry || +dax_is_zero_entry (entry) ||dax_is_empty_entry (entry)) { +/* +* Because we are looking for entry from file's mapping +* and index, so the entry may not be inserted for now, +* or even a zero/empty entry. We don't think this is +* an error case. So, return a special value and do +* not output @page. +*/ + entry = (void *)~0UL ; + }else { + *page =pfn_to_page (dax_to_pfn (entry)); +dax_lock_entry (&xas, entry); + } +xas_unlock_irq (&xas); +break ; + } +rcu_read_unlock (); +return (dax_entry_t )entry; +} + +void dax_unlock_mapping_entry (struct address_space *mapping,pgoff_t index, +dax_entry_t cookie) +{ +XA_STATE (xas, &mapping->i_pages, index); + +if (cookie == ~0UL ) +return ; + +dax_unlock_entry (&xas, (void *)cookie); +} +/* * Find page cache entry at given index. If it is a DAX entry, return it * with the entry locked. If the page cache doesn't contain an entry at
include/linux/dax.h +15 -0
@@ -158,6 +158,10 @@ struct page *dax_layout_busy_page(struct address_space *mapping);struct page *dax_layout_busy_page_range (struct address_space *mapping,loff_t start,loff_t end);dax_entry_t dax_lock_page (struct page *page);void dax_unlock_page (struct page *page,dax_entry_t cookie); +dax_entry_t dax_lock_mapping_entry (struct address_space *mapping, +unsigned long index,struct page **page); +void dax_unlock_mapping_entry (struct address_space *mapping, +unsigned long index,dax_entry_t cookie);#else static inline struct page *dax_layout_busy_page (struct address_space *mapping) {
@@ -185,6 +189,17 @@ static inline dax_entry_t dax_lock_page(struct page *page)static inline void dax_unlock_page (struct page *page,dax_entry_t cookie) { } + +static inline dax_entry_t dax_lock_mapping_entry (struct address_space *mapping, +unsigned long index,struct page **page) +{ +return 0 ; +} + +static inline void dax_unlock_mapping_entry (struct address_space *mapping, +unsigned long index,dax_entry_t cookie) +{ +}#endif int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
Signature · 1 line
2.35.1
PATCH v11 5/8 mm: move pgoff_address() to vma_pgoff_address()
In reply to Shiyang RuanSince it is not a DAX-specific function, move it into mm and rename it to be a generic helper.
--- fs/dax.c | 12 +----------- include/linux/mm.h | 13 +++++++++++++ 2 files changed, 14 insertions(+), 11 deletions(-)
fs/dax.c +1 -11
@@ -853,16 +853,6 @@ static void *dax_insert_entry(struct xa_state *xas,return entry; } -static inline -unsigned long pgoff_address (pgoff_t pgoff,struct vm_area_struct *vma) -{ -unsigned long address; - - address = vma->vm_start + ((pgoff - vma->vm_pgoff) <<PAGE_SHIFT ); -VM_BUG_ON_VMA (address < vma->vm_start || address >= vma->vm_end, vma); -return address; -} -/* Walk all mappings of a given index of a file and writeprotect them */ static void dax_entry_mkclean (struct address_space *mapping,pgoff_t index,unsigned long pfn)
@@ -882,7 +872,7 @@ static void dax_entry_mkclean(struct address_space *mapping, pgoff_t index,if (!(vma->vm_flags &VM_SHARED ))continue ; - address =pgoff_address (index, vma); + address =vma_pgoff_address (vma, index);/* * follow_invalidate_pte() will use the range to call
include/linux/mm.h +13 -0
@@ -2816,6 +2816,19 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)return (vma->vm_end - vma->vm_start) >>PAGE_SHIFT ; } +/* +* Get user virtual address at the specific offset within a vma. +*/ +static inline unsigned long vma_pgoff_address (struct vm_area_struct *vma, +pgoff_t pgoff) +{ +unsigned long address; + + address = vma->vm_start + ((pgoff - vma->vm_pgoff) <<PAGE_SHIFT ); +VM_BUG_ON_VMA (address < vma->vm_start || address >= vma->vm_end, vma); +return address; +} +/* Look up the first VMA which exactly match the interval vm_start ... vm_end */ static inline struct vm_area_struct *find_exact_vma (struct mm_struct *mm,unsigned long vm_start,unsigned long vm_end)
Signature · 1 line
2.35.1
Re: [PATCH v11 5/8] mm: move pgoff_address() to vma_pgoff_address()
Quoted 2 lines · Shiyang Ruan
Since it is not a DAX-specific function, move it into mm and rename it to be a generic helper.
FYI, there is a patch in -mm and linux-next:
"mm: rmap: introduce pfn_mkclean_range() to cleans PTEs"
that adds a vma_pgoff_address which seems like a bit of a superset of the one added in this patch, but only is in mm/internal.h.
Re: [PATCH v11 5/8] mm: move pgoff_address() to vma_pgoff_address()
Quoted 10 lines · Christoph Hellwig
Quoted 2 lines · Shiyang Ruan
Since it is not a DAX-specific function, move it into mm and rename it to be a generic helper.
FYI, there is a patch in -mm and linux-next:
"mm: rmap: introduce
pfn_mkclean_range()to cleans PTEs"that adds a
vma_pgoff_addresswhich seems like a bit of a superset of the one added in this patch, but only is inmm/internal.h.
Yes. The function in this patch handles more cases.
So, let me rebase onto this patch and move the function into /include/linux/mm.h, so that fs/dax.c can also use it. Is this ok?
--
Thanks,
Ruan.
PATCH v11 6/8 mm: Introduce mf_dax_kill_procs() for fsdax case
In reply to Shiyang RuanThis function is called at the end of RMAP routine, i.e. filesystem recovery function, to collect and kill processes using a shared page of DAX file. The difference with mf_generic_kill_procs() is, it accepts file's (mapping,offset) instead of struct page because different files' mappings and offsets may share the same page in fsdax mode. It will be called when filesystem's RMAP results are found.
--- include/linux/mm.h | 4 ++ mm/memory-failure.c | 96 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 90 insertions(+), 10 deletions(-)
include/linux/mm.h +4 -0
@@ -3195,6 +3195,10 @@ enum mf_flags {MF_SOFT_OFFLINE =1 <<3 , MF_UNPOISON = 1 << 4, }; +#if IS_ENABLED (CONFIG_FS_DAX ) +int mf_dax_kill_procs (struct address_space *mapping,pgoff_t index, +unsigned long count,int mf_flags); +#endif /* CONFIG_FS_DAX */ extern int memory_failure (unsigned long pfn,int flags);extern void memory_failure_queue (unsigned long pfn,int flags);extern void memory_failure_queue_kick (int cpu);
mm/memory-failure.c +86 -10
140 lines not on this page · raw message
Signature · 1 line
2.35.1
Re: [PATCH v11 6/8] mm: Introduce mf_dax_kill_procs() for fsdax case
Quoted 3 lines · Shiyang Ruan
This function is called at the end of RMAP routine, i.e. filesystem recovery function, to collect and kill processes using a shared page of DAX file.
I think just throwing RMAP inhere is rather confusing.
Quoted 4 lines
The difference with
mf_generic_kill_procs()is, it accepts file's (mapping,offset) instead of struct page because different files' mappings and offsets may share the same page in fsdax mode. It will be called when filesystem's RMAP results are found.
So maybe I'd word the whole log as something like:
This new function is a variant of mf_generic_kill_procs that accepts a file, offset pair instead o a struct to support multiple files sharing a DAX mapping. It is intended to be called by the file systems as part of the memory_failure handler after the file system performed a reverse mapping from the storage address to the file and file offset.
Otherwise looks good:
include/linux/mm.h enum mf_flags { · line 3201
Quoted 11 lines
index
9b1d56c5c224..0420189e4788100644include/linux/mm.h +4
-0@@ -3195,6 +3195,10 @@ enum mf_flags {MF_SOFT_OFFLINE =1 <<3 , MF_UNPOISON = 1 << 4, }; +#if IS_ENABLED (CONFIG_FS_DAX ) +int mf_dax_kill_procs (struct address_space *mapping,pgoff_t index, +unsigned long count,int mf_flags); +#endif /* CONFIG_FS_DAX */
No need for the ifdef here, having the stable declaration around is just fine.
include/linux/mm.h enum mf_flags { · line 3202
Quoted 1 line
include/linux/mm.h +1
-0+#if IS_ENABLED (CONFIG_FS_DAX )
No need for the IS_ENABLED as CONFIG_FS_DAX can't be modular. A good old #ifdef will do it.
Otherwise looks good:
PATCH v11 7/8 xfs: Implement ->notify_failure() for XFS
In reply to Shiyang RuanIntroduce xfs_notify_failure.c to handle failure related works, such as implement ->notify_failure(), register/unregister dax holder in xfs, and so on.
If the rmap feature of XFS enabled, we can query it to find files and metadata which are associated with the corrupt data. For now all we do is kill processes with that file mapped into their address spaces, but future patches could actually do something about corrupt metadata.
After that, the memory failure needs to notify the processes who are using those files.
--- fs/xfs/Makefile | 1 + fs/xfs/xfs_buf.c | 12 ++ fs/xfs/xfs_fsops.c | 3 + fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_notify_failure.c | 235 ++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_notify_failure.h | 10 ++ fs/xfs/xfs_super.c | 6 + 7 files changed, 268 insertions(+) create mode 100644 fs/xfs/xfs_notify_failure.c create mode 100644 fs/xfs/xfs_notify_failure.h
fs/xfs/Makefile +1 -0
@@ -84,6 +84,7 @@ xfs-y += xfs_aops.o \ xfs_message.o \ xfs_mount.o \ xfs_mru_cache.o \ + xfs_notify_failure.o \ xfs_pwork.o \ xfs_reflink.o \ xfs_stats.o \
fs/xfs/xfs_buf.c +12 -0
@@ -19,6 +19,7 @@#include "xfs_errortag.h" #include "xfs_error.h" #include "xfs_ag.h" +#include "xfs_notify_failure.h" static struct kmem_cache *xfs_buf_cache;
@@ -1892,6 +1893,8 @@ xfs_free_buftarg(list_lru_destroy (&btp->bt_lru);blkdev_issue_flush (btp->bt_bdev); +if (btp->bt_daxdev) +dax_unregister_holder (btp->bt_daxdev, btp->bt_mount);fs_put_dax (btp->bt_daxdev);kmem_free (btp);
@@ -1939,6 +1942,7 @@ xfs_alloc_buftarg( struct block_device *bdev) {xfs_buftarg_t *btp; +int error; btp =kmem_zalloc (sizeof (*btp),KM_NOFS );
@@ -1946,6 +1950,14 @@ xfs_alloc_buftarg( btp->bt_dev = bdev->bd_dev; btp->bt_bdev = bdev; btp->bt_daxdev =fs_dax_get_by_bdev (bdev, &btp->bt_dax_part_off); +if (btp->bt_daxdev) { + error =dax_register_holder (btp->bt_daxdev, mp, + &xfs_dax_holder_operations); +if (error) { +xfs_err (mp,"DAX device already in use?!" ); + goto error_free; + } + }/* * Buffer IO error rate limiting. Limit it to no more than 10 messages
fs/xfs/xfs_fsops.c +3 -0
@@ -542,6 +542,9 @@ xfs_do_force_shutdown( }else if (flags &SHUTDOWN_CORRUPT_INCORE ) { tag =XFS_PTAG_SHUTDOWN_CORRUPT ; why ="Corruption of in-memory data" ; + }else if (flags &SHUTDOWN_CORRUPT_ONDISK ) { + tag =XFS_PTAG_SHUTDOWN_CORRUPT ; + why ="Corruption of on-disk metadata" ; }else { tag =XFS_PTAG_SHUTDOWN_IOERROR ; why ="Metadata I/O Error" ;
fs/xfs/xfs_mount.h +1 -0
@@ -435,6 +435,7 @@ void xfs_do_force_shutdown(struct xfs_mount *mp, int flags, char *fname,#define SHUTDOWN_LOG_IO_ERROR 0x0002/* write attempt to the log failed */ #define SHUTDOWN_FORCE_UMOUNT 0x0004/* shutdown from a forced unmount */ #define SHUTDOWN_CORRUPT_INCORE 0x0008/* corrupt in-memory data structures */ +#define SHUTDOWN_CORRUPT_ONDISK 0x0010/* corrupt metadata on device */ #define XFS_SHUTDOWN_STRINGS \ { SHUTDOWN_META_IO_ERROR, "metadata_io" }, \
fs/xfs/xfs_notify_failure.c new file +235 -0
235 lines not on this page · raw message
fs/xfs/xfs_notify_failure.h new file +10 -0
@@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2022 Fujitsu. All Rights Reserved. +*/ +#ifndef __XFS_NOTIFY_FAILURE_H__ +#define __XFS_NOTIFY_FAILURE_H__ + +extern const struct dax_holder_operations xfs_dax_holder_operations; + +#endif /* __XFS_NOTIFY_FAILURE_H__ */
fs/xfs/xfs_super.c +6 -0
@@ -353,6 +353,12 @@ xfs_setup_dax_always(return -EINVAL ; } +if (xfs_has_reflink (mp) && !xfs_has_rmapbt (mp)) { +xfs_alert (mp, +"need rmapbt when both DAX and reflink enabled." ); +return -EINVAL ; + } +xfs_warn (mp,"DAX enabled. Warning: EXPERIMENTAL, use at your own risk" );return 0 ;
Signature · 1 line
2.35.1
kernel test robot
build botRe: [PATCH v11 7/8] xfs: Implement ->notify_failure() for XFS
Thank you for the patch! Yet something to improve:
Hi Shiyang,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on xfs-linux/for-next]
[also build test ERROR on linux/master]
[cannot apply to hnaz-mm/master linus/master v5.17-rc5 next-20220225] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Shiyang-Ruan/fsdax-introduce-fs-query-to-support-reflink/20220227-200849 base: https://git.kernel.org/pub/scm/fs/xfs/xfs-linux.git for-next config: i386-randconfig-a003 (https://download.01.org/0day-ci/archive/20220227/[email protected]/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/9f4bfbd2bae60e9f172e0b7332b2af32aa5baa87
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Shiyang-Ruan/fsdax-introduce-fs-query-to-support-reflink/20220227-200849 git checkout 9f4bfbd2bae60e9f172e0b7332b2af32aa5baa87
# save the config file to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
ld: fs/xfs/xfs_buf.o: in function `xfs_free_buftarg':
>> fs/xfs/xfs_buf.c:1897: undefined reference to `dax_unregister_holder' ld: fs/xfs/xfs_notify_failure.o: in function `xfs_dax_notify_failure': >> fs/xfs/xfs_notify_failure.c:187: undefined reference to `dax_holder'
vim +1897 fs/xfs/xfs_buf.c
1885
1886 void
1887 xfs_free_buftarg(
1888 struct xfs_buftarg *btp)
1889 {
1890 unregister_shrinker(&btp->bt_shrinker);
1891 ASSERT(percpu_counter_sum(&btp->bt_io_count) == 0);
1892 percpu_counter_destroy(&btp->bt_io_count);
1893 list_lru_destroy(&btp->bt_lru);
1894
1895 blkdev_issue_flush(btp->bt_bdev);
1896 if (btp->bt_daxdev)
> 1897 dax_unregister_holder(btp->bt_daxdev, btp->bt_mount);
1898 fs_put_dax(btp->bt_daxdev);
1899
1900 kmem_free(btp);
1901 }
1902
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
kernel test robot
build botRe: [PATCH v11 7/8] xfs: Implement ->notify_failure() for XFS
In reply to Shiyang RuanThank you for the patch! Yet something to improve:
Hi Shiyang,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on xfs-linux/for-next]
[also build test ERROR on linux/master]
[cannot apply to hnaz-mm/master linus/master v5.17-rc5 next-20220225] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Shiyang-Ruan/fsdax-introduce-fs-query-to-support-reflink/20220227-200849 base: https://git.kernel.org/pub/scm/fs/xfs/xfs-linux.git for-next config: hexagon-buildonly-randconfig-r005-20220227 (https://download.01.org/0day-ci/archive/20220227/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project d271fc04d5b97b12e6b797c6067d3c96a8d7470e)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/9f4bfbd2bae60e9f172e0b7332b2af32aa5baa87
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Shiyang-Ruan/fsdax-introduce-fs-query-to-support-reflink/20220227-200849 git checkout 9f4bfbd2bae60e9f172e0b7332b2af32aa5baa87
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> ld.lld: error: undefined symbol: dax_unregister_holder >>> referenced by xfs_buf.c >>> xfs/xfs_buf.o:(xfs_free_buftarg) in archive fs/built-in.a >>> referenced by xfs_buf.c >>> xfs/xfs_buf.o:(xfs_free_buftarg) in archive fs/built-in.a -- >> ld.lld: error: undefined symbol: dax_holder >>> referenced by xfs_notify_failure.c >>> xfs/xfs_notify_failure.o:(xfs_dax_notify_failure) in archive fs/built-in.a >>> referenced by xfs_notify_failure.c >>> xfs/xfs_notify_failure.o:(xfs_dax_notify_failure) in archive fs/built-in.a
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
kernel test robot
build botRe: [PATCH v11 7/8] xfs: Implement ->notify_failure() for XFS
In reply to Shiyang RuanThank you for the patch! Yet something to improve:
Hi Shiyang,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on xfs-linux/for-next]
[also build test ERROR on linux/master]
[cannot apply to hnaz-mm/master linus/master v5.17-rc5 next-20220225] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Shiyang-Ruan/fsdax-introduce-fs-query-to-support-reflink/20220227-200849 base: https://git.kernel.org/pub/scm/fs/xfs/xfs-linux.git for-next config: riscv-randconfig-p001-20220227 (https://download.01.org/0day-ci/archive/20220227/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/9f4bfbd2bae60e9f172e0b7332b2af32aa5baa87
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Shiyang-Ruan/fsdax-introduce-fs-query-to-support-reflink/20220227-200849 git checkout 9f4bfbd2bae60e9f172e0b7332b2af32aa5baa87
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=riscv SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
riscv64-linux-ld: fs/xfs/xfs_buf.o: in function `.L828':
>> xfs_buf.c:(.text+0x3f7c): undefined reference to `dax_unregister_holder' riscv64-linux-ld: fs/xfs/xfs_notify_failure.o: in function `xfs_dax_notify_failure': >> xfs_notify_failure.c:(.text+0x2b0): undefined reference to `dax_holder'
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
Re: [PATCH v11 7/8] xfs: Implement ->notify_failure() for XFS
In reply to Shiyang RuanQuoted 19 lines
fs/xfs/xfs_buf.c +3
-0@@ -1892,6 +1893,8 @@ xfs_free_buftarg(list_lru_destroy (&btp->bt_lru);blkdev_issue_flush (btp->bt_bdev); +if (btp->bt_daxdev) +dax_unregister_holder (btp->bt_daxdev, btp->bt_mount);fs_put_dax (btp->bt_daxdev);kmem_free (btp);@@ -1939,6 +1942,7 @@ xfs_alloc_buftarg( struct block_device *bdev) {xfs_buftarg_t *btp; +int error; btp =kmem_zalloc (sizeof (*btp),KM_NOFS );@@ -1946,6 +1950,14 @@ xfs_alloc_buftarg( btp->bt_dev = bdev->bd_dev;
fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 1960
Quoted 10 lines
fs/xfs/xfs_buf.c +8
-0btp->bt_bdev = bdev; btp->bt_daxdev =fs_dax_get_by_bdev (bdev, &btp->bt_dax_part_off); +if (btp->bt_daxdev) { + error =dax_register_holder (btp->bt_daxdev, mp, + &xfs_dax_holder_operations); +if (error) { +xfs_err (mp,"DAX device already in use?!" ); + goto error_free; + } + }
It seems to me that just passing the holder and holder ops to fs_dax_get_by_bdev and the holder to dax_unregister_holder would significantly simply the interface here.
Dan, what do you think?
fs/xfs/xfs_notify_failure.c line 31
Quoted 1 line
fs/xfs/xfs_notify_failure.c new file +1
-0+#if IS_ENABLED (CONFIG_MEMORY_FAILURE ) &&IS_ENABLED (CONFIG_FS_DAX )
No real need for the IS_ENABLED. Also any reason to even build this file if the options are not set? It seems like xfs_dax_holder_operations should just be defined to NULL and the whole file not supported if we can't support the functionality.
Dan: not for this series, but is there any reason not to require MEMORY_FAILURE for DAX to start with?
fs/xfs/xfs_notify_failure.c line 211
Quoted 4 lines
fs/xfs/xfs_notify_failure.c new file +4
-0+ + ddev_start = mp->m_ddev_targp->bt_dax_part_off; + ddev_end = ddev_start + + (mp->m_ddev_targp->bt_bdev->bd_nr_sectors <<SECTOR_SHIFT ) -1 ;
This should use bdev_nr_bytes.
But didn't we say we don't want to support notifications on partitioned devices and thus don't actually need all this?
fs/xfs/xfs_notify_failure.c line 214
Quoted 3 lines
fs/xfs/xfs_notify_failure.c new file +3
-0+ +/* Ignore the range out of filesystem area */ +if ((offset + len) < ddev_start)
No need for the inner braces.
fs/xfs/xfs_notify_failure.c line 226
Quoted 1 line
fs/xfs/xfs_notify_failure.c new file +1
-0+if ((offset + len) > ddev_end)
No need for the braces either.
Quoted 6 lines
fs/xfs/xfs_notify_failure.h new file +0
-0
fs/xfs/xfs_notify_failure.h line 10
Quoted 10 lines
fs/xfs/xfs_notify_failure.h new file +10
-0@@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2022 Fujitsu. All Rights Reserved. +*/ +#ifndef __XFS_NOTIFY_FAILURE_H__ +#define __XFS_NOTIFY_FAILURE_H__ + +extern const struct dax_holder_operations xfs_dax_holder_operations; + +#endif /* __XFS_NOTIFY_FAILURE_H__ */
Dowe really need a new header for this vs just sequeezing it into xfs_super.h or something like that?
fs/xfs/xfs_super.c xfs_setup_dax_always( · line 360
Quoted 13 lines
fs/xfs/xfs_super.c +5
-0@@ -353,6 +353,12 @@ xfs_setup_dax_always(return -EINVAL ; } +if (xfs_has_reflink (mp) && !xfs_has_rmapbt (mp)) { +xfs_alert (mp, +"need rmapbt when both DAX and reflink enabled." ); +return -EINVAL ; + }
Right now we can't even enable reflink with DAX yet, so adding this here seems premature - it should go into the patch allowing DAX+reflink.
Re: [PATCH v11 7/8] xfs: Implement ->notify_failure() for XFS
Quoted 34 lines · Christoph Hellwig
Quoted 19 lines
fs/xfs/xfs_buf.c +3
-0@@ -1892,6 +1893,8 @@ xfs_free_buftarg(list_lru_destroy (&btp->bt_lru);blkdev_issue_flush (btp->bt_bdev); +if (btp->bt_daxdev) +dax_unregister_holder (btp->bt_daxdev, btp->bt_mount);fs_put_dax (btp->bt_daxdev);kmem_free (btp);@@ -1939,6 +1942,7 @@ xfs_alloc_buftarg( struct block_device *bdev) {xfs_buftarg_t *btp; +int error; btp =kmem_zalloc (sizeof (*btp),KM_NOFS );@@ -1946,6 +1950,14 @@ xfs_alloc_buftarg( btp->bt_dev = bdev->bd_dev;fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 1960
Quoted 10 lines
fs/xfs/xfs_buf.c +8
-0btp->bt_bdev = bdev; btp->bt_daxdev =fs_dax_get_by_bdev (bdev, &btp->bt_dax_part_off); +if (btp->bt_daxdev) { + error =dax_register_holder (btp->bt_daxdev, mp, + &xfs_dax_holder_operations); +if (error) { +xfs_err (mp,"DAX device already in use?!" ); + goto error_free; + } + }It seems to me that just passing the holder and holder ops to
fs_dax_get_by_bdevand the holder todax_unregister_holderwould significantly simply the interface here.
Quoted 8 lines
Dan, what do you think?
fs/xfs/xfs_notify_failure.c line 31
Quoted 1 line
fs/xfs/xfs_notify_failure.c new file +1
-0+#if IS_ENABLED (CONFIG_MEMORY_FAILURE ) &&IS_ENABLED (CONFIG_FS_DAX )No real need for the
IS_ENABLED. Also any reason to even build this file if the options are not set? It seems likexfs_dax_holder_operationsshould just be defined to NULL and the whole file not supported if we can't support the functionality.
Got it. These two CONFIG seem not related for now. So, I think I should wrap these code with #ifdef CONFIG_MEMORY_FAILURE here, and add xfs-$(CONFIG_FS_DAX) += xfs_notify_failure.o in the makefile.
Quoted 10 lines
Dan: not for this series, but is there any reason not to require
MEMORY_FAILUREfor DAX to start with?fs/xfs/xfs_notify_failure.c line 211
Quoted 4 lines
fs/xfs/xfs_notify_failure.c new file +4
-0+ + ddev_start = mp->m_ddev_targp->bt_dax_part_off; + ddev_end = ddev_start + + (mp->m_ddev_targp->bt_bdev->bd_nr_sectors <<SECTOR_SHIFT ) -1 ;This should use
bdev_nr_bytes.
OK.
Quoted 10 lines
But didn't we say we don't want to support notifications on partitioned devices and thus don't actually need all this?
fs/xfs/xfs_notify_failure.c line 214
Quoted 3 lines
fs/xfs/xfs_notify_failure.c new file +3
-0+ +/* Ignore the range out of filesystem area */ +if ((offset + len) < ddev_start)No need for the inner braces.
Quoted 3 lines
fs/xfs/xfs_notify_failure.c line 226
Quoted 1 line
fs/xfs/xfs_notify_failure.c new file +1
-0+if ((offset + len) > ddev_end)No need for the braces either.
Really no need? It is to make sure the range to be handled won't out of the filesystem area. And make sure the @offset and @len are valid and correct after subtract the bbdev_start.
Quoted 12 lines
Quoted 12 lines
fs/xfs/xfs_notify_failure.h new file +5
-0@@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2022 Fujitsu. All Rights Reserved. +*/ +#ifndef __XFS_NOTIFY_FAILURE_H__
Quoted 8 lines
fs/xfs/xfs_notify_failure.h line 10
Quoted 5 lines
fs/xfs/xfs_notify_failure.h new file +5
-0+#define __XFS_NOTIFY_FAILURE_H__ + +extern const struct dax_holder_operations xfs_dax_holder_operations; + +#endif /* __XFS_NOTIFY_FAILURE_H__ */ Dowe really need a new header for this vs just sequeezing it into
xfs_super.hor something like that?
Yes, I'll move it into xfs_super.h. The xfs_notify_failure.c was splitted from xfs_super.c in the old patch. There is no need to create a header file for only single line of code.
Quoted 9 lines
Quoted 9 lines
fs/xfs/xfs_super.c +0
-0@@ -353,6 +353,12 @@ xfs_setup_dax_always(return -EINVAL ; }
Quoted 9 lines
fs/xfs/xfs_super.c xfs_setup_dax_always( · line 360
Quoted 5 lines
fs/xfs/xfs_super.c +5
-0+if (xfs_has_reflink (mp) && !xfs_has_rmapbt (mp)) { +xfs_alert (mp, +"need rmapbt when both DAX and reflink enabled." ); +return -EINVAL ; + }Right now we can't even enable reflink with DAX yet, so adding this here seems premature - it should go into the patch allowing DAX+reflink.
Yes. I'll remove it for now.
--
Thanks,
Ruan.
Re: [PATCH v11 7/8] xfs: Implement ->notify_failure() for XFS
Quoted 10 lines · Shiyang Ruan
Quoted 6 lines
Quoted 1 line
+#if
IS_ENABLED(CONFIG_MEMORY_FAILURE)&&IS_ENABLED(CONFIG_FS_DAX)No real need for the
IS_ENABLED. Also any reason to even build this file if the options are not set? It seems likexfs_dax_holder_operationsshould just be defined to NULL and the whole file not supported if we can't support the functionality.Got it. These two CONFIG seem not related for now. So, I think I should wrap these code with #ifdef
CONFIG_MEMORY_FAILUREhere, and addxfs-$(CONFIG_FS_DAX) += xfs_notify_failure.oin the makefile.
I'd do
ifeq ($(CONFIG_MEMORY_FAILURE),y)
xfs-$(CONFIG_FS_DAX) += xfs_notify_failure.o
endif
in the makefile and keep it out of the actual source file entirely.
Quoted 6 lines
Quoted 6 lines
fs/xfs/xfs_notify_failure.c line 214
Quoted 3 lines
fs/xfs/xfs_notify_failure.c new file +3
-0+ +/* Ignore the range out of filesystem area */ +if ((offset + len) < ddev_start)No need for the inner braces.
Quoted 7 lines
Quoted 3 lines
fs/xfs/xfs_notify_failure.c line 226
Quoted 1 line
fs/xfs/xfs_notify_failure.c new file +1
-0+if ((offset + len) > ddev_end)No need for the braces either.
Really no need? It is to make sure the range to be handled won't out of the filesystem area. And make sure the @offset and @len are valid and correct after subtract the
bbdev_start.
Yes, but there is no need for the braces per the precedence rules in C. So these could be:
if (offset + len < ddev_start)
and
if (offset + len > ddev_end)
Re: [PATCH v11 7/8] xfs: Implement ->notify_failure() for XFS
In reply to Christoph HellwigQuoted 34 lines · Christoph Hellwig
Quoted 19 lines
fs/xfs/xfs_buf.c +3
-0@@ -1892,6 +1893,8 @@ xfs_free_buftarg(list_lru_destroy (&btp->bt_lru);blkdev_issue_flush (btp->bt_bdev); +if (btp->bt_daxdev) +dax_unregister_holder (btp->bt_daxdev, btp->bt_mount);fs_put_dax (btp->bt_daxdev);kmem_free (btp);@@ -1939,6 +1942,7 @@ xfs_alloc_buftarg( struct block_device *bdev) {xfs_buftarg_t *btp; +int error; btp =kmem_zalloc (sizeof (*btp),KM_NOFS );@@ -1946,6 +1950,14 @@ xfs_alloc_buftarg( btp->bt_dev = bdev->bd_dev;fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 1960
Quoted 10 lines
fs/xfs/xfs_buf.c +8
-0btp->bt_bdev = bdev; btp->bt_daxdev =fs_dax_get_by_bdev (bdev, &btp->bt_dax_part_off); +if (btp->bt_daxdev) { + error =dax_register_holder (btp->bt_daxdev, mp, + &xfs_dax_holder_operations); +if (error) { +xfs_err (mp,"DAX device already in use?!" ); + goto error_free; + } + }It seems to me that just passing the holder and holder ops to
fs_dax_get_by_bdevand the holder todax_unregister_holderwould significantly simply the interface here.
Quoted 1 line
Dan, what do you think?
Hi Dan,
Could you give some advise on this API? Is it needed to move dax_register_holder's job into fs_dax_get_by_bdev()?
--
Thanks,
Ruan
Quoted 68 lines
fs/xfs/xfs_notify_failure.c line 31
Quoted 2 lines
fs/xfs/xfs_notify_failure.c new file +1
-0+#if IS_ENABLED (CONFIG_MEMORY_FAILURE ) &&IS_ENABLED (CONFIG_FS_DAX )No real need for the
IS_ENABLED. Also any reason to even build this file if the options are not set? It seems likexfs_dax_holder_operationsshould just be defined to NULL and the whole file not supported if we can't support the functionality.Dan: not for this series, but is there any reason not to require
MEMORY_FAILUREfor DAX to start with?fs/xfs/xfs_notify_failure.c line 211
Quoted 4 lines
fs/xfs/xfs_notify_failure.c new file +4
-0+ + ddev_start = mp->m_ddev_targp->bt_dax_part_off; + ddev_end = ddev_start + + (mp->m_ddev_targp->bt_bdev->bd_nr_sectors <<SECTOR_SHIFT ) -1 ;This should use
bdev_nr_bytes.But didn't we say we don't want to support notifications on partitioned devices and thus don't actually need all this?
fs/xfs/xfs_notify_failure.c line 214
Quoted 3 lines
fs/xfs/xfs_notify_failure.c new file +3
-0+ +/* Ignore the range out of filesystem area */ +if ((offset + len) < ddev_start)No need for the inner braces.
fs/xfs/xfs_notify_failure.c line 226
Quoted 1 line
fs/xfs/xfs_notify_failure.c new file +1
-0+if ((offset + len) > ddev_end)No need for the braces either.
Quoted 6 lines
fs/xfs/xfs_notify_failure.h new file +0
-0fs/xfs/xfs_notify_failure.h line 10
Quoted 10 lines
fs/xfs/xfs_notify_failure.h new file +10
-0@@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2022 Fujitsu. All Rights Reserved. +*/ +#ifndef __XFS_NOTIFY_FAILURE_H__ +#define __XFS_NOTIFY_FAILURE_H__ + +extern const struct dax_holder_operations xfs_dax_holder_operations; + +#endif /* __XFS_NOTIFY_FAILURE_H__ */ Dowe really need a new header for this vs just sequeezing it into
xfs_super.hor something like that?fs/xfs/xfs_super.c xfs_setup_dax_always( · line 360
Quoted 13 lines
fs/xfs/xfs_super.c +5
-0@@ -353,6 +353,12 @@ xfs_setup_dax_always(return -EINVAL ; } +if (xfs_has_reflink (mp) && !xfs_has_rmapbt (mp)) { +xfs_alert (mp, +"need rmapbt when both DAX and reflink enabled." ); +return -EINVAL ; + }Right now we can't even enable reflink with DAX yet, so adding this here seems premature - it should go into the patch allowing DAX+reflink.
Re: [PATCH v11 7/8] xfs: Implement ->notify_failure() for XFS
Quoted 38 lines · Shiyang Ruan
Quoted 34 lines · Christoph Hellwig
Quoted 19 lines
fs/xfs/xfs_buf.c +3
-0@@ -1892,6 +1893,8 @@ xfs_free_buftarg(list_lru_destroy (&btp->bt_lru);blkdev_issue_flush (btp->bt_bdev); +if (btp->bt_daxdev) +dax_unregister_holder (btp->bt_daxdev, btp->bt_mount);fs_put_dax (btp->bt_daxdev);kmem_free (btp);@@ -1939,6 +1942,7 @@ xfs_alloc_buftarg( struct block_device *bdev) {xfs_buftarg_t *btp; +int error; btp =kmem_zalloc (sizeof (*btp),KM_NOFS );@@ -1946,6 +1950,14 @@ xfs_alloc_buftarg( btp->bt_dev = bdev->bd_dev;fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 1960
Quoted 10 lines
fs/xfs/xfs_buf.c +8
-0btp->bt_bdev = bdev; btp->bt_daxdev =fs_dax_get_by_bdev (bdev, &btp->bt_dax_part_off); +if (btp->bt_daxdev) { + error =dax_register_holder (btp->bt_daxdev, mp, + &xfs_dax_holder_operations); +if (error) { +xfs_err (mp,"DAX device already in use?!" ); + goto error_free; + } + }It seems to me that just passing the holder and holder ops to
fs_dax_get_by_bdevand the holder todax_unregister_holderwould significantly simply the interface here.
Quoted 6 lines
Quoted 1 line
Dan, what do you think?
Hi Dan,
Could you give some advise on this API? Is it needed to move dax_register_holder's job into
fs_dax_get_by_bdev()?
Yes, works for me to just add them as optional arguments.
Re: [PATCH v11 7/8] xfs: Implement ->notify_failure() for XFS
In reply to Christoph HellwigQuoted 35 lines · Christoph Hellwig
Quoted 20 lines
fs/xfs/xfs_buf.c +3
-0@@ -1892,6 +1893,8 @@ xfs_free_buftarg(list_lru_destroy (&btp->bt_lru);blkdev_issue_flush (btp->bt_bdev); +if (btp->bt_daxdev) +dax_unregister_holder (btp->bt_daxdev, btp->bt_mount);fs_put_dax (btp->bt_daxdev);kmem_free (btp);@@ -1939,6 +1942,7 @@ xfs_alloc_buftarg( struct block_device *bdev) {xfs_buftarg_t *btp; +int error; btp =kmem_zalloc (sizeof (*btp),KM_NOFS );@@ -1946,6 +1950,14 @@ xfs_alloc_buftarg( btp->bt_dev = bdev->bd_dev;fs/xfs/xfs_buf.c xfs_alloc_buftarg( · line 1960
Quoted 10 lines
fs/xfs/xfs_buf.c +8
-0btp->bt_bdev = bdev; btp->bt_daxdev =fs_dax_get_by_bdev (bdev, &btp->bt_dax_part_off); +if (btp->bt_daxdev) { + error =dax_register_holder (btp->bt_daxdev, mp, + &xfs_dax_holder_operations); +if (error) { +xfs_err (mp,"DAX device already in use?!" ); + goto error_free; + } + }It seems to me that just passing the holder and holder ops to
fs_dax_get_by_bdevand the holder todax_unregister_holderwould significantly simply the interface here.
Quoted 1 line
Dan, what do you think?
Yes, makes sense, just like the optional holder arguments to blkdev_get_by_*().
Quoted 10 lines
fs/xfs/xfs_notify_failure.c line 31
Quoted 2 lines
fs/xfs/xfs_notify_failure.c new file +1
-0+#if IS_ENABLED (CONFIG_MEMORY_FAILURE ) &&IS_ENABLED (CONFIG_FS_DAX )No real need for the
IS_ENABLED. Also any reason to even build this file if the options are not set? It seems likexfs_dax_holder_operationsshould just be defined to NULL and the whole file not supported if we can't support the functionality.Dan: not for this series, but is there any reason not to require
MEMORY_FAILUREfor DAX to start with?
Given that DAX ties some storage semantics to memory and storage supports EIO I can see an argument to require memory_failure() for DAX, and especially for DAX on CXL where hotplug is supported it will be necessary. Linux currently has no facility to consult PCI drivers about removal actions, so the only recourse for a force removed CXL device is mass memory_failure().
Quoted 10 lines
fs/xfs/xfs_notify_failure.c line 211
Quoted 5 lines
fs/xfs/xfs_notify_failure.c new file +4
-0+ + ddev_start = mp->m_ddev_targp->bt_dax_part_off; + ddev_end = ddev_start + + (mp->m_ddev_targp->bt_bdev->bd_nr_sectors <<SECTOR_SHIFT ) -1 ;This should use
bdev_nr_bytes.But didn't we say we don't want to support notifications on partitioned devices and thus don't actually need all this?
Right.
PATCH v11 8/8 fsdax: set a CoW flag when associate reflink mappings
In reply to Shiyang RuanIntroduce a PAGE_MAPPING_DAX_COW flag to support association with CoW file mappings. In this case, since the dax-rmap has already took the responsibility to look up for shared files by given dax page, the page->mapping is no longer to used for rmap but for marking that this dax page is shared. And to make sure disassociation works fine, we use page->index as refcount, and clear page->mapping to the initial state when page->index is decreased to 0.
With the help of this new flag, it is able to distinguish normal case and CoW case, and keep the warning in normal case.
==
PS: The @cow added for dax_associate_entry(), is used to let it know whether the entry is to be shared during iomap operation. It is decided by iomap,srcmap's flag, and will be used in another patchset( fsdax,xfs: Add reflink&dedupe support for fsdax[1]).
In this patch, we set @cow always false for now.
[1] https://lore.kernel.org/linux-xfs/[email protected]/
==
--- fs/dax.c | 65 ++++++++++++++++++++++++++++++++------ include/linux/page-flags.h | 6 ++++ 2 files changed, 62 insertions(+), 9 deletions(-)
fs/dax.c +56 -9
@@ -334,13 +334,46 @@ static unsigned long dax_end_pfn(void *entry)for (pfn =dax_to_pfn (entry); \ pfn <dax_end_pfn (entry); pfn++) +static inline void dax_mapping_set_cow_flag(struct address_space *mapping) +{ + mapping = (struct address_space *)PAGE_MAPPING_DAX_COW ; +} + +static inline bool dax_mapping_is_cow (struct address_space *mapping) +{ +return (unsigned long )mapping ==PAGE_MAPPING_DAX_COW ; +} +/* -* TODO: for reflink+dax we need a way to associate a single page with -* multiple address_space instances at different linear_page_index() -* offsets. +* Set or Update the page->mapping with FS_DAX_MAPPING_COW flag. +* Return true if it is an Update. +*/ +static inline bool dax_mapping_set_cow (struct page *page) +{ +if (page->mapping) { +/* flag already set */ +if (dax_mapping_is_cow (page->mapping)) +return false; + +/* +* This page has been mapped even before it is shared, just +* need to set this FS_DAX_MAPPING_COW flag. +*/ +dax_mapping_set_cow_flag (page->mapping); +return true; + } +/* Newly associate CoW mapping */ +dax_mapping_set_cow_flag (page->mapping); +return false; +} + +/* +* When it is called in dax_insert_entry(), the cow flag will indicate that +* whether this entry is shared by multiple files. If so, set the page->mapping +* to be FS_DAX_MAPPING_COW, and use page->index as refcount. */ static void dax_associate_entry (void *entry,struct address_space *mapping, -struct vm_area_struct *vma,unsigned long address) +struct vm_area_struct *vma,unsigned long address,bool cow) {unsigned long size =dax_entry_size (entry), pfn, index;int i =0 ;
@@ -352,9 +385,17 @@ static void dax_associate_entry(void *entry, struct address_space *mapping,for_each_mapped_pfn (entry, pfn) {struct page *page =pfn_to_page (pfn); -WARN_ON_ONCE (page->mapping); - page->mapping = mapping; - page->index = index + i++; +if (cow) { +if (dax_mapping_set_cow (page)) { +/* Was normal, now updated to CoW */ + page->index =2 ; + }else + page->index++; + }else { +WARN_ON_ONCE (page->mapping); + page->mapping = mapping; + page->index = index + i++; + } } }
@@ -370,7 +411,12 @@ static void dax_disassociate_entry(void *entry, struct address_space *mapping,struct page *page =pfn_to_page (pfn);WARN_ON_ONCE (trunc &&page_ref_count (page) >1 ); -WARN_ON_ONCE (page->mapping && page->mapping != mapping); +if (!dax_mapping_is_cow (page->mapping)) { +/* keep the CoW flag if this page is still shared */ +if (page->index-- >0 ) +continue ; + }else +WARN_ON_ONCE (page->mapping && page->mapping != mapping); page->mapping =NULL ; page->index =0 ; }
@@ -829,7 +875,8 @@ static void *dax_insert_entry(struct xa_state *xas,void *old;dax_disassociate_entry (entry, mapping, false); -dax_associate_entry (new_entry, mapping, vmf->vma, vmf->address); +dax_associate_entry (new_entry, mapping, vmf->vma, vmf->address, + false);/* * 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
include/linux/page-flags.h +6 -0
@@ -572,6 +572,12 @@ __PAGEFLAG(Reported, reported, PF_NO_COMPOUND)#define PAGE_MAPPING_KSM (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE)#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE) +/* +* Different with flags above, this flag is used only for fsdax mode. It +* indicates that this page->mapping is now under reflink case. +*/ +#define PAGE_MAPPING_DAX_COW 0x1 + static __always_inline int PageMappingFlags(struct page *page) {return ((unsigned long )page->mapping &PAGE_MAPPING_FLAGS ) !=0 ;
Signature · 1 line
2.35.1
kernel test robot
build botRe: [PATCH v11 8/8] fsdax: set a CoW flag when associate reflink mappings
Thank you for the patch! Perhaps something to improve:
Hi Shiyang,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on xfs-linux/for-next]
[also build test WARNING on linux/master]
[cannot apply to hnaz-mm/master linus/master v5.17-rc5 next-20220225] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Shiyang-Ruan/fsdax-introduce-fs-query-to-support-reflink/20220227-200849 base: https://git.kernel.org/pub/scm/fs/xfs/xfs-linux.git for-next config: i386-randconfig-a013 (https://download.01.org/0day-ci/archive/20220227/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project d271fc04d5b97b12e6b797c6067d3c96a8d7470e)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/a0ac78065bbb4fbb3e5477c32686eca3b9f0e1ef
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Shiyang-Ruan/fsdax-introduce-fs-query-to-support-reflink/20220227-200849 git checkout a0ac78065bbb4fbb3e5477c32686eca3b9f0e1ef
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> fs/dax.c:337:67: warning: parameter 'mapping' set but not used [-Wunused-but-set-parameter]
static inline void dax_mapping_set_cow_flag(struct address_space *mapping)
^1 warning generated.
vim +/mapping +337 fs/dax.c
328
329 /*
330 * Iterate through all mapped pfns represented by an entry, i.e. skip
331 * 'empty' and 'zero' entries.
332 */
333 #define for_each_mapped_pfn(entry, pfn) \
334 for (pfn = dax_to_pfn(entry); \
335 pfn < dax_end_pfn(entry); pfn++)
336
> 337 static inline void dax_mapping_set_cow_flag(struct address_space *mapping)
338 {
339 mapping = (struct address_space *)PAGE_MAPPING_DAX_COW;
340 }
341
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
ping ;)
Quoted 71 lines · Shiyang Ruan
This patchset is aimed to support shared pages tracking for fsdax.
Changes since V10:
- Usecmpxchg()to prevent concurrent registration/unregistration
- Usephys_addr_tfor ->memory_failure()
- Adddax_entry_lock()fordax_lock_mapping_entry()
- Fix offset and length calculation at the boundary of a filesystemThis patchset moves owner tracking from
dax_assocaite_entry()to pmem device driver, by introducing an interface ->memory_failure() for struct pagemap. This interface is called bymemory_failure()in mm, and implemented by pmem device.Then call holder operations to find the filesystem which the corrupted data located in, and call filesystem handler to track files or metadata associated with this page.
Finally we are able to try to fix the corrupted data in filesystem and do other necessary processing, such as killing processes who are using the files affected.
The call trace is like this:
memory_failure()|* fsdax case |------------ |pgmap->ops->memory_failure() => pmem_pgmap_memory_failure() | dax_holder_notify_failure() => | dax_device->holder_ops->notify_failure() => | - xfs_dax_notify_failure() | |* xfs_dax_notify_failure() | |-------------------------- | | xfs_rmap_query_range() | | xfs_dax_failure_fn() | | * corrupted on metadata | | try to recover data, call xfs_force_shutdown() | | * corrupted on file data | | try to recover data, call mf_dax_kill_procs() |* normal case |------------- |mf_generic_kill_procs()==
Shiyang Ruan (8):
dax: Introduce holder fordax_device
mm: factor helpers formemory_failure_dev_pagemappagemap,pmem: Introduce ->memory_failure()
fsdax: Introducedax_lock_mapping_entry()
mm: movepgoff_address()tovma_pgoff_address()
mm: Introducemf_dax_kill_procs()for fsdax case
xfs: Implement ->notify_failure() for XFS
fsdax: set a CoW flag when associate reflink mappingsdrivers/dax/super.c | 89 +++++++++++++ drivers/nvdimm/pmem.c | 16 +++ fs/dax.c | 140 ++++++++++++++++++--- fs/xfs/Makefile | 1 + fs/xfs/xfs_buf.c | 12 ++ fs/xfs/xfs_fsops.c | 3 + fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_notify_failure.c | 235 +++++++++++++++++++++++++++++++++++ fs/xfs/xfs_notify_failure.h | 10 ++ fs/xfs/xfs_super.c | 6 + include/linux/dax.h | 47 +++++++ include/linux/memremap.h | 12 ++ include/linux/mm.h | 17 +++ include/linux/page-flags.h | 6 + mm/memory-failure.c | 240 ++++++++++++++++++++++++++---------- 15 files changed, 747 insertions(+), 88 deletions(-)create mode 100644
fs/xfs/xfs_notify_failure.c
create mode 100644fs/xfs/xfs_notify_failure.h