提交 c4020b2d 编写于 作者: C Chao Yu 提交者: Jaegeuk Kim

f2fs: support F2FS_IOC_PRECACHE_EXTENTS

This patch introduces a new ioctl F2FS_IOC_PRECACHE_EXTENTS to precache
extent info like ext4, in order to gain better performance during
triggering AIO by eliminating synchronous waiting of mapping info.

Referred commit: 7869a4a6 ("ext4: add support for extent pre-caching")

In addition, with newly added extent precache abilitiy, this patch add
to support FIEMAP_FLAG_CACHE in ->fiemap.
Signed-off-by: NChao Yu <yuchao0@huawei.com>
Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
上级 1ad71a27
...@@ -865,6 +865,7 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from) ...@@ -865,6 +865,7 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
map.m_len = 0; map.m_len = 0;
map.m_next_pgofs = NULL; map.m_next_pgofs = NULL;
map.m_next_extent = NULL;
map.m_seg_type = NO_CHECK_TYPE; map.m_seg_type = NO_CHECK_TYPE;
if (direct_io) { if (direct_io) {
...@@ -931,6 +932,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, ...@@ -931,6 +932,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
blkcnt_t prealloc; blkcnt_t prealloc;
struct extent_info ei = {0,0,0}; struct extent_info ei = {0,0,0};
block_t blkaddr; block_t blkaddr;
unsigned int start_pgofs;
if (!maxblocks) if (!maxblocks)
return 0; return 0;
...@@ -946,6 +948,8 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, ...@@ -946,6 +948,8 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
map->m_pblk = ei.blk + pgofs - ei.fofs; map->m_pblk = ei.blk + pgofs - ei.fofs;
map->m_len = min((pgoff_t)maxblocks, ei.fofs + ei.len - pgofs); map->m_len = min((pgoff_t)maxblocks, ei.fofs + ei.len - pgofs);
map->m_flags = F2FS_MAP_MAPPED; map->m_flags = F2FS_MAP_MAPPED;
if (map->m_next_extent)
*map->m_next_extent = pgofs + map->m_len;
goto out; goto out;
} }
...@@ -964,10 +968,14 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, ...@@ -964,10 +968,14 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
if (map->m_next_pgofs) if (map->m_next_pgofs)
*map->m_next_pgofs = *map->m_next_pgofs =
get_next_page_offset(&dn, pgofs); get_next_page_offset(&dn, pgofs);
if (map->m_next_extent)
*map->m_next_extent =
get_next_page_offset(&dn, pgofs);
} }
goto unlock_out; goto unlock_out;
} }
start_pgofs = pgofs;
prealloc = 0; prealloc = 0;
last_ofs_in_node = ofs_in_node = dn.ofs_in_node; last_ofs_in_node = ofs_in_node = dn.ofs_in_node;
end_offset = ADDRS_PER_PAGE(dn.node_page, inode); end_offset = ADDRS_PER_PAGE(dn.node_page, inode);
...@@ -1001,6 +1009,8 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, ...@@ -1001,6 +1009,8 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
map->m_pblk = 0; map->m_pblk = 0;
goto sync_out; goto sync_out;
} }
if (flag == F2FS_GET_BLOCK_PRECACHE)
goto sync_out;
if (flag == F2FS_GET_BLOCK_FIEMAP && if (flag == F2FS_GET_BLOCK_FIEMAP &&
blkaddr == NULL_ADDR) { blkaddr == NULL_ADDR) {
if (map->m_next_pgofs) if (map->m_next_pgofs)
...@@ -1059,6 +1069,16 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, ...@@ -1059,6 +1069,16 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
else if (dn.ofs_in_node < end_offset) else if (dn.ofs_in_node < end_offset)
goto next_block; goto next_block;
if (flag == F2FS_GET_BLOCK_PRECACHE) {
if (map->m_flags & F2FS_MAP_MAPPED) {
unsigned int ofs = start_pgofs - map->m_lblk;
f2fs_update_extent_cache_range(&dn,
start_pgofs, map->m_pblk + ofs,
map->m_len - ofs);
}
}
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
if (create) { if (create) {
...@@ -1068,6 +1088,17 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, ...@@ -1068,6 +1088,17 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
goto next_dnode; goto next_dnode;
sync_out: sync_out:
if (flag == F2FS_GET_BLOCK_PRECACHE) {
if (map->m_flags & F2FS_MAP_MAPPED) {
unsigned int ofs = start_pgofs - map->m_lblk;
f2fs_update_extent_cache_range(&dn,
start_pgofs, map->m_pblk + ofs,
map->m_len - ofs);
}
if (map->m_next_extent)
*map->m_next_extent = pgofs + 1;
}
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
unlock_out: unlock_out:
if (create) { if (create) {
...@@ -1089,6 +1120,7 @@ static int __get_data_block(struct inode *inode, sector_t iblock, ...@@ -1089,6 +1120,7 @@ static int __get_data_block(struct inode *inode, sector_t iblock,
map.m_lblk = iblock; map.m_lblk = iblock;
map.m_len = bh->b_size >> inode->i_blkbits; map.m_len = bh->b_size >> inode->i_blkbits;
map.m_next_pgofs = next_pgofs; map.m_next_pgofs = next_pgofs;
map.m_next_extent = NULL;
map.m_seg_type = seg_type; map.m_seg_type = seg_type;
err = f2fs_map_blocks(inode, &map, create, flag); err = f2fs_map_blocks(inode, &map, create, flag);
...@@ -1212,6 +1244,12 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, ...@@ -1212,6 +1244,12 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
u32 flags = 0; u32 flags = 0;
int ret = 0; int ret = 0;
if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) {
ret = f2fs_precache_extents(inode);
if (ret)
return ret;
}
ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR); ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR);
if (ret) if (ret)
return ret; return ret;
...@@ -1313,6 +1351,7 @@ static int f2fs_mpage_readpages(struct address_space *mapping, ...@@ -1313,6 +1351,7 @@ static int f2fs_mpage_readpages(struct address_space *mapping,
map.m_len = 0; map.m_len = 0;
map.m_flags = 0; map.m_flags = 0;
map.m_next_pgofs = NULL; map.m_next_pgofs = NULL;
map.m_next_extent = NULL;
map.m_seg_type = NO_CHECK_TYPE; map.m_seg_type = NO_CHECK_TYPE;
for (; nr_pages; nr_pages--) { for (; nr_pages; nr_pages--) {
......
...@@ -358,6 +358,7 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal, ...@@ -358,6 +358,7 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal,
#define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32)
#define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32) #define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32)
#define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32) #define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32)
#define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15)
#define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY
#define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
...@@ -553,6 +554,7 @@ struct f2fs_map_blocks { ...@@ -553,6 +554,7 @@ struct f2fs_map_blocks {
unsigned int m_len; unsigned int m_len;
unsigned int m_flags; unsigned int m_flags;
pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */
pgoff_t *m_next_extent; /* point to next possible extent */
int m_seg_type; int m_seg_type;
}; };
...@@ -563,6 +565,7 @@ enum { ...@@ -563,6 +565,7 @@ enum {
F2FS_GET_BLOCK_BMAP, F2FS_GET_BLOCK_BMAP,
F2FS_GET_BLOCK_PRE_DIO, F2FS_GET_BLOCK_PRE_DIO,
F2FS_GET_BLOCK_PRE_AIO, F2FS_GET_BLOCK_PRE_AIO,
F2FS_GET_BLOCK_PRECACHE,
}; };
/* /*
...@@ -2564,6 +2567,7 @@ int f2fs_getattr(const struct path *path, struct kstat *stat, ...@@ -2564,6 +2567,7 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
int f2fs_setattr(struct dentry *dentry, struct iattr *attr); int f2fs_setattr(struct dentry *dentry, struct iattr *attr);
int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end);
void truncate_data_blocks_range(struct dnode_of_data *dn, int count); void truncate_data_blocks_range(struct dnode_of_data *dn, int count);
int f2fs_precache_extents(struct inode *inode);
long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
int f2fs_pin_file_control(struct inode *inode, bool inc); int f2fs_pin_file_control(struct inode *inode, bool inc);
......
...@@ -1423,7 +1423,7 @@ static int expand_inode_data(struct inode *inode, loff_t offset, ...@@ -1423,7 +1423,7 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
{ {
struct f2fs_sb_info *sbi = F2FS_I_SB(inode); struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
struct f2fs_map_blocks map = { .m_next_pgofs = NULL, struct f2fs_map_blocks map = { .m_next_pgofs = NULL,
.m_seg_type = NO_CHECK_TYPE }; .m_next_extent = NULL, .m_seg_type = NO_CHECK_TYPE };
pgoff_t pg_end; pgoff_t pg_end;
loff_t new_size = i_size_read(inode); loff_t new_size = i_size_read(inode);
loff_t off_end; loff_t off_end;
...@@ -2072,7 +2072,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, ...@@ -2072,7 +2072,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
{ {
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
struct f2fs_map_blocks map = { .m_next_pgofs = NULL, struct f2fs_map_blocks map = { .m_next_pgofs = NULL,
.m_seg_type = NO_CHECK_TYPE }; .m_next_extent = NULL, .m_seg_type = NO_CHECK_TYPE };
struct extent_info ei = {0,0,0}; struct extent_info ei = {0,0,0};
pgoff_t pg_start, pg_end; pgoff_t pg_start, pg_end;
unsigned int blk_per_seg = sbi->blocks_per_seg; unsigned int blk_per_seg = sbi->blocks_per_seg;
...@@ -2749,6 +2749,43 @@ static int f2fs_ioc_get_pin_file(struct file *filp, unsigned long arg) ...@@ -2749,6 +2749,43 @@ static int f2fs_ioc_get_pin_file(struct file *filp, unsigned long arg)
return put_user(pin, (u32 __user *)arg); return put_user(pin, (u32 __user *)arg);
} }
int f2fs_precache_extents(struct inode *inode)
{
struct f2fs_inode_info *fi = F2FS_I(inode);
struct f2fs_map_blocks map;
pgoff_t m_next_extent;
loff_t end;
int err;
if (is_inode_flag_set(inode, FI_NO_EXTENT))
return -EOPNOTSUPP;
map.m_lblk = 0;
map.m_next_pgofs = NULL;
map.m_next_extent = &m_next_extent;
map.m_seg_type = NO_CHECK_TYPE;
end = F2FS_I_SB(inode)->max_file_blocks;
while (map.m_lblk < end) {
map.m_len = end - map.m_lblk;
down_write(&fi->dio_rwsem[WRITE]);
err = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_PRECACHE);
up_write(&fi->dio_rwsem[WRITE]);
if (err)
return err;
map.m_lblk = m_next_extent;
}
return err;
}
static int f2fs_ioc_precache_extents(struct file *filp, unsigned long arg)
{
return f2fs_precache_extents(file_inode(filp));
}
long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{ {
if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp)))))
...@@ -2803,6 +2840,8 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -2803,6 +2840,8 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
return f2fs_ioc_get_pin_file(filp, arg); return f2fs_ioc_get_pin_file(filp, arg);
case F2FS_IOC_SET_PIN_FILE: case F2FS_IOC_SET_PIN_FILE:
return f2fs_ioc_set_pin_file(filp, arg); return f2fs_ioc_set_pin_file(filp, arg);
case F2FS_IOC_PRECACHE_EXTENTS:
return f2fs_ioc_precache_extents(filp, arg);
default: default:
return -ENOTTY; return -ENOTTY;
} }
...@@ -2880,6 +2919,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -2880,6 +2919,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
case F2FS_IOC_FSSETXATTR: case F2FS_IOC_FSSETXATTR:
case F2FS_IOC_GET_PIN_FILE: case F2FS_IOC_GET_PIN_FILE:
case F2FS_IOC_SET_PIN_FILE: case F2FS_IOC_SET_PIN_FILE:
case F2FS_IOC_PRECACHE_EXTENTS:
break; break;
default: default:
return -ENOIOCTLCMD; return -ENOIOCTLCMD;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册