aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGu Zheng <guz.fnst@cn.fujitsu.com>2013-10-22 02:52:26 -0400
committerJaegeuk Kim <jaegeuk.kim@samsung.com>2013-10-22 07:16:02 -0400
commit7bd59381c82defe19875284c48b1ac9dacd16e8f (patch)
tree872cece782fc04b77b220060022f43d08886090b
parent435f2a1b58ac8f50894f23549c97791085f7cba2 (diff)
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. v2: Fix the wrong use of 'retry' tag pointed out by Gao feng. Use more neat code to remove redundant tag suggested by Haicheng Li. Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
-rw-r--r--fs/f2fs/checkpoint.c26
-rw-r--r--fs/f2fs/f2fs.h15
-rw-r--r--fs/f2fs/gc.c8
-rw-r--r--fs/f2fs/node.c27
4 files changed, 35 insertions, 41 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 8d16071a3b23..6fb484c84ee7 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -226,12 +226,8 @@ void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
226 break; 226 break;
227 orphan = NULL; 227 orphan = NULL;
228 } 228 }
229retry: 229
230 new = kmem_cache_alloc(orphan_entry_slab, GFP_ATOMIC); 230 new = f2fs_kmem_cache_alloc(orphan_entry_slab, GFP_ATOMIC);
231 if (!new) {
232 cond_resched();
233 goto retry;
234 }
235 new->ino = ino; 231 new->ino = ino;
236 232
237 /* add new_oentry into list which is sorted by inode number */ 233 /* 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)
484 480
485 if (!S_ISDIR(inode->i_mode)) 481 if (!S_ISDIR(inode->i_mode))
486 return; 482 return;
487retry: 483
488 new = kmem_cache_alloc(inode_entry_slab, GFP_NOFS); 484 new = f2fs_kmem_cache_alloc(inode_entry_slab, GFP_NOFS);
489 if (!new) {
490 cond_resched();
491 goto retry;
492 }
493 new->inode = inode; 485 new->inode = inode;
494 INIT_LIST_HEAD(&new->list); 486 INIT_LIST_HEAD(&new->list);
495 487
@@ -506,13 +498,9 @@ retry:
506void add_dirty_dir_inode(struct inode *inode) 498void add_dirty_dir_inode(struct inode *inode)
507{ 499{
508 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); 500 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
509 struct dir_inode_entry *new; 501 struct dir_inode_entry *new =
510retry: 502 f2fs_kmem_cache_alloc(inode_entry_slab, GFP_NOFS);
511 new = kmem_cache_alloc(inode_entry_slab, GFP_NOFS); 503
512 if (!new) {
513 cond_resched();
514 goto retry;
515 }
516 new->inode = inode; 504 new->inode = inode;
517 INIT_LIST_HEAD(&new->list); 505 INIT_LIST_HEAD(&new->list);
518 506
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 171c52fc95bb..29492754bd7d 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -18,6 +18,7 @@
18#include <linux/crc32.h> 18#include <linux/crc32.h>
19#include <linux/magic.h> 19#include <linux/magic.h>
20#include <linux/kobject.h> 20#include <linux/kobject.h>
21#include <linux/sched.h>
21 22
22/* 23/*
23 * For mount options 24 * For mount options
@@ -787,6 +788,20 @@ static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
787 return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, ctor); 788 return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, ctor);
788} 789}
789 790
791static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
792 gfp_t flags)
793{
794 void *entry;
795retry:
796 entry = kmem_cache_alloc(cachep, flags);
797 if (!entry) {
798 cond_resched();
799 goto retry;
800 }
801
802 return entry;
803}
804
790#define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 805#define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
791 806
792static inline bool IS_INODE(struct page *page) 807static inline bool IS_INODE(struct page *page)
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index fbad96846c7c..7914b92a6967 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -361,12 +361,8 @@ static void add_gc_inode(struct inode *inode, struct list_head *ilist)
361 iput(inode); 361 iput(inode);
362 return; 362 return;
363 } 363 }
364repeat: 364
365 new_ie = kmem_cache_alloc(winode_slab, GFP_NOFS); 365 new_ie = f2fs_kmem_cache_alloc(winode_slab, GFP_NOFS);
366 if (!new_ie) {
367 cond_resched();
368 goto repeat;
369 }
370 new_ie->inode = inode; 366 new_ie->inode = inode;
371 list_add_tail(&new_ie->list, ilist); 367 list_add_tail(&new_ie->list, ilist);
372} 368}
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index ef80f791b02b..4fa3fd5def34 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1296,23 +1296,18 @@ static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build)
1296 if (nid == 0) 1296 if (nid == 0)
1297 return 0; 1297 return 0;
1298 1298
1299 if (!build) 1299 if (build) {
1300 goto retry; 1300 /* do not add allocated nids */
1301 1301 read_lock(&nm_i->nat_tree_lock);
1302 /* do not add allocated nids */ 1302 ne = __lookup_nat_cache(nm_i, nid);
1303 read_lock(&nm_i->nat_tree_lock); 1303 if (ne && nat_get_blkaddr(ne) != NULL_ADDR)
1304 ne = __lookup_nat_cache(nm_i, nid); 1304 allocated = true;
1305 if (ne && nat_get_blkaddr(ne) != NULL_ADDR) 1305 read_unlock(&nm_i->nat_tree_lock);
1306 allocated = true; 1306 if (allocated)
1307 read_unlock(&nm_i->nat_tree_lock); 1307 return 0;
1308 if (allocated)
1309 return 0;
1310retry:
1311 i = kmem_cache_alloc(free_nid_slab, GFP_NOFS);
1312 if (!i) {
1313 cond_resched();
1314 goto retry;
1315 } 1308 }
1309
1310 i = f2fs_kmem_cache_alloc(free_nid_slab, GFP_NOFS);
1316 i->nid = nid; 1311 i->nid = nid;
1317 i->state = NID_NEW; 1312 i->state = NID_NEW;
1318 1313