f2fs: fix not to check IS_ERR for null pointer
Subsystems (3)
Jaegeuk Kim
maintainerPATCH 1/19 f2fs: fix not to check IS_ERR for null pointer
The acl can have null, error pointer, or valid pointer. So, we should check its pointer existence too.
--- fs/f2fs/acl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/acl.c +1 -1
@@ -190,7 +190,7 @@ static struct posix_acl *__f2fs_get_acl(struct inode *inode, int type, acl =ERR_PTR (retval);kfree (value); -if (!IS_ERR (acl)) +if (!IS_ERR_OR_NULL (acl))set_cached_acl (inode, type, acl);return acl;
Signature · 1 line
2.1.1
Jaegeuk Kim
maintainerPATCH 2/19 f2fs: add missing version info in superblock
The mkfs.f2fs remains kernel version in superblock, but f2fs module has not added that so far.
--- include/linux/f2fs_fs.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/f2fs_fs.h +5 -0
@@ -50,6 +50,8 @@#define MAX_ACTIVE_NODE_LOGS 8#define MAX_ACTIVE_DATA_LOGS 8 +#define VERSION_LEN 256 +/* * For superblock */
@@ -86,6 +88,9 @@ struct f2fs_super_block {__le32 extension_count;/* # of extensions below */ __u8 extension_list[F2FS_MAX_EXTENSION ][8 ];/* extension array */ __le32 cp_payload; +__u8 version[VERSION_LEN ];/* the kernel version */ +__u8 init_version[VERSION_LEN ];/* the initial kernel version */ +__u8 reserved[892 ];/* valid reserved region */ } __packed;/*
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 3/19 f2fs: move existing definitions into f2fs.h
In reply to Jaegeuk KimThis patch moves some inode-related definitions from node.h to f2fs.h to add new features.
--- fs/f2fs/f2fs.h | 22 ++++++++++++++++++++++ fs/f2fs/node.h | 22 ---------------------- 2 files changed, 22 insertions(+), 22 deletions(-)
fs/f2fs/f2fs.h +22 -0
@@ -320,6 +320,13 @@ struct extent_tree {#define FADVISE_COLD_BIT 0x01#define FADVISE_LOST_PINO_BIT 0x02 +#define file_is_cold (inode) is_file(inode, FADVISE_COLD_BIT) +#define file_wrong_pino (inode) is_file(inode, FADVISE_LOST_PINO_BIT) +#define file_set_cold (inode) set_file(inode, FADVISE_COLD_BIT) +#define file_lost_pino (inode) set_file(inode, FADVISE_LOST_PINO_BIT) +#define file_clear_cold (inode) clear_file(inode, FADVISE_COLD_BIT) +#define file_got_pino (inode) clear_file(inode, FADVISE_LOST_PINO_BIT) +#define DEF_DIR_LEVEL 0struct f2fs_inode_info {
@@ -1391,6 +1398,21 @@ static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)kunmap (page); } +static inline int is_file (struct inode *inode,int type) +{ +return F2FS_I (inode)->i_advise & type; +} + +static inline void set_file (struct inode *inode,int type) +{ +F2FS_I (inode)->i_advise |= type; +} + +static inline void clear_file (struct inode *inode,int type) +{ +F2FS_I (inode)->i_advise &= ~type; +} +static inline int f2fs_readonly (struct super_block *sb) {return sb->s_flags &MS_RDONLY ;
fs/f2fs/node.h +0 -22
@@ -343,28 +343,6 @@ static inline nid_t get_nid(struct page *p, int off, bool i)* - Mark cold node blocks in their node footer * - Mark cold data pages in page cache */ -static inline int is_file (struct inode *inode,int type) -{ -return F2FS_I (inode)->i_advise & type; -} - -static inline void set_file (struct inode *inode,int type) -{ -F2FS_I (inode)->i_advise |= type; -} - -static inline void clear_file (struct inode *inode,int type) -{ -F2FS_I (inode)->i_advise &= ~type; -} - -#define file_is_cold (inode) is_file(inode, FADVISE_COLD_BIT) -#define file_wrong_pino (inode) is_file(inode, FADVISE_LOST_PINO_BIT) -#define file_set_cold (inode) set_file(inode, FADVISE_COLD_BIT) -#define file_lost_pino (inode) set_file(inode, FADVISE_LOST_PINO_BIT) -#define file_clear_cold (inode) clear_file(inode, FADVISE_COLD_BIT) -#define file_got_pino (inode) clear_file(inode, FADVISE_LOST_PINO_BIT) -static inline int is_cold_data (struct page *page) {return PageChecked (page);
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 4/19 f2fs: add feature facility in superblock
In reply to Jaegeuk KimThis patch introduces a feature in superblock, which will indicate any new features for f2fs.
--- fs/f2fs/f2fs.h | 7 +++++++ include/linux/f2fs_fs.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-)
fs/f2fs/f2fs.h +7 -0
@@ -70,6 +70,13 @@ struct f2fs_mount_info {unsigned int opt; }; +#define F2FS_HAS_FEATURE (sb, mask) \ + ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) +#define F2FS_SET_FEATURE (sb, mask) \ + F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask) +#define F2FS_CLEAR_FEATURE (sb, mask) \ + F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask) +#define CRCPOLY_LE 0xedb88320static inline __u32 f2fs_crc32 (void *buf,size_t len)
include/linux/f2fs_fs.h +2 -1
@@ -90,7 +90,8 @@ struct f2fs_super_block {__le32 cp_payload;__u8 version[VERSION_LEN ];/* the kernel version */ __u8 init_version[VERSION_LEN ];/* the initial kernel version */ -__u8 reserved[892 ];/* valid reserved region */ +__le32 feature;/* defined features */ +__u8 reserved[888 ];/* valid reserved region */ } __packed;/*
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 5/19 f2fs: add f2fs_map_blocks
In reply to Jaegeuk KimThis patch introduces f2fs_map_blocks structure likewise ext4_map_blocks. Now, f2fs uses f2fs_map_blocks when handling get_block.
--- fs/f2fs/data.c | 72 ++++++++++++++++++++++++++------------------- fs/f2fs/f2fs.h | 16 ++++++++++ include/trace/events/f2fs.h | 28 +++++++++--------- 3 files changed, 71 insertions(+), 45 deletions(-)
fs/f2fs/data.c +41 -31
@@ -251,19 +251,6 @@ int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index)return err; } -static void f2fs_map_bh (struct super_block *sb,pgoff_t pgofs, -struct extent_info *ei,struct buffer_head *bh_result) -{ -unsigned int blkbits = sb->s_blocksize_bits; -size_t max_size = bh_result->b_size; -size_t mapped_size; - -clear_buffer_new (bh_result); -map_bh (bh_result, sb, ei->blk + pgofs - ei->fofs); - mapped_size = (ei->fofs + ei->len - pgofs) << blkbits; - bh_result->b_size =min (max_size, mapped_size); -} -static bool lookup_extent_info (struct inode *inode,pgoff_t pgofs,struct extent_info *ei) {
@@ -1208,18 +1195,18 @@ out: }/* -* get_data_block() now supported readahead/bmap/rw direct_IO with mapped bh. +* f2fs_map_blocks() now supported readahead/bmap/rw direct_IO with +* f2fs_map_blocks structure. * If original data blocks are allocated, then give them to blockdev. * Otherwise, * a. preallocate requested block addresses * b. do not use extent cache for better performance * c. give the block addresses to blockdev */ -static int __get_data_block (struct inode *inode,sector_t iblock, -struct buffer_head *bh_result,int create,bool fiemap) +static int f2fs_map_blocks (struct inode *inode,struct f2fs_map_blocks *map, +int create,bool fiemap) { -unsigned int blkbits = inode->i_sb->s_blocksize_bits; -unsigned maxblocks = bh_result->b_size >> blkbits; +unsigned int maxblocks = map->m_len;struct dnode_of_data dn;int mode = create ?ALLOC_NODE :LOOKUP_NODE_RA ;pgoff_t pgofs, end_offset;
@@ -1227,11 +1214,16 @@ static int __get_data_block(struct inode *inode, sector_t iblock,struct extent_info ei;bool allocated = false; -/* Get the page offset from the block offset(iblock) */ - pgofs = (pgoff_t)(iblock >> (PAGE_CACHE_SHIFT - blkbits)); + map->m_len =0 ; + map->m_flags =0 ; + +/* it only supports block size == page size */ + pgofs = (pgoff_t )map->m_lblk;if (f2fs_lookup_extent_cache (inode, pgofs, &ei)) { -f2fs_map_bh (inode->i_sb, pgofs, &ei, bh_result); + map->m_pblk = ei.blk + pgofs - ei.fofs; + map->m_len =min ((pgoff_t )maxblocks, ei.fofs + ei.len - pgofs); + map->m_flags =F2FS_MAP_MAPPED ; goto out; }
@@ -1250,21 +1242,21 @@ static int __get_data_block(struct inode *inode, sector_t iblock, goto put_out;if (dn.data_blkaddr !=NULL_ADDR ) { -clear_buffer_new (bh_result); -map_bh (bh_result, inode->i_sb, dn.data_blkaddr); + map->m_flags =F2FS_MAP_MAPPED ; + map->m_pblk = dn.data_blkaddr; }else if (create) { err =__allocate_data_block (&dn);if (err) goto put_out; allocated = true; -set_buffer_new (bh_result); -map_bh (bh_result, inode->i_sb, dn.data_blkaddr); + map->m_flags =F2FS_MAP_NEW |F2FS_MAP_MAPPED ; + map->m_pblk = dn.data_blkaddr; }else { goto put_out; } end_offset =ADDRS_PER_PAGE (dn.node_page,F2FS_I (inode)); - bh_result->b_size = (((size_t )1 ) << blkbits); + map->m_len =1 ; dn.ofs_in_node++; pgofs++;
@@ -1288,22 +1280,22 @@ get_next: end_offset =ADDRS_PER_PAGE (dn.node_page,F2FS_I (inode)); } -if (maxblocks > (bh_result->b_size >> blkbits)) { +if (maxblocks > map->m_len) {block_t blkaddr =datablock_addr (dn.node_page, dn.ofs_in_node);if (blkaddr ==NULL_ADDR && create) { err =__allocate_data_block (&dn);if (err) goto sync_out; allocated = true; -set_buffer_new (bh_result); + map->m_flags |=F2FS_MAP_NEW ; blkaddr = dn.data_blkaddr; }/* Give more consecutive addresses for the readahead */ -if (blkaddr == (bh_result->b_blocknr + ofs)) { +if (map->m_pblk !=NEW_ADDR && blkaddr == (map->m_pblk + ofs)) { ofs++; dn.ofs_in_node++; pgofs++; - bh_result->b_size += (((size_t )1 ) << blkbits); + map->m_len++; goto get_next; } }
@@ -1316,10 +1308,28 @@ unlock_out:if (create)f2fs_unlock_op (F2FS_I_SB (inode)); out: -trace_f2fs_get_data_block (inode, iblock, bh_result, err); +trace_f2fs_map_blocks (inode, map, err);return err; } +static int __get_data_block (struct inode *inode,sector_t iblock, +struct buffer_head *bh,int create,bool fiemap) +{ +struct f2fs_map_blocks map; +int ret; + + map.m_lblk = iblock; + map.m_len = bh->b_size >> inode->i_blkbits; + + ret =f2fs_map_blocks (inode, &map, create, fiemap); +if (!ret) { +map_bh (bh, inode->i_sb, map.m_pblk); + bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS ) | map.m_flags; + bh->b_size = map.m_len << inode->i_blkbits; + } +return ret; +} +static int get_data_block (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create) {
fs/f2fs/f2fs.h +16 -0
@@ -322,6 +322,22 @@ struct extent_tree { };/* +* This structure is taken from ext4_map_blocks. +* +* Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). +*/ +#define F2FS_MAP_NEW (1 << BH_New) +#define F2FS_MAP_MAPPED (1 << BH_Mapped) +#define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED) + +struct f2fs_map_blocks { +block_t m_pblk; +block_t m_lblk; +unsigned int m_len; +unsigned int m_flags; +}; + +/* * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. */ #define FADVISE_COLD_BIT 0x01
include/trace/events/f2fs.h +14 -14
@@ -117,6 +117,7 @@ TRACE_DEFINE_ENUM(CP_DISCARD); { CP_DISCARD, "Discard" })struct victim_sel_policy ; +struct f2fs_map_blocks ; DECLARE_EVENT_CLASS(f2fs__inode,
@@ -481,36 +482,35 @@ TRACE_EVENT(f2fs_truncate_partial_nodes, __entry->err) ); -TRACE_EVENT (f2fs_get_data_block, - TP_PROTO(struct inode *inode, sector_t iblock, - struct buffer_head *bh, int ret), +TRACE_EVENT (f2fs_map_blocks, + TP_PROTO(struct inode *inode, struct f2fs_map_blocks *map, int ret), -TP_ARGS (inode, iblock, bh, ret), +TP_ARGS (inode, map, ret),TP_STRUCT__entry ( __field(dev_t, dev) __field(ino_t, ino) - __field(sector_t, iblock) - __field(sector_t, bh_start) - __field(size_t, bh_size) + __field(block_t, m_lblk) + __field(block_t, m_pblk) + __field(unsigned int, m_len)__field (int, ret) ),TP_fast_assign ( __entry->dev = inode->i_sb->s_dev; __entry->ino = inode->i_ino; - __entry->iblock = iblock; - __entry->bh_start = bh->b_blocknr; - __entry->bh_size = bh->b_size; + __entry->m_lblk = map->m_lblk; + __entry->m_pblk = map->m_pblk; + __entry->m_len = map->m_len; __entry->ret = ret; ),TP_printk ("dev = (%d,%d), ino = %lu, file offset = %llu, " -"start blkaddr = 0x%llx, len = 0x%llx bytes, err = %d" , +"start blkaddr = 0x%llx, len = 0x%llx, err = %d" ,show_dev_ino (__entry), - (unsigned long long )__entry->iblock, - (unsigned long long )__entry->bh_start, - (unsigned long long )__entry->bh_size, + (unsigned long long )__entry->m_lblk, + (unsigned long long )__entry->m_pblk, + (unsigned long long )__entry->m_len, __entry->ret) );
Signature · 1 line
2.1.1
Jaegeuk Kim
maintainerPATCH 6/19 f2fs: introduce f2fs_commit_super
In reply to Jaegeuk KimThis patch introduces f2fs_commit_super to write updated superblock.
--- fs/f2fs/f2fs.h | 1 + fs/f2fs/super.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+)
fs/f2fs/f2fs.h +1 -0
@@ -1535,6 +1535,7 @@ static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)/* * super.c */ +int f2fs_commit_super (struct f2fs_sb_info *);int f2fs_sync_fs (struct super_block *,int ); extern __printf(3, 4) void f2fs_msg(struct super_block *, const char *, const char *, ...);
fs/f2fs/super.c +24 -0
@@ -966,6 +966,30 @@ retry:return 0 ; } +int f2fs_commit_super (struct f2fs_sb_info *sbi) +{ +struct buffer_head *sbh = sbi->raw_super_buf; +sector_t block = sbh->b_blocknr; +int err; + +/* write back-up superblock first */ + sbh->b_blocknr = block ?0 :1 ; +mark_buffer_dirty (sbh); + err =sync_dirty_buffer (sbh); + + sbh->b_blocknr = block; +if (err) + goto out; + +/* write current valid superblock */ +mark_buffer_dirty (sbh); + err =sync_dirty_buffer (sbh); +out: +clear_buffer_write_io_error (sbh); +set_buffer_uptodate (sbh); +return err; +} +static int f2fs_fill_super (struct super_block *sb,void *data,int silent) {struct f2fs_sb_info *sbi;
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 7/19 f2fs: expose f2fs_mpage_readpages
In reply to Jaegeuk KimThis patch implements f2fs_mpage_readpages for further optimization on encryption support.
The basic code was taken from fs/mpage.c, and changed to be simple by adjusting that block_size is equal to page_size in f2fs.
--- fs/f2fs/data.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 154 insertions(+), 3 deletions(-)
fs/f2fs/data.c +154 -3
@@ -18,6 +18,7 @@#include <linux/bio.h> #include <linux/prefetch.h> #include <linux/uio.h> +#include <linux/cleancache.h> #include "f2fs.h" #include "node.h"
@@ -47,6 +48,30 @@ static void f2fs_read_end_io(struct bio *bio, int err)bio_put (bio); } +/* +* I/O completion handler for multipage BIOs. +* copied from fs/mpage.c +*/ +static void mpage_end_io (struct bio *bio,int err) +{ +struct bio_vec *bv; +int i; + +bio_for_each_segment_all (bv, bio, i) { +struct page *page = bv->bv_page; + +if (!err) { +SetPageUptodate (page); + }else { +ClearPageUptodate (page); +SetPageError (page); + } +unlock_page (page); + } + +bio_put (bio); +} +static void f2fs_write_end_io (struct bio *bio,int err) {struct f2fs_sb_info *sbi = bio->bi_private;
@@ -1349,6 +1374,133 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, start, len, get_data_block_fiemap); } +/* +* This function was originally taken from fs/mpage.c, and customized for f2fs. +* Major change was from block_size == page_size in f2fs by default. +*/ +static int f2fs_mpage_readpages (struct address_space *mapping, +struct list_head *pages,struct page *page, +unsigned nr_pages) +{ +struct bio *bio =NULL ; +unsigned page_idx; +sector_t last_block_in_bio =0 ; +struct inode *inode = mapping->host; +const unsigned blkbits = inode->i_blkbits; +const unsigned blocksize =1 << blkbits; +sector_t block_in_file; +sector_t last_block; +sector_t last_block_in_file; +sector_t block_nr; +struct block_device *bdev = inode->i_sb->s_bdev; +struct f2fs_map_blocks map; + + map.m_pblk =0 ; + map.m_lblk =0 ; + map.m_len =0 ; + map.m_flags =0 ; + +for (page_idx =0 ; nr_pages; page_idx++, nr_pages--) { + +prefetchw (&page->flags); +if (pages) { + page = list_entry(pages->prev, struct page, lru); +list_del (&page->lru); +if (add_to_page_cache_lru (page, mapping, + page->index,GFP_KERNEL )) + goto next_page; + } + + block_in_file = (sector_t )page->index; + last_block = block_in_file + nr_pages; + last_block_in_file = (i_size_read (inode) + blocksize -1 ) >> + blkbits; +if (last_block > last_block_in_file) + last_block = last_block_in_file; + +/* +* Map blocks using the previous result first. +*/ +if ((map.m_flags &F2FS_MAP_MAPPED ) && + block_in_file > map.m_lblk && + block_in_file < (map.m_lblk + map.m_len)) + goto got_it; + +/* +* Then do more f2fs_map_blocks() calls until we are +* done with this page. +*/ + map.m_flags =0 ; + +if (block_in_file < last_block) { + map.m_lblk = block_in_file; + map.m_len = last_block - block_in_file; + +if (f2fs_map_blocks (inode, &map,0 , false)) + goto set_error_page; + } +got_it: +if ((map.m_flags &F2FS_MAP_MAPPED )) { + block_nr = map.m_pblk + block_in_file - map.m_lblk; +SetPageMappedToDisk (page); + +if (!PageUptodate (page) && !cleancache_get_page (page)) { +SetPageUptodate (page); + goto confused; + } + }else { +zero_user_segment (page,0 ,PAGE_CACHE_SIZE ); +SetPageUptodate (page); +unlock_page (page); + goto next_page; + } + +/* +* This page will go to BIO. Do we need to send this +* BIO off first? +*/ +if (bio && (last_block_in_bio != block_nr -1 )) { +submit_and_realloc: +submit_bio (READ , bio); + bio =NULL ; + } +if (bio ==NULL ) { + bio =bio_alloc (GFP_KERNEL , +min_t (int, nr_pages,bio_get_nr_vecs (bdev))); +if (!bio) + goto set_error_page; + bio->bi_bdev = bdev; + bio->bi_iter.bi_sector =SECTOR_FROM_BLOCK (block_nr); + bio->bi_end_io = mpage_end_io; + bio->bi_private =NULL ; + } + +if (bio_add_page (bio, page, blocksize,0 ) < blocksize) + goto submit_and_realloc; + + last_block_in_bio = block_nr; + goto next_page; +set_error_page: +SetPageError (page); +zero_user_segment (page,0 ,PAGE_CACHE_SIZE ); +unlock_page (page); + goto next_page; +confused: +if (bio) { +submit_bio (READ , bio); + bio =NULL ; + } +unlock_page (page); +next_page: +if (pages) +page_cache_release (page); + } +BUG_ON (pages && !list_empty (pages)); +if (bio) +submit_bio (READ , bio); +return 0 ; +} +static int f2fs_read_data_page (struct file *file,struct page *page) {struct inode *inode = page->mapping->host;
@@ -1360,8 +1512,7 @@ static int f2fs_read_data_page(struct file *file, struct page *page)if (f2fs_has_inline_data (inode)) ret =f2fs_read_inline_data (inode, page);if (ret == -EAGAIN ) - ret =mpage_readpage (page, get_data_block); - + ret =f2fs_mpage_readpages (page->mapping,NULL , page,1 );return ret; }
@@ -1375,7 +1526,7 @@ static int f2fs_read_data_pages(struct file *file,if (f2fs_has_inline_data (inode))return 0 ; -return mpage_readpages (mapping, pages, nr_pages, get_data_block); +return f2fs_mpage_readpages (mapping, pages,NULL , nr_pages); }int do_write_data_page (struct page *page,struct f2fs_io_info *fio)
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 8/19 f2fs: clean up f2fs_lookup
In reply to Jaegeuk KimThis patch cleans up to avoid deep indentation.
--- fs/f2fs/namei.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
fs/f2fs/namei.c +16 -15
@@ -232,31 +232,32 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,struct inode *inode =NULL ;struct f2fs_dir_entry *de;struct page *page; +nid_t ino;if (dentry->d_name.len >F2FS_NAME_LEN )return ERR_PTR (-ENAMETOOLONG ); de =f2fs_find_entry (dir, &dentry->d_name, &page); -if (de) { -nid_t ino =le32_to_cpu (de->ino); -f2fs_dentry_kunmap (dir, page); -f2fs_put_page (page,0 ); +if (!de) +return d_splice_alias (inode, dentry); - inode =f2fs_iget (dir->i_sb, ino); -if (IS_ERR (inode)) -return ERR_CAST (inode); + ino =le32_to_cpu (de->ino); +f2fs_dentry_kunmap (dir, page); +f2fs_put_page (page,0 ); -if (f2fs_has_inline_dots (inode)) { -int err; + inode =f2fs_iget (dir->i_sb, ino); +if (IS_ERR (inode)) +return ERR_CAST (inode); + +if (f2fs_has_inline_dots (inode)) { +int err; - err =__recover_dot_dentries (inode, dir->i_ino); -if (err) { -iget_failed (inode); -return ERR_PTR (err); - } + err =__recover_dot_dentries (inode, dir->i_ino); +if (err) { +iget_failed (inode); +return ERR_PTR (err); } } -return d_splice_alias (inode, dentry); }
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 9/19 f2fs: add f2fs_may_inline_{data, dentry}
In reply to Jaegeuk KimThis patch adds f2fs_may_inline_data and f2fs_may_inline_dentry.
--- fs/f2fs/f2fs.h | 3 ++- fs/f2fs/file.c | 2 +- fs/f2fs/inline.c | 13 ++++++++++++- fs/f2fs/namei.c | 4 ++-- 4 files changed, 17 insertions(+), 5 deletions(-)
fs/f2fs/f2fs.h +2 -1
@@ -1839,7 +1839,8 @@ extern struct kmem_cache *inode_entry_slab;/* * inline.c */ -bool f2fs_may_inline (struct inode *); +bool f2fs_may_inline_data (struct inode *); +bool f2fs_may_inline_dentry (struct inode *);void read_inline_data (struct page *,struct page *);bool truncate_inline_inode (struct page *,u64 );int f2fs_read_inline_data (struct inode *,struct page *);
fs/f2fs/file.c +1 -1
@@ -560,7 +560,7 @@ void f2fs_truncate(struct inode *inode)trace_f2fs_truncate (inode);/* we should check inline_data size */ -if (f2fs_has_inline_data (inode) && !f2fs_may_inline (inode)) { +if (f2fs_has_inline_data (inode) && !f2fs_may_inline_data (inode)) {if (f2fs_convert_inline_inode (inode))return ; }
fs/f2fs/inline.c +12 -1
@@ -13,7 +13,7 @@#include "f2fs.h" -bool f2fs_may_inline (struct inode *inode) +bool f2fs_may_inline_data (struct inode *inode) {if (!test_opt (F2FS_I_SB (inode),INLINE_DATA ))return false;
@@ -30,6 +30,17 @@ bool f2fs_may_inline(struct inode *inode)return true; } +bool f2fs_may_inline_dentry (struct inode *inode) +{ +if (!test_opt (F2FS_I_SB (inode),INLINE_DENTRY )) +return false; + +if (!S_ISDIR (inode->i_mode)) +return false; + +return true; +} +void read_inline_data (struct page *page,struct page *ipage) {void *src_addr, *dst_addr;
fs/f2fs/namei.c +2 -2
@@ -56,9 +56,9 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) goto out; } -if (f2fs_may_inline (inode)) +if (f2fs_may_inline_data (inode))set_inode_flag (F2FS_I (inode),FI_INLINE_DATA ); -if (test_opt (sbi,INLINE_DENTRY ) &&S_ISDIR (inode->i_mode)) +if (f2fs_may_inline_dentry (inode))set_inode_flag (F2FS_I (inode),FI_INLINE_DENTRY );trace_f2fs_new_inode (inode,0 );
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 10/19 f2fs: add sbi and page pointer in f2fs_io_info
In reply to Jaegeuk KimThis patch adds f2fs_sb_info and page pointers in f2fs_io_info structure. With this change, we can reduce a lot of parameters for IO functions.
--- fs/f2fs/checkpoint.c | 9 +++++++-- fs/f2fs/data.c | 47 +++++++++++++++++++++++++++++------------------ fs/f2fs/f2fs.h | 18 ++++++++---------- fs/f2fs/file.c | 2 +- fs/f2fs/gc.c | 4 +++- fs/f2fs/inline.c | 4 +++- fs/f2fs/node.c | 8 ++++++-- fs/f2fs/segment.c | 38 ++++++++++++++++++++------------------ fs/f2fs/super.c | 2 +- fs/f2fs/trace.c | 6 +++--- fs/f2fs/trace.h | 2 +- 11 files changed, 82 insertions(+), 58 deletions(-)
fs/f2fs/checkpoint.c +7 -2
@@ -52,6 +52,7 @@ struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)struct address_space *mapping =META_MAPPING (sbi);struct page *page;struct f2fs_io_info fio = { + .sbi = sbi, .type =META , .rw =READ_SYNC |REQ_META |REQ_PRIO , .blk_addr = index,
@@ -65,7 +66,9 @@ repeat:if (PageUptodate (page)) goto out; -if (f2fs_submit_page_bio (sbi, page, &fio)) + fio.page = page; + +if (f2fs_submit_page_bio (&fio)) goto repeat;lock_page (page);
@@ -117,6 +120,7 @@ int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, int typestruct page *page;block_t blkno = start;struct f2fs_io_info fio = { + .sbi = sbi, .type =META , .rw =READ_SYNC |REQ_META |REQ_PRIO };
@@ -160,7 +164,8 @@ int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, int typecontinue ; } -f2fs_submit_page_mbio (sbi, page, &fio); + fio.page = page; +f2fs_submit_page_mbio (&fio);f2fs_put_page (page,0 ); } out:
fs/f2fs/data.c +29 -18
160 lines not on this page · raw message
fs/f2fs/f2fs.h +8 -10
@@ -601,9 +601,11 @@ enum page_type { };struct f2fs_io_info { +struct f2fs_sb_info *sbi;/* f2fs_sb_info pointer */ enum page_type type;/* contains DATA/NODE/META/META_FLUSH */ int rw;/* contains R/RS/W/WS with REQ_META/REQ_PRIO */ block_t blk_addr;/* block address to be written */ +struct page *page;/* page to be written */ };#define is_read_io (rw) (((rw) & 1) == READ)
@@ -1601,11 +1603,9 @@ void allocate_new_segments(struct f2fs_sb_info *);int f2fs_trim_fs (struct f2fs_sb_info *,struct fstrim_range *);struct page *get_sum_page (struct f2fs_sb_info *,unsigned int );void write_meta_page (struct f2fs_sb_info *,struct page *); -void write_node_page (struct f2fs_sb_info *,struct page *, -unsigned int ,struct f2fs_io_info *); -void write_data_page (struct page *,struct dnode_of_data *, -struct f2fs_io_info *); -void rewrite_data_page (struct page *,struct f2fs_io_info *); +void write_node_page (unsigned int ,struct f2fs_io_info *); +void write_data_page (struct dnode_of_data *,struct f2fs_io_info *); +void rewrite_data_page (struct f2fs_io_info *);void recover_data_page (struct f2fs_sb_info *,struct page *,struct f2fs_summary *,block_t ,block_t ); void allocate_data_block(struct f2fs_sb_info *, struct page *,
@@ -1653,10 +1653,8 @@ void destroy_checkpoint_caches(void);* data.c */ void f2fs_submit_merged_bio (struct f2fs_sb_info *,enum page_type ,int ); -int f2fs_submit_page_bio (struct f2fs_sb_info *,struct page *, -struct f2fs_io_info *); -void f2fs_submit_page_mbio (struct f2fs_sb_info *,struct page *, -struct f2fs_io_info *); +int f2fs_submit_page_bio (struct f2fs_io_info *); +void f2fs_submit_page_mbio (struct f2fs_io_info *);void set_data_blkaddr (struct dnode_of_data *);int reserve_new_block (struct dnode_of_data *);int f2fs_reserve_block (struct dnode_of_data *,pgoff_t );
@@ -1668,7 +1666,7 @@ void f2fs_preserve_extent_tree(struct inode *);struct page *find_data_page (struct inode *,pgoff_t ,bool );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 page *,struct f2fs_io_info *); +int do_write_data_page (struct f2fs_io_info *);int f2fs_fiemap (struct inode *inode,struct fiemap_extent_info *,u64 ,u64 );void init_extent_cache_info (struct f2fs_sb_info *);int __init create_extent_cache (void );
fs/f2fs/file.c +1 -1
@@ -271,7 +271,7 @@ flush_out: ret =f2fs_issue_flush (sbi); out:trace_f2fs_sync_file_exit (inode, need_cp, datasync, ret); -f2fs_trace_ios (NULL ,NULL ,1 ); +f2fs_trace_ios (NULL ,1 );return ret; }
fs/f2fs/gc.c +3 -1
@@ -521,8 +521,10 @@ static int check_dnode(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,static void move_data_page (struct inode *inode,struct page *page,int gc_type) {struct f2fs_io_info fio = { + .sbi =F2FS_I_SB (inode), .type =DATA , .rw =WRITE_SYNC , + .page = page, };if (gc_type ==BG_GC ) {
@@ -536,7 +538,7 @@ static void move_data_page(struct inode *inode, struct page *page, int gc_type)if (clear_page_dirty_for_io (page))inode_dec_dirty_pages (inode);set_cold_data (page); -do_write_data_page (page, &fio); +do_write_data_page (&fio);clear_cold_data (page); } out:
fs/f2fs/inline.c +3 -1
@@ -106,8 +106,10 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) {void *src_addr, *dst_addr;struct f2fs_io_info fio = { + .sbi =F2FS_I_SB (dn->inode), .type =DATA , .rw =WRITE_SYNC |REQ_PRIO , + .page = page, };int dirty, err;
@@ -141,7 +143,7 @@ no_update:/* write data page to try to make data consistent */ set_page_writeback (page); fio.blk_addr = dn->data_blkaddr; -write_data_page (page, dn, &fio); +write_data_page (dn, &fio);set_data_blkaddr (dn);f2fs_update_extent_cache (dn);f2fs_wait_on_page_writeback (page,DATA );
fs/f2fs/node.c +6 -2
@@ -995,8 +995,10 @@ static int read_node_page(struct page *page, int rw)struct f2fs_sb_info *sbi =F2FS_P_SB (page);struct node_info ni;struct f2fs_io_info fio = { + .sbi = sbi, .type =NODE , .rw = rw, + .page = page, };get_node_info (sbi, page->index, &ni);
@@ -1011,7 +1013,7 @@ static int read_node_page(struct page *page, int rw)return LOCKED_PAGE ; fio.blk_addr = ni.blk_addr; -return f2fs_submit_page_bio (sbi, page, &fio); +return f2fs_submit_page_bio (&fio); }/*
@@ -1293,8 +1295,10 @@ static int f2fs_write_node_page(struct page *page,nid_t nid;struct node_info ni;struct f2fs_io_info fio = { + .sbi = sbi, .type =NODE , .rw = (wbc->sync_mode ==WB_SYNC_ALL ) ?WRITE_SYNC :WRITE , + .page = page, };trace_f2fs_writepage (page,NODE );
@@ -1329,7 +1333,7 @@ static int f2fs_write_node_page(struct page *page,set_page_writeback (page); fio.blk_addr = ni.blk_addr; -write_node_page (sbi, page, nid, &fio); +write_node_page (nid, &fio);set_node_addr (sbi, &ni, fio.blk_addr,is_fsync_dnode (page));dec_page_count (sbi,F2FS_DIRTY_NODES );up_read (&sbi->node_write);
fs/f2fs/segment.c +20 -18
@@ -216,6 +216,7 @@ void commit_inmem_pages(struct inode *inode, bool abort)struct inmem_pages *cur, *tmp;bool submit_bio = false;struct f2fs_io_info fio = { + .sbi = sbi, .type =DATA , .rw =WRITE_SYNC |REQ_PRIO , };
@@ -241,7 +242,8 @@ void commit_inmem_pages(struct inode *inode, bool abort)if (clear_page_dirty_for_io (cur->page))inode_dec_dirty_pages (inode);trace_f2fs_commit_inmem_page (cur->page,INMEM ); -do_write_data_page (cur->page, &fio); + fio.page = cur->page; +do_write_data_page (&fio); submit_bio = true; }f2fs_put_page (cur->page,1 );
@@ -1206,56 +1208,56 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,mutex_unlock (&curseg->curseg_mutex); } -static void do_write_page (struct f2fs_sb_info *sbi,struct page *page, -struct f2fs_summary *sum, -struct f2fs_io_info *fio) +static void do_write_page (struct f2fs_summary *sum,struct f2fs_io_info *fio) { -int type =__get_segment_type (page, fio->type); +int type =__get_segment_type (fio->page, fio->type); -allocate_data_block (sbi, page, fio->blk_addr, &fio->blk_addr, sum, type); +allocate_data_block (fio->sbi, fio->page, fio->blk_addr, + &fio->blk_addr, sum, type);/* writeout dirty page into bdev */ -f2fs_submit_page_mbio (sbi, page, fio); +f2fs_submit_page_mbio (fio); }void write_meta_page (struct f2fs_sb_info *sbi,struct page *page) {struct f2fs_io_info fio = { + .sbi = sbi, .type =META , .rw =WRITE_SYNC |REQ_META |REQ_PRIO , .blk_addr = page->index, + .page = page, };set_page_writeback (page); -f2fs_submit_page_mbio (sbi, page, &fio); +f2fs_submit_page_mbio (&fio); } -void write_node_page (struct f2fs_sb_info *sbi,struct page *page, -unsigned int nid,struct f2fs_io_info *fio) +void write_node_page (unsigned int nid,struct f2fs_io_info *fio) {struct f2fs_summary sum; +set_summary (&sum, nid,0 ,0 ); -do_write_page (sbi, page, &sum, fio); +do_write_page (&sum, fio); } -void write_data_page (struct page *page,struct dnode_of_data *dn, -struct f2fs_io_info *fio) +void write_data_page (struct dnode_of_data *dn,struct f2fs_io_info *fio) { -struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode); +struct f2fs_sb_info *sbi = fio->sbi;struct f2fs_summary sum;struct node_info ni;f2fs_bug_on (sbi, dn->data_blkaddr ==NULL_ADDR );get_node_info (sbi, dn->nid, &ni);set_summary (&sum, dn->nid, dn->ofs_in_node, ni.version); -do_write_page (sbi, page, &sum, fio); +do_write_page (&sum, fio); dn->data_blkaddr = fio->blk_addr; } -void rewrite_data_page (struct page *page,struct f2fs_io_info *fio) +void rewrite_data_page (struct f2fs_io_info *fio) { -stat_inc_inplace_blocks (F2FS_P_SB (page)); -f2fs_submit_page_mbio (F2FS_P_SB (page), page, fio); +stat_inc_inplace_blocks (fio->sbi); +f2fs_submit_page_mbio (fio); } void recover_data_page(struct f2fs_sb_info *sbi,
fs/f2fs/super.c +1 -1
@@ -520,7 +520,7 @@ int f2fs_sync_fs(struct super_block *sb, int sync) }else {f2fs_balance_fs (sbi); } -f2fs_trace_ios (NULL ,NULL ,1 ); +f2fs_trace_ios (NULL ,1 );return 0 ; }
fs/f2fs/trace.c +3 -3
@@ -80,7 +80,7 @@ out:radix_tree_preload_end (); } -void f2fs_trace_ios (struct page *page,struct f2fs_io_info *fio,int flush) +void f2fs_trace_ios (struct f2fs_io_info *fio,int flush) {struct inode *inode;pid_t pid;
@@ -91,8 +91,8 @@ void f2fs_trace_ios(struct page *page, struct f2fs_io_info *fio, int flush)return ; } - inode = page->mapping->host; - pid =page_private (page); + inode = fio->page->mapping->host; + pid =page_private (fio->page); major =MAJOR (inode->i_sb->s_dev); minor =MINOR (inode->i_sb->s_dev);
fs/f2fs/trace.h +1 -1
@@ -33,7 +33,7 @@ struct last_io_info { };extern void f2fs_trace_pid (struct page *); -extern void f2fs_trace_ios (struct page *,struct f2fs_io_info *,int ); +extern void f2fs_trace_ios (struct f2fs_io_info *,int );extern void f2fs_build_trace_ios (void );extern void f2fs_destroy_trace_ios (void );#else
Signature · 1 line
2.1.1
Jaegeuk Kim
maintainerPATCH 11/19 f2fs: move get_page for gc victims
In reply to Jaegeuk KimThis patch moves getting victim page into move_data_page.
--- fs/f2fs/gc.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
fs/f2fs/gc.c +15 -13
@@ -518,14 +518,13 @@ static int check_dnode(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,return 1 ; } -static void move_data_page (struct inode *inode,struct page *page,int gc_type) +static void move_data_page (struct inode *inode,block_t bidx,int gc_type) { -struct f2fs_io_info fio = { - .sbi =F2FS_I_SB (inode), - .type =DATA , - .rw =WRITE_SYNC , - .page = page, - }; +struct page *page; + + page =get_lock_data_page (inode, bidx); +if (IS_ERR (page)) +return ;if (gc_type ==BG_GC ) {if (PageWriteback (page))
@@ -533,6 +532,12 @@ static void move_data_page(struct inode *inode, struct page *page, int gc_type)set_page_dirty (page);set_cold_data (page); }else { +struct f2fs_io_info fio = { + .sbi =F2FS_I_SB (inode), + .type =DATA , + .rw =WRITE_SYNC , + .page = page, + };f2fs_wait_on_page_writeback (page,DATA );if (clear_page_dirty_for_io (page))
@@ -618,12 +623,9 @@ next_step:/* phase 3 */ inode =find_gc_inode (gc_list, dni.ino);if (inode) { - start_bidx =start_bidx_of_node (nofs,F2FS_I (inode)); - data_page =get_lock_data_page (inode, - start_bidx + ofs_in_node); -if (IS_ERR (data_page)) -continue ; -move_data_page (inode, data_page, gc_type); + start_bidx =start_bidx_of_node (nofs,F2FS_I (inode)) + + ofs_in_node; +move_data_page (inode, start_bidx, gc_type);stat_inc_data_blk_count (sbi,1 , gc_type); } }
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 12/19 f2fs: introduce dot and dotdot name check
In reply to Jaegeuk KimThis patch adds an inline function to check dot and dotdot names.
--- fs/f2fs/f2fs.h | 11 +++++++++++ fs/f2fs/hash.c | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-)
fs/f2fs/f2fs.h +11 -0
@@ -1454,6 +1454,17 @@ static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) sbi->sb->s_flags |=MS_RDONLY ; } +static inline bool is_dot_dotdot (const struct qstr *str) +{ +if (str->len ==1 && str->name[0 ] =='.' ) +return true; + +if (str->len ==2 && str->name[0 ] =='.' && str->name[1 ] =='.' ) +return true; + +return false; +} +#define get_inode_mode (i) \ ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
fs/f2fs/hash.c +1 -2
@@ -79,8 +79,7 @@ f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info)const unsigned char *name = name_info->name;size_t len = name_info->len; -if ((len <=2 ) && (name[0 ] =='.' ) && - (name[1 ] =='.' || name[1 ] =='\0' )) +if (is_dot_dotdot (name_info))return 0 ;/* Initialize the default seed for the hash checksum functions */
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 13/19 f2fs: fix race on allocating and deallocating a dentry block
In reply to Jaegeuk KimThere are two threads:
f2fs_delete_entry() get_new_data_page()
f2fs_reserve_block() dn.blkaddr = XXX
lock_page(dentry_block)
truncate_hole()
dn.blkaddr = NULL
unlock_page(dentry_block)
lock_page(dentry_block) fill the block from XXX address add new dentries unlock_page(dentry_block)
Later, f2fs_write_data_page() will truncate the dentry_block, since its block address is NULL.
The reason for this was due to the wrong lock order.
In this case, we should do f2fs_reserve_block() after locking its dentry block.
--- fs/f2fs/data.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
fs/f2fs/data.c +12 -15
@@ -1076,20 +1076,22 @@ struct page *get_new_data_page(struct inode *inode,struct page *page;struct dnode_of_data dn;int err; +repeat: + page =grab_cache_page (mapping, index); +if (!page) +return ERR_PTR (-ENOMEM );set_new_dnode (&dn, inode, ipage,NULL ,0 ); err =f2fs_reserve_block (&dn, index); -if (err) +if (err) { +f2fs_put_page (page,1 );return ERR_PTR (err); -repeat: - page =grab_cache_page (mapping, index); -if (!page) { - err = -ENOMEM ; - goto put_err; } +if (!ipage) +f2fs_put_dnode (&dn);if (PageUptodate (page)) -return page; + goto got_it;if (dn.data_blkaddr ==NEW_ADDR ) {zero_user_segment (page,0 ,PAGE_CACHE_SIZE );
@@ -1104,20 +1106,19 @@ repeat: }; err =f2fs_submit_page_bio (&fio);if (err) - goto put_err; +return ERR_PTR (err);lock_page (page);if (unlikely (!PageUptodate (page))) {f2fs_put_page (page,1 ); - err = -EIO ; - goto put_err; +return ERR_PTR (-EIO ); }if (unlikely (page->mapping != mapping)) {f2fs_put_page (page,1 ); goto repeat; } } - +got_it:if (new_i_size &&i_size_read (inode) < ((index +1 ) <<PAGE_CACHE_SHIFT )) {i_size_write (inode, ((index +1 ) <<PAGE_CACHE_SHIFT ));
@@ -1125,10 +1126,6 @@ repeat:set_inode_flag (F2FS_I (inode),FI_UPDATE_DIR ); }return page; - -put_err: -f2fs_put_dnode (&dn); -return ERR_PTR (err); }static int __allocate_data_block (struct dnode_of_data *dn)
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 14/19 f2fs: add need_dentry_mark
In reply to Jaegeuk KimThis patch introduces need_dentry_mark() to clean up and avoid redundant node locks.
--- fs/f2fs/f2fs.h | 1 + fs/f2fs/node.c | 35 +++++++++++++++++------------------ 2 files changed, 18 insertions(+), 18 deletions(-)
fs/f2fs/f2fs.h +1 -0
@@ -1565,6 +1565,7 @@ struct dnode_of_data;struct node_info ;bool available_free_memory (struct f2fs_sb_info *,int ); +int need_dentry_mark (struct f2fs_sb_info *,nid_t );bool is_checkpointed_node (struct f2fs_sb_info *,nid_t );bool need_inode_block_update (struct f2fs_sb_info *,nid_t );void get_node_info (struct f2fs_sb_info *,nid_t ,struct node_info *);
fs/f2fs/node.c +17 -18
@@ -195,32 +195,35 @@ static unsigned int __gang_lookup_nat_set(struct f2fs_nm_info *nm_i, start, nr); } -bool is_checkpointed_node (struct f2fs_sb_info *sbi,nid_t nid) +int need_dentry_mark (struct f2fs_sb_info *sbi,nid_t nid) {struct f2fs_nm_info *nm_i =NM_I (sbi);struct nat_entry *e; -bool is_cp = true; +bool need = false;down_read (&nm_i->nat_tree_lock); e =__lookup_nat_cache (nm_i, nid); -if (e && !get_nat_flag (e,IS_CHECKPOINTED )) - is_cp = false; +if (e) { +if (!get_nat_flag (e,IS_CHECKPOINTED ) && + !get_nat_flag (e,HAS_FSYNCED_INODE )) + need = true; + }up_read (&nm_i->nat_tree_lock); -return is_cp; +return need; } -static bool has_fsynced_inode (struct f2fs_sb_info *sbi,nid_t ino) +bool is_checkpointed_node (struct f2fs_sb_info *sbi,nid_t nid) {struct f2fs_nm_info *nm_i =NM_I (sbi);struct nat_entry *e; -bool fsynced = false; +bool is_cp = true;down_read (&nm_i->nat_tree_lock); - e =__lookup_nat_cache (nm_i, ino); -if (e &&get_nat_flag (e,HAS_FSYNCED_INODE )) - fsynced = true; + e =__lookup_nat_cache (nm_i, nid); +if (e && !get_nat_flag (e,IS_CHECKPOINTED )) + is_cp = false;up_read (&nm_i->nat_tree_lock); -return fsynced; +return is_cp; }bool need_inode_block_update (struct f2fs_sb_info *sbi,nid_t ino)
@@ -1206,13 +1209,9 @@ continue_unlock:/* called by fsync() */ if (ino &&IS_DNODE (page)) {set_fsync_mark (page,1 ); -if (IS_INODE (page)) { -if (!is_checkpointed_node (sbi, ino) && - !has_fsynced_inode (sbi, ino)) -set_dentry_mark (page,1 ); -else -set_dentry_mark (page,0 ); - } +if (IS_INODE (page)) +set_dentry_mark (page, +need_dentry_mark (sbi, ino)); nwritten++; }else {set_fsync_mark (page,0 );
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 15/19 f2fs: fix counting the number of inline_data inodes
In reply to Jaegeuk KimThis patch fixes to count the missing symlink case.
--- fs/f2fs/namei.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/namei.c +3 -3
@@ -61,6 +61,9 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)if (f2fs_may_inline_dentry (inode))set_inode_flag (F2FS_I (inode),FI_INLINE_DENTRY ); +stat_inc_inline_inode (inode); +stat_inc_inline_dir (inode); +trace_f2fs_new_inode (inode,0 );mark_inode_dirty (inode);return inode;
@@ -136,7 +139,6 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,alloc_nid_done (sbi, ino); -stat_inc_inline_inode (inode);d_instantiate (dentry, inode);unlock_new_inode (inode);
@@ -384,7 +386,6 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) goto out_fail;f2fs_unlock_op (sbi); -stat_inc_inline_dir (inode);alloc_nid_done (sbi, inode->i_ino);d_instantiate (dentry, inode);
@@ -770,7 +771,6 @@ static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)alloc_nid_done (sbi, inode->i_ino); -stat_inc_inline_inode (inode);d_tmpfile (dentry, inode);unlock_new_inode (inode);return 0 ;
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 16/19 f2fs: split find_data_page according to specific purposes
In reply to Jaegeuk KimThis patch splits find_data_page as follows.
1. f2fs_gc
- use get_read_data_page() with read only
2. find_in_level
- use find_data_page without locked page
3. truncate_partial_page
- In the case cache_only mode, just drop cached page.
- Ohterwise, use get_lock_data_page() and guarantee to truncate
--- fs/f2fs/data.c | 127 ++++++++++++++++++++++----------------------------------- fs/f2fs/dir.c | 2 +- fs/f2fs/f2fs.h | 3 +- fs/f2fs/file.c | 26 +++++++----- fs/f2fs/gc.c | 5 +-- 5 files changed, 68 insertions(+), 95 deletions(-)
fs/f2fs/data.c +48 -79
@@ -917,7 +917,7 @@ void f2fs_update_extent_cache(struct dnode_of_data *dn)sync_inode_page (dn); } -struct page *find_data_page (struct inode *inode,pgoff_t index,bool sync) +struct page *get_read_data_page (struct inode *inode,pgoff_t index,int rw) {struct address_space *mapping = inode->i_mapping;struct dnode_of_data dn;
@@ -927,84 +927,9 @@ struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync)struct f2fs_io_info fio = { .sbi =F2FS_I_SB (inode), .type =DATA , - .rw = sync ?READ_SYNC :READA , + .rw = rw, }; -/* -* If sync is false, it needs to check its block allocation. -* This is need and triggered by two flows: -* gc and truncate_partial_data_page. -*/ -if (!sync) - goto search; - - page =find_get_page (mapping, index); -if (page &&PageUptodate (page)) -return page; -f2fs_put_page (page,0 ); -search: -if (f2fs_lookup_extent_cache (inode, index, &ei)) { - dn.data_blkaddr = ei.blk + index - ei.fofs; - goto got_it; - } - -set_new_dnode (&dn, inode,NULL ,NULL ,0 ); - err =get_dnode_of_data (&dn, index,LOOKUP_NODE ); -if (err) -return ERR_PTR (err); -f2fs_put_dnode (&dn); - -if (dn.data_blkaddr ==NULL_ADDR ) -return ERR_PTR (-ENOENT ); - -/* By fallocate(), there is no cached page, but with NEW_ADDR */ -if (unlikely (dn.data_blkaddr ==NEW_ADDR )) -return ERR_PTR (-EINVAL ); - -got_it: - page =grab_cache_page (mapping, index); -if (!page) -return ERR_PTR (-ENOMEM ); - -if (PageUptodate (page)) { -unlock_page (page); -return page; - } - - fio.blk_addr = dn.data_blkaddr; - fio.page = page; - err =f2fs_submit_page_bio (&fio); -if (err) -return ERR_PTR (err); - -if (sync) { -wait_on_page_locked (page); -if (unlikely (!PageUptodate (page))) { -f2fs_put_page (page,0 ); -return ERR_PTR (-EIO ); - } - } -return page; -} - -/* -* If it tries to access a hole, return an error. -* Because, the callers, functions in dir.c and GC, should be able to know -* whether this page exists or not. -*/ -struct page *get_lock_data_page (struct inode *inode,pgoff_t index) -{ -struct address_space *mapping = inode->i_mapping; -struct dnode_of_data dn; -struct page *page; -struct extent_info ei; -int err; -struct f2fs_io_info fio = { - .sbi =F2FS_I_SB (inode), - .type =DATA , - .rw =READ_SYNC , - }; -repeat: page =grab_cache_page (mapping, index);if (!page)return ERR_PTR (-ENOMEM );
@@ -1026,10 +951,11 @@ repeat:f2fs_put_page (page,1 );return ERR_PTR (-ENOENT ); } - got_it: -if (PageUptodate (page)) +if (PageUptodate (page)) { +unlock_page (page);return page; + }/* * A new dentry page is allocated but not able to be written, since its
@@ -1040,6 +966,7 @@ got_it:if (dn.data_blkaddr ==NEW_ADDR ) {zero_user_segment (page,0 ,PAGE_CACHE_SIZE );SetPageUptodate (page); +unlock_page (page);return page; }
@@ -1048,7 +975,49 @@ got_it: err =f2fs_submit_page_bio (&fio);if (err)return ERR_PTR (err); +return page; +} + +struct page *find_data_page (struct inode *inode,pgoff_t index) +{ +struct address_space *mapping = inode->i_mapping; +struct page *page; + + page =find_get_page (mapping, index); +if (page &&PageUptodate (page)) +return page; +f2fs_put_page (page,0 ); + + page =get_read_data_page (inode, index,READ_SYNC ); +if (IS_ERR (page)) +return page; + +if (PageUptodate (page)) +return page; + +wait_on_page_locked (page); +if (unlikely (!PageUptodate (page))) { +f2fs_put_page (page,0 ); +return ERR_PTR (-EIO ); + } +return page; +} + +/* +* If it tries to access a hole, return an error. +* Because, the callers, functions in dir.c and GC, should be able to know +* whether this page exists or not. +*/ +struct page *get_lock_data_page (struct inode *inode,pgoff_t index) +{ +struct address_space *mapping = inode->i_mapping; +struct page *page; +repeat: + page =get_read_data_page (inode, index,READ_SYNC ); +if (IS_ERR (page)) +return page; +/* wait for read completion */ lock_page (page);if (unlikely (!PageUptodate (page))) {f2fs_put_page (page,1 );
fs/f2fs/dir.c +1 -1
@@ -177,7 +177,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir,for (; bidx < end_block; bidx++) {/* no need to allocate new dentry pages to all the indices */ - dentry_page =find_data_page (dir, bidx, true); + dentry_page =find_data_page (dir, bidx);if (IS_ERR (dentry_page)) { room = true;continue ;
fs/f2fs/f2fs.h +2 -1
@@ -1675,7 +1675,8 @@ void f2fs_destroy_extent_tree(struct inode *);void f2fs_init_extent_cache (struct inode *,struct f2fs_extent *);void f2fs_update_extent_cache (struct dnode_of_data *);void f2fs_preserve_extent_tree (struct inode *); -struct page *find_data_page (struct inode *,pgoff_t ,bool ); +struct page *get_read_data_page (struct inode *,pgoff_t ,int ); +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 *);
fs/f2fs/file.c +15 -11
@@ -461,28 +461,32 @@ void truncate_data_blocks(struct dnode_of_data *dn) }static int truncate_partial_data_page (struct inode *inode,u64 from, -bool force) +bool cache_only) {unsigned offset = from & (PAGE_CACHE_SIZE -1 ); +pgoff_t index = from >>PAGE_CACHE_SHIFT ; +struct address_space *mapping = inode->i_mapping;struct page *page; -if (!offset && !force) +if (!offset && !cache_only)return 0 ; - page =find_data_page (inode, from >>PAGE_CACHE_SHIFT , force); -if (IS_ERR (page)) +if (cache_only) { + page =grab_cache_page (mapping, index); +if (page &&PageUptodate (page)) + goto truncate_out; +f2fs_put_page (page,1 );return 0 ; + } -lock_page (page); -if (unlikely (!PageUptodate (page) || - page->mapping != inode->i_mapping)) - goto out; - + page =get_lock_data_page (inode, index); +if (IS_ERR (page)) +return 0 ; +truncate_out:f2fs_wait_on_page_writeback (page,DATA );zero_user (page, offset,PAGE_CACHE_SIZE - offset); -if (!force) +if (!cache_only)set_page_dirty (page); -out:f2fs_put_page (page,1 );return 0 ; }
fs/f2fs/gc.c +2 -3
@@ -607,9 +607,8 @@ next_step:continue ; start_bidx =start_bidx_of_node (nofs,F2FS_I (inode)); - - data_page =find_data_page (inode, - start_bidx + ofs_in_node, false); + data_page =get_read_data_page (inode, + start_bidx + ofs_in_node,READA );if (IS_ERR (data_page)) {iput (inode);continue ;
Signature · 1 line
2.1.1
Jaegeuk Kim
maintainerPATCH 17/19 f2fs: revmove spin_lock for write_orphan_inodes
In reply to Jaegeuk KimThis patch removes spin_lock, since this is covered by f2fs_lock_op already. And, we should avoid to use page operations inside spin_lock.
--- fs/f2fs/checkpoint.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/f2fs/checkpoint.c +6 -3
@@ -514,7 +514,12 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)grab_meta_page (sbi, start_blk + index); index =1 ; -spin_lock (&im->ino_lock); + +/* +* we don't need to do spin_lock(&im->ino_lock) here, since all the +* orphan inode operations are covered under f2fs_lock_op(). +* And, spin_lock should be avoided due to page operations below. +*/ head = &im->ino_list;/* loop for each orphan inode entry and write them in Jornal block */
@@ -554,8 +559,6 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)set_page_dirty (page);f2fs_put_page (page,1 ); } - -spin_unlock (&im->ino_lock); } static struct page *validate_checkpoint(struct f2fs_sb_info *sbi,
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 18/19 f2fs: introduce discard_map for f2fs_trim_fs
In reply to Jaegeuk KimThis patch adds a bitmap for discard issues from f2fs_trim_fs. There-in rule is to issue discard commands only for invalidated blocks after mount.
Once mount is done, f2fs_trim_fs trims out whole invalid area. After ehn, it will not issue and discrads redundantly.
--- fs/f2fs/debug.c | 2 +- fs/f2fs/f2fs.h | 21 +++++++++++++++++++++ fs/f2fs/segment.c | 52 +++++++++++++++++++++++++++++++++++++++------------- fs/f2fs/segment.h | 1 + 4 files changed, 62 insertions(+), 14 deletions(-)
fs/f2fs/debug.c +1 -1
@@ -143,7 +143,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi) si->base_mem +=sizeof (struct sit_info ); si->base_mem +=MAIN_SEGS (sbi) *sizeof (struct seg_entry ); si->base_mem +=f2fs_bitmap_size (MAIN_SEGS (sbi)); - si->base_mem +=2 *SIT_VBLOCK_MAP_SIZE *MAIN_SEGS (sbi); + si->base_mem +=3 *SIT_VBLOCK_MAP_SIZE *MAIN_SEGS (sbi); si->base_mem +=SIT_VBLOCK_MAP_SIZE ;if (sbi->segs_per_sec >1 ) si->base_mem +=MAIN_SECS (sbi) *sizeof (struct sec_entry );
fs/f2fs/f2fs.h +21 -0
@@ -117,6 +117,8 @@ enum {#define DEF_BATCHED_TRIM_SECTIONS 32#define BATCHED_TRIM_SEGMENTS (sbi) \ (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) +#define BATCHED_TRIM_BLOCKS (sbi) \ + (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg)struct cp_control {int reason;
@@ -698,6 +700,7 @@ struct f2fs_sb_info {block_t user_block_count;/* # of user blocks */ block_t total_valid_block_count;/* # of valid blocks */ block_t alloc_valid_block_count;/* # of allocated blocks */ +block_t discard_blks;/* discard command candidats */ block_t last_valid_block_count;/* for recovery */ u32 s_next_generation;/* for NFS support */ atomic_t nr_pages[NR_COUNT_TYPE ];/* # of pages, see count_type */
@@ -1225,6 +1228,24 @@ static inline int f2fs_test_bit(unsigned int nr, char *addr)return mask & *addr; } +static inline void f2fs_set_bit (unsigned int nr,char *addr) +{ +int mask; + + addr += (nr >>3 ); + mask =1 << (7 - (nr &0x07 )); + *addr |= mask; +} + +static inline void f2fs_clear_bit (unsigned int nr,char *addr) +{ +int mask; + + addr += (nr >>3 ); + mask =1 << (7 - (nr &0x07 )); + *addr &= ~mask; +} +static inline int f2fs_test_and_set_bit (unsigned int nr,char *addr) {int mask;
fs/f2fs/segment.c +39 -13
130 lines not on this page · raw message
fs/f2fs/segment.h +1 -0
@@ -163,6 +163,7 @@ struct seg_entry {*/ unsigned short ckpt_valid_blocks;unsigned char *ckpt_valid_map; +unsigned char *discard_map;unsigned char type;/* segment type like CURSEG_XXX_TYPE */ unsigned long long mtime;/* modification time of the segment */ };
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jaegeuk Kim
maintainerPATCH 19/19 f2fs: issue discard with finally produced len and minlen
In reply to Jaegeuk KimThis patch determines to issue discard commands by comparing given minlen and the length of produced final candidates.
--- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/f2fs.h | 2 +- fs/f2fs/segment.c | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-)
fs/f2fs/checkpoint.c +1 -1
@@ -1043,7 +1043,7 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)if (unlikely (f2fs_cp_error (sbi)))return ; -clear_prefree_segments (sbi); +clear_prefree_segments (sbi, cpc);clear_sbi_flag (sbi,SBI_IS_DIRTY ); }
fs/f2fs/f2fs.h +1 -1
@@ -1628,7 +1628,7 @@ int create_flush_cmd_control(struct f2fs_sb_info *);void destroy_flush_cmd_control (struct f2fs_sb_info *);void invalidate_blocks (struct f2fs_sb_info *,block_t );void refresh_sit_entry (struct f2fs_sb_info *,block_t ,block_t ); -void clear_prefree_segments (struct f2fs_sb_info *); +void clear_prefree_segments (struct f2fs_sb_info *,struct cp_control *);void release_discard_addrs (struct f2fs_sb_info *);void discard_next_dnode (struct f2fs_sb_info *,block_t );int npages_for_summary_flush (struct f2fs_sb_info *,bool );
fs/f2fs/segment.c +6 -4
@@ -597,7 +597,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)mutex_unlock (&dirty_i->seglist_lock); } -void clear_prefree_segments (struct f2fs_sb_info *sbi) +void clear_prefree_segments (struct f2fs_sb_info *sbi,struct cp_control *cpc) {struct list_head *head = &(SM_I (sbi)->discard_list);struct discard_entry *entry, *this;
@@ -630,7 +630,10 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi)/* send small discards */ list_for_each_entry_safe (entry, this, head, list) { +if (cpc->reason ==CP_DISCARD && entry->len < cpc->trim_minlen) + goto skip;f2fs_issue_discard (sbi, entry->blkaddr, entry->len); +skip:list_del (&entry->list);SM_I (sbi)->nr_discards -= entry->len;kmem_cache_free (discard_entry_slab, entry);
@@ -1072,8 +1075,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)unsigned int start_segno, end_segno;struct cp_control cpc; -if (range->minlen >SEGMENT_SIZE (sbi) || start >=MAX_BLKADDR (sbi) || - range->len < sbi->blocksize) +if (start >=MAX_BLKADDR (sbi) || range->len < sbi->blocksize)return -EINVAL ; cpc.trimmed =0 ;
@@ -1085,7 +1087,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) end_segno = (end >=MAX_BLKADDR (sbi)) ?MAIN_SEGS (sbi) -1 :GET_SEGNO (sbi, end); cpc.reason =CP_DISCARD ; - cpc.trim_minlen =F2FS_BYTES_TO_BLK (range->minlen); + cpc.trim_minlen =max_t (__u64,1 ,F2FS_BYTES_TO_BLK (range->minlen));/* do checkpoint to issue discard commands safely */ for (; start_segno <= end_segno; start_segno = cpc.trim_end +1 ) {
Signature · 9 lines
2.1.1 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y