Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7bd59381 authored by Gu Zheng's avatar Gu Zheng Committed by Jaegeuk Kim
Browse files

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: default avatarGu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk.kim@samsung.com>
parent 435f2a1b
Loading
Loading
Loading
Loading
+7 −19
Original line number Original line Diff line number Diff line
@@ -226,12 +226,8 @@ void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
			break;
			break;
		orphan = NULL;
		orphan = NULL;
	}
	}
retry:

	new = kmem_cache_alloc(orphan_entry_slab, GFP_ATOMIC);
	new = f2fs_kmem_cache_alloc(orphan_entry_slab, GFP_ATOMIC);
	if (!new) {
		cond_resched();
		goto retry;
	}
	new->ino = ino;
	new->ino = ino;


	/* add new_oentry into list which is sorted by inode number */
	/* 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))
	if (!S_ISDIR(inode->i_mode))
		return;
		return;
retry:

	new = kmem_cache_alloc(inode_entry_slab, GFP_NOFS);
	new = f2fs_kmem_cache_alloc(inode_entry_slab, GFP_NOFS);
	if (!new) {
		cond_resched();
		goto retry;
	}
	new->inode = inode;
	new->inode = inode;
	INIT_LIST_HEAD(&new->list);
	INIT_LIST_HEAD(&new->list);


@@ -506,13 +498,9 @@ void set_dirty_dir_page(struct inode *inode, struct page *page)
void add_dirty_dir_inode(struct inode *inode)
void add_dirty_dir_inode(struct inode *inode)
{
{
	struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
	struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
	struct dir_inode_entry *new;
	struct dir_inode_entry *new =
retry:
			f2fs_kmem_cache_alloc(inode_entry_slab, GFP_NOFS);
	new = kmem_cache_alloc(inode_entry_slab, GFP_NOFS);

	if (!new) {
		cond_resched();
		goto retry;
	}
	new->inode = inode;
	new->inode = inode;
	INIT_LIST_HEAD(&new->list);
	INIT_LIST_HEAD(&new->list);


+15 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@
#include <linux/crc32.h>
#include <linux/crc32.h>
#include <linux/magic.h>
#include <linux/magic.h>
#include <linux/kobject.h>
#include <linux/kobject.h>
#include <linux/sched.h>


/*
/*
 * For mount options
 * For mount options
@@ -787,6 +788,20 @@ static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
	return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, ctor);
	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;
retry:
	entry = kmem_cache_alloc(cachep, flags);
	if (!entry) {
		cond_resched();
		goto retry;
	}

	return entry;
}

#define RAW_IS_INODE(p)	((p)->footer.nid == (p)->footer.ino)
#define RAW_IS_INODE(p)	((p)->footer.nid == (p)->footer.ino)


static inline bool IS_INODE(struct page *page)
static inline bool IS_INODE(struct page *page)
+2 −6
Original line number Original line Diff line number Diff line
@@ -361,12 +361,8 @@ static void add_gc_inode(struct inode *inode, struct list_head *ilist)
		iput(inode);
		iput(inode);
		return;
		return;
	}
	}
repeat:

	new_ie = kmem_cache_alloc(winode_slab, GFP_NOFS);
	new_ie = f2fs_kmem_cache_alloc(winode_slab, GFP_NOFS);
	if (!new_ie) {
		cond_resched();
		goto repeat;
	}
	new_ie->inode = inode;
	new_ie->inode = inode;
	list_add_tail(&new_ie->list, ilist);
	list_add_tail(&new_ie->list, ilist);
}
}
+11 −16
Original line number Original line Diff line number Diff line
@@ -1296,9 +1296,7 @@ static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build)
	if (nid == 0)
	if (nid == 0)
		return 0;
		return 0;


	if (!build)
	if (build) {
		goto retry;

		/* do not add allocated nids */
		/* do not add allocated nids */
		read_lock(&nm_i->nat_tree_lock);
		read_lock(&nm_i->nat_tree_lock);
		ne = __lookup_nat_cache(nm_i, nid);
		ne = __lookup_nat_cache(nm_i, nid);
@@ -1307,12 +1305,9 @@ static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid, bool build)
		read_unlock(&nm_i->nat_tree_lock);
		read_unlock(&nm_i->nat_tree_lock);
		if (allocated)
		if (allocated)
			return 0;
			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->nid = nid;
	i->state = NID_NEW;
	i->state = NID_NEW;