@@ -801,6 +801,7 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
unsigned flags, struct iomap *iomap)
{
struct block_device *bdev;
+ struct dax_device *dax_dev;
unsigned int blkbits = inode->i_blkbits;
unsigned long first_block = offset >> blkbits;
unsigned long max_blocks = (length + (1 << blkbits) - 1) >> blkbits;
@@ -817,10 +818,12 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
bdev = inode->i_sb->s_bdev;
iomap->bdev = bdev;
iomap->offset = (u64)first_block << blkbits;
- if (blk_queue_dax(bdev->bd_queue))
- iomap->dax_dev = fs_dax_get_by_host(bdev->bd_disk->disk_name);
- else
- iomap->dax_dev = NULL;
+ dax_dev = inode->i_sb->s_daxdev;
+ if (blk_queue_dax(bdev->bd_queue) && !dax_dev) {
+ dax_dev = fs_dax_get_by_host(bdev->bd_disk->disk_name);
+ inode->i_sb->s_daxdev = dax_dev;
+ }
+ iomap->dax_dev = dax_dev;
if (ret == 0) {
iomap->type = IOMAP_HOLE;
@@ -3405,6 +3405,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
unsigned flags, struct iomap *iomap)
{
struct block_device *bdev;
+ struct dax_device *dax_dev;
unsigned int blkbits = inode->i_blkbits;
unsigned long first_block = offset >> blkbits;
unsigned long last_block = (offset + length - 1) >> blkbits;
@@ -3475,10 +3476,12 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
iomap->flags = 0;
bdev = inode->i_sb->s_bdev;
iomap->bdev = bdev;
- if (blk_queue_dax(bdev->bd_queue))
- iomap->dax_dev = fs_dax_get_by_host(bdev->bd_disk->disk_name);
- else
- iomap->dax_dev = NULL;
+ dax_dev = inode->i_sb->s_daxdev;
+ if (blk_queue_dax(bdev->bd_queue) && !dax_dev) {
+ dax_dev = fs_dax_get_by_host(bdev->bd_disk->disk_name);
+ inode->i_sb->s_daxdev = dax_dev;
+ }
+ iomap->dax_dev = dax_dev;
iomap->offset = first_block << blkbits;
if (ret == 0) {
@@ -1334,6 +1334,9 @@ struct super_block {
struct hlist_bl_head s_anon; /* anonymous dentries for (nfs) exporting */
struct list_head s_mounts; /* list of mounts; _not_ for fs use */
struct block_device *s_bdev;
+#ifdef CONFIG_FS_DAX
+ struct dax_device *s_daxdev; /* cached dax_device */
+#endif
struct backing_dev_info *s_bdi;
struct mtd_info *s_mtd;
struct hlist_node s_instances;
The ->iomap_begin() operation is a hot path, so cache the fs_dax_get_by_host() result to avoid the incurring the hash lookup overhead. Cc: Jan Kara <jack@suse.com> Cc: "Theodore Ts'o" <tytso@mit.edu> Cc: Andreas Dilger <adilger.kernel@dilger.ca> Reported-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- fs/ext2/inode.c | 11 +++++++---- fs/ext4/inode.c | 11 +++++++---- include/linux/fs.h | 3 +++ 3 files changed, 17 insertions(+), 8 deletions(-)