f2fs: support file defragment
RFC PATCH 1/1 f2fs: support file defragment
This patch introduces a new ioctl F2FS_IOC_DEFRAGMENT to support file defragment in a specified range of regular file.
Signed-off-by Chao Yu <[email protected]>
--- fs/f2fs/data.c | 6 +- fs/f2fs/f2fs.h | 8 +++ fs/f2fs/file.c | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+), 1 deletion(-)
fs/f2fs/data.c +5 -1
@@ -561,7 +561,7 @@ out:* b. do not use extent cache for better performance * c. give the block addresses to blockdev */ -static int f2fs_map_blocks (struct inode *inode,struct f2fs_map_blocks *map, +int f2fs_map_blocks (struct inode *inode,struct f2fs_map_blocks *map,int create,int flag) {unsigned int maxblocks = map->m_len;
@@ -1336,6 +1336,10 @@ static int f2fs_write_data_pages(struct address_space *mapping, available_free_memory(sbi, DIRTY_DENTS)) goto skip_write; +/* skip writing during file defragment */ +if (is_inode_flag_set (F2FS_I (inode),FI_DO_DEFRAG )) + goto skip_write; +/* during POR, we don't need to trigger writepage at all. */ if (unlikely (is_sbi_flag_set (sbi,SBI_POR_DOING ))) goto skip_write;
fs/f2fs/f2fs.h +8 -0
@@ -230,6 +230,7 @@ static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size,#define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4)#define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)#define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) +#define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 7)#define F2FS_IOC_SET_ENCRYPTION_POLICY \ _IOR('f', 19, struct f2fs_encryption_policy)
@@ -255,6 +256,11 @@ static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size,#define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS#endif +struct f2fs_defragment { +u64 start; +u64 len; +}; +/* * For INODE and NODE manager */
@@ -1391,6 +1397,7 @@ enum {FI_DROP_CACHE ,/* drop dirty page cache */ FI_DATA_EXIST ,/* indicate data exists */ FI_INLINE_DOTS ,/* indicate inline dot dentries */ + FI_DO_DEFRAG, /* indicate defragment is running */ };static inline void set_inode_flag (struct f2fs_inode_info *fi,int flag)
@@ -1799,6 +1806,7 @@ struct page *find_data_page(struct inode *, pgoff_t);struct page *get_lock_data_page (struct inode *,pgoff_t );struct page *get_new_data_page (struct inode *,struct page *,pgoff_t ,bool );int do_write_data_page (struct f2fs_io_info *); +int f2fs_map_blocks (struct inode *,struct f2fs_map_blocks *,int ,int );int f2fs_fiemap (struct inode *inode,struct fiemap_extent_info *,u64 ,u64 );void f2fs_invalidate_page (struct page *,unsigned int ,unsigned int );int f2fs_release_page (struct page *,gfp_t );
fs/f2fs/file.c +183 -0
195 lines not on this page · raw message
Signature · 1 line
2.5.2