f2fs: use __GFP_NOFAIL to avoid infinite loop
authorJaegeuk Kim <jaegeuk@kernel.org>
Thu, 20 Aug 2015 15:51:56 +0000 (08:51 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 24 Aug 2015 16:37:21 +0000 (09:37 -0700)
__GFP_NOFAIL can avoid retrying the whole path of kmem_cache_alloc and
bio_alloc.
And, it also fixes the use cases of GFP_ATOMIC correctly.

Suggested-by: Chao Yu <chao2.yu@samsung.com>
Reviewed-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/checkpoint.c
fs/f2fs/f2fs.h
fs/f2fs/node.c
fs/f2fs/segment.c

index 890e4d4c39d754693d21be0ae646084ddf1f5808..c5a38e352a80952dc833c5740eec11f64eadec59 100644 (file)
@@ -336,26 +336,18 @@ const struct address_space_operations f2fs_meta_aops = {
 static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
 {
        struct inode_management *im = &sbi->im[type];
-       struct ino_entry *e;
+       struct ino_entry *e, *tmp;
+
+       tmp = f2fs_kmem_cache_alloc(ino_entry_slab, GFP_NOFS);
 retry:
-       if (radix_tree_preload(GFP_NOFS)) {
-               cond_resched();
-               goto retry;
-       }
+       radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
 
        spin_lock(&im->ino_lock);
-
        e = radix_tree_lookup(&im->ino_root, ino);
        if (!e) {
-               e = kmem_cache_alloc(ino_entry_slab, GFP_ATOMIC);
-               if (!e) {
-                       spin_unlock(&im->ino_lock);
-                       radix_tree_preload_end();
-                       goto retry;
-               }
+               e = tmp;
                if (radix_tree_insert(&im->ino_root, ino, e)) {
                        spin_unlock(&im->ino_lock);
-                       kmem_cache_free(ino_entry_slab, e);
                        radix_tree_preload_end();
                        goto retry;
                }
@@ -368,6 +360,9 @@ retry:
        }
        spin_unlock(&im->ino_lock);
        radix_tree_preload_end();
+
+       if (e != tmp)
+               kmem_cache_free(ino_entry_slab, tmp);
 }
 
 static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
index 66410178aba1c3c9ce203b665b0d090de767c8af..ece5e704dfd00eb5b2abf4b28c711f050bad9ceb 100644 (file)
@@ -1252,13 +1252,10 @@ static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
                                                gfp_t flags)
 {
        void *entry;
-retry:
-       entry = kmem_cache_alloc(cachep, flags);
-       if (!entry) {
-               cond_resched();
-               goto retry;
-       }
 
+       entry = kmem_cache_alloc(cachep, flags);
+       if (!entry)
+               entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL);
        return entry;
 }
 
@@ -1267,12 +1264,9 @@ static inline struct bio *f2fs_bio_alloc(int npages)
        struct bio *bio;
 
        /* No failure on bio allocation */
-retry:
        bio = bio_alloc(GFP_NOIO, npages);
-       if (!bio) {
-               cond_resched();
-               goto retry;
-       }
+       if (!bio)
+               bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
        return bio;
 }
 
index 6bef5a2788b45d1aac1d7dbb069c5abb7a6c2f89..777066d29fa80e619fe5ca21960af01b81b5f4e1 100644 (file)
@@ -159,7 +159,7 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
 
        head = radix_tree_lookup(&nm_i->nat_set_root, set);
        if (!head) {
-               head = f2fs_kmem_cache_alloc(nat_entry_set_slab, GFP_ATOMIC);
+               head = f2fs_kmem_cache_alloc(nat_entry_set_slab, GFP_NOFS);
 
                INIT_LIST_HEAD(&head->entry_list);
                INIT_LIST_HEAD(&head->set_list);
@@ -246,7 +246,7 @@ static struct nat_entry *grab_nat_entry(struct f2fs_nm_info *nm_i, nid_t nid)
 {
        struct nat_entry *new;
 
-       new = f2fs_kmem_cache_alloc(nat_entry_slab, GFP_ATOMIC);
+       new = f2fs_kmem_cache_alloc(nat_entry_slab, GFP_NOFS);
        f2fs_radix_tree_insert(&nm_i->nat_root, nid, new);
        memset(new, 0, sizeof(struct nat_entry));
        nat_set_nid(new, nid);
index 6273e2cde93e751330c0aa29be3ffcbd80e9a8cb..78e6d06968477d023cbd4f8c71ccc1e3fd6329fe 100644 (file)
@@ -1753,7 +1753,7 @@ static struct page *get_next_sit_page(struct f2fs_sb_info *sbi,
 static struct sit_entry_set *grab_sit_entry_set(void)
 {
        struct sit_entry_set *ses =
-                       f2fs_kmem_cache_alloc(sit_entry_set_slab, GFP_ATOMIC);
+                       f2fs_kmem_cache_alloc(sit_entry_set_slab, GFP_NOFS);
 
        ses->entry_cnt = 0;
        INIT_LIST_HEAD(&ses->set_list);