Skip to content

Commit 55fa609

Browse files
dgchinnerAl Viro
authored andcommitted
fs: move i_sb_list out from under inode_lock
Protect the per-sb inode list with a new global lock inode_sb_list_lock and use it to protect the list manipulations and traversals. This lock replaces the inode_lock as the inodes on the list can be validity checked while holding the inode->i_lock and hence the inode_lock is no longer needed to protect the list. Signed-off-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent f283c86 commit 55fa609

6 files changed

Lines changed: 67 additions & 56 deletions

File tree

‎fs/drop_caches.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/writeback.h>
99
#include <linux/sysctl.h>
1010
#include <linux/gfp.h>
11+
#include "internal.h"
1112

1213
/* A global variable is a bit ugly, but it keeps the code simple */
1314
int sysctl_drop_caches;
@@ -16,7 +17,7 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
1617
{
1718
struct inode *inode, *toput_inode = NULL;
1819

19-
spin_lock(&inode_lock);
20+
spin_lock(&inode_sb_list_lock);
2021
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
2122
spin_lock(&inode->i_lock);
2223
if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) ||
@@ -26,13 +27,13 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
2627
}
2728
__iget(inode);
2829
spin_unlock(&inode->i_lock);
29-
spin_unlock(&inode_lock);
30+
spin_unlock(&inode_sb_list_lock);
3031
invalidate_mapping_pages(inode->i_mapping, 0, -1);
3132
iput(toput_inode);
3233
toput_inode = inode;
33-
spin_lock(&inode_lock);
34+
spin_lock(&inode_sb_list_lock);
3435
}
35-
spin_unlock(&inode_lock);
36+
spin_unlock(&inode_sb_list_lock);
3637
iput(toput_inode);
3738
}
3839

‎fs/fs-writeback.c‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ static void wait_sb_inodes(struct super_block *sb)
11231123
*/
11241124
WARN_ON(!rwsem_is_locked(&sb->s_umount));
11251125

1126-
spin_lock(&inode_lock);
1126+
spin_lock(&inode_sb_list_lock);
11271127

11281128
/*
11291129
* Data integrity sync. Must wait for all pages under writeback,
@@ -1143,14 +1143,15 @@ static void wait_sb_inodes(struct super_block *sb)
11431143
}
11441144
__iget(inode);
11451145
spin_unlock(&inode->i_lock);
1146-
spin_unlock(&inode_lock);
1146+
spin_unlock(&inode_sb_list_lock);
1147+
11471148
/*
1148-
* We hold a reference to 'inode' so it couldn't have
1149-
* been removed from s_inodes list while we dropped the
1150-
* inode_lock. We cannot iput the inode now as we can
1151-
* be holding the last reference and we cannot iput it
1152-
* under inode_lock. So we keep the reference and iput
1153-
* it later.
1149+
* We hold a reference to 'inode' so it couldn't have been
1150+
* removed from s_inodes list while we dropped the
1151+
* inode_sb_list_lock. We cannot iput the inode now as we can
1152+
* be holding the last reference and we cannot iput it under
1153+
* inode_sb_list_lock. So we keep the reference and iput it
1154+
* later.
11541155
*/
11551156
iput(old_inode);
11561157
old_inode = inode;
@@ -1159,9 +1160,9 @@ static void wait_sb_inodes(struct super_block *sb)
11591160

11601161
cond_resched();
11611162

1162-
spin_lock(&inode_lock);
1163+
spin_lock(&inode_sb_list_lock);
11631164
}
1164-
spin_unlock(&inode_lock);
1165+
spin_unlock(&inode_sb_list_lock);
11651166
iput(old_inode);
11661167
}
11671168

‎fs/inode.c‎

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@
3434
* inode->i_state, inode->i_hash, __iget()
3535
* inode_lru_lock protects:
3636
* inode_lru, inode->i_lru
37+
* inode_sb_list_lock protects:
38+
* sb->s_inodes, inode->i_sb_list
3739
*
3840
* Lock ordering:
3941
* inode_lock
4042
* inode->i_lock
43+
*
44+
* inode_sb_list_lock
45+
* inode->i_lock
4146
* inode_lru_lock
4247
*/
4348

@@ -99,6 +104,8 @@ static struct hlist_head *inode_hashtable __read_mostly;
99104
*/
100105
DEFINE_SPINLOCK(inode_lock);
101106

107+
__cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
108+
102109
/*
103110
* iprune_sem provides exclusion between the icache shrinking and the
104111
* umount path.
@@ -378,26 +385,23 @@ static void inode_lru_list_del(struct inode *inode)
378385
spin_unlock(&inode_lru_lock);
379386
}
380387

381-
static inline void __inode_sb_list_add(struct inode *inode)
382-
{
383-
list_add(&inode->i_sb_list, &inode->i_sb->s_inodes);
384-
}
385-
386388
/**
387389
* inode_sb_list_add - add inode to the superblock list of inodes
388390
* @inode: inode to add
389391
*/
390392
void inode_sb_list_add(struct inode *inode)
391393
{
392-
spin_lock(&inode_lock);
393-
__inode_sb_list_add(inode);
394-
spin_unlock(&inode_lock);
394+
spin_lock(&inode_sb_list_lock);
395+
list_add(&inode->i_sb_list, &inode->i_sb->s_inodes);
396+
spin_unlock(&inode_sb_list_lock);
395397
}
396398
EXPORT_SYMBOL_GPL(inode_sb_list_add);
397399

398-
static inline void __inode_sb_list_del(struct inode *inode)
400+
static inline void inode_sb_list_del(struct inode *inode)
399401
{
402+
spin_lock(&inode_sb_list_lock);
400403
list_del_init(&inode->i_sb_list);
404+
spin_unlock(&inode_sb_list_lock);
401405
}
402406

403407
static unsigned long hash(struct super_block *sb, unsigned long hashval)
@@ -481,9 +485,10 @@ static void evict(struct inode *inode)
481485

482486
spin_lock(&inode_lock);
483487
list_del_init(&inode->i_wb_list);
484-
__inode_sb_list_del(inode);
485488
spin_unlock(&inode_lock);
486489

490+
inode_sb_list_del(inode);
491+
487492
if (op->evict_inode) {
488493
op->evict_inode(inode);
489494
} else {
@@ -539,7 +544,7 @@ void evict_inodes(struct super_block *sb)
539544
struct inode *inode, *next;
540545
LIST_HEAD(dispose);
541546

542-
spin_lock(&inode_lock);
547+
spin_lock(&inode_sb_list_lock);
543548
list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) {
544549
if (atomic_read(&inode->i_count))
545550
continue;
@@ -555,7 +560,7 @@ void evict_inodes(struct super_block *sb)
555560
spin_unlock(&inode->i_lock);
556561
list_add(&inode->i_lru, &dispose);
557562
}
558-
spin_unlock(&inode_lock);
563+
spin_unlock(&inode_sb_list_lock);
559564

560565
dispose_list(&dispose);
561566

@@ -584,7 +589,7 @@ int invalidate_inodes(struct super_block *sb, bool kill_dirty)
584589
struct inode *inode, *next;
585590
LIST_HEAD(dispose);
586591

587-
spin_lock(&inode_lock);
592+
spin_lock(&inode_sb_list_lock);
588593
list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) {
589594
spin_lock(&inode->i_lock);
590595
if (inode->i_state & (I_NEW | I_FREEING | I_WILL_FREE)) {
@@ -607,7 +612,7 @@ int invalidate_inodes(struct super_block *sb, bool kill_dirty)
607612
spin_unlock(&inode->i_lock);
608613
list_add(&inode->i_lru, &dispose);
609614
}
610-
spin_unlock(&inode_lock);
615+
spin_unlock(&inode_sb_list_lock);
611616

612617
dispose_list(&dispose);
613618

@@ -867,16 +872,14 @@ struct inode *new_inode(struct super_block *sb)
867872
{
868873
struct inode *inode;
869874

870-
spin_lock_prefetch(&inode_lock);
875+
spin_lock_prefetch(&inode_sb_list_lock);
871876

872877
inode = alloc_inode(sb);
873878
if (inode) {
874-
spin_lock(&inode_lock);
875879
spin_lock(&inode->i_lock);
876880
inode->i_state = 0;
877881
spin_unlock(&inode->i_lock);
878-
__inode_sb_list_add(inode);
879-
spin_unlock(&inode_lock);
882+
inode_sb_list_add(inode);
880883
}
881884
return inode;
882885
}
@@ -945,7 +948,7 @@ static struct inode *get_new_inode(struct super_block *sb,
945948
inode->i_state = I_NEW;
946949
hlist_add_head(&inode->i_hash, head);
947950
spin_unlock(&inode->i_lock);
948-
__inode_sb_list_add(inode);
951+
inode_sb_list_add(inode);
949952
spin_unlock(&inode_lock);
950953

951954
/* Return the locked inode with I_NEW set, the
@@ -994,7 +997,7 @@ static struct inode *get_new_inode_fast(struct super_block *sb,
994997
inode->i_state = I_NEW;
995998
hlist_add_head(&inode->i_hash, head);
996999
spin_unlock(&inode->i_lock);
997-
__inode_sb_list_add(inode);
1000+
inode_sb_list_add(inode);
9981001
spin_unlock(&inode_lock);
9991002

10001003
/* Return the locked inode with I_NEW set, the

‎fs/internal.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ extern long do_handle_open(int mountdirfd,
125125
/*
126126
* inode.c
127127
*/
128+
extern spinlock_t inode_sb_list_lock;
129+
128130
extern int get_nr_dirty_inodes(void);
129131
extern void evict_inodes(struct super_block *);
130132
extern int invalidate_inodes(struct super_block *, bool);

‎fs/notify/inode_mark.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <linux/fsnotify_backend.h>
3030
#include "fsnotify.h"
3131

32+
#include "../internal.h"
33+
3234
/*
3335
* Recalculate the mask of events relevant to a given inode locked.
3436
*/
@@ -237,15 +239,14 @@ int fsnotify_add_inode_mark(struct fsnotify_mark *mark,
237239
* fsnotify_unmount_inodes - an sb is unmounting. handle any watched inodes.
238240
* @list: list of inodes being unmounted (sb->s_inodes)
239241
*
240-
* Called with inode_lock held, protecting the unmounting super block's list
241-
* of inodes, and with iprune_mutex held, keeping shrink_icache_memory() at bay.
242-
* We temporarily drop inode_lock, however, and CAN block.
242+
* Called during unmount with no locks held, so needs to be safe against
243+
* concurrent modifiers. We temporarily drop inode_sb_list_lock and CAN block.
243244
*/
244245
void fsnotify_unmount_inodes(struct list_head *list)
245246
{
246247
struct inode *inode, *next_i, *need_iput = NULL;
247248

248-
spin_lock(&inode_lock);
249+
spin_lock(&inode_sb_list_lock);
249250
list_for_each_entry_safe(inode, next_i, list, i_sb_list) {
250251
struct inode *need_iput_tmp;
251252

@@ -293,12 +294,11 @@ void fsnotify_unmount_inodes(struct list_head *list)
293294
}
294295

295296
/*
296-
* We can safely drop inode_lock here because we hold
297+
* We can safely drop inode_sb_list_lock here because we hold
297298
* references on both inode and next_i. Also no new inodes
298-
* will be added since the umount has begun. Finally,
299-
* iprune_mutex keeps shrink_icache_memory() away.
299+
* will be added since the umount has begun.
300300
*/
301-
spin_unlock(&inode_lock);
301+
spin_unlock(&inode_sb_list_lock);
302302

303303
if (need_iput_tmp)
304304
iput(need_iput_tmp);
@@ -310,7 +310,7 @@ void fsnotify_unmount_inodes(struct list_head *list)
310310

311311
iput(inode);
312312

313-
spin_lock(&inode_lock);
313+
spin_lock(&inode_sb_list_lock);
314314
}
315-
spin_unlock(&inode_lock);
315+
spin_unlock(&inode_sb_list_lock);
316316
}

‎fs/quota/dquot.c‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
#include <linux/buffer_head.h>
7777
#include <linux/capability.h>
7878
#include <linux/quotaops.h>
79-
#include <linux/writeback.h> /* for inode_lock, oddly enough.. */
79+
#include "../internal.h" /* ugh */
8080

8181
#include <asm/uaccess.h>
8282

@@ -900,7 +900,7 @@ static void add_dquot_ref(struct super_block *sb, int type)
900900
int reserved = 0;
901901
#endif
902902

903-
spin_lock(&inode_lock);
903+
spin_lock(&inode_sb_list_lock);
904904
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
905905
spin_lock(&inode->i_lock);
906906
if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) ||
@@ -915,19 +915,23 @@ static void add_dquot_ref(struct super_block *sb, int type)
915915
#endif
916916
__iget(inode);
917917
spin_unlock(&inode->i_lock);
918-
spin_unlock(&inode_lock);
918+
spin_unlock(&inode_sb_list_lock);
919919

920920
iput(old_inode);
921921
__dquot_initialize(inode, type);
922-
/* We hold a reference to 'inode' so it couldn't have been
923-
* removed from s_inodes list while we dropped the inode_lock.
924-
* We cannot iput the inode now as we can be holding the last
925-
* reference and we cannot iput it under inode_lock. So we
926-
* keep the reference and iput it later. */
922+
923+
/*
924+
* We hold a reference to 'inode' so it couldn't have been
925+
* removed from s_inodes list while we dropped the
926+
* inode_sb_list_lock We cannot iput the inode now as we can be
927+
* holding the last reference and we cannot iput it under
928+
* inode_sb_list_lock. So we keep the reference and iput it
929+
* later.
930+
*/
927931
old_inode = inode;
928-
spin_lock(&inode_lock);
932+
spin_lock(&inode_sb_list_lock);
929933
}
930-
spin_unlock(&inode_lock);
934+
spin_unlock(&inode_sb_list_lock);
931935
iput(old_inode);
932936

933937
#ifdef CONFIG_QUOTA_DEBUG
@@ -1008,7 +1012,7 @@ static void remove_dquot_ref(struct super_block *sb, int type,
10081012
struct inode *inode;
10091013
int reserved = 0;
10101014

1011-
spin_lock(&inode_lock);
1015+
spin_lock(&inode_sb_list_lock);
10121016
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
10131017
/*
10141018
* We have to scan also I_NEW inodes because they can already
@@ -1022,7 +1026,7 @@ static void remove_dquot_ref(struct super_block *sb, int type,
10221026
remove_inode_dquot_ref(inode, type, tofree_head);
10231027
}
10241028
}
1025-
spin_unlock(&inode_lock);
1029+
spin_unlock(&inode_sb_list_lock);
10261030
#ifdef CONFIG_QUOTA_DEBUG
10271031
if (reserved) {
10281032
printk(KERN_WARNING "VFS (%s): Writes happened after quota"

0 commit comments

Comments
 (0)