Merge tag 'stable/for-linus-3.19-rc0-tag' of git://git.kernel.org/pub/scm/linux/kerne...
[firefly-linux-kernel-4.4.55.git] / fs / f2fs / segment.c
index 9a33e34d26ce9dcd31f0af918a3df510d6d47c52..42607a679923356c314d4b77399ff3e4b6cf8320 100644 (file)
@@ -179,13 +179,15 @@ void register_inmem_page(struct inode *inode, struct page *page)
        struct f2fs_inode_info *fi = F2FS_I(inode);
        struct inmem_pages *new;
        int err;
-retry:
+
+       SetPagePrivate(page);
+
        new = f2fs_kmem_cache_alloc(inmem_entry_slab, GFP_NOFS);
 
        /* add atomic page indices to the list */
        new->page = page;
        INIT_LIST_HEAD(&new->list);
-
+retry:
        /* increase reference count with clean state */
        mutex_lock(&fi->inmem_lock);
        err = radix_tree_insert(&fi->inmem_root, page->index, new);
@@ -195,11 +197,11 @@ retry:
                return;
        } else if (err) {
                mutex_unlock(&fi->inmem_lock);
-               kmem_cache_free(inmem_entry_slab, new);
                goto retry;
        }
        get_page(page);
        list_add_tail(&new->list, &fi->inmem_pages);
+       inc_page_count(F2FS_I_SB(inode), F2FS_INMEM_PAGES);
        mutex_unlock(&fi->inmem_lock);
 }
 
@@ -215,6 +217,7 @@ void invalidate_inmem_page(struct inode *inode, struct page *page)
                f2fs_put_page(cur->page, 0);
                list_del(&cur->list);
                kmem_cache_free(inmem_entry_slab, cur);
+               dec_page_count(F2FS_I_SB(inode), F2FS_INMEM_PAGES);
        }
        mutex_unlock(&fi->inmem_lock);
 }
@@ -256,6 +259,7 @@ void commit_inmem_pages(struct inode *inode, bool abort)
                f2fs_put_page(cur->page, 1);
                list_del(&cur->list);
                kmem_cache_free(inmem_entry_slab, cur);
+               dec_page_count(F2FS_I_SB(inode), F2FS_INMEM_PAGES);
        }
        if (submit_bio)
                f2fs_submit_merged_bio(sbi, DATA, WRITE);