diff mbox series

[V3,4/8] fs/ext4: Update ext4_should_use_dax()

Message ID 20200520055753.3733520-5-ira.weiny@intel.com
State Superseded
Headers show
Series Enable ext4 support for per-file/directory DAX operations | expand

Commit Message

Ira Weiny May 20, 2020, 5:57 a.m. UTC
From: Ira Weiny <ira.weiny@intel.com>

S_DAX should only be enabled when the underlying block device supports
dax.

Change ext4_should_use_dax() to check for device support prior to the
over riding mount option.

While we are at it change the function to ext4_should_enable_dax() as
this better reflects the ask as well as matches xfs.

Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>

---
Changes from RFC
	Change function name to 'should enable'
	Clean up bool conversion
	Reorder this for better bisect-ability
---
 fs/ext4/inode.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Comments

Jan Kara May 20, 2020, 1:37 p.m. UTC | #1
On Tue 19-05-20 22:57:49, ira.weiny@intel.com wrote:
> From: Ira Weiny <ira.weiny@intel.com>
> 
> S_DAX should only be enabled when the underlying block device supports
> dax.
> 
> Change ext4_should_use_dax() to check for device support prior to the
> over riding mount option.
> 
> While we are at it change the function to ext4_should_enable_dax() as
> this better reflects the ask as well as matches xfs.
> 
> Reviewed-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>

...

> @@ -4412,7 +4410,13 @@ static bool ext4_should_use_dax(struct inode *inode)
>  		return false;
>  	if (ext4_test_inode_flag(inode, EXT4_INODE_VERITY))
>  		return false;
> -	return true;
> +	if (!bdev_dax_supported(inode->i_sb->s_bdev,
> +				inode->i_sb->s_blocksize))
> +		return false;
> +	if (test_opt(inode->i_sb, DAX_ALWAYS))
> +		return true;
> +
> +	return false;
>  }

Now that I think about it - shouldn't we rather cache the result of
bdev_dax_supported() in sb on mount and then just check the flag here?
Because bdev_dax_supported() isn't exactly cheap (it does a lot of checks
and mappings, tries to read from the pmem, ...).

								Honza
Ira Weiny May 20, 2020, 7:40 p.m. UTC | #2
On Wed, May 20, 2020 at 03:37:28PM +0200, Jan Kara wrote:
> On Tue 19-05-20 22:57:49, ira.weiny@intel.com wrote:
> > From: Ira Weiny <ira.weiny@intel.com>
> > 
> > S_DAX should only be enabled when the underlying block device supports
> > dax.
> > 
> > Change ext4_should_use_dax() to check for device support prior to the
> > over riding mount option.
> > 
> > While we are at it change the function to ext4_should_enable_dax() as
> > this better reflects the ask as well as matches xfs.
> > 
> > Reviewed-by: Jan Kara <jack@suse.cz>
> > Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> 
> ...
> 
> > @@ -4412,7 +4410,13 @@ static bool ext4_should_use_dax(struct inode *inode)
> >  		return false;
> >  	if (ext4_test_inode_flag(inode, EXT4_INODE_VERITY))
> >  		return false;
> > -	return true;
> > +	if (!bdev_dax_supported(inode->i_sb->s_bdev,
> > +				inode->i_sb->s_blocksize))
> > +		return false;
> > +	if (test_opt(inode->i_sb, DAX_ALWAYS))
> > +		return true;
> > +
> > +	return false;
> >  }
> 
> Now that I think about it - shouldn't we rather cache the result of
> bdev_dax_supported() in sb on mount and then just check the flag here?
> Because bdev_dax_supported() isn't exactly cheap (it does a lot of checks
> and mappings, tries to read from the pmem, ...).

Sounds reasonable.

Not sure which flags are appropriate.  So add it here?

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 1a3daf2d18ef..0b4db9ce7756 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1979,6 +1979,7 @@ static inline bool ext4_has_incompat_features(struct super_block *sb)
  */
 #define EXT4_FLAGS_RESIZING    0
 #define EXT4_FLAGS_SHUTDOWN    1
+#define EXT4_FLAGS_BDEV_IS_DAX 2
 
 static inline int ext4_forced_shutdown(struct ext4_sb_info *sbi)
 {
Jan Kara May 21, 2020, 10:24 a.m. UTC | #3
On Wed 20-05-20 12:40:50, Ira Weiny wrote:
> On Wed, May 20, 2020 at 03:37:28PM +0200, Jan Kara wrote:
> > On Tue 19-05-20 22:57:49, ira.weiny@intel.com wrote:
> > > From: Ira Weiny <ira.weiny@intel.com>
> > > 
> > > S_DAX should only be enabled when the underlying block device supports
> > > dax.
> > > 
> > > Change ext4_should_use_dax() to check for device support prior to the
> > > over riding mount option.
> > > 
> > > While we are at it change the function to ext4_should_enable_dax() as
> > > this better reflects the ask as well as matches xfs.
> > > 
> > > Reviewed-by: Jan Kara <jack@suse.cz>
> > > Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> > 
> > ...
> > 
> > > @@ -4412,7 +4410,13 @@ static bool ext4_should_use_dax(struct inode *inode)
> > >  		return false;
> > >  	if (ext4_test_inode_flag(inode, EXT4_INODE_VERITY))
> > >  		return false;
> > > -	return true;
> > > +	if (!bdev_dax_supported(inode->i_sb->s_bdev,
> > > +				inode->i_sb->s_blocksize))
> > > +		return false;
> > > +	if (test_opt(inode->i_sb, DAX_ALWAYS))
> > > +		return true;
> > > +
> > > +	return false;
> > >  }
> > 
> > Now that I think about it - shouldn't we rather cache the result of
> > bdev_dax_supported() in sb on mount and then just check the flag here?
> > Because bdev_dax_supported() isn't exactly cheap (it does a lot of checks
> > and mappings, tries to read from the pmem, ...).
> 
> Sounds reasonable.
> 
> Not sure which flags are appropriate.  So add it here?

Yes, sounds good. Thanks!

								Honza

> 
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 1a3daf2d18ef..0b4db9ce7756 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -1979,6 +1979,7 @@ static inline bool ext4_has_incompat_features(struct super_block *sb)
>   */
>  #define EXT4_FLAGS_RESIZING    0
>  #define EXT4_FLAGS_SHUTDOWN    1
> +#define EXT4_FLAGS_BDEV_IS_DAX 2
>  
>  static inline int ext4_forced_shutdown(struct ext4_sb_info *sbi)
>  {
>
diff mbox series

Patch

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index a10ff12194db..d3a4c2ed7a1c 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4398,10 +4398,8 @@  int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc)
 		!ext4_test_inode_state(inode, EXT4_STATE_XATTR));
 }
 
-static bool ext4_should_use_dax(struct inode *inode)
+static bool ext4_should_enable_dax(struct inode *inode)
 {
-	if (!test_opt(inode->i_sb, DAX_ALWAYS))
-		return false;
 	if (!S_ISREG(inode->i_mode))
 		return false;
 	if (ext4_should_journal_data(inode))
@@ -4412,7 +4410,13 @@  static bool ext4_should_use_dax(struct inode *inode)
 		return false;
 	if (ext4_test_inode_flag(inode, EXT4_INODE_VERITY))
 		return false;
-	return true;
+	if (!bdev_dax_supported(inode->i_sb->s_bdev,
+				inode->i_sb->s_blocksize))
+		return false;
+	if (test_opt(inode->i_sb, DAX_ALWAYS))
+		return true;
+
+	return false;
 }
 
 void ext4_set_inode_flags(struct inode *inode)
@@ -4430,7 +4434,7 @@  void ext4_set_inode_flags(struct inode *inode)
 		new_fl |= S_NOATIME;
 	if (flags & EXT4_DIRSYNC_FL)
 		new_fl |= S_DIRSYNC;
-	if (ext4_should_use_dax(inode))
+	if (ext4_should_enable_dax(inode))
 		new_fl |= S_DAX;
 	if (flags & EXT4_ENCRYPT_FL)
 		new_fl |= S_ENCRYPTED;