Skip to content

Commit 17b692f

Browse files
Gu ZhengJaegeuk Kim
authored andcommitted
f2fs: use spinlock rather than mutex for better speed
With the 2 previous changes, all the long time operations are moved out of the protection region, so here we can use spinlock rather than mutex (orphan_inode_mutex) for lower overhead. Signed-off-by: Gu Zheng <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent c1ef372 commit 17b692f

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

fs/f2fs/checkpoint.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,22 @@ int acquire_orphan_inode(struct f2fs_sb_info *sbi)
196196
{
197197
int err = 0;
198198

199-
mutex_lock(&sbi->orphan_inode_mutex);
199+
spin_lock(&sbi->orphan_inode_lock);
200200
if (unlikely(sbi->n_orphans >= sbi->max_orphans))
201201
err = -ENOSPC;
202202
else
203203
sbi->n_orphans++;
204-
mutex_unlock(&sbi->orphan_inode_mutex);
204+
spin_unlock(&sbi->orphan_inode_lock);
205205

206206
return err;
207207
}
208208

209209
void release_orphan_inode(struct f2fs_sb_info *sbi)
210210
{
211-
mutex_lock(&sbi->orphan_inode_mutex);
211+
spin_lock(&sbi->orphan_inode_lock);
212212
f2fs_bug_on(sbi->n_orphans == 0);
213213
sbi->n_orphans--;
214-
mutex_unlock(&sbi->orphan_inode_mutex);
214+
spin_unlock(&sbi->orphan_inode_lock);
215215
}
216216

217217
void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
@@ -222,12 +222,12 @@ void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
222222
new = f2fs_kmem_cache_alloc(orphan_entry_slab, GFP_ATOMIC);
223223
new->ino = ino;
224224

225-
mutex_lock(&sbi->orphan_inode_mutex);
225+
spin_lock(&sbi->orphan_inode_lock);
226226
head = &sbi->orphan_inode_list;
227227
list_for_each(this, head) {
228228
orphan = list_entry(this, struct orphan_inode_entry, list);
229229
if (orphan->ino == ino) {
230-
mutex_unlock(&sbi->orphan_inode_mutex);
230+
spin_unlock(&sbi->orphan_inode_lock);
231231
kmem_cache_free(orphan_entry_slab, new);
232232
return;
233233
}
@@ -242,15 +242,15 @@ void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
242242
list_add(&new->list, this->prev);
243243
else
244244
list_add_tail(&new->list, head);
245-
mutex_unlock(&sbi->orphan_inode_mutex);
245+
spin_unlock(&sbi->orphan_inode_lock);
246246
}
247247

248248
void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
249249
{
250250
struct list_head *head;
251251
struct orphan_inode_entry *orphan;
252252

253-
mutex_lock(&sbi->orphan_inode_mutex);
253+
spin_lock(&sbi->orphan_inode_lock);
254254
head = &sbi->orphan_inode_list;
255255
list_for_each_entry(orphan, head, list) {
256256
if (orphan->ino == ino) {
@@ -261,7 +261,7 @@ void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
261261
break;
262262
}
263263
}
264-
mutex_unlock(&sbi->orphan_inode_mutex);
264+
spin_unlock(&sbi->orphan_inode_lock);
265265
}
266266

267267
static void recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
@@ -318,7 +318,7 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
318318
pages[index] = grab_meta_page(sbi, start_blk + index);
319319

320320
index = 1;
321-
mutex_lock(&sbi->orphan_inode_mutex);
321+
spin_lock(&sbi->orphan_inode_lock);
322322
head = &sbi->orphan_inode_list;
323323

324324
/* loop for each orphan inode entry and write them in Jornal block */
@@ -357,7 +357,7 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
357357
f2fs_put_page(page, 1);
358358
}
359359

360-
mutex_unlock(&sbi->orphan_inode_mutex);
360+
spin_unlock(&sbi->orphan_inode_lock);
361361
}
362362

363363
static struct page *validate_checkpoint(struct f2fs_sb_info *sbi,
@@ -828,7 +828,7 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
828828

829829
void init_orphan_info(struct f2fs_sb_info *sbi)
830830
{
831-
mutex_init(&sbi->orphan_inode_mutex);
831+
spin_lock_init(&sbi->orphan_inode_lock);
832832
INIT_LIST_HEAD(&sbi->orphan_inode_list);
833833
sbi->n_orphans = 0;
834834
/*

fs/f2fs/f2fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ struct f2fs_sb_info {
412412

413413
/* for orphan inode management */
414414
struct list_head orphan_inode_list; /* orphan inode list */
415-
struct mutex orphan_inode_mutex; /* for orphan inode list */
415+
spinlock_t orphan_inode_lock; /* for orphan inode list */
416416
unsigned int n_orphans; /* # of orphan inodes */
417417
unsigned int max_orphans; /* max orphan inodes */
418418

0 commit comments

Comments
 (0)