Skip to content

Commit 8cf037a

Browse files
committed
ext2: perform dax_device lookup at mount
The ->iomap_begin() operation is a hot path, so cache the fs_dax_get_by_host() result at mount time to avoid the incurring the hash lookup overhead on a per-i/o basis. Cc: "Theodore Ts'o" <tytso@mit.edu> Cc: Andreas Dilger <adilger.kernel@dilger.ca> Reviewed-by: Jan Kara <jack@suse.cz> Reported-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 486aff5 commit 8cf037a

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎fs/ext2/ext2.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct ext2_sb_info {
114114
*/
115115
spinlock_t s_lock;
116116
struct mb_cache *s_ea_block_cache;
117+
struct dax_device *s_daxdev;
117118
};
118119

119120
static inline spinlock_t *

‎fs/ext2/inode.c‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,10 @@ int ext2_get_block(struct inode *inode, sector_t iblock,
800800
static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
801801
unsigned flags, struct iomap *iomap)
802802
{
803-
struct block_device *bdev;
804803
unsigned int blkbits = inode->i_blkbits;
805804
unsigned long first_block = offset >> blkbits;
806805
unsigned long max_blocks = (length + (1 << blkbits) - 1) >> blkbits;
806+
struct ext2_sb_info *sbi = EXT2_SB(inode->i_sb);
807807
bool new = false, boundary = false;
808808
u32 bno;
809809
int ret;
@@ -814,13 +814,9 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
814814
return ret;
815815

816816
iomap->flags = 0;
817-
bdev = inode->i_sb->s_bdev;
818-
iomap->bdev = bdev;
817+
iomap->bdev = inode->i_sb->s_bdev;
819818
iomap->offset = (u64)first_block << blkbits;
820-
if (blk_queue_dax(bdev->bd_queue))
821-
iomap->dax_dev = fs_dax_get_by_host(bdev->bd_disk->disk_name);
822-
else
823-
iomap->dax_dev = NULL;
819+
iomap->dax_dev = sbi->s_daxdev;
824820

825821
if (ret == 0) {
826822
iomap->type = IOMAP_HOLE;
@@ -842,7 +838,6 @@ static int
842838
ext2_iomap_end(struct inode *inode, loff_t offset, loff_t length,
843839
ssize_t written, unsigned flags, struct iomap *iomap)
844840
{
845-
fs_put_dax(iomap->dax_dev);
846841
if (iomap->type == IOMAP_MAPPED &&
847842
written < length &&
848843
(flags & IOMAP_WRITE))

‎fs/ext2/super.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ static void ext2_put_super (struct super_block * sb)
171171
brelse (sbi->s_sbh);
172172
sb->s_fs_info = NULL;
173173
kfree(sbi->s_blockgroup_lock);
174+
fs_put_dax(sbi->s_daxdev);
174175
kfree(sbi);
175176
}
176177

@@ -813,6 +814,7 @@ static unsigned long descriptor_loc(struct super_block *sb,
813814

814815
static int ext2_fill_super(struct super_block *sb, void *data, int silent)
815816
{
817+
struct dax_device *dax_dev = fs_dax_get_by_bdev(sb->s_bdev);
816818
struct buffer_head * bh;
817819
struct ext2_sb_info * sbi;
818820
struct ext2_super_block * es;
@@ -842,6 +844,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
842844
}
843845
sb->s_fs_info = sbi;
844846
sbi->s_sb_block = sb_block;
847+
sbi->s_daxdev = dax_dev;
845848

846849
spin_lock_init(&sbi->s_lock);
847850

@@ -1200,6 +1203,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
12001203
kfree(sbi->s_blockgroup_lock);
12011204
kfree(sbi);
12021205
failed:
1206+
fs_put_dax(dax_dev);
12031207
return ret;
12041208
}
12051209

0 commit comments

Comments
 (0)