f2fs: introduce f2fs_kmem_cache_alloc to hide the unfailed kmem cache allocation
Subsystems (2)
PATCH 1/1 f2fs: introduce f2fs_kmem_cache_alloc to hide the unfailed kmem cache allocation
Introduce the unfailed version of kmem_cache_alloc named f2fs_kmem_cache_alloc to hide the retry routine and make the code a bit cleaner.
--- fs/f2fs/checkpoint.c | 26 +++++++------------------- fs/f2fs/f2fs.h | 13 +++++++++++++ fs/f2fs/gc.c | 8 ++------ fs/f2fs/node.c | 6 +----- 4 files changed, 23 insertions(+), 30 deletions(-)
fs/f2fs/checkpoint.c +7 -19
@@ -226,12 +226,8 @@ void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)break ; orphan =NULL ; } -retry: - new =kmem_cache_alloc (orphan_entry_slab,GFP_ATOMIC ); -if (!new) { -cond_resched (); - goto retry; - } + + new =f2fs_kmem_cache_alloc (orphan_entry_slab,GFP_ATOMIC ); new->ino = ino;/* add new_oentry into list which is sorted by inode number */
@@ -484,12 +480,8 @@ void set_dirty_dir_page(struct inode *inode, struct page *page)if (!S_ISDIR (inode->i_mode))return ; -retry: - new =kmem_cache_alloc (inode_entry_slab,GFP_NOFS ); -if (!new) { -cond_resched (); - goto retry; - } + + new =f2fs_kmem_cache_alloc (inode_entry_slab,GFP_NOFS ); new->inode = inode;INIT_LIST_HEAD (&new->list);
@@ -506,13 +498,9 @@ retry:void add_dirty_dir_inode (struct inode *inode) {struct f2fs_sb_info *sbi =F2FS_SB (inode->i_sb); -struct dir_inode_entry *new; -retry: - new =kmem_cache_alloc (inode_entry_slab,GFP_NOFS ); -if (!new) { -cond_resched (); - goto retry; - } +struct dir_inode_entry *new = +f2fs_kmem_cache_alloc (inode_entry_slab,GFP_NOFS ); + new->inode = inode;INIT_LIST_HEAD (&new->list);
fs/f2fs/f2fs.h +13 -0
@@ -787,6 +787,19 @@ static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,return kmem_cache_create (name, size,0 ,SLAB_RECLAIM_ACCOUNT , ctor); } +static inline void *f2fs_kmem_cache_alloc (struct kmem_cache *cachep, +gfp_t flags) +{ +void *entry =kmem_cache_alloc (cachep, flags); +retry: +if (!entry) { +cond_resched (); + goto retry; + } + +return entry; +} +#define RAW_IS_INODE (p) ((p)->footer.nid == (p)->footer.ino)static inline bool IS_INODE (struct page *page)
fs/f2fs/gc.c +2 -6
@@ -361,12 +361,8 @@ static void add_gc_inode(struct inode *inode, struct list_head *ilist)iput (inode);return ; } -repeat: - new_ie =kmem_cache_alloc (winode_slab,GFP_NOFS ); -if (!new_ie) { -cond_resched (); - goto repeat; - } + + new_ie =f2fs_kmem_cache_alloc (winode_slab,GFP_NOFS ); new_ie->inode = inode;list_add_tail (&new_ie->list, ilist); }
fs/f2fs/node.c +1 -5
@@ -1308,11 +1308,7 @@ static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build)if (allocated)return 0 ; retry: - i =kmem_cache_alloc (free_nid_slab,GFP_NOFS ); -if (!i) { -cond_resched (); - goto retry; - } + i =f2fs_kmem_cache_alloc (free_nid_slab,GFP_NOFS ); i->nid = nid; i->state =NID_NEW ;
Signature · 1 line
1.7.7
Looks neat.
Quoted 129 lines · Gu Zheng
Introduce the unfailed version of
kmem_cache_allocnamedf2fs_kmem_cache_allocto hide the retry routine and make the code a bit cleaner.Signed-off-by Gu Zheng <[email protected]>--- fs/f2fs/checkpoint.c | 26 +++++++------------------- fs/f2fs/f2fs.h | 13 +++++++++++++ fs/f2fs/gc.c | 8 ++------ fs/f2fs/node.c | 6 +----- 4 files changed, 23 insertions(+), 30 deletions(-)fs/f2fs/checkpoint.c +7
-19@@ -226,12 +226,8 @@ void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)break ; orphan =NULL ; } -retry: - new =kmem_cache_alloc (orphan_entry_slab,GFP_ATOMIC ); -if (!new) { -cond_resched (); - goto retry; - } + + new =f2fs_kmem_cache_alloc (orphan_entry_slab,GFP_ATOMIC ); new->ino = ino;/* add new_oentry into list which is sorted by inode number */ @@ -484,12 +480,8 @@ void set_dirty_dir_page(struct inode *inode, struct page *page)if (!S_ISDIR (inode->i_mode))return ; -retry: - new =kmem_cache_alloc (inode_entry_slab,GFP_NOFS ); -if (!new) { -cond_resched (); - goto retry; - } + + new =f2fs_kmem_cache_alloc (inode_entry_slab,GFP_NOFS ); new->inode = inode;INIT_LIST_HEAD (&new->list);@@ -506,13 +498,9 @@ retry:void add_dirty_dir_inode (struct inode *inode) {struct f2fs_sb_info *sbi =F2FS_SB (inode->i_sb); -struct dir_inode_entry *new; -retry: - new =kmem_cache_alloc (inode_entry_slab,GFP_NOFS ); -if (!new) { -cond_resched (); - goto retry; - } +struct dir_inode_entry *new = +f2fs_kmem_cache_alloc (inode_entry_slab,GFP_NOFS ); + new->inode = inode;INIT_LIST_HEAD (&new->list);fs/f2fs/f2fs.h +13
-0@@ -787,6 +787,19 @@ static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,return kmem_cache_create (name, size,0 ,SLAB_RECLAIM_ACCOUNT , ctor); } +static inline void *f2fs_kmem_cache_alloc (struct kmem_cache *cachep, +gfp_t flags) +{ +void *entry =kmem_cache_alloc (cachep, flags); +retry: +if (!entry) { +cond_resched (); + goto retry; + } + +return entry; +} +#define RAW_IS_INODE (p) ((p)->footer.nid == (p)->footer.ino)static inline bool IS_INODE (struct page *page)fs/f2fs/gc.c +2
-6@@ -361,12 +361,8 @@ static void add_gc_inode(struct inode *inode, struct list_head *ilist)iput (inode);return ; } -repeat: - new_ie =kmem_cache_alloc (winode_slab,GFP_NOFS ); -if (!new_ie) { -cond_resched (); - goto repeat; - } + + new_ie =f2fs_kmem_cache_alloc (winode_slab,GFP_NOFS ); new_ie->inode = inode;list_add_tail (&new_ie->list, ilist); }fs/f2fs/node.c +1
-5@@ -1308,11 +1308,7 @@ static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build)if (allocated)return 0 ; retry: - i =kmem_cache_alloc (free_nid_slab,GFP_NOFS ); -if (!i) { -cond_resched (); - goto retry; - } + i =f2fs_kmem_cache_alloc (free_nid_slab,GFP_NOFS ); i->nid = nid; i->state =NID_NEW ;Signature · 6 lines
1.7.7 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
fs/f2fs/f2fs.h static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, · line 794
Quoted 5 lines · Gu Zheng
fs/f2fs/f2fs.h +5
-0+static inline void *f2fs_kmem_cache_alloc (struct kmem_cache *cachep, +gfp_t flags) +{ +void *entry =kmem_cache_alloc (cachep, flags); +retry:
retry after kmem_cache_alloc?
Quoted 7 lines
fs/f2fs/f2fs.h +7
-0+if (!entry) { +cond_resched (); + goto retry; + } + +return entry; +}
Quoted 8 lines · Gao feng
fs/f2fs/f2fs.h static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, · line 794
Quoted 5 lines · Gu Zheng
fs/f2fs/f2fs.h +5
-0+static inline void *f2fs_kmem_cache_alloc (struct kmem_cache *cachep, +gfp_t flags) +{ +void *entry =kmem_cache_alloc (cachep, flags); +retry:retry after
kmem_cache_alloc?
Good catch.
Sorry for the carelessness in my previous review. Besides this, I also found another issue as below:
Quoted 9 lines · Gu Zheng
fs/f2fs/node.c static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build) · line 1310
Quoted 8 lines
fs/f2fs/node.c +0
-0@@ -1308,11 +1308,7 @@ static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build)if (allocated)return 0 ; retry:
-retry?
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
Quoted 3 lines · Haicheng Li
Looks neat.
Reviewed-by Haicheng Li <[email protected]>
pls. ignore this mail.
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
Quoted 8 lines · Gao feng
fs/f2fs/f2fs.h static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, · line 794
Quoted 5 lines · Gu Zheng
fs/f2fs/f2fs.h +5
-0+static inline void *f2fs_kmem_cache_alloc (struct kmem_cache *cachep, +gfp_t flags) +{ +void *entry =kmem_cache_alloc (cachep, flags); +retry:retry after
kmem_cache_alloc?
Oh~, stupid mistake, thanks for your reminder.:)
Quoted 15 lines
fs/f2fs/f2fs.h static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, · line 801
Quoted 8 lines
fs/f2fs/f2fs.h +7
-0+if (!entry) { +cond_resched (); + goto retry; + } + +return entry; +}--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
Quoted 16 lines · Haicheng Li
Quoted 8 lines · Gao feng
fs/f2fs/f2fs.h static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, · line 794
Quoted 5 lines · Gu Zheng
fs/f2fs/f2fs.h +5
-0+static inline void *f2fs_kmem_cache_alloc (struct kmem_cache *cachep, +gfp_t flags) +{ +void *entry =kmem_cache_alloc (cachep, flags); +retry:retry after
kmem_cache_alloc?Good catch.
Sorry for the carelessness in my previous review. Besides this, I also found another issue as below:
Quoted 1 line · Gu Zheng
Quoted 9 lines
Quoted 8 lines
fs/f2fs/node.c static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build) · line 1310
Quoted 8 lines
fs/f2fs/node.c +0
-0@@ -1308,11 +1308,7 @@ static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build)if (allocated)return 0 ; retry:-retry?
Can be removed here, this tag still used by front goto jumping. But it seems that we need to use another suitable name rather than "retry".
Regards,
Gu
Quoted 3 lines
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
Quoted 28 lines · Gu Zheng
Quoted 16 lines · Haicheng Li
Quoted 8 lines · Gao feng
Review
Quoted 5 lines · Gu Zheng
(quoted diff) +5
-0+static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, + gfp_t flags) +{ + void *entry = kmem_cache_alloc(cachep, flags); +retry:retry after
kmem_cache_alloc?Good catch.
Sorry for the carelessness in my previous review. Besides this, I also found another issue as below:
Quoted 1 line · Gu Zheng
Quoted 9 lines
Quoted 8 lines
fs/f2fs/node.c static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build) · line 1310
Quoted 8 lines
fs/f2fs/node.c +0
-0@@ -1308,11 +1308,7 @@ static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build)if (allocated)return 0 ; retry:-retry?
Quoted 2 lines
Can be removed here, this tag still used by front goto jumping. But it seems that we need to use another suitable name rather than "retry".
how about like this?
---
fs/f2fs/node.c +10 -11
@@ -1296,18 +1296,17 @@ static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build)if (nid ==0 )return 0 ; -if (!build) - goto retry; +if (build) { +/* do not add allocated nids */ +read_lock (&nm_i->nat_tree_lock); + ne =__lookup_nat_cache (nm_i, nid); +if (ne &&nat_get_blkaddr (ne) !=NULL_ADDR ) + allocated = true; +read_unlock (&nm_i->nat_tree_lock); +if (allocated) +return 0 ; + } -/* do not add allocated nids */ -read_lock (&nm_i->nat_tree_lock); - ne =__lookup_nat_cache (nm_i, nid); -if (ne &&nat_get_blkaddr (ne) !=NULL_ADDR ) - allocated = true; -read_unlock (&nm_i->nat_tree_lock); -if (allocated) -return 0 ; -retry: i =f2fs_kmem_cache_alloc (free_nid_slab,GFP_NOFS ); i->nid = nid; i->state =NID_NEW ;
Quoted 44 lines · Haicheng Li
Quoted 28 lines · Gu Zheng
Quoted 16 lines · Haicheng Li
Quoted 8 lines · Gao feng
Review
Quoted 5 lines · Gu Zheng
(quoted diff) +5
-0+static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, + gfp_t flags) +{ + void *entry = kmem_cache_alloc(cachep, flags); +retry:retry after
kmem_cache_alloc?Good catch.
Sorry for the carelessness in my previous review. Besides this, I also found another issue as below:
Quoted 1 line · Gu Zheng
Quoted 9 lines
Quoted 8 lines
fs/f2fs/node.c static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build) · line 1310
Quoted 8 lines
fs/f2fs/node.c +0
-0@@ -1308,11 +1308,7 @@ static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build)if (allocated)return 0 ; retry:-retry?
Quoted 2 lines
Can be removed here, this tag still used by front goto jumping. But it seems that we need to use another suitable name rather than "retry".
how about like this?
---fs/f2fs/node.c +0
-2@@ -1296,18 +1296,17 @@ static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build)if (nid ==0 )return 0 ; -if (!build) - goto retry;
fs/f2fs/node.c static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build) · line 1308
Quoted 10 lines
fs/f2fs/node.c +10
-0+if (build) { +/* do not add allocated nids */ +read_lock (&nm_i->nat_tree_lock); + ne =__lookup_nat_cache (nm_i, nid); +if (ne &&nat_get_blkaddr (ne) !=NULL_ADDR ) + allocated = true; +read_unlock (&nm_i->nat_tree_lock); +if (allocated) +return 0 ; + }
Good, it's more neat, I'll take this, thanks.:)
Regards,
Gu
Quoted 4 lines
fs/f2fs/node.c +0
-3-/* do not add allocated nids */ -read_lock (&nm_i->nat_tree_lock); - ne =__lookup_nat_cache (nm_i, nid);
fs/f2fs/node.c static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build)
Quoted 10 lines
fs/f2fs/node.c +0
-6-if (ne &&nat_get_blkaddr (ne) !=NULL_ADDR ) - allocated = true; -read_unlock (&nm_i->nat_tree_lock); -if (allocated) -return 0 ; -retry: i =f2fs_kmem_cache_alloc (free_nid_slab,GFP_NOFS ); i->nid = nid; i->state =NID_NEW ;
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk