Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1739331 > unrolled thread
| Started by | Ross Zwisler <ross.zwisler@linux.intel.com> |
|---|---|
| First post | 2017-09-26 01:20 +0200 |
| Last post | 2017-09-26 08:40 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 6/7] mm, fs: introduce file_operations->post_mmap() Ross Zwisler <ross.zwisler@linux.intel.com> - 2017-09-26 01:20 +0200
Re: [PATCH 6/7] mm, fs: introduce file_operations->post_mmap() Dan Williams <dan.j.williams@intel.com> - 2017-09-26 01:40 +0200
Re: [PATCH 6/7] mm, fs: introduce file_operations->post_mmap() Christoph Hellwig <hch@lst.de> - 2017-09-26 08:40 +0200
| From | Ross Zwisler <ross.zwisler@linux.intel.com> |
|---|---|
| Date | 2017-09-26 01:20 +0200 |
| Subject | [PATCH 6/7] mm, fs: introduce file_operations->post_mmap() |
| Message-ID | <utKPp-4Lc-3@gated-at.bofh.it> |
When mappings are created the vma->vm_flags that they use vary based on
whether the inode being mapped is using DAX or not. This setup happens in
XFS via mmap_region()=>call_mmap()=>xfs_file_mmap().
For us to be able to safely use the DAX per-inode flag we need to prevent
S_DAX transitions when any mappings are present, and we will do that by
looking at the address_space->i_mmap tree and returning -EBUSY if any
mappings are present.
Unfortunately at the time that the filesystem's file_operations->mmap()
entry point is called the mapping has not yet been added to the
address_space->i_mmap tree. This means that at that point in time we
cannot determine whether or not the mapping will be set up to support DAX.
Fix this by adding a new file_operations entry called post_mmap() which is
called after the mapping has been added to the address_space->i_mmap tree.
This post_mmap() op now happens at a time when we can be sure whether the
mapping will use DAX or not, and we can set up the vma->vm_flags
appropriately.
Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
---
fs/xfs/xfs_file.c | 15 ++++++++++++++-
include/linux/fs.h | 1 +
mm/mmap.c | 2 ++
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 2816858..9d66aaa 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -1087,9 +1087,21 @@ xfs_file_mmap(
{
file_accessed(filp);
vma->vm_ops = &xfs_file_vm_ops;
+ return 0;
+}
+
+/* This call happens during mmap(), after the vma has been inserted into the
+ * inode->i_mapping->i_mmap tree. At this point the decision on whether or
+ * not to use DAX for this mapping has been set and will not change for the
+ * duration of the mapping.
+ */
+STATIC void
+xfs_file_post_mmap(
+ struct file *filp,
+ struct vm_area_struct *vma)
+{
if (IS_DAX(file_inode(filp)))
vma->vm_flags |= VM_MIXEDMAP | VM_HUGEPAGE;
- return 0;
}
const struct file_operations xfs_file_operations = {
@@ -1103,6 +1115,7 @@ const struct file_operations xfs_file_operations = {
.compat_ioctl = xfs_file_compat_ioctl,
#endif
.mmap = xfs_file_mmap,
+ .post_mmap = xfs_file_post_mmap,
.open = xfs_file_open,
.release = xfs_file_release,
.fsync = xfs_file_fsync,
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 339e737..7c06838 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1701,6 +1701,7 @@ struct file_operations {
long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
int (*mmap) (struct file *, struct vm_area_struct *);
+ void (*post_mmap) (struct file *, struct vm_area_struct *);
int (*open) (struct inode *, struct file *);
int (*flush) (struct file *, fl_owner_t id);
int (*release) (struct inode *, struct file *);
diff --git a/mm/mmap.c b/mm/mmap.c
index 680506f..ee7458a 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1711,6 +1711,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
vma_link(mm, vma, prev, rb_link, rb_parent);
/* Once vma denies write, undo our temporary denial count */
if (file) {
+ if (file->f_op->post_mmap)
+ file->f_op->post_mmap(file, vma);
if (vm_flags & VM_SHARED)
mapping_unmap_writable(file->f_mapping);
if (vm_flags & VM_DENYWRITE)
--
2.9.5
[toc] | [next] | [standalone]
| From | Dan Williams <dan.j.williams@intel.com> |
|---|---|
| Date | 2017-09-26 01:40 +0200 |
| Message-ID | <utL8J-4Uf-1@gated-at.bofh.it> |
| In reply to | #1739331 |
On Mon, Sep 25, 2017 at 4:14 PM, Ross Zwisler
<ross.zwisler@linux.intel.com> wrote:
> When mappings are created the vma->vm_flags that they use vary based on
> whether the inode being mapped is using DAX or not. This setup happens in
> XFS via mmap_region()=>call_mmap()=>xfs_file_mmap().
>
> For us to be able to safely use the DAX per-inode flag we need to prevent
> S_DAX transitions when any mappings are present, and we will do that by
> looking at the address_space->i_mmap tree and returning -EBUSY if any
> mappings are present.
>
> Unfortunately at the time that the filesystem's file_operations->mmap()
> entry point is called the mapping has not yet been added to the
> address_space->i_mmap tree. This means that at that point in time we
> cannot determine whether or not the mapping will be set up to support DAX.
>
> Fix this by adding a new file_operations entry called post_mmap() which is
> called after the mapping has been added to the address_space->i_mmap tree.
> This post_mmap() op now happens at a time when we can be sure whether the
> mapping will use DAX or not, and we can set up the vma->vm_flags
> appropriately.
>
> Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
> ---
> fs/xfs/xfs_file.c | 15 ++++++++++++++-
> include/linux/fs.h | 1 +
> mm/mmap.c | 2 ++
> 3 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index 2816858..9d66aaa 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
> @@ -1087,9 +1087,21 @@ xfs_file_mmap(
> {
> file_accessed(filp);
> vma->vm_ops = &xfs_file_vm_ops;
> + return 0;
> +}
> +
> +/* This call happens during mmap(), after the vma has been inserted into the
> + * inode->i_mapping->i_mmap tree. At this point the decision on whether or
> + * not to use DAX for this mapping has been set and will not change for the
> + * duration of the mapping.
> + */
> +STATIC void
> +xfs_file_post_mmap(
> + struct file *filp,
> + struct vm_area_struct *vma)
> +{
> if (IS_DAX(file_inode(filp)))
> vma->vm_flags |= VM_MIXEDMAP | VM_HUGEPAGE;
It's not clear to me what this is actually protecting? vma_is_dax()
returns true regardless of the vm_flags state , so what is the benefit
to delaying the vm_flags setting to ->post_mmap()?
Also, why is this a file_operation and not a vm_operation?
[toc] | [prev] | [next] | [standalone]
| From | Christoph Hellwig <hch@lst.de> |
|---|---|
| Date | 2017-09-26 08:40 +0200 |
| Message-ID | <utRHc-10R-23@gated-at.bofh.it> |
| In reply to | #1739331 |
On Mon, Sep 25, 2017 at 05:14:03PM -0600, Ross Zwisler wrote: > When mappings are created the vma->vm_flags that they use vary based on > whether the inode being mapped is using DAX or not. This setup happens in > XFS via mmap_region()=>call_mmap()=>xfs_file_mmap(). > > For us to be able to safely use the DAX per-inode flag we need to prevent > S_DAX transitions when any mappings are present, and we will do that by > looking at the address_space->i_mmap tree and returning -EBUSY if any > mappings are present. > > Unfortunately at the time that the filesystem's file_operations->mmap() > entry point is called the mapping has not yet been added to the > address_space->i_mmap tree. This means that at that point in time we > cannot determine whether or not the mapping will be set up to support DAX. > > Fix this by adding a new file_operations entry called post_mmap() which is > called after the mapping has been added to the address_space->i_mmap tree. > This post_mmap() op now happens at a time when we can be sure whether the > mapping will use DAX or not, and we can set up the vma->vm_flags > appropriately. Just like in the read/write path we'll need a flag that is passed down from the VM based on checking IS_DAX once and exactly once instead.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web