vfs scalability patches updated
Subsystems (70)
PATCH 22/52 fs: dcache rationalise dget variants
In reply to [email protected]dget_locked was a shortcut to avoid the lazy lru manipulation when we already held dcache_lock (lru manipulation was relatively cheap at that point). However, how that the lru lock is an innermost one, we never hold it at any caller, so the lock cost can now be avoided. We already have well working lazy dcache LRU, so it should be fine to defer LRU manipulations to scan time.
--- arch/powerpc/platforms/cell/spufs/inode.c | 2 - drivers/infiniband/hw/ipath/ipath_fs.c | 2 - fs/autofs4/root.c | 4 +-- fs/configfs/inode.c | 2 - fs/dcache.c | 34 ++++++++---------------------- fs/exportfs/expfs.c | 2 - fs/ncpfs/dir.c | 2 - fs/ocfs2/dcache.c | 2 - fs/smbfs/cache.c | 2 - fs/sysfs/dir.c | 2 - include/linux/dcache.h | 15 ++----------- kernel/cgroup.c | 2 - security/selinux/selinuxfs.c | 2 - 13 files changed, 25 insertions(+), 48 deletions(-)
arch/powerpc/platforms/cell/spufs/inode.c +1 -1
@@ -160,7 +160,7 @@ static void spufs_prune_dir(struct dentrlist_for_each_entry_safe (dentry, tmp, &dir->d_subdirs, d_u.d_child) {spin_lock (&dentry->d_lock);if (!(d_unhashed (dentry)) && dentry->d_inode) { -dget_locked_dlock (dentry); +dget_dlock (dentry);__d_drop (dentry);spin_unlock (&dentry->d_lock);simple_unlink (dir->d_inode, dentry);
drivers/infiniband/hw/ipath/ipath_fs.c +1 -1
@@ -275,7 +275,7 @@ static int remove_file(struct dentry *paspin_lock (&tmp->d_lock);if (!(d_unhashed (tmp) && tmp->d_inode)) { -dget_locked_dlock (tmp); +dget_dlock (tmp);__d_drop (tmp);spin_unlock (&tmp->d_lock);simple_unlink (parent->d_inode, tmp);
fs/configfs/inode.c +1 -1
@@ -251,7 +251,7 @@ void configfs_drop_dentry(struct configfif (dentry) {spin_lock (&dentry->d_lock);if (!(d_unhashed (dentry) && dentry->d_inode)) { -dget_locked_dlock (dentry); +dget_dlock (dentry);__d_drop (dentry);spin_unlock (&dentry->d_lock);simple_unlink (parent->d_inode, dentry);
fs/dcache.c +11 -18
@@ -287,29 +287,23 @@ void d_drop(struct dentry *dentry)EXPORT_SYMBOL (d_drop);/* This must be called with d_lock held */ -static inline struct dentry *__dget_locked_dlock (struct dentry *dentry) +static inline struct dentry *__dget_dlock (struct dentry *dentry) { dentry->d_count++; -dentry_lru_del_init (dentry);return dentry; } -static inline struct dentry *__dget_locked (struct dentry *dentry) +static inline struct dentry *__dget (struct dentry *dentry) {spin_lock (&dentry->d_lock); -__dget_locked_dlock (dentry); +__dget_dlock (dentry);spin_unlock (&dentry->d_lock);return dentry; } -struct dentry *dget_locked_dlock (struct dentry *dentry) -{ -return __dget_locked_dlock (dentry); -} -struct dentry *dget_locked (struct dentry *dentry) { -return __dget_locked (dentry); +return __dget (dentry); }EXPORT_SYMBOL (dget_locked);
@@ -534,7 +528,7 @@ static struct dentry * __d_find_alias(st (alias->d_flags & DCACHE_DISCONNECTED)) discon_alias = alias; else if (!want_discon) { -__dget_locked_dlock (alias); +__dget_dlock (alias);spin_unlock (&alias->d_lock);return alias; }
@@ -542,7 +536,7 @@ static struct dentry * __d_find_alias(stspin_unlock (&alias->d_lock); }if (discon_alias) -__dget_locked (discon_alias); +__dget (discon_alias);return discon_alias; }
@@ -571,7 +565,7 @@ restart:list_for_each_entry (dentry, &inode->i_dentry, d_alias) {spin_lock (&dentry->d_lock);if (!dentry->d_count) { -__dget_locked_dlock (dentry); +__dget_dlock (dentry);__d_drop (dentry);spin_unlock (&dentry->d_lock);spin_unlock (&inode->i_lock);
@@ -1349,7 +1343,7 @@ static struct dentry *__d_instantiate_uncontinue ;if (memcmp (qstr->name, name, len))continue ; -dget_locked (alias); +dget (alias);return alias; }
@@ -1593,7 +1587,7 @@ struct dentry *d_add_ci(struct dentry *d* reference to it, move it in place and use it. */ new = list_entry(inode->i_dentry.next, struct dentry, d_alias); -dget_locked (new); +dget (new);spin_unlock (&inode->i_lock);security_d_instantiate (found, inode);d_move (new, found);
@@ -1629,8 +1623,7 @@ EXPORT_SYMBOL(d_add_ci);* * The dentry unused LRU is not updated even if lookup finds the required dentry * in there. It is updated in places such as prune_dcache, shrink_dcache_sb, -* select_parent and __dget_locked. This laziness saves lookup from LRU lock -* acquisition. +* select_parent. This laziness saves lookup from LRU lock acquisition. * * d_lookup() is protected against the concurrent renames in some unrelated * directory using the seqlockt_t rename_lock.
@@ -1767,7 +1760,7 @@ int d_validate(struct dentry *dentry, sthlist_bl_for_each_entry_rcu (lhp, node, &b->head, d_hash) {if (dentry == lhp) {rcu_read_unlock (); -__dget_locked_dlock (dentry); +__dget_dlock (dentry);spin_unlock (&dentry->d_lock);return 1 ; }
fs/exportfs/expfs.c +1 -1
@@ -51,7 +51,7 @@ find_acceptable_alias(struct dentry *res inode = result->d_inode;spin_lock (&inode->i_lock);list_for_each_entry (dentry, &inode->i_dentry, d_alias) { -dget_locked (dentry); +dget (dentry);spin_unlock (&inode->i_lock);if (toput)dput (toput);
fs/ncpfs/dir.c +1 -1
@@ -370,7 +370,7 @@ ncp_dget_fpos(struct dentry *dentry, str dent = list_entry(next, struct dentry, d_u.d_child);if ((unsigned long )dent->d_fsdata == fpos) {if (dent->d_inode) -dget_locked (dent); +dget (dent);else dent =NULL ;spin_unlock (&parent->d_lock);
fs/ocfs2/dcache.c +1 -1
@@ -160,7 +160,7 @@ struct dentry *ocfs2_find_local_alias(stmlog (0 ,"dentry found: %.*s\n" , dentry->d_name.len, dentry->d_name.name); -dget_locked_dlock (dentry); +dget_dlock (dentry);spin_unlock (&dentry->d_lock);break ; }
fs/smbfs/cache.c +1 -1
@@ -102,7 +102,7 @@ smb_dget_fpos(struct dentry *dentry, str dent = list_entry(next, struct dentry, d_u.d_child);if ((unsigned long )dent->d_fsdata == fpos) {if (dent->d_inode) -dget_locked (dent); +dget (dent);else dent =NULL ; goto out_unlock;
include/linux/dcache.h +3 -12
@@ -306,23 +306,17 @@ extern char *dentry_path(struct dentry */* Allocation counts.. */ /** -* dget, dget_locked - get a reference to a dentry +* dget, dget_dlock - get a reference to a dentry * @dentry: dentry to get a reference to * * Given a dentry or %NULL pointer increment the reference count * if appropriate and return the dentry. A dentry will not be -* destroyed when it has references. dget() should never be -* called for dentries with zero reference counter. For these cases -* (preferably none, functions in dcache.c are sufficient for normal -* needs and they take necessary precautions) you should hold dcache_lock -* and call dget_locked() instead of dget(). +* destroyed when it has references. */ static inline struct dentry *dget_dlock (struct dentry *dentry) { -if (dentry) { -BUG_ON (!dentry->d_count); +if (dentry) dentry->d_count++; - }return dentry; }
@@ -336,9 +330,6 @@ static inline struct dentry *dget(structreturn dentry; } -extern struct dentry *dget_locked (struct dentry *); -extern struct dentry *dget_locked_dlock (struct dentry *); -extern struct dentry *dget_parent (struct dentry *dentry);/**
kernel/cgroup.c +1 -1
@@ -880,7 +880,7 @@ static void cgroup_clear_directory(struc/* This should never be called on a cgroup * directory with child cgroups */ BUG_ON (d->d_inode->i_mode &S_IFDIR ); -dget_locked_dlock (d); +dget_dlock (d);spin_unlock (&d->d_lock);spin_unlock (&dentry->d_lock);d_delete (d);
security/selinux/selinuxfs.c +1 -1
@@ -950,7 +950,7 @@ static void sel_remove_entries(struct delist_del_init (node);if (d->d_inode) { -dget_locked_dlock (d); +dget_dlock (d);spin_unlock (&de->d_lock);spin_unlock (&d->d_lock);d_delete (d);
drivers/infiniband/hw/qib/qib_fs.c +1 -1
@@ -453,7 +453,7 @@ static int remove_file(struct dentry *paspin_lock (&tmp->d_lock);if (!(d_unhashed (tmp) && tmp->d_inode)) { -dget_locked_dlock (tmp); +dget_dlock (tmp);__d_drop (tmp);spin_unlock (&tmp->d_lock);simple_unlink (parent->d_inode, tmp);
PATCH 24/52 fs: dcache reduce d_parent locking
In reply to [email protected]Use RCU property of dcache to simplify locking in some places where we take d_parent and d_lock.
Comment: don't need rcu_deref because we take the spinlock and recheck it.
--
fs/dcache.c +20 -17
@@ -311,23 +311,18 @@ struct dentry *dget_parent(struct dentrystruct dentry *ret; repeat: -spin_lock (&dentry->d_lock); +rcu_read_lock (); ret = dentry->d_parent; -if (!ret) - goto out; -if (dentry == ret) { - ret->d_count++; - goto out; - } -if (!spin_trylock (&ret->d_lock)) { -spin_unlock (&dentry->d_lock); +spin_lock (&ret->d_lock); +if (unlikely (ret != dentry->d_parent)) { +spin_unlock (&ret->d_lock); +rcu_read_unlock (); goto repeat; } +rcu_read_unlock ();BUG_ON (!ret->d_count); ret->d_count++;spin_unlock (&ret->d_lock); -out: -spin_unlock (&dentry->d_lock);return ret; }EXPORT_SYMBOL (dget_parent);
@@ -601,14 +596,22 @@ static void prune_one_dentry(struct dentif (inode)spin_lock (&inode->i_lock); again: -spin_lock (&dentry->d_lock); -if (dentry->d_parent && dentry != dentry->d_parent) { -if (!spin_trylock (&dentry->d_parent->d_lock)) { -spin_unlock (&dentry->d_lock); +rcu_read_lock (); + parent = dentry->d_parent; +if (parent) { +spin_lock (&parent->d_lock); +if (unlikely (parent != dentry->d_parent)) { +spin_unlock (&parent->d_lock); +rcu_read_unlock (); goto again; } - parent = dentry->d_parent; - } +if (parent != dentry) +spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED ); +else + parent =NULL ; + }else +spin_lock (&dentry->d_lock); +rcu_read_unlock (); dentry->d_count--;if (dentry->d_count) {if (parent)
PATCH 27/52 fs: icache lock inode hash
In reply to [email protected]Add a new lock, inode_hash_lock, to protect the inode hash table lists.
--- fs/inode.c | 29 ++++++++++++++++++++++++++++- include/linux/writeback.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-)
fs/inode.c +32 -1
@@ -30,10 +30,14 @@* Usage: * sb_inode_list_lock protects: * s_inodes, i_sb_list +* inode_hash_lock protects: +* inode hash table, i_hash * * Ordering: * inode_lock * sb_inode_list_lock +* inode_lock +* inode_hash_lock */ /* * This is needed for the following functions:
@@ -94,6 +98,7 @@ static struct hlist_head *inode_hashtabl*/ DEFINE_SPINLOCK (inode_lock);DEFINE_SPINLOCK (sb_inode_list_lock); +DEFINE_SPINLOCK (inode_hash_lock);/* * iprune_sem provides exclusion between the kswapd or try_to_free_pages
@@ -353,7 +358,9 @@ static void dispose_list(struct list_heaclear_inode (inode);spin_lock (&inode_lock); +spin_lock (&inode_hash_lock);hlist_del_init (&inode->i_hash); +spin_unlock (&inode_hash_lock);spin_lock (&sb_inode_list_lock);list_del_init (&inode->i_sb_list);spin_unlock (&sb_inode_list_lock);
@@ -563,17 +570,20 @@ static struct inode *find_inode(struct sstruct inode *inode =NULL ; repeat: +spin_lock (&inode_hash_lock);hlist_for_each_entry (inode, node, head, i_hash) {if (inode->i_sb != sb)continue ;if (!test (inode, data))continue ;if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE )) { +spin_unlock (&inode_hash_lock);__wait_on_freeing_inode (inode); goto repeat; }break ; } +spin_unlock (&inode_hash_lock);return node ? inode :NULL ; }
@@ -588,17 +598,20 @@ static struct inode *find_inode_fast(strstruct inode *inode =NULL ; repeat: +spin_lock (&inode_hash_lock);hlist_for_each_entry (inode, node, head, i_hash) {if (inode->i_ino != ino)continue ;if (inode->i_sb != sb)continue ;if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE )) { +spin_unlock (&inode_hash_lock);__wait_on_freeing_inode (inode); goto repeat; }break ; } +spin_unlock (&inode_hash_lock);return node ? inode :NULL ; }
@@ -621,8 +634,11 @@ __inode_add_to_lists(struct super_blockspin_lock (&sb_inode_list_lock);list_add (&inode->i_sb_list, &sb->s_inodes);spin_unlock (&sb_inode_list_lock); -if (head) +if (head) { +spin_lock (&inode_hash_lock);hlist_add_head (&inode->i_hash, head); +spin_unlock (&inode_hash_lock); + } }/**
@@ -1100,7 +1116,9 @@ int insert_inode_locked(struct inode *inwhile (1 ) {struct hlist_node *node;struct inode *old =NULL ; +spin_lock (&inode_lock); +spin_lock (&inode_hash_lock);hlist_for_each_entry (old, node, head, i_hash) {if (old->i_ino != ino)continue ;
@@ -1112,9 +1130,11 @@ int insert_inode_locked(struct inode *in }if (likely (!node)) {hlist_add_head (&inode->i_hash, head); +spin_unlock (&inode_hash_lock);spin_unlock (&inode_lock);return 0 ; } +spin_unlock (&inode_hash_lock);__iget (old);spin_unlock (&inode_lock);wait_on_inode (old);
@@ -1140,6 +1160,7 @@ int insert_inode_locked4(struct inode *istruct inode *old =NULL ;spin_lock (&inode_lock); +spin_lock (&inode_hash_lock);hlist_for_each_entry (old, node, head, i_hash) {if (old->i_sb != sb)continue ;
@@ -1151,9 +1172,11 @@ int insert_inode_locked4(struct inode *i }if (likely (!node)) {hlist_add_head (&inode->i_hash, head); +spin_unlock (&inode_hash_lock);spin_unlock (&inode_lock);return 0 ; } +spin_unlock (&inode_hash_lock);__iget (old);spin_unlock (&inode_lock);wait_on_inode (old);
@@ -1178,7 +1201,9 @@ void __insert_inode_hash(struct inode *i {struct hlist_head *head = inode_hashtable +hash (inode->i_sb, hashval);spin_lock (&inode_lock); +spin_lock (&inode_hash_lock);hlist_add_head (&inode->i_hash, head); +spin_unlock (&inode_hash_lock);spin_unlock (&inode_lock); }EXPORT_SYMBOL (__insert_inode_hash);
@@ -1192,7 +1217,9 @@ EXPORT_SYMBOL(__insert_inode_hash);void remove_inode_hash (struct inode *inode) {spin_lock (&inode_lock); +spin_lock (&inode_hash_lock);hlist_del_init (&inode->i_hash); +spin_unlock (&inode_hash_lock);spin_unlock (&inode_lock); }EXPORT_SYMBOL (remove_inode_hash);
@@ -1234,7 +1261,9 @@ void generic_delete_inode(struct inode *clear_inode (inode); }spin_lock (&inode_lock); +spin_lock (&inode_hash_lock);hlist_del_init (&inode->i_hash); +spin_unlock (&inode_hash_lock);spin_unlock (&inode_lock);wake_up_inode (inode);BUG_ON (inode->i_state !=I_CLEAR );
@@ -1271,7 +1300,9 @@ int generic_detach_inode(struct inode *iWARN_ON (inode->i_state &I_NEW ); inode->i_state &= ~I_WILL_FREE ; inodes_stat.nr_unused--; +spin_lock (&inode_hash_lock);hlist_del_init (&inode->i_hash); +spin_unlock (&inode_hash_lock); }list_del_init (&inode->i_list);spin_lock (&sb_inode_list_lock);
include/linux/writeback.h +1 -0
@@ -11,6 +11,7 @@ struct backing_dev_info;extern spinlock_t inode_lock;extern spinlock_t sb_inode_list_lock; +extern spinlock_t inode_hash_lock;extern struct list_head inode_in_use;extern struct list_head inode_unused;
PATCH 33/52 fs: icache atomic last_ino, iunique lock
In reply to [email protected]Make last_ino atomic in preperation for removing inode_lock. Make a new lock for iunique counter, for removing inode_lock.
--- fs/inode.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
fs/inode.c +22 -6
@@ -742,7 +742,7 @@ struct inode *new_inode(struct super_blo* error if st_ino won't fit in target struct field. Use 32bit counter * here to attempt to avoid that. */ -static unsigned int last_ino; +static atomic_t last_ino =ATOMIC_INIT (0 );struct inode *inode;spin_lock_prefetch (&inode_lock);
@@ -752,7 +752,7 @@ struct inode *new_inode(struct super_blospin_lock (&inode_lock);spin_lock (&sb_inode_list_lock);spin_lock (&inode->i_lock); - inode->i_ino = ++last_ino; + inode->i_ino =atomic_inc_return (&last_ino); inode->i_state =0 ;__inode_add_to_lists (sb,NULL , inode);spin_unlock (&inode->i_lock);
@@ -903,6 +903,22 @@ static struct inode *get_new_inode_fast(return inode; } +static int test_inode_iunique (struct super_block * sb,struct hlist_head *head,unsigned long ino) +{ +struct hlist_node *node; +struct inode * inode =NULL ; + +spin_lock (&inode_hash_lock); +hlist_for_each_entry (inode, node, head, i_hash) { +if (inode->i_ino == ino && inode->i_sb == sb) { +spin_unlock (&inode_hash_lock); +return 0 ; + } + } +spin_unlock (&inode_hash_lock); +return 1 ; +} +/** * iunique - get a unique inode number * @sb: superblock
@@ -924,20 +940,20 @@ ino_t iunique(struct super_block *sb, in* error if st_ino won't fit in target struct field. Use 32bit counter * here to attempt to avoid that. */ +static DEFINE_SPINLOCK (unique_lock);static unsigned int counter; -struct inode *inode;struct hlist_head *head;ino_t res;spin_lock (&inode_lock); +spin_lock (&unique_lock);do {if (counter <= max_reserved) counter = max_reserved +1 ; res = counter++; head = inode_hashtable +hash (sb, res); - inode =find_inode_fast (sb, head, res); -spin_unlock (&inode->i_lock); - }while (inode !=NULL ); + }while (!test_inode_iunique (sb, head, res)); +spin_unlock (&unique_lock);spin_unlock (&inode_lock);return res;
PATCH 2/52 fs: fix superblock iteration race
In reply to [email protected]list_for_each_entry_safe is not suitable to protect against concurrent modification of the list. 6754af6 introduced a race in sb walking.
list_for_each_entry can use the trick of pinning the current entry in the list before we drop and retake the lock because it subsequently follows cur->next. However list_for_each_entry_safe saves n=cur->next for following before entering the loop body, so when the lock is dropped, n may be deleted.
--- fs/dcache.c | 2 ++ fs/super.c | 6 ++++++ include/linux/list.h | 15 +++++++++++++++ 3 files changed, 23 insertions(+)
fs/dcache.c +2 -0
@@ -590,6 +590,8 @@ static void prune_dcache(int count)up_read (&sb->s_umount); }spin_lock (&sb_lock); +/* lock was dropped, must reset next */ +list_safe_reset_next (sb, n, s_list); count -= pruned;__put_super (sb);/* more work left to do? */
fs/super.c +6 -0
@@ -374,6 +374,8 @@ void sync_supers(void)up_read (&sb->s_umount);spin_lock (&sb_lock); +/* lock was dropped, must reset next */ +list_safe_reset_next (sb, n, s_list);__put_super (sb); } }
@@ -405,6 +407,8 @@ void iterate_supers(void (*f)(struct supup_read (&sb->s_umount);spin_lock (&sb_lock); +/* lock was dropped, must reset next */ +list_safe_reset_next (sb, n, s_list);__put_super (sb); }spin_unlock (&sb_lock);
@@ -585,6 +589,8 @@ static void do_emergency_remount(struct }up_write (&sb->s_umount);spin_lock (&sb_lock); +/* lock was dropped, must reset next */ +list_safe_reset_next (sb, n, s_list);__put_super (sb); }spin_unlock (&sb_lock);
include/linux/list.h +15 -0
@@ -544,6 +544,21 @@ static inline void list_splice_tail_init &pos->member != (head); \ pos = n, n = list_entry(n->member.prev, typeof(*n), member)) +/** +* list_safe_reset_next - reset a stale list_for_each_entry_safe loop +* @pos: the loop cursor used in the list_for_each_entry_safe loop +* @n: temporary storage used in list_for_each_entry_safe +* @member: the name of the list_struct within the struct. +* +* list_safe_reset_next is not safe to use in general if the list may be +* modified concurrently (eg. the lock is dropped in the loop body). An +* exception to this is if the cursor element (pos) is pinned in the list, +* and list_safe_reset_next is called after re-taking the lock and before +* completing the current iteration of the loop body. +*/ +#define list_safe_reset_next (pos, n, member) \ + n = list_entry(pos->member.next, typeof(*pos), member) +/* * Double linked lists with a single pointer list head. * Mostly useful for hash tables where the two pointer list head is
PATCH 36/52 fs: icache per-bucket inode hash locks
In reply to [email protected]Remove the global inode_hash_lock and replace it with per-hash-bucket locks.
--- fs/inode.c | 167 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 90 insertions(+), 77 deletions(-)
fs/inode.c +110 -88
@@ -25,12 +25,13 @@#include <linux/mount.h> #include <linux/async.h> #include <linux/posix_acl.h> +#include <linux/bit_spinlock.h> /* * Usage: * sb_inode_list_lock protects: * s_inodes, i_sb_list -* inode_hash_lock protects: +* inode_hash_bucket lock protects: * inode hash table, i_hash * wb_inode_list_lock protects: * inode_in_use, inode_unused, b_io, b_more_io, b_dirty, i_list
@@ -46,7 +47,7 @@* sb_inode_list_lock * inode->i_lock * wb_inode_list_lock -* inode_hash_lock +* inode_hash_bucket lock */ /* * This is needed for the following functions:
@@ -97,7 +98,22 @@ static unsigned int i_hash_shift __read_LIST_HEAD (inode_in_use);LIST_HEAD (inode_unused); -static struct hlist_head *inode_hashtable__read_mostly ; + +struct inode_hash_bucket { +struct hlist_bl_head head; +}; + +static inline void spin_lock_bucket (struct inode_hash_bucket *b) +{ +bit_spin_lock (0 , (unsigned long *)b); +} + +static inline void spin_unlock_bucket (struct inode_hash_bucket *b) +{ +__bit_spin_unlock (0 , (unsigned long *)b); +} + +static struct inode_hash_bucket *inode_hashtable__read_mostly ;/* * A simple spinlock to protect the list manipulations.
@@ -107,7 +123,6 @@ static struct hlist_head *inode_hashtabl*/ DEFINE_SPINLOCK (sb_inode_list_lock);DEFINE_SPINLOCK (wb_inode_list_lock); -static DEFINE_SPINLOCK (inode_hash_lock);/* * iprune_sem provides exclusion between the kswapd or try_to_free_pages
@@ -280,7 +295,7 @@ void destroy_inode(struct inode *inode)void inode_init_once (struct inode *inode) {memset (inode,0 ,sizeof (*inode)); -INIT_HLIST_NODE (&inode->i_hash); +INIT_HLIST_BL_NODE (&inode->i_hash);INIT_LIST_HEAD (&inode->i_dentry);INIT_LIST_HEAD (&inode->i_devices);INIT_RADIX_TREE (&inode->i_data.page_tree,GFP_ATOMIC );
@@ -596,20 +611,21 @@ static void __wait_on_freeing_inode(stru* add any additional branch in the common code. */ static struct inode *find_inode (struct super_block *sb, -struct hlist_head *head, +struct inode_hash_bucket *b,int (*test)(struct inode *,void *),void *data) { -struct hlist_node *node; +struct hlist_bl_node *node;struct inode *inode =NULL ; repeat: -spin_lock (&inode_hash_lock); -hlist_for_each_entry (inode, node, head, i_hash) { +spin_lock_bucket (b); +hlist_bl_for_each_entry (inode, node, &b->head, i_hash) {if (inode->i_sb != sb)continue ;if (!spin_trylock (&inode->i_lock)) { -spin_unlock (&inode_hash_lock); +spin_unlock_bucket (b); +cpu_relax (); goto repeat; }if (!test (inode, data)) {
@@ -617,13 +633,13 @@ repeat:continue ; }if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE )) { -spin_unlock (&inode_hash_lock); +spin_unlock_bucket (b);__wait_on_freeing_inode (inode); goto repeat; }break ; } -spin_unlock (&inode_hash_lock); +spin_unlock_bucket (b);return node ? inode :NULL ; }
@@ -632,30 +648,32 @@ repeat:* iget_locked for details. */ static struct inode *find_inode_fast (struct super_block *sb, -struct hlist_head *head,unsigned long ino) +struct inode_hash_bucket *b, +unsigned long ino) { -struct hlist_node *node; +struct hlist_bl_node *node;struct inode *inode =NULL ; repeat: -spin_lock (&inode_hash_lock); -hlist_for_each_entry (inode, node, head, i_hash) { +spin_lock_bucket (b); +hlist_bl_for_each_entry (inode, node, &b->head, i_hash) {if (inode->i_ino != ino)continue ;if (inode->i_sb != sb)continue ;if (!spin_trylock (&inode->i_lock)) { -spin_unlock (&inode_hash_lock); +spin_unlock_bucket (b); +cpu_relax (); goto repeat; }if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE )) { -spin_unlock (&inode_hash_lock); +spin_unlock_bucket (b);__wait_on_freeing_inode (inode); goto repeat; }break ; } -spin_unlock (&inode_hash_lock); +spin_unlock_bucket (b);return node ? inode :NULL ; }
@@ -670,7 +688,7 @@ static unsigned long hash(struct super_b }static inline void -__inode_add_to_lists (struct super_block *sb,struct hlist_head *head, +__inode_add_to_lists (struct super_block *sb,struct inode_hash_bucket *b,struct inode *inode) {atomic_inc (&inodes_stat.nr_inodes);
@@ -679,10 +697,10 @@ __inode_add_to_lists(struct super_blockspin_lock (&wb_inode_list_lock);list_add (&inode->i_list, &inode_in_use);spin_unlock (&wb_inode_list_lock); -if (head) { -spin_lock (&inode_hash_lock); -hlist_add_head (&inode->i_hash, head); -spin_unlock (&inode_hash_lock); +if (b) { +spin_lock_bucket (b); +hlist_bl_add_head (&inode->i_hash, &b->head); +spin_unlock_bucket (b); } }
@@ -700,11 +718,11 @@ __inode_add_to_lists(struct super_block*/ void inode_add_to_lists (struct super_block *sb,struct inode *inode) { -struct hlist_head *head = inode_hashtable +hash (sb, inode->i_ino); +struct inode_hash_bucket *b = inode_hashtable +hash (sb, inode->i_ino);spin_lock (&sb_inode_list_lock);spin_lock (&inode->i_lock); -__inode_add_to_lists (sb, head, inode); +__inode_add_to_lists (sb, b, inode);spin_unlock (&inode->i_lock); }EXPORT_SYMBOL_GPL (inode_add_to_lists);
@@ -786,7 +804,7 @@ EXPORT_SYMBOL(unlock_new_inode);* -- [email protected] */ static struct inode *get_new_inode (struct super_block *sb, -struct hlist_head *head, +struct inode_hash_bucket *b,int (*test)(struct inode *,void *),int (*set)(struct inode *,void *),void *data)
@@ -798,7 +816,7 @@ static struct inode *get_new_inode(strucstruct inode *old;/* We released the lock, so.. */ - old =find_inode (sb, head, test, data); + old =find_inode (sb, b, test, data);if (!old) {spin_lock (&sb_inode_list_lock);spin_lock (&inode->i_lock);
@@ -806,7 +824,7 @@ static struct inode *get_new_inode(struc goto set_failed; inode->i_state =I_NEW ; -__inode_add_to_lists (sb, head, inode); +__inode_add_to_lists (sb, b, inode);spin_unlock (&inode->i_lock);/* Return the locked inode with I_NEW set, the
@@ -840,7 +858,7 @@ set_failed:* comment at iget_locked for details. */ static struct inode *get_new_inode_fast (struct super_block *sb, -struct hlist_head *head,unsigned long ino) +struct inode_hash_bucket *b,unsigned long ino) {struct inode *inode;
@@ -849,13 +867,13 @@ static struct inode *get_new_inode_fast(struct inode *old;/* We released the lock, so.. */ - old =find_inode_fast (sb, head, ino); + old =find_inode_fast (sb, b, ino);if (!old) {spin_lock (&sb_inode_list_lock);spin_lock (&inode->i_lock); inode->i_ino = ino; inode->i_state =I_NEW ; -__inode_add_to_lists (sb, head, inode); +__inode_add_to_lists (sb, b, inode);spin_unlock (&inode->i_lock);/* Return the locked inode with I_NEW set, the
@@ -878,19 +896,20 @@ static struct inode *get_new_inode_fast(return inode; } -static int test_inode_iunique (struct super_block * sb,struct hlist_head *head,unsigned long ino) +static int test_inode_iunique (struct super_block *sb, +struct inode_hash_bucket *b,unsigned long ino) { -struct hlist_node *node; -struct inode * inode =NULL ; +struct hlist_bl_node *node; +struct inode *inode =NULL ; -spin_lock (&inode_hash_lock); -hlist_for_each_entry (inode, node, head, i_hash) { +spin_lock_bucket (b); +hlist_bl_for_each_entry (inode, node, &b->head, i_hash) {if (inode->i_ino == ino && inode->i_sb == sb) { -spin_unlock (&inode_hash_lock); +spin_unlock_bucket (b);return 0 ; } } -spin_unlock (&inode_hash_lock); +spin_unlock_bucket (b);return 1 ; }
@@ -917,7 +936,7 @@ ino_t iunique(struct super_block *sb, in*/ static DEFINE_SPINLOCK (unique_lock);static unsigned int counter; -struct hlist_head *head; +struct inode_hash_bucket *b;ino_t res;spin_lock (&unique_lock);
@@ -925,8 +944,8 @@ ino_t iunique(struct super_block *sb, inif (counter <= max_reserved) counter = max_reserved +1 ; res = counter++; - head = inode_hashtable +hash (sb, res); - }while (!test_inode_iunique (sb, head, res)); + b = inode_hashtable +hash (sb, res); + }while (!test_inode_iunique (sb, b, res));spin_unlock (&unique_lock);return res;
@@ -973,12 +992,13 @@ EXPORT_SYMBOL(igrab);* Note, @test is called with the inode_lock held, so can't sleep. */ static struct inode *ifind (struct super_block *sb, -struct hlist_head *head,int (*test)(struct inode *,void *), +struct inode_hash_bucket *b, +int (*test)(struct inode *,void *),void *data,const int wait) {struct inode *inode; - inode =find_inode (sb, head, test, data); + inode =find_inode (sb, b, test, data);if (inode) {__iget (inode);spin_unlock (&inode->i_lock);
@@ -1005,11 +1025,12 @@ static struct inode *ifind(struct super_* Otherwise NULL is returned. */ static struct inode *ifind_fast (struct super_block *sb, -struct hlist_head *head,unsigned long ino) +struct inode_hash_bucket *b, +unsigned long ino) {struct inode *inode; - inode =find_inode_fast (sb, head, ino); + inode =find_inode_fast (sb, b, ino);if (inode) {__iget (inode);spin_unlock (&inode->i_lock);
@@ -1043,9 +1064,9 @@ static struct inode *ifind_fast(struct sstruct inode *ilookup5_nowait (struct super_block *sb,unsigned long hashval,int (*test)(struct inode *,void *),void *data) { -struct hlist_head *head = inode_hashtable +hash (sb, hashval); +struct inode_hash_bucket *b = inode_hashtable +hash (sb, hashval); -return ifind (sb, head, test, data,0 ); +return ifind (sb, b, test, data,0 ); }EXPORT_SYMBOL (ilookup5_nowait);
@@ -1071,9 +1092,9 @@ EXPORT_SYMBOL(ilookup5_nowait);struct inode *ilookup5 (struct super_block *sb,unsigned long hashval,int (*test)(struct inode *,void *),void *data) { -struct hlist_head *head = inode_hashtable +hash (sb, hashval); +struct inode_hash_bucket *b = inode_hashtable +hash (sb, hashval); -return ifind (sb, head, test, data,1 ); +return ifind (sb, b, test, data,1 ); }EXPORT_SYMBOL (ilookup5);
@@ -1093,9 +1114,9 @@ EXPORT_SYMBOL(ilookup5);*/ struct inode *ilookup (struct super_block *sb,unsigned long ino) { -struct hlist_head *head = inode_hashtable +hash (sb, ino); +struct inode_hash_bucket *b = inode_hashtable +hash (sb, ino); -return ifind_fast (sb, head, ino); +return ifind_fast (sb, b, ino); }EXPORT_SYMBOL (ilookup);
@@ -1123,17 +1144,17 @@ struct inode *iget5_locked(struct super_int (*test)(struct inode *,void *), int (*set)(struct inode *, void *), void *data) { - struct hlist_head *head = inode_hashtable + hash(sb, hashval); + struct inode_hash_bucket *b = inode_hashtable + hash(sb, hashval);struct inode *inode; - inode =ifind (sb, head, test, data,1 ); + inode =ifind (sb, b, test, data,1 );if (inode)return inode;/* * get_new_inode() will do the right thing, re-trying the search * in case it had to block at any point. */ -return get_new_inode (sb, head, test, set, data); +return get_new_inode (sb, b, test, set, data); }EXPORT_SYMBOL (iget5_locked);
@@ -1154,17 +1175,17 @@ EXPORT_SYMBOL(iget5_locked);*/ struct inode *iget_locked (struct super_block *sb,unsigned long ino) { -struct hlist_head *head = inode_hashtable +hash (sb, ino); +struct inode_hash_bucket *b = inode_hashtable +hash (sb, ino);struct inode *inode; - inode =ifind_fast (sb, head, ino); + inode =ifind_fast (sb, b, ino);if (inode)return inode;/* * get_new_inode_fast() will do the right thing, re-trying the search * in case it had to block at any point. */ -return get_new_inode_fast (sb, head, ino); +return get_new_inode_fast (sb, b, ino); }EXPORT_SYMBOL (iget_locked);
@@ -1172,16 +1193,16 @@ int insert_inode_locked(struct inode *in {struct super_block *sb = inode->i_sb;ino_t ino = inode->i_ino; -struct hlist_head *head = inode_hashtable +hash (sb, ino); +struct inode_hash_bucket *b = inode_hashtable +hash (sb, ino); inode->i_state |=I_NEW ;while (1 ) { -struct hlist_node *node; +struct hlist_bl_node *node;struct inode *old =NULL ; repeat: -spin_lock (&inode_hash_lock); -hlist_for_each_entry (old, node, head, i_hash) { +spin_lock_bucket (b); +hlist_bl_for_each_entry (old, node, &b->head, i_hash) {if (old->i_ino != ino)continue ;if (old->i_sb != sb)
@@ -1189,21 +1210,21 @@ repeat:if (old->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE ))continue ;if (!spin_trylock (&old->i_lock)) { -spin_unlock (&inode_hash_lock); +spin_unlock_bucket (b); goto repeat; }break ; }if (likely (!node)) { -hlist_add_head (&inode->i_hash, head); -spin_unlock (&inode_hash_lock); +hlist_bl_add_head (&inode->i_hash, &b->head); +spin_unlock_bucket (b);return 0 ; } -spin_unlock (&inode_hash_lock); +spin_unlock_bucket (b);__iget (old);spin_unlock (&old->i_lock);wait_on_inode (old); -if (unlikely (!hlist_unhashed (&old->i_hash))) { +if (unlikely (!hlist_bl_unhashed (&old->i_hash))) {iput (old);return -EBUSY ; }
@@ -1216,17 +1237,17 @@ int insert_inode_locked4(struct inode *i int (*test)(struct inode *, void *), void *data) { struct super_block *sb = inode->i_sb; -struct hlist_head *head = inode_hashtable +hash (sb, hashval); +struct inode_hash_bucket *b = inode_hashtable +hash (sb, hashval); inode->i_state |=I_NEW ;while (1 ) { -struct hlist_node *node; +struct hlist_bl_node *node;struct inode *old =NULL ; repeat: -spin_lock (&inode_hash_lock); -hlist_for_each_entry (old, node, head, i_hash) { +spin_lock_bucket (b); +hlist_bl_for_each_entry (old, node, &b->head, i_hash) {if (old->i_sb != sb)continue ;if (!test (old, data))
@@ -1234,21 +1255,21 @@ repeat:if (old->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE ))continue ;if (!spin_trylock (&old->i_lock)) { -spin_unlock (&inode_hash_lock); +spin_unlock_bucket (b); goto repeat; }break ; }if (likely (!node)) { -hlist_add_head (&inode->i_hash, head); -spin_unlock (&inode_hash_lock); +hlist_bl_add_head (&inode->i_hash, &b->head); +spin_unlock_bucket (b);return 0 ; } -spin_unlock (&inode_hash_lock); +spin_unlock_bucket (b);__iget (old);spin_unlock (&old->i_lock);wait_on_inode (old); -if (unlikely (!hlist_unhashed (&old->i_hash))) { +if (unlikely (!hlist_bl_unhashed (&old->i_hash))) {iput (old);return -EBUSY ; }
@@ -1267,12 +1288,12 @@ EXPORT_SYMBOL(insert_inode_locked4);*/ void __insert_inode_hash (struct inode *inode,unsigned long hashval) { -struct hlist_head *head = inode_hashtable +hash (inode->i_sb, hashval); +struct inode_hash_bucket *b = inode_hashtable +hash (inode->i_sb, hashval);spin_lock (&inode->i_lock); -spin_lock (&inode_hash_lock); -hlist_add_head (&inode->i_hash, head); -spin_unlock (&inode_hash_lock); +spin_lock_bucket (b); +hlist_bl_add_head (&inode->i_hash, &b->head); +spin_unlock_bucket (b);spin_unlock (&inode->i_lock); }EXPORT_SYMBOL (__insert_inode_hash);
@@ -1286,9 +1307,10 @@ EXPORT_SYMBOL(__insert_inode_hash);*/ void __remove_inode_hash (struct inode *inode) { -spin_lock (&inode_hash_lock); -hlist_del_init (&inode->i_hash); -spin_unlock (&inode_hash_lock); +struct inode_hash_bucket *b = inode_hashtable +hash (inode->i_sb, inode->i_ino); +spin_lock_bucket (b); +hlist_bl_del_init (&inode->i_hash); +spin_unlock_bucket (b); }/**
@@ -1370,7 +1392,7 @@ int generic_detach_inode(struct inode *i {struct super_block *sb = inode->i_sb; -if (!hlist_unhashed (&inode->i_hash)) { +if (!hlist_bl_unhashed (&inode->i_hash)) {if (!(inode->i_state & (I_DIRTY |I_SYNC ))) {spin_lock (&wb_inode_list_lock);list_move (&inode->i_list, &inode_unused);
@@ -1699,7 +1721,7 @@ void __init inode_init_early(void) inode_hashtable = alloc_large_system_hash("Inode-cache", - sizeof(struct hlist_head), + sizeof(struct inode_hash_bucket), ihash_entries, 14, HASH_EARLY,
@@ -1708,7 +1730,7 @@ void __init inode_init_early(void) 0);for (loop =0 ; loop < (1 << i_hash_shift); loop++) -INIT_HLIST_HEAD (&inode_hashtable[loop]); +INIT_HLIST_BL_HEAD (&inode_hashtable[loop].head); }void __init inode_init (void )
@@ -1730,7 +1752,7 @@ void __init inode_init(void) inode_hashtable = alloc_large_system_hash("Inode-cache", - sizeof(struct hlist_head), + sizeof(struct inode_hash_bucket), ihash_entries, 14, 0,
@@ -1739,7 +1761,7 @@ void __init inode_init(void) 0);for (loop =0 ; loop < (1 << i_hash_shift); loop++) -INIT_HLIST_HEAD (&inode_hashtable[loop]); +INIT_HLIST_BL_HEAD (&inode_hashtable[loop].head); }void init_special_inode (struct inode *inode,umode_t mode,dev_t rdev)
fs/fs-writeback.c +1 -1
@@ -1147,7 +1147,7 @@ void __mark_inode_dirty(struct inode *in* dirty list. Add blockdev inodes as well. */ if (!S_ISBLK (inode->i_mode)) { -if (hlist_unhashed (&inode->i_hash)) +if (hlist_bl_unhashed (&inode->i_hash)) goto out; }if (inode->i_state & (I_FREEING |I_CLEAR ))
include/linux/fs.h +1 -1
@@ -723,7 +723,7 @@ struct posix_acl;#define ACL_NOT_CACHED ((void *)(-1))struct inode { -struct hlist_node i_hash; +struct hlist_bl_node i_hash;struct list_head i_list;/* backing dev IO list */ struct list_head i_sb_list;struct list_head i_dentry;
mm/shmem.c +2 -2
@@ -2122,7 +2122,7 @@ static int shmem_encode_fh(struct dentryif (*len <3 )return 255 ; -if (hlist_unhashed (&inode->i_hash)) { +if (hlist_bl_unhashed (&inode->i_hash)) {/* Unfortunately insert_inode_hash is not idempotent, * so as we hash inodes here rather than at creation * time, we need a lock to ensure we only try
@@ -2130,7 +2130,7 @@ static int shmem_encode_fh(struct dentry*/ static DEFINE_SPINLOCK (lock);spin_lock (&lock); -if (hlist_unhashed (&inode->i_hash)) +if (hlist_bl_unhashed (&inode->i_hash))__insert_inode_hash (inode, inode->i_ino + inode->i_generation);spin_unlock (&lock);
fs/btrfs/inode.c +1 -1
@@ -3849,7 +3849,7 @@ again: p = &root->inode_tree.rb_node; parent =NULL ; -if (hlist_unhashed (&inode->i_hash)) +if (hlist_bl_unhashed (&inode->i_hash))return ;spin_lock (&root->inode_lock);
fs/reiserfs/xattr.c +1 -1
@@ -424,7 +424,7 @@ int reiserfs_prepare_write(struct file *static void update_ctime (struct inode *inode) {struct timespec now =current_fs_time (inode->i_sb); -if (hlist_unhashed (&inode->i_hash) || !inode->i_nlink || +if (hlist_bl_unhashed (&inode->i_hash) || !inode->i_nlink ||timespec_equal (&inode->i_ctime, &now))return ;
fs/hfs/hfs_fs.h +1 -1
@@ -148,7 +148,7 @@ struct hfs_sb_info {int fs_div; -struct hlist_head rsrc_inodes; +struct hlist_bl_head rsrc_inodes; };#define HFS_FLG_BITMAP_DIRTY 0
fs/hfs/inode.c +1 -1
@@ -500,7 +500,7 @@ static struct dentry *hfs_file_lookup(stHFS_I (inode)->rsrc_inode = dir;HFS_I (dir)->rsrc_inode = inode;igrab (dir); -hlist_add_head (&inode->i_hash, &HFS_SB (dir->i_sb)->rsrc_inodes); +hlist_bl_add_head (&inode->i_hash, &HFS_SB (dir->i_sb)->rsrc_inodes);mark_inode_dirty (inode); out:d_add (dentry, inode);
fs/hfsplus/hfsplus_fs.h +1 -1
@@ -144,7 +144,7 @@ struct hfsplus_sb_info {unsigned long flags; -struct hlist_head rsrc_inodes; +struct hlist_bl_head rsrc_inodes; };#define HFSPLUS_SB_WRITEBACKUP 0x0001
fs/hfsplus/inode.c +1 -1
@@ -178,7 +178,7 @@ static struct dentry *hfsplus_file_lookuHFSPLUS_I (inode).rsrc_inode = dir;HFSPLUS_I (dir).rsrc_inode = inode;igrab (dir); -hlist_add_head (&inode->i_hash, &HFSPLUS_SB (sb).rsrc_inodes); +hlist_bl_add_head (&inode->i_hash, &HFSPLUS_SB (sb).rsrc_inodes);mark_inode_dirty (inode); out:d_add (dentry, inode);
fs/nilfs2/gcinode.c +10 -10
@@ -187,13 +187,13 @@ int nilfs_init_gccache(struct the_nilfsINIT_LIST_HEAD (&nilfs->ns_gc_inodes); nilfs->ns_gc_inodes_h = -kmalloc (sizeof (struct hlist_head ) *NILFS_GCINODE_HASH_SIZE , +kmalloc (sizeof (struct hlist_bl_head ) *NILFS_GCINODE_HASH_SIZE ,GFP_NOFS );if (nilfs->ns_gc_inodes_h ==NULL )return -ENOMEM ;for (loop =0 ; loop <NILFS_GCINODE_HASH_SIZE ; loop++) -INIT_HLIST_HEAD (&nilfs->ns_gc_inodes_h[loop]); +INIT_HLIST_BL_HEAD (&nilfs->ns_gc_inodes_h[loop]);return 0 ; }
@@ -245,18 +245,18 @@ static unsigned long ihash(ino_t ino, __*/ struct inode *nilfs_gc_iget (struct the_nilfs *nilfs,ino_t ino,__u64 cno) { -struct hlist_head *head = nilfs->ns_gc_inodes_h +ihash (ino, cno); -struct hlist_node *node; +struct hlist_bl_head *head = nilfs->ns_gc_inodes_h +ihash (ino, cno); +struct hlist_bl_node *node;struct inode *inode; -hlist_for_each_entry (inode, node, head, i_hash) { +hlist_bl_for_each_entry (inode, node, head, i_hash) {if (inode->i_ino == ino &&NILFS_I (inode)->i_cno == cno)return inode; } inode =alloc_gcinode (nilfs, ino, cno);if (likely (inode)) { -hlist_add_head (&inode->i_hash, head); +hlist_bl_add_head (&inode->i_hash, head);list_add (&NILFS_I (inode)->i_dirty, &nilfs->ns_gc_inodes); }return inode;
@@ -275,14 +275,14 @@ void nilfs_clear_gcinode(struct inode *i*/ void nilfs_remove_all_gcinode (struct the_nilfs *nilfs) { -struct hlist_head *head = nilfs->ns_gc_inodes_h; -struct hlist_node *node, *n; +struct hlist_bl_head *head = nilfs->ns_gc_inodes_h; +struct hlist_bl_node *node, *n;struct inode *inode;int loop;for (loop =0 ; loop <NILFS_GCINODE_HASH_SIZE ; loop++, head++) { -hlist_for_each_entry_safe (inode, node, n, head, i_hash) { -hlist_del_init (&inode->i_hash); +hlist_bl_for_each_entry_safe (inode, node, n, head, i_hash) { +hlist_bl_del_init (&inode->i_hash);list_del_init (&NILFS_I (inode)->i_dirty);nilfs_clear_gcinode (inode);/* might sleep */ }
fs/nilfs2/segment.c +1 -1
@@ -2447,7 +2447,7 @@ nilfs_remove_written_gcinodes(struct thelist_for_each_entry_safe (ii, n, head, i_dirty) {if (!test_bit (NILFS_I_UPDATED , &ii->i_state))continue ; -hlist_del_init (&ii->vfs_inode.i_hash); +hlist_bl_del_init (&ii->vfs_inode.i_hash);list_del_init (&ii->i_dirty);nilfs_clear_gcinode (&ii->vfs_inode); }
fs/nilfs2/the_nilfs.h +1 -1
@@ -164,7 +164,7 @@ struct the_nilfs {/* GC inode list and hash table head */ struct list_head ns_gc_inodes; -struct hlist_head *ns_gc_inodes_h; +struct hlist_bl_head *ns_gc_inodes_h;/* Disk layout information (static) */ unsigned int ns_blocksize_bits;
PATCH 39/52 fs: icache rcu walk for i_sb_list
In reply to [email protected]This enables locking to be reduced and ordering simplified.
--- fs/drop_caches.c | 10 ++++---- fs/inode.c | 53 +++++++++++++++----------------------------- fs/notify/inode_mark.c | 10 -------- fs/notify/inotify/inotify.c | 10 -------- fs/quota/dquot.c | 16 ++++++------- 5 files changed, 32 insertions(+), 67 deletions(-)
fs/drop_caches.c +5 -5
@@ -16,8 +16,8 @@ static void drop_pagecache_sb(struct sup {struct inode *inode, *toput_inode =NULL ; -spin_lock (&sb_inode_list_lock); -list_for_each_entry (inode, &sb->s_inodes, i_sb_list) { +rcu_read_lock (); +list_for_each_entry_rcu (inode, &sb->s_inodes, i_sb_list) {spin_lock (&inode->i_lock);if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE |I_NEW ) || inode->i_mapping->nrpages ==0 ) {
@@ -26,13 +26,13 @@ static void drop_pagecache_sb(struct sup }__iget (inode);spin_unlock (&inode->i_lock); -spin_unlock (&sb_inode_list_lock); +rcu_read_unlock ();invalidate_mapping_pages (inode->i_mapping,0 ,-1 );iput (toput_inode); toput_inode = inode; -spin_lock (&sb_inode_list_lock); +rcu_read_lock (); } -spin_unlock (&sb_inode_list_lock); +rcu_read_unlock ();iput (toput_inode); }
fs/inode.c +23 -38
161 lines not on this page · raw message
fs/notify/inode_mark.c +0 -10
@@ -412,14 +412,6 @@ void fsnotify_unmount_inodes(struct listspin_unlock (&next_i->i_lock); } -/* -* We can safely drop inode_lock here because we hold -* references on both inode and next_i. Also no new inodes -* will be added since the umount has begun. Finally, -* iprune_mutex keeps shrink_icache_memory() away. -*/ -spin_unlock (&sb_inode_list_lock); -if (need_iput_tmp)iput (need_iput_tmp);
@@ -429,7 +421,5 @@ void fsnotify_unmount_inodes(struct listfsnotify_inode_delete (inode);iput (inode); - -spin_lock (&sb_inode_list_lock); } }
fs/notify/inotify/inotify.c +0 -10
@@ -434,14 +434,6 @@ void inotify_unmount_inodes(struct list_spin_unlock (&next_i->i_lock); } -/* -* We can safely drop inode_lock here because we hold -* references on both inode and next_i. Also no new inodes -* will be added since the umount has begun. Finally, -* iprune_mutex keeps shrink_icache_memory() away. -*/ -spin_unlock (&sb_inode_list_lock); -if (need_iput_tmp)iput (need_iput_tmp);
@@ -459,8 +451,6 @@ void inotify_unmount_inodes(struct list_ }mutex_unlock (&inode->inotify_mutex);iput (inode); - -spin_lock (&sb_inode_list_lock); } }EXPORT_SYMBOL_GPL (inotify_unmount_inodes);
fs/quota/dquot.c +8 -8
@@ -883,8 +883,8 @@ static void add_dquot_ref(struct super_bint reserved =0 ;#endif -spin_lock (&sb_inode_list_lock); -list_for_each_entry (inode, &sb->s_inodes, i_sb_list) { +rcu_read_lock (); +list_for_each_entry_rcu (inode, &sb->s_inodes, i_sb_list) {spin_lock (&inode->i_lock);if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE |I_NEW )) {spin_unlock (&inode->i_lock);
@@ -905,7 +905,7 @@ static void add_dquot_ref(struct super_b__iget (inode);spin_unlock (&inode->i_lock); -spin_unlock (&sb_inode_list_lock); +rcu_read_unlock ();iput (old_inode);__dquot_initialize (inode, type);
@@ -915,9 +915,9 @@ static void add_dquot_ref(struct super_b* reference and we cannot iput it under inode_lock. So we * keep the reference and iput it later. */ old_inode = inode; -spin_lock (&sb_inode_list_lock); +rcu_read_lock (); } -spin_unlock (&sb_inode_list_lock); +rcu_read_unlock ();iput (old_inode);#ifdef CONFIG_QUOTA_DEBUG
@@ -995,8 +995,8 @@ static void remove_dquot_ref(struct supe {struct inode *inode; -spin_lock (&sb_inode_list_lock); -list_for_each_entry (inode, &sb->s_inodes, i_sb_list) { +rcu_read_lock (); +list_for_each_entry_rcu (inode, &sb->s_inodes, i_sb_list) {/* * We have to scan also I_NEW inodes because they can already * have quota pointer initialized. Luckily, we need to touch
@@ -1006,7 +1006,7 @@ static void remove_dquot_ref(struct supeif (!IS_NOQUOTA (inode))remove_inode_dquot_ref (inode, type, tofree_head); } -spin_unlock (&sb_inode_list_lock); +rcu_read_unlock (); }/* Gather all references from inodes and drop them */
PATCH 28/52 fs: icache lock i_state
In reply to [email protected]Protect i_state updates with i_lock
--- fs/drop_caches.c | 9 ++++-- fs/fs-writeback.c | 37 +++++++++++++++++++----- fs/inode.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++-------- fs/nilfs2/gcdat.c | 1 fs/quota/dquot.c | 14 +++++++-- 5 files changed, 117 insertions(+), 25 deletions(-)
fs/drop_caches.c +6 -3
@@ -19,11 +19,14 @@ static void drop_pagecache_sb(struct supspin_lock (&inode_lock);spin_lock (&sb_inode_list_lock);list_for_each_entry (inode, &sb->s_inodes, i_sb_list) { -if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE |I_NEW )) -continue ; -if (inode->i_mapping->nrpages ==0 ) +spin_lock (&inode->i_lock); +if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE |I_NEW ) + || inode->i_mapping->nrpages ==0 ) { +spin_unlock (&inode->i_lock);continue ; + }__iget (inode); +spin_unlock (&inode->i_lock);spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);invalidate_mapping_pages (inode->i_mapping,0 ,-1 );
fs/fs-writeback.c +26 -4
@@ -398,10 +398,12 @@ static void inode_wait_for_writeback(strwait_queue_head_t *wqh; wqh =bit_waitqueue (&inode->i_state, __I_SYNC); -while (inode->i_state &I_SYNC ) { +while (inode->i_state &I_SYNC ) { +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock);__wait_on_bit (wqh, &wq, inode_wait,TASK_UNINTERRUPTIBLE );spin_lock (&inode_lock); +spin_lock (&inode->i_lock); } }
@@ -455,6 +457,7 @@ writeback_single_inode(struct inode *ino/* Set I_SYNC, reset I_DIRTY_PAGES */ inode->i_state |=I_SYNC ; inode->i_state &= ~I_DIRTY_PAGES ; +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock); ret =do_writepages (mapping, wbc);
@@ -476,8 +479,10 @@ writeback_single_inode(struct inode *ino* write_inode() */ spin_lock (&inode_lock); +spin_lock (&inode->i_lock); dirty = inode->i_state &I_DIRTY ; inode->i_state &= ~(I_DIRTY_SYNC |I_DIRTY_DATASYNC ); +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock);/* Don't write the inode if only I_DIRTY_PAGES was set */ if (dirty & (I_DIRTY_SYNC |I_DIRTY_DATASYNC )) {
@@ -487,6 +492,7 @@ writeback_single_inode(struct inode *ino }spin_lock (&inode_lock); +spin_lock (&inode->i_lock); inode->i_state &= ~I_SYNC ;if (!(inode->i_state & (I_FREEING |I_CLEAR ))) {if ((inode->i_state &I_DIRTY_PAGES ) && wbc->for_kupdate) {
@@ -630,7 +636,9 @@ static int writeback_sb_inodes(struct suif (sb != inode->i_sb)/* finish with this superblock */ return 0 ; +spin_lock (&inode->i_lock);if (inode->i_state & (I_NEW |I_WILL_FREE )) { +spin_unlock (&inode->i_lock);requeue_io (inode);continue ; }
@@ -638,8 +646,10 @@ static int writeback_sb_inodes(struct su* Was this inode dirtied after sync_sb_inodes was called? * This keeps sync from extra jobs and livelock. */ -if (inode_dirtied_after (inode, wbc->wb_start)) +if (inode_dirtied_after (inode, wbc->wb_start)) { +spin_unlock (&inode->i_lock);return 1 ; + }BUG_ON (inode->i_state & (I_FREEING |I_CLEAR ));__iget (inode);
@@ -652,6 +662,7 @@ static int writeback_sb_inodes(struct su*/ redirty_tail (inode); } +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock);iput (inode);cond_resched ();
@@ -1090,6 +1101,7 @@ void __mark_inode_dirty(struct inode *inblock_dump___mark_inode_dirty (inode);spin_lock (&inode_lock); +spin_lock (&inode->i_lock);if ((inode->i_state & flags) != flags) {const int was_dirty = inode->i_state &I_DIRTY ;
@@ -1134,6 +1146,7 @@ void __mark_inode_dirty(struct inode *in } } out: +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock); }EXPORT_SYMBOL (__mark_inode_dirty);
@@ -1178,12 +1191,17 @@ static void wait_sb_inodes(struct super_list_for_each_entry (inode, &sb->s_inodes, i_sb_list) {struct address_space *mapping; -if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE |I_NEW )) -continue ; mapping = inode->i_mapping;if (mapping->nrpages ==0 )continue ; + +spin_lock (&inode->i_lock); +if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE |I_NEW )) { +spin_unlock (&inode->i_lock); +continue ; + }__iget (inode); +spin_unlock (&inode->i_lock);spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);/*
@@ -1287,7 +1305,9 @@ int write_inode_now(struct inode *inode,might_sleep ();spin_lock (&inode_lock); +spin_lock (&inode->i_lock); ret =writeback_single_inode (inode, &wbc); +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock);if (sync)inode_sync_wait (inode);
@@ -1311,7 +1331,9 @@ int sync_inode(struct inode *inode, struint ret;spin_lock (&inode_lock); +spin_lock (&inode->i_lock); ret =writeback_single_inode (inode, wbc); +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock);return ret; }
fs/inode.c +74 -11
322 lines not on this page · raw message
fs/nilfs2/gcdat.c +1 -0
@@ -27,6 +27,7 @@#include "page.h" #include "mdt.h" +/* XXX: what protects i_state? */ int nilfs_init_gcdat_inode (struct the_nilfs *nilfs) {struct inode *dat = nilfs->ns_dat, *gcdat = nilfs->ns_gc_dat;
fs/quota/dquot.c +11 -3
@@ -886,18 +886,26 @@ static void add_dquot_ref(struct super_bspin_lock (&inode_lock);spin_lock (&sb_inode_list_lock);list_for_each_entry (inode, &sb->s_inodes, i_sb_list) { -if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE |I_NEW )) +spin_lock (&inode->i_lock); +if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE |I_NEW )) { +spin_unlock (&inode->i_lock);continue ; + }#ifdef CONFIG_QUOTA_DEBUG if (unlikely (inode_get_rsv_space (inode) >0 )) reserved =1 ;#endif -if (!atomic_read (&inode->i_writecount)) +if (!atomic_read (&inode->i_writecount)) { +spin_unlock (&inode->i_lock);continue ; -if (!dqinit_needed (inode, type)) + } +if (!dqinit_needed (inode, type)) { +spin_unlock (&inode->i_lock);continue ; + }__iget (inode); +spin_unlock (&inode->i_lock);spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);
PATCH 47/52 fs: keep inode with backing-dev
In reply to [email protected]Having inode on writeback lists of a different bdi than inode->i_mapping->backing_dev_info makes it very difficult to do per-bdi locking of the writeback lists. Add functions to move these inodes over when the mapping backing dev is changed.
i_mapping.backing_dev_info is renamed to i_mapping.a_bdi while we're here. Succinct is nice, and it catches conversion errors.
--
include/linux/backing-dev.h +10 -4
@@ -316,19 +316,25 @@ static inline bool bdi_cap_flush_forker(return bdi == &default_backing_dev_info; } +void mapping_set_bdi (struct address_space *mapping,struct backing_dev_info *bdi); +static inline void mapping_new_set_bdi (struct address_space *mapping,struct backing_dev_info *bdi) +{ + mapping->a_bdi = bdi; +} +static inline bool mapping_cap_writeback_dirty (struct address_space *mapping) { -return bdi_cap_writeback_dirty (mapping->backing_dev_info); +return bdi_cap_writeback_dirty (mapping->a_bdi); }static inline bool mapping_cap_account_dirty (struct address_space *mapping) { -return bdi_cap_account_dirty (mapping->backing_dev_info); +return bdi_cap_account_dirty (mapping->a_bdi); }static inline bool mapping_cap_swap_backed (struct address_space *mapping) { -return bdi_cap_swap_backed (mapping->backing_dev_info); +return bdi_cap_swap_backed (mapping->a_bdi); }static inline int bdi_sched_wait (void *word)
@@ -347,7 +353,7 @@ static inline void blk_run_backing_dev(sstatic inline void blk_run_address_space (struct address_space *mapping) {if (mapping) -blk_run_backing_dev (mapping->backing_dev_info,NULL ); +blk_run_backing_dev (mapping->a_bdi,NULL ); }#endif /* _LINUX_BACKING_DEV_H */
include/linux/fs.h +1 -1
@@ -635,7 +635,7 @@ struct address_space {pgoff_t writeback_index;/* writeback starts here */ const struct address_space_operations *a_ops;/* methods */ unsigned long flags;/* error bits/gfp mask */ -struct backing_dev_info *backing_dev_info;/* device readahead, etc */ +struct backing_dev_info *a_bdi;/* device readahead, etc */ spinlock_t private_lock;/* for use by the address_space */ struct list_head private_list;/* ditto */ struct address_space *assoc_mapping;/* ditto */
mm/backing-dev.c +57 -3
74 lines not on this page · raw message
drivers/char/mem.c +1 -1
@@ -871,7 +871,7 @@ static int memory_open(struct inode *ino filp->f_op = dev->fops;if (dev->dev_info) - filp->f_mapping->backing_dev_info = dev->dev_info; +mapping_set_bdi (filp->f_mapping, dev->dev_info);if (dev->fops->open)return dev->fops->open (inode, filp);
drivers/char/raw.c +1 -1
@@ -109,7 +109,7 @@ static int raw_release(struct inode *inoif (--raw_devices[minor].inuse ==0 ) {/* Here inode->i_mapping == bdev->bd_inode->i_mapping */ inode->i_mapping = &inode->i_data; - inode->i_mapping->backing_dev_info = &default_backing_dev_info; +mapping_set_bdi (inode->i_mapping, &default_backing_dev_info); }mutex_unlock (&raw_mutex);
fs/block_dev.c +7 -6
@@ -539,7 +539,7 @@ struct block_device *bdget(dev_t dev) inode->i_bdev = bdev; inode->i_data.a_ops = &def_blk_aops;mapping_set_gfp_mask (&inode->i_data,GFP_USER ); - inode->i_data.backing_dev_info = &default_backing_dev_info; +mapping_new_set_bdi (&inode->i_data, &default_backing_dev_info);spin_lock (&bdev_lock);list_add (&bdev->bd_list, &all_bdevs);spin_unlock (&bdev_lock);
@@ -1404,7 +1404,7 @@ static int __blkdev_get(struct block_dev bdi =blk_get_backing_dev_info (bdev);if (bdi ==NULL ) bdi = &default_backing_dev_info; - bdev->bd_inode->i_data.backing_dev_info = bdi; +mapping_set_bdi (&bdev->bd_inode->i_data, bdi); }if (bdev->bd_invalidated)rescan_partitions (disk, bdev);
@@ -1419,8 +1419,8 @@ static int __blkdev_get(struct block_devif (ret) goto out_clear; bdev->bd_contains = whole; - bdev->bd_inode->i_data.backing_dev_info = - whole->bd_inode->i_data.backing_dev_info; +mapping_set_bdi (&bdev->bd_inode->i_data, + whole->bd_inode->i_data.a_bdi); bdev->bd_part =disk_get_part (disk, partno);if (!(disk->flags &GENHD_FL_UP ) || !bdev->bd_part || !bdev->bd_part->nr_sects) {
@@ -1454,7 +1454,7 @@ static int __blkdev_get(struct block_devdisk_put_part (bdev->bd_part); bdev->bd_disk =NULL ; bdev->bd_part =NULL ; - bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; +mapping_set_bdi (&bdev->bd_inode->i_data, &default_backing_dev_info);if (bdev != bdev->bd_contains)__blkdev_put (bdev->bd_contains, mode,1 ); bdev->bd_contains =NULL ;
@@ -1551,7 +1551,8 @@ static int __blkdev_put(struct block_devdisk_put_part (bdev->bd_part); bdev->bd_part =NULL ; bdev->bd_disk =NULL ; - bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; +mapping_set_bdi (&bdev->bd_inode->i_data, + &default_backing_dev_info);if (bdev != bdev->bd_contains) victim = bdev->bd_contains; bdev->bd_contains =NULL ;
fs/btrfs/disk-io.c +1 -1
@@ -1636,7 +1636,7 @@ struct btrfs_root *open_ctree(struct sup*/ fs_info->btree_inode->i_size =OFFSET_MAX ; fs_info->btree_inode->i_mapping->a_ops = &btree_aops; - fs_info->btree_inode->i_mapping->backing_dev_info = &fs_info->bdi; +mapping_new_set_bdi (fs_info->btree_inode->i_mapping, &fs_info->bdi);RB_CLEAR_NODE (&BTRFS_I (fs_info->btree_inode)->rb_node); extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree,
fs/btrfs/inode.c +5 -5
@@ -2480,7 +2480,7 @@ static void btrfs_read_locked_inode(struswitch (inode->i_mode &S_IFMT ) {case S_IFREG : inode->i_mapping->a_ops = &btrfs_aops; - inode->i_mapping->backing_dev_info = &root->fs_info->bdi; +mapping_new_set_bdi (inode->i_mapping, &root->fs_info->bdi);BTRFS_I (inode)->io_tree.ops = &btrfs_extent_io_ops; inode->i_fop = &btrfs_file_operations; inode->i_op = &btrfs_file_inode_operations;
@@ -2495,7 +2495,7 @@ static void btrfs_read_locked_inode(strucase S_IFLNK : inode->i_op = &btrfs_symlink_inode_operations; inode->i_mapping->a_ops = &btrfs_symlink_aops; - inode->i_mapping->backing_dev_info = &root->fs_info->bdi; +mapping_new_set_bdi (inode->i_mapping, &root->fs_info->bdi);break ;default : inode->i_op = &btrfs_special_inode_operations;
@@ -4705,7 +4705,7 @@ static int btrfs_create(struct inode *di drop_inode =1 ; else { inode->i_mapping->a_ops = &btrfs_aops; - inode->i_mapping->backing_dev_info = &root->fs_info->bdi; +mapping_new_set_bdi (inode->i_mapping, &root->fs_info->bdi); inode->i_fop = &btrfs_file_operations; inode->i_op = &btrfs_file_inode_operations;BTRFS_I (inode)->io_tree.ops = &btrfs_extent_io_ops;
@@ -6700,7 +6700,7 @@ static int btrfs_symlink(struct inode *d drop_inode =1 ; else { inode->i_mapping->a_ops = &btrfs_aops; - inode->i_mapping->backing_dev_info = &root->fs_info->bdi; +mapping_new_set_bdi (inode->i_mapping, &root->fs_info->bdi); inode->i_fop = &btrfs_file_operations; inode->i_op = &btrfs_file_inode_operations;BTRFS_I (inode)->io_tree.ops = &btrfs_extent_io_ops;
@@ -6740,7 +6740,7 @@ static int btrfs_symlink(struct inode *d inode->i_op = &btrfs_symlink_inode_operations; inode->i_mapping->a_ops = &btrfs_symlink_aops; - inode->i_mapping->backing_dev_info = &root->fs_info->bdi; +mapping_new_set_bdi (inode->i_mapping, &root->fs_info->bdi);inode_set_bytes (inode, name_len);btrfs_i_size_write (inode, name_len -1 ); err =btrfs_update_inode (trans, root, inode);
fs/ceph/inode.c +2 -2
@@ -623,8 +623,8 @@ static int fill_inode(struct inode *inod } inode->i_mapping->a_ops = &ceph_aops; - inode->i_mapping->backing_dev_info = - &ceph_sb_to_client (inode->i_sb)->backing_dev_info; +mapping_new_set_bdi (inode->i_mapping, + &ceph_sb_to_client (inode->i_sb)->backing_dev_info);switch (inode->i_mode &S_IFMT ) {case S_IFIFO :
fs/configfs/inode.c +2 -1
@@ -136,7 +136,8 @@ struct inode * configfs_new_inode(mode_tstruct inode * inode =new_inode (configfs_sb);if (inode) { inode->i_mapping->a_ops = &configfs_aops; - inode->i_mapping->backing_dev_info = &configfs_backing_dev_info; +mapping_new_set_bdi (inode->i_mapping, + &configfs_backing_dev_info); inode->i_op = &configfs_inode_operations;if (sd->s_iattr) {
fs/gfs2/glock.c +2 -1
@@ -8,6 +8,7 @@*/ #include <linux/sched.h> +#include <linux/backing-dev.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/buffer_head.h>
@@ -796,7 +797,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, mapping->flags =0 ;mapping_set_gfp_mask (mapping,GFP_NOFS ); mapping->assoc_mapping =NULL ; - mapping->backing_dev_info = s->s_bdi; +mapping_new_set_bdi (mapping, s->s_bdi); mapping->writeback_index =0 ; }
fs/hugetlbfs/inode.c +2 -1
@@ -476,7 +476,8 @@ static struct inode *hugetlbfs_get_inode inode->i_uid = uid; inode->i_gid = gid; inode->i_mapping->a_ops = &hugetlbfs_aops; - inode->i_mapping->backing_dev_info =&hugetlbfs_backing_dev_info; +mapping_new_set_bdi (inode->i_mapping, + &hugetlbfs_backing_dev_info); inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;INIT_LIST_HEAD (&inode->i_mapping->private_list); info =HUGETLBFS_I (inode);
fs/inode.c +3 -3
@@ -237,7 +237,7 @@ int inode_init_always(struct super_block mapping->flags =0 ;mapping_set_gfp_mask (mapping,GFP_HIGHUSER_MOVABLE ); mapping->assoc_mapping =NULL ; - mapping->backing_dev_info = &default_backing_dev_info; +mapping_new_set_bdi (mapping, &default_backing_dev_info); mapping->writeback_index =0 ;/*
@@ -248,8 +248,8 @@ int inode_init_always(struct super_blockif (sb->s_bdev) {struct backing_dev_info *bdi; - bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info; - mapping->backing_dev_info = bdi; + bdi = sb->s_bdev->bd_inode->i_mapping->a_bdi; +mapping_new_set_bdi (mapping, bdi); } inode->i_private =NULL ; inode->i_mapping = mapping;
fs/logfs/inode.c +1 -1
@@ -258,7 +258,7 @@ struct inode *logfs_new_meta_inode(struc mapping->flags =0 ;mapping_set_gfp_mask (mapping,GFP_NOFS ); mapping->assoc_mapping =NULL ; - mapping->backing_dev_info = &default_backing_dev_info; +mapping_new_set_bdi (mapping, &default_backing_dev_info); inode->i_mapping = mapping; inode->i_nlink =1 ; }
fs/nilfs2/btnode.c +1 -1
@@ -59,7 +59,7 @@ void nilfs_btnode_cache_init(struct addr btnc->flags =0 ;mapping_set_gfp_mask (btnc,GFP_NOFS ); btnc->assoc_mapping =NULL ; - btnc->backing_dev_info = bdi; +mapping_new_set_bdi (btnc, bdi); btnc->a_ops = &def_btnode_aops; }
fs/nilfs2/mdt.c +1 -1
@@ -516,7 +516,7 @@ nilfs_mdt_new_common(struct the_nilfs *n mapping->flags =0 ;mapping_set_gfp_mask (mapping, gfp_mask); mapping->assoc_mapping =NULL ; - mapping->backing_dev_info = nilfs->ns_bdi; +mapping_new_set_bdi (mapping, nilfs->ns_bdi); inode->i_mapping = mapping; }
fs/ocfs2/dlmfs/dlmfs.c +2 -2
@@ -403,7 +403,7 @@ static struct inode *dlmfs_get_root_inod inode->i_mode = mode; inode->i_uid =current_fsuid (); inode->i_gid =current_fsgid (); - inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info; +mapping_new_set_bdi (inode->i_mapping, &dlmfs_backing_dev_info); inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;inc_nlink (inode);
@@ -428,7 +428,7 @@ static struct inode *dlmfs_get_inode(str inode->i_mode = mode; inode->i_uid =current_fsuid (); inode->i_gid =current_fsgid (); - inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info; +mapping_new_set_bdi (inode->i_mapping, &dlmfs_backing_dev_info); inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ; ip =DLMFS_I (inode);
fs/ramfs/inode.c +1 -1
@@ -60,7 +60,7 @@ struct inode *ramfs_get_inode(struct supif (inode) {inode_init_owner (inode, dir, mode); inode->i_mapping->a_ops = &ramfs_aops; - inode->i_mapping->backing_dev_info = &ramfs_backing_dev_info; +mapping_new_set_bdi (inode->i_mapping, &ramfs_backing_dev_info);mapping_set_gfp_mask (inode->i_mapping,GFP_HIGHUSER );mapping_set_unevictable (inode->i_mapping); inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;
fs/sysfs/inode.c +1 -1
@@ -251,7 +251,7 @@ static void sysfs_init_inode(struct sysf inode->i_private =sysfs_get (sd); inode->i_mapping->a_ops = &sysfs_aops; - inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; +mapping_new_set_bdi (inode->i_mapping, &sysfs_backing_dev_info); inode->i_op = &sysfs_inode_operations;set_default_inode_attr (inode, sd->s_mode);
fs/ubifs/dir.c +1 -1
@@ -109,7 +109,7 @@ struct inode *ubifs_new_inode(struct ubiubifs_current_time (inode); inode->i_mapping->nrpages =0 ;/* Disable readahead */ - inode->i_mapping->backing_dev_info = &c->bdi; +mapping_new_set_bdi (inode->i_mapping, &c->bdi);switch (mode &S_IFMT ) {case S_IFREG :
fs/ubifs/super.c +1 -1
@@ -157,7 +157,7 @@ struct inode *ubifs_iget(struct super_bl goto out_invalid;/* Disable read-ahead */ - inode->i_mapping->backing_dev_info = &c->bdi; +mapping_new_set_bdi (inode->i_mapping, &c->bdi);switch (inode->i_mode &S_IFMT ) {case S_IFREG :
fs/xfs/linux-2.6/xfs_buf.c +2 -2
@@ -636,7 +636,7 @@ xfs_buf_readahead( {struct backing_dev_info *bdi; - bdi = target->bt_mapping->backing_dev_info; + bdi = target->bt_mapping->a_bdi;if (bdi_read_congested (bdi))return ;
@@ -1610,7 +1610,7 @@ xfs_mapping_buftarg( bdi = &default_backing_dev_info; mapping = &inode->i_data; mapping->a_ops = &mapping_aops; - mapping->backing_dev_info = bdi; +mapping_new_set_bdi (mapping, bdi);mapping_set_gfp_mask (mapping,GFP_NOFS ); btp->bt_mapping = mapping;return 0 ;
kernel/cgroup.c +1 -1
@@ -782,7 +782,7 @@ static struct inode *cgroup_new_inode(mo inode->i_uid =current_fsuid (); inode->i_gid =current_fsgid (); inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ; - inode->i_mapping->backing_dev_info = &cgroup_backing_dev_info; +mapping_new_set_bdi (inode->i_mapping, &cgroup_backing_dev_info); }return inode; }
mm/shmem.c +1 -1
@@ -1561,7 +1561,7 @@ static struct inode *shmem_get_inode(strif (inode) {inode_init_owner (inode, dir, mode); inode->i_blocks =0 ; - inode->i_mapping->backing_dev_info = &shmem_backing_dev_info; +mapping_new_set_bdi (inode->i_mapping, &shmem_backing_dev_info); inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ; inode->i_generation =get_seconds (); info =SHMEM_I (inode);
fs/afs/write.c +4 -4
@@ -438,7 +438,7 @@ no_more:*/ int afs_writepage (struct page *page,struct writeback_control *wbc) { -struct backing_dev_info *bdi = page->mapping->backing_dev_info; +struct backing_dev_info *bdi = page->mapping->a_bdi;struct afs_writeback *wb;int ret;
@@ -469,7 +469,7 @@ static int afs_writepages_region(structstruct writeback_control *wbc, pgoff_t index, pgoff_t end, pgoff_t *_next) { - struct backing_dev_info *bdi = mapping->backing_dev_info; + struct backing_dev_info *bdi = mapping->a_bdi;struct afs_writeback *wb;struct page *page;int ret, n;
@@ -548,7 +548,7 @@ static int afs_writepages_region(structint afs_writepages (struct address_space *mapping,struct writeback_control *wbc) { -struct backing_dev_info *bdi = mapping->backing_dev_info; +struct backing_dev_info *bdi = mapping->a_bdi;pgoff_t start, end, next;int ret;
@@ -680,7 +680,7 @@ int afs_writeback_all(struct afs_vnode * {struct address_space *mapping = vnode->vfs_inode.i_mapping;struct writeback_control wbc = { - .bdi = mapping->backing_dev_info, + .bdi = mapping->a_bdi, .sync_mode =WB_SYNC_ALL , .nr_to_write =LONG_MAX , .range_cyclic =1 ,
fs/btrfs/extent_io.c +1 -1
@@ -2628,7 +2628,7 @@ int extent_write_locked_range(struct ext .sync_io = mode == WB_SYNC_ALL, };struct writeback_control wbc_writepages = { - .bdi = inode->i_mapping->backing_dev_info, + .bdi = inode->i_mapping->a_bdi, .sync_mode = mode, .older_than_this =NULL , .nr_to_write = nr_pages *2 ,
fs/btrfs/file.c +1 -1
@@ -872,7 +872,7 @@ static ssize_t btrfs_file_aio_write(stru goto out; count = ocount; - current->backing_dev_info = inode->i_mapping->backing_dev_info; + current->backing_dev_info = inode->i_mapping->a_bdi; err =generic_write_checks (file, &pos, &count,S_ISBLK (inode->i_mode));if (err) goto out;
fs/buffer.c +1 -1
@@ -3264,7 +3264,7 @@ void block_sync_page(struct page *page)smp_mb (); mapping =page_mapping (page);if (mapping) -blk_run_backing_dev (mapping->backing_dev_info, page); +blk_run_backing_dev (mapping->a_bdi, page); }EXPORT_SYMBOL (block_sync_page);
mm/fadvise.c +2 -2
@@ -72,7 +72,7 @@ SYSCALL_DEFINE(fadvise64_64)(int fd, lofelse endbyte--;/* inclusive */ - bdi = mapping->backing_dev_info; + bdi = mapping->a_bdi;switch (advice) {case POSIX_FADV_NORMAL :
@@ -116,7 +116,7 @@ SYSCALL_DEFINE(fadvise64_64)(int fd, lofcase POSIX_FADV_NOREUSE :break ;case POSIX_FADV_DONTNEED : -if (!bdi_write_congested (mapping->backing_dev_info)) +if (!bdi_write_congested (mapping->a_bdi))filemap_flush (mapping);/* First and last FULL page! */
mm/filemap.c +2 -2
@@ -136,7 +136,7 @@ void __remove_from_page_cache(struct pag*/ if (PageDirty (page) &&mapping_cap_account_dirty (mapping)) {dec_zone_page_state (page,NR_FILE_DIRTY ); -dec_bdi_stat (mapping->backing_dev_info,BDI_RECLAIMABLE ); +dec_bdi_stat (mapping->a_bdi,BDI_RECLAIMABLE ); } }
@@ -2375,7 +2375,7 @@ ssize_t __generic_file_aio_write(structvfs_check_frozen (inode->i_sb,SB_FREEZE_WRITE );/* We can write back this queue in page reclaim */ - current->backing_dev_info = mapping->backing_dev_info; + current->backing_dev_info = mapping->a_bdi; written =0 ; err =generic_write_checks (file, &pos, &count,S_ISBLK (inode->i_mode));
mm/filemap_xip.c +1 -1
@@ -409,7 +409,7 @@ xip_file_write(struct file *filp, constvfs_check_frozen (inode->i_sb,SB_FREEZE_WRITE );/* We can write back this queue in page reclaim */ - current->backing_dev_info = mapping->backing_dev_info; + current->backing_dev_info = mapping->a_bdi; ret =generic_write_checks (filp, &pos, &count,S_ISBLK (inode->i_mode));if (ret)
mm/page-writeback.c +6 -7
@@ -491,7 +491,7 @@ static void balance_dirty_pages(struct aunsigned long pages_written =0 ;unsigned long pause =1 ; -struct backing_dev_info *bdi = mapping->backing_dev_info; +struct backing_dev_info *bdi = mapping->a_bdi;for (;;) {struct writeback_control wbc = {
@@ -633,7 +633,7 @@ void balance_dirty_pages_ratelimited_nr(unsigned long *p; ratelimit = ratelimit_pages; -if (mapping->backing_dev_info->dirty_exceeded) +if (mapping->a_bdi->dirty_exceeded) ratelimit =8 ;/*
@@ -1093,7 +1093,7 @@ void account_page_dirtied(struct page *p {if (mapping_cap_account_dirty (mapping)) {__inc_zone_page_state (page,NR_FILE_DIRTY ); -__inc_bdi_stat (mapping->backing_dev_info,BDI_RECLAIMABLE ); +__inc_bdi_stat (mapping->a_bdi,BDI_RECLAIMABLE );task_dirty_inc (current);task_io_account_write (PAGE_CACHE_SIZE ); }
@@ -1268,8 +1268,7 @@ int clear_page_dirty_for_io(struct page*/ if (TestClearPageDirty (page)) {dec_zone_page_state (page,NR_FILE_DIRTY ); -dec_bdi_stat (mapping->backing_dev_info, -BDI_RECLAIMABLE ); +dec_bdi_stat (mapping->a_bdi,BDI_RECLAIMABLE );return 1 ; }return 0 ;
@@ -1284,7 +1283,7 @@ int test_clear_page_writeback(struct pagint ret;if (mapping) { -struct backing_dev_info *bdi = mapping->backing_dev_info; +struct backing_dev_info *bdi = mapping->a_bdi;unsigned long flags;spin_lock_irqsave (&mapping->tree_lock, flags);
@@ -1313,7 +1312,7 @@ int test_set_page_writeback(struct pageint ret;if (mapping) { -struct backing_dev_info *bdi = mapping->backing_dev_info; +struct backing_dev_info *bdi = mapping->a_bdi;unsigned long flags;spin_lock_irqsave (&mapping->tree_lock, flags);
mm/readahead.c +3 -3
@@ -25,7 +25,7 @@void file_ra_state_init (struct file_ra_state *ra,struct address_space *mapping) { - ra->ra_pages = mapping->backing_dev_info->ra_pages; + ra->ra_pages = mapping->a_bdi->ra_pages; ra->prev_pos =-1 ; }EXPORT_SYMBOL_GPL (file_ra_state_init);
@@ -549,7 +549,7 @@ page_cache_async_readahead(struct addres/* * Defer asynchronous read-ahead on IO congestion. */ -if (bdi_read_congested (mapping->backing_dev_info)) +if (bdi_read_congested (mapping->a_bdi))return ;/* do read-ahead */
@@ -564,7 +564,7 @@ page_cache_async_readahead(struct addres* explicitly kick off the IO. */ if (PageUptodate (page)) -blk_run_backing_dev (mapping->backing_dev_info,NULL ); +blk_run_backing_dev (mapping->a_bdi,NULL );#endif }EXPORT_SYMBOL_GPL (page_cache_async_readahead);
mm/swap.c +1 -1
@@ -501,7 +501,7 @@ void __init swap_setup(void)unsigned long megs = totalram_pages >> (20 -PAGE_SHIFT );#ifdef CONFIG_SWAP -bdi_init (swapper_space.backing_dev_info); +bdi_init (swapper_space.a_bdi);#endif /* Use a smaller cluster for small-memory machines */
mm/swap_state.c +1 -1
@@ -45,7 +45,7 @@ struct address_space swapper_space = { .tree_lock = __SPIN_LOCK_UNLOCKED(swapper_space.tree_lock), .a_ops = &swap_aops, .i_mmap_nonlinear = LIST_HEAD_INIT(swapper_space.i_mmap_nonlinear), - .backing_dev_info = &swap_backing_dev_info, + .a_bdi = &swap_backing_dev_info, };#define INC_CACHE_INFO (x) do { swap_cache_info.x++; } while (0)
mm/swapfile.c +1 -1
@@ -116,7 +116,7 @@ void swap_unplug_io_fn(struct backing_de*/ WARN_ON (page_count (page) <=1 ); - bdi = bdev->bd_inode->i_mapping->backing_dev_info; + bdi = bdev->bd_inode->i_mapping->a_bdi;blk_run_backing_dev (bdi, page); }up_read (&swap_unplug_sem);
mm/truncate.c +1 -2
@@ -75,8 +75,7 @@ void cancel_dirty_page(struct page *pagestruct address_space *mapping = page->mapping;if (mapping &&mapping_cap_account_dirty (mapping)) {dec_zone_page_state (page,NR_FILE_DIRTY ); -dec_bdi_stat (mapping->backing_dev_info, -BDI_RECLAIMABLE ); +dec_bdi_stat (mapping->a_bdi,BDI_RECLAIMABLE );if (account_size)task_io_account_cancelled_write (account_size); }
mm/vmscan.c +1 -1
@@ -361,7 +361,7 @@ static pageout_t pageout(struct page *pa }if (mapping->a_ops->writepage ==NULL )return PAGE_ACTIVATE ; -if (!may_write_to_queue (mapping->backing_dev_info)) +if (!may_write_to_queue (mapping->a_bdi))return PAGE_KEEP ;if (clear_page_dirty_for_io (page)) {
fs/ext2/ialloc.c +1 -1
@@ -177,7 +177,7 @@ static void ext2_preread_inode(struct instruct ext2_group_desc * gdp;struct backing_dev_info *bdi; - bdi = inode->i_mapping->backing_dev_info; + bdi = inode->i_mapping->a_bdi;if (bdi_read_congested (bdi))return ;if (bdi_write_congested (bdi))
fs/fs-writeback.c +1 -1
@@ -28,7 +28,7 @@#include <linux/buffer_head.h> #include "internal.h" -#define inode_to_bdi (inode) ((inode)->i_mapping->backing_dev_info) +#define inode_to_bdi (inode) ((inode)->i_mapping->a_bdi)/* * We don't actually have pdflush, but this one is exported though /proc...
drivers/mtd/mtdchar.c +1 -1
@@ -99,7 +99,7 @@ static int mtd_open(struct inode *inode,if (mtd_ino->i_state &I_NEW ) { mtd_ino->i_private = mtd; mtd_ino->i_mode =S_IFCHR ; - mtd_ino->i_data.backing_dev_info = mtd->backing_dev_info; +mapping_new_set_bdi (&mtd_ino->i_data, mtd->backing_dev_info);unlock_new_inode (mtd_ino); } file->f_mapping = mtd_ino->i_mapping;
fs/ceph/addr.c +2 -3
@@ -108,8 +108,7 @@ static int ceph_set_page_dirty(struct paif (mapping_cap_account_dirty (mapping)) {__inc_zone_page_state (page,NR_FILE_DIRTY ); -__inc_bdi_stat (mapping->backing_dev_info, -BDI_RECLAIMABLE ); +__inc_bdi_stat (mapping->a_bdi,BDI_RECLAIMABLE );task_io_account_write (PAGE_CACHE_SIZE ); } radix_tree_tag_set(&mapping->page_tree,
@@ -593,7 +592,7 @@ static int ceph_writepages_start(struct struct writeback_control *wbc) {struct inode *inode = mapping->host; -struct backing_dev_info *bdi = mapping->backing_dev_info; +struct backing_dev_info *bdi = mapping->a_bdi;struct ceph_inode_info *ci =ceph_inode (inode);struct ceph_client *client;pgoff_t index, start, end;
fs/cifs/file.c +1 -1
@@ -1365,7 +1365,7 @@ static int cifs_partialpagewrite(structstatic int cifs_writepages (struct address_space *mapping,struct writeback_control *wbc) { -struct backing_dev_info *bdi = mapping->backing_dev_info; +struct backing_dev_info *bdi = mapping->a_bdi;unsigned int bytes_to_write;unsigned int bytes_written;struct cifs_sb_info *cifs_sb;
fs/fuse/file.c +3 -3
@@ -945,7 +945,7 @@ static ssize_t fuse_file_aio_write(strucvfs_check_frozen (inode->i_sb,SB_FREEZE_WRITE );/* We can write back this queue in page reclaim */ - current->backing_dev_info = mapping->backing_dev_info; + current->backing_dev_info = mapping->a_bdi; err =generic_write_checks (file, &pos, &count,S_ISBLK (inode->i_mode));if (err)
@@ -1133,7 +1133,7 @@ static void fuse_writepage_finish(struct {struct inode *inode = req->inode;struct fuse_inode *fi =get_fuse_inode (inode); -struct backing_dev_info *bdi = inode->i_mapping->backing_dev_info; +struct backing_dev_info *bdi = inode->i_mapping->a_bdi;list_del (&req->writepages_entry);dec_bdi_stat (bdi,BDI_WRITEBACK );
@@ -1247,7 +1247,7 @@ static int fuse_writepage_locked(struct req->end = fuse_writepage_end; req->inode = inode; -inc_bdi_stat (mapping->backing_dev_info,BDI_WRITEBACK ); +inc_bdi_stat (mapping->a_bdi,BDI_WRITEBACK );inc_zone_page_state (tmp_page,NR_WRITEBACK_TEMP );end_page_writeback (page);
fs/fuse/inode.c +1 -1
@@ -254,7 +254,7 @@ struct inode *fuse_iget(struct super_bloif ((inode->i_state &I_NEW )) { inode->i_flags |=S_NOATIME |S_NOCMTIME ; inode->i_generation = generation; - inode->i_data.backing_dev_info = &fc->bdi; +mapping_new_set_bdi (&inode->i_data, &fc->bdi);fuse_init_inode (inode, attr);unlock_new_inode (inode); }else if ((inode->i_mode ^ attr->mode) &S_IFMT ) {
fs/nfs/inode.c +1 -1
@@ -280,7 +280,7 @@ nfs_fhget(struct super_block *sb, structif (S_ISREG (inode->i_mode)) { inode->i_fop = &nfs_file_operations; inode->i_data.a_ops = &nfs_file_aops; - inode->i_data.backing_dev_info = &NFS_SB (sb)->backing_dev_info; +mapping_new_set_bdi (&inode->i_data, &NFS_SB (sb)->backing_dev_info); }else if (S_ISDIR (inode->i_mode)) { inode->i_op =NFS_SB (sb)->nfs_client->rpc_ops->dir_inode_ops; inode->i_fop = &nfs_dir_operations;
fs/nfs/write.c +3 -4
@@ -444,7 +444,7 @@ nfs_mark_request_commit(struct nfs_page nfsi->ncommit++;spin_unlock (&inode->i_lock);inc_zone_page_state (req->wb_page,NR_UNSTABLE_NFS ); -inc_bdi_stat (req->wb_page->mapping->backing_dev_info,BDI_RECLAIMABLE ); +inc_bdi_stat (req->wb_page->mapping->a_bdi,BDI_RECLAIMABLE );__mark_inode_dirty (inode,I_DIRTY_DATASYNC ); }
@@ -455,7 +455,7 @@ nfs_clear_request_commit(struct nfs_pageif (test_and_clear_bit (PG_CLEAN , &(req)->wb_flags)) {dec_zone_page_state (page,NR_UNSTABLE_NFS ); -dec_bdi_stat (page->mapping->backing_dev_info,BDI_RECLAIMABLE ); +dec_bdi_stat (page->mapping->a_bdi,BDI_RECLAIMABLE );return 1 ; }return 0 ;
@@ -1307,8 +1307,7 @@ nfs_commit_list(struct inode *inode, strnfs_list_remove_request (req);nfs_mark_request_commit (req);dec_zone_page_state (req->wb_page,NR_UNSTABLE_NFS ); -dec_bdi_stat (req->wb_page->mapping->backing_dev_info, -BDI_RECLAIMABLE ); +dec_bdi_stat (req->wb_page->mapping->a_bdi,BDI_RECLAIMABLE );nfs_clear_page_tag_locked (req); }nfs_commit_clear_lock (NFS_I (inode));
fs/nilfs2/the_nilfs.c +1 -1
@@ -613,7 +613,7 @@ int init_nilfs(struct the_nilfs *nilfs, nilfs->ns_mount_state =le16_to_cpu (sbp->s_state); - bdi = nilfs->ns_bdev->bd_inode->i_mapping->backing_dev_info; + bdi = nilfs->ns_bdev->bd_inode->i_mapping->a_bdi; nilfs->ns_bdi = bdi ? : &default_backing_dev_info;/* Finding last segment */
fs/ntfs/file.c +1 -1
@@ -2088,7 +2088,7 @@ static ssize_t ntfs_file_aio_write_noloc pos = *ppos;vfs_check_frozen (inode->i_sb,SB_FREEZE_WRITE );/* We can write back this queue in page reclaim. */ - current->backing_dev_info = mapping->backing_dev_info; + current->backing_dev_info = mapping->a_bdi; written =0 ; err =generic_write_checks (file, &pos, &count,S_ISBLK (inode->i_mode));if (err)
fs/ocfs2/file.c +1 -1
@@ -2129,7 +2129,7 @@ relock: goto out_dio; } }else { - current->backing_dev_info = file->f_mapping->backing_dev_info; + current->backing_dev_info = file->f_mapping->a_bdi; written =generic_file_buffered_write (iocb, iov, nr_segs, *ppos, ppos, count,0 ); current->backing_dev_info =NULL ;
fs/romfs/super.c +2 -2
@@ -356,8 +356,8 @@ static struct inode *romfs_iget(struct s i->i_fop = &romfs_ro_fops; i->i_data.a_ops = &romfs_aops;if (i->i_sb->s_mtd) - i->i_data.backing_dev_info = - i->i_sb->s_mtd->backing_dev_info; +mapping_new_set_bdi (&i->i_data, + i->i_sb->s_mtd->backing_dev_info);if (nextfh &ROMFH_EXEC ) mode |=S_IXUGO ;break ;
fs/xfs/linux-2.6/xfs_file.c +1 -1
@@ -756,7 +756,7 @@ start: goto out_unlock_internal;/* We can write back this queue in page reclaim */ - current->backing_dev_info = mapping->backing_dev_info; + current->backing_dev_info = mapping->a_bdi;if ((ioflags &IO_ISDIRECT )) {if (mapping->nrpages) {
PATCH 52/52 fs: icache less I_FREEING time
In reply to [email protected]Problem with inode reclaim is that it puts inodes into I_FREEING state and then continues to gather more, during which it may iput, invalidate_mapping_pages, be preempted, etc. Holding these inodes in I_FREEING can cause pauses.
After the inode scalability work, there is not a big reason to batch up inodes to reclaim them, so dispose them as they are found from the LRU.
fs/inode.c +20 -14
@@ -390,6 +390,19 @@ EXPORT_SYMBOL(clear_inode);static void inode_sb_list_del (struct inode *inode); +static void dispose_one_inode (struct inode *inode) +{ +clear_inode (inode); + +spin_lock (&inode->i_lock); +__remove_inode_hash (inode); +inode_sb_list_del (inode); +spin_unlock (&inode->i_lock); + +wake_up_inode (inode); +destroy_inode (inode); +} +/* * dispose_list - dispose of the contents of a local list * @head: the head of the list to free
@@ -409,15 +422,8 @@ static void dispose_list(struct list_heaif (inode->i_data.nrpages)truncate_inode_pages (&inode->i_data,0 ); -clear_inode (inode); - -spin_lock (&inode->i_lock); -__remove_inode_hash (inode); -inode_sb_list_del (inode); -spin_unlock (&inode->i_lock); - -wake_up_inode (inode); -destroy_inode (inode); +dispose_one_inode (inode); +cond_resched (); nr_disposed++; } }
@@ -526,7 +532,6 @@ EXPORT_SYMBOL(invalidate_inodes);*/ static void prune_icache (struct zone *zone,unsigned long nr_to_scan) { -LIST_HEAD (freeable);unsigned long reap =0 ;down_read (&iprune_sem);
@@ -563,8 +568,6 @@ again:__iget (inode);spin_unlock (&inode->i_lock); -dispose_list (&freeable); -if (remove_inode_buffers (inode)) reap +=invalidate_mapping_pages (&inode->i_data,0 ,-1 );
@@ -572,11 +575,15 @@ again:spin_lock (&zone->inode_lru_lock);continue ; } -list_move (&inode->i_lru, &freeable); +list_del_init (&inode->i_lru);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ;spin_unlock (&inode->i_lock); zone->inode_nr_lru--; +spin_unlock (&zone->inode_lru_lock); +dispose_one_inode (inode); +cond_resched (); +spin_lock (&zone->inode_lru_lock); }if (current_is_kswapd ())__count_vm_events (KSWAPD_INODESTEAL , reap);
@@ -584,7 +591,6 @@ again:__count_vm_events (PGINODESTEAL , reap);spin_unlock (&zone->inode_lru_lock); -dispose_list (&freeable);up_read (&iprune_sem); }
PATCH 11/52 fs: dcache scale nr_dentry
In reply to [email protected]Make dentry_stat_t.nr_dentry an atomic_t type, and move it from under dcache_lock.
--- fs/dcache.c | 20 +++++++++----------- include/linux/dcache.h | 4 ++-- kernel/sysctl.c | 6 ++++++ 3 files changed, 17 insertions(+), 13 deletions(-)
fs/dcache.c +9 -11
@@ -88,6 +88,7 @@ static struct hlist_head *dentry_hashtab/* Statistics gathering. */ struct dentry_stat_t dentry_stat = { + .nr_dentry =ATOMIC_INIT (0 ), .age_limit =45 , };
@@ -106,11 +107,11 @@ static void d_callback(struct rcu_head * }/* -* no dcache_lock, please. The caller must decrement dentry_stat.nr_dentry -* inside dcache_lock. +* no dcache_lock, please. */ static void d_free (struct dentry *dentry) { +atomic_dec (&dentry_stat.nr_dentry);if (dentry->d_op && dentry->d_op->d_release) dentry->d_op->d_release (dentry);/* if dentry was never inserted into hash, immediate free is OK */
@@ -217,7 +218,6 @@ static struct dentry *d_kill(struct dentstruct dentry *parent;list_del (&dentry->d_u.d_child); - dentry_stat.nr_dentry--;/* For d_free, below */ /*drops the locks, at that point nobody can reach this dentry */ dentry_iput (dentry);if (IS_ROOT (dentry))
@@ -787,10 +787,7 @@ static void shrink_dcache_for_umount_sub struct dentry, d_u.d_child); } out: -/* several dentries were freed, need to correct nr_dentry */ -spin_lock (&dcache_lock); - dentry_stat.nr_dentry -= detached; -spin_unlock (&dcache_lock); +return ; }/*
@@ -1047,11 +1044,12 @@ struct dentry *d_alloc(struct dentry * pINIT_LIST_HEAD (&dentry->d_u.d_child); } -spin_lock (&dcache_lock); -if (parent) +if (parent) { +spin_lock (&dcache_lock);list_add (&dentry->d_u.d_child, &parent->d_subdirs); - dentry_stat.nr_dentry++; -spin_unlock (&dcache_lock); +spin_unlock (&dcache_lock); + } +atomic_inc (&dentry_stat.nr_dentry);return dentry; }
include/linux/dcache.h +2 -2
@@ -37,8 +37,8 @@ struct qstr { };struct dentry_stat_t { -int nr_dentry; -int nr_unused; +atomic_t nr_dentry; +int nr_unused;/* protected by dcache_lru_lock */ int age_limit;/* age in seconds */ int want_pages;/* pages requested by system */ int dummy[2 ];
kernel/sysctl.c +6 -0
@@ -1371,6 +1371,12 @@ static struct ctl_table fs_table[] = { .extra2 = &sysctl_nr_open_max, }, { +/* +* dentry_stat has an atomic_t member, so this is a bit of +* a hack, but it works for the moment, and I won't bother +* changing it now because we'll probably want to change to +* a more scalable counter anyway. +*/ .procname = "dentry-state", .data = &dentry_stat, .maxlen = 6*sizeof(int),
PATCH 15/52 fs: dcache scale inode alias list
In reply to [email protected]Add a new lock, dcache_inode_lock, to protect the inode's i_dentry list from concurrent modification. d_alias is also protected by d_lock.
--- fs/affs/amigaffs.c | 2 + fs/dcache.c | 56 +++++++++++++++++++++++++++++++++++++++----- fs/exportfs/expfs.c | 4 +++ fs/nfs/getroot.c | 4 +++ fs/notify/fsnotify.c | 2 + fs/notify/inotify/inotify.c | 2 + fs/ocfs2/dcache.c | 3 +- fs/sysfs/dir.c | 3 ++ include/linux/dcache.h | 1 9 files changed, 70 insertions(+), 7 deletions(-)
fs/dcache.c +53 -6
@@ -37,6 +37,8 @@/* * Usage: +* dcache_inode_lock protects: +* - i_dentry, d_alias, d_inode * dcache_hash_lock protects: * - the dcache hash table * dcache_lru_lock protects:
@@ -49,12 +51,14 @@* - d_unhashed() * - d_parent and d_subdirs * - childrens' d_child and d_parent +* - d_alias, d_inode * * Ordering: * dcache_lock -* dentry->d_lock -* dcache_lru_lock -* dcache_hash_lock +* dcache_inode_lock +* dentry->d_lock +* dcache_lru_lock +* dcache_hash_lock * * If there is an ancestor relationship: * dentry->d_parent->...->d_parent->d_lock
@@ -70,11 +74,13 @@int sysctl_vfs_cache_pressure__read_mostly =100 ;EXPORT_SYMBOL_GPL (sysctl_vfs_cache_pressure); +__cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_inode_lock );__cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_hash_lock );static __cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_lru_lock );__cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_lock );__cacheline_aligned_in_smp DEFINE_SEQLOCK (rename_lock ); +EXPORT_SYMBOL (dcache_inode_lock);EXPORT_SYMBOL (dcache_hash_lock);EXPORT_SYMBOL (dcache_lock);
@@ -139,6 +145,7 @@ static void d_free(struct dentry *dentry*/ static void dentry_iput (struct dentry * dentry) __releases(dentry->d_lock) +__releases (dcache_inode_lock)__releases (dcache_lock) {struct inode *inode = dentry->d_inode;
@@ -146,6 +153,7 @@ static void dentry_iput(struct dentry * dentry->d_inode =NULL ;list_del_init (&dentry->d_alias);spin_unlock (&dentry->d_lock); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);if (!inode->i_nlink)fsnotify_inoderemove (inode);
@@ -155,6 +163,7 @@ static void dentry_iput(struct dentry *iput (inode); }else {spin_unlock (&dentry->d_lock); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock); } }
@@ -226,6 +235,7 @@ static void dentry_lru_del_init(struct d*/ static struct dentry *d_kill (struct dentry *dentry) __releases(dentry->d_lock) +__releases (dcache_inode_lock)__releases (dcache_lock) {struct dentry *parent;
@@ -290,15 +300,20 @@ repeat:* want to reduce dcache_lock anyway so this will * get improved. */ +drop1:spin_unlock (&dentry->d_lock); goto repeat; } +if (!spin_trylock (&dcache_inode_lock)) { +drop2: +spin_unlock (&dcache_lock); + goto drop1; + } parent = dentry->d_parent;if (parent && parent != dentry) {if (!spin_trylock (&parent->d_lock)) { -spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); - goto repeat; +spin_unlock (&dcache_inode_lock); + goto drop2; } } }
@@ -328,6 +343,7 @@ repeat:spin_unlock (&dentry->d_lock);if (parent && parent != dentry)spin_unlock (&parent->d_lock); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);return ;
@@ -510,7 +526,9 @@ struct dentry * d_find_alias(struct inodif (!list_empty (&inode->i_dentry)) {spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock); de =__d_find_alias (inode,0 ); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock); }return de;
@@ -526,18 +544,21 @@ void d_prune_aliases(struct inode *inodestruct dentry *dentry; restart:spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock);list_for_each_entry (dentry, &inode->i_dentry, d_alias) {spin_lock (&dentry->d_lock);if (!dentry->d_count) {__dget_locked_dlock (dentry);__d_drop (dentry);spin_unlock (&dentry->d_lock); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);dput (dentry); goto restart; }spin_unlock (&dentry->d_lock); } +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock); }EXPORT_SYMBOL (d_prune_aliases);
@@ -566,6 +587,7 @@ static void prune_one_dentry(struct dentstruct dentry *parent =NULL ;spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock); again:spin_lock (&dentry->d_lock);if (dentry->d_parent && dentry != dentry->d_parent) {
@@ -580,6 +602,7 @@ again:if (parent)spin_unlock (&parent->d_lock);spin_unlock (&dentry->d_lock); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);return ; }
@@ -650,6 +673,7 @@ restart:spin_unlock (&dcache_lru_lock);spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock); again:spin_lock (&dcache_lru_lock);/* lru_lock also protects tmp list */ while (!list_empty (&tmp)) {
@@ -681,8 +705,10 @@ again1:prune_one_dentry (dentry);/* dcache_lock and dentry->d_lock dropped */ spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock);spin_lock (&dcache_lru_lock); } +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);if (count ==NULL && !list_empty (&sb->s_dentry_lru))
@@ -1198,9 +1224,11 @@ EXPORT_SYMBOL(d_alloc_name);/* the caller must hold dcache_lock */ static void __d_instantiate (struct dentry *dentry,struct inode *inode) { +spin_lock (&dentry->d_lock);if (inode)list_add (&dentry->d_alias, &inode->i_dentry); dentry->d_inode = inode; +spin_unlock (&dentry->d_lock);fsnotify_d_instantiate (dentry, inode); }
@@ -1223,7 +1251,9 @@ void d_instantiate(struct dentry *entry, {BUG_ON (!list_empty (&entry->d_alias));spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock);__d_instantiate (entry, inode); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);security_d_instantiate (entry, inode); }
@@ -1284,7 +1314,9 @@ struct dentry *d_instantiate_unique(struBUG_ON (!list_empty (&entry->d_alias));spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock); result =__d_instantiate_unique (entry, inode); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);if (!result) {
@@ -1375,8 +1407,10 @@ struct dentry *d_obtain_alias(struct ino tmp->d_parent = tmp;/* make sure dput doesn't croak */ spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock); res =__d_find_alias (inode,0 );if (res) { +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);dput (tmp); goto out_iput;
@@ -1391,6 +1425,7 @@ struct dentry *d_obtain_alias(struct inolist_add (&tmp->d_alias, &inode->i_dentry);hlist_add_head (&tmp->d_hash, &inode->i_sb->s_anon);spin_unlock (&tmp->d_lock); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);return tmp;
@@ -1423,9 +1458,11 @@ struct dentry *d_splice_alias(struct inoif (inode &&S_ISDIR (inode->i_mode)) {spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock); new =__d_find_alias (inode,1 );if (new) {BUG_ON (!(new->d_flags &DCACHE_DISCONNECTED )); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);security_d_instantiate (new, inode);d_move (new, dentry);
@@ -1433,6 +1470,7 @@ struct dentry *d_splice_alias(struct ino }else {/* already taking dcache_lock, so d_add() by hand */ __d_instantiate (dentry, inode); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);security_d_instantiate (dentry, inode);d_rehash (dentry);
@@ -1507,8 +1545,10 @@ struct dentry *d_add_ci(struct dentry *d* already has a dentry. */ spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock);if (!S_ISDIR (inode->i_mode) ||list_empty (&inode->i_dentry)) {__d_instantiate (found, inode); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);security_d_instantiate (found, inode);return found;
@@ -1520,6 +1560,7 @@ struct dentry *d_add_ci(struct dentry *d*/ new = list_entry(inode->i_dentry.next, struct dentry, d_alias);dget_locked (new); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);security_d_instantiate (found, inode);d_move (new, found);
@@ -1738,6 +1779,7 @@ void d_delete(struct dentry * dentry)* Are we the only user? */ spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock);spin_lock (&dentry->d_lock); isdir =S_ISDIR (dentry->d_inode->i_mode);if (dentry->d_count ==1 ) {
@@ -1751,6 +1793,7 @@ void d_delete(struct dentry * dentry)__d_drop (dentry);spin_unlock (&dentry->d_lock); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);fsnotify_nameremove (dentry, isdir);
@@ -2003,6 +2046,7 @@ out_unalias:d_move_locked (alias, dentry); ret = alias; out_err: +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);if (m2)mutex_unlock (m2);
@@ -2068,6 +2112,7 @@ struct dentry *d_materialise_unique(struBUG_ON (!d_unhashed (dentry));spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock);if (!inode) { actual = dentry;
@@ -2111,6 +2156,7 @@ found:_d_rehash (actual);spin_unlock (&dcache_hash_lock);spin_unlock (&actual->d_lock); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock); out_nolock:if (actual == dentry) {
@@ -2122,6 +2168,7 @@ out_nolock:return actual; shouldnt_be_hashed: +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);BUG (); }
include/linux/dcache.h +1 -0
@@ -188,6 +188,7 @@ d_iput: no no no yes#define DCACHE_CANT_MOUNT 0x0100 +extern spinlock_t dcache_inode_lock;extern spinlock_t dcache_hash_lock;extern spinlock_t dcache_lock;extern seqlock_t rename_lock;
fs/notify/inotify/inotify.c +2 -0
@@ -182,6 +182,7 @@ static void set_dentry_child_flags(strucstruct dentry *alias;spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock);list_for_each_entry (alias, &inode->i_dentry, d_alias) {struct dentry *child;
@@ -199,6 +200,7 @@ static void set_dentry_child_flags(struc }spin_unlock (&alias->d_lock); } +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock); }
fs/exportfs/expfs.c +4 -0
@@ -48,8 +48,10 @@ find_acceptable_alias(struct dentry *resreturn result;spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock);list_for_each_entry (dentry, &result->d_inode->i_dentry, d_alias) {dget_locked (dentry); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);if (toput)dput (toput);
@@ -58,8 +60,10 @@ find_acceptable_alias(struct dentry *resreturn dentry; }spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock); toput = dentry; } +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);if (toput)
fs/affs/amigaffs.c +2 -0
@@ -129,6 +129,7 @@ affs_fix_dcache(struct dentry *dentry, ustruct list_head *head, *next;spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock); head = &inode->i_dentry; next = head->next;while (next != head) {
@@ -139,6 +140,7 @@ affs_fix_dcache(struct dentry *dentry, u } next = next->next; } +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock); }
fs/ocfs2/dcache.c +2 -1
@@ -152,7 +152,7 @@ struct dentry *ocfs2_find_local_alias(ststruct dentry *dentry =NULL ;spin_lock (&dcache_lock); - +spin_lock (&dcache_inode_lock);list_for_each (p, &inode->i_dentry) { dentry = list_entry(p, struct dentry, d_alias);
@@ -170,6 +170,7 @@ struct dentry *ocfs2_find_local_alias(st dentry =NULL ; } +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock);return dentry;
fs/nfs/getroot.c +4 -0
@@ -65,7 +65,11 @@ static int nfs_superblock_set_dummy_root* Oops, since the test for IS_ROOT() will fail. */ spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock); +spin_lock (&sb->s_root->d_lock);list_del_init (&sb->s_root->d_alias); +spin_unlock (&sb->s_root->d_lock); +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock); }return 0 ;
fs/notify/fsnotify.c +2 -0
@@ -54,6 +54,7 @@ void __fsnotify_update_child_dentry_flag watched =fsnotify_inode_watches_children (inode);spin_lock (&dcache_lock); +spin_lock (&dcache_inode_lock);/* run all of the dentries associated with this inode. Since this is a * directory, there damn well better only be one item on this list */ list_for_each_entry (alias, &inode->i_dentry, d_alias) {
@@ -76,6 +77,7 @@ void __fsnotify_update_child_dentry_flag }spin_unlock (&alias->d_lock); } +spin_unlock (&dcache_inode_lock);spin_unlock (&dcache_lock); }
PATCH 35/52 fs: icache factor hash lock into functions
In reply to [email protected]Make inode_hash_lock private by adding a function __remove_inode_hash that can be used by filesystems defining their own drop_inode functions.
--- fs/inode.c | 42 +++++++++++++++++++++++++++--------------- include/linux/fs.h | 1 + include/linux/writeback.h | 1 - 3 files changed, 28 insertions(+), 16 deletions(-)
fs/inode.c +27 -15
@@ -107,7 +107,7 @@ static struct hlist_head *inode_hashtabl*/ DEFINE_SPINLOCK (sb_inode_list_lock);DEFINE_SPINLOCK (wb_inode_list_lock); -DEFINE_SPINLOCK (inode_hash_lock); +static DEFINE_SPINLOCK (inode_hash_lock);/* * iprune_sem provides exclusion between the kswapd or try_to_free_pages
@@ -377,9 +377,7 @@ static void dispose_list(struct list_heaspin_lock (&sb_inode_list_lock);spin_lock (&inode->i_lock); -spin_lock (&inode_hash_lock); -hlist_del_init (&inode->i_hash); -spin_unlock (&inode_hash_lock); +__remove_inode_hash (inode);list_del_init (&inode->i_sb_list);spin_unlock (&inode->i_lock);spin_unlock (&sb_inode_list_lock);
@@ -1280,6 +1278,20 @@ void __insert_inode_hash(struct inode *iEXPORT_SYMBOL (__insert_inode_hash);/** +* __remove_inode_hash - remove an inode from the hash +* @inode: inode to unhash +* +* Remove an inode from the superblock. inode->i_lock must be +* held. +*/ +void __remove_inode_hash (struct inode *inode) +{ +spin_lock (&inode_hash_lock); +hlist_del_init (&inode->i_hash); +spin_unlock (&inode_hash_lock); +} + +/** * remove_inode_hash - remove an inode from the hash * @inode: inode to unhash *
@@ -1288,9 +1300,7 @@ EXPORT_SYMBOL(__insert_inode_hash);void remove_inode_hash (struct inode *inode) {spin_lock (&inode->i_lock); -spin_lock (&inode_hash_lock); -hlist_del_init (&inode->i_hash); -spin_unlock (&inode_hash_lock); +__remove_inode_hash (inode);spin_unlock (&inode->i_lock); }EXPORT_SYMBOL (remove_inode_hash);
@@ -1332,11 +1342,15 @@ void generic_delete_inode(struct inode *truncate_inode_pages (&inode->i_data,0 );clear_inode (inode); } -spin_lock (&inode->i_lock); -spin_lock (&inode_hash_lock); -hlist_del_init (&inode->i_hash); -spin_unlock (&inode_hash_lock); -spin_unlock (&inode->i_lock); +/* +* i_lock not required to delete from hash. If there was a +* concurrency window, then it would be possible for the other +* thread to touch the inode after it has been freed, with +* destroy_inode. +* XXX: yes it is because find_inode_fast checks it. Maybe we +* can avoid it though... +*/ +remove_inode_hash (inode);wake_up_inode (inode);BUG_ON (inode->i_state !=I_CLEAR );destroy_inode (inode);
@@ -1377,9 +1391,7 @@ int generic_detach_inode(struct inode *ispin_lock (&inode->i_lock);WARN_ON (inode->i_state &I_NEW ); inode->i_state &= ~I_WILL_FREE ; -spin_lock (&inode_hash_lock); -hlist_del_init (&inode->i_hash); -spin_unlock (&inode_hash_lock); +__remove_inode_hash (inode);atomic_dec (&inodes_stat.nr_unused); }spin_lock (&wb_inode_list_lock);
include/linux/fs.h +1 -0
@@ -2181,6 +2181,7 @@ extern int should_remove_suid(struct denextern int file_remove_suid (struct file *);extern void __insert_inode_hash (struct inode *,unsigned long hashval); +extern void __remove_inode_hash (struct inode *);extern void remove_inode_hash (struct inode *);static inline void insert_inode_hash (struct inode *inode) {__insert_inode_hash (inode, inode->i_ino);
include/linux/writeback.h +0 -1
@@ -11,7 +11,6 @@ struct backing_dev_info;extern spinlock_t sb_inode_list_lock;extern spinlock_t wb_inode_list_lock; -extern spinlock_t inode_hash_lock;extern struct list_head inode_in_use;extern struct list_head inode_unused;
PATCH 6/52 fs: scale files_lock
In reply to [email protected]Improve scalability of files_lock by adding per-cpu, per-sb files lists, protected with an lglock. The lglock provides fast access to the per-cpu lists to add and remove files. It also provides a snapshot of all the per-cpu lists (although this is very slow).
One difficulty with this approach is that a file can be removed from the list by another CPU. We must track which per-cpu list the file is on. Scalability could suffer if files are frequently removed from different cpu's list.
However loads with frequent removal of files imply short interval between adding and removing the files, and the scheduler attempts to avoid moving processes too far away. Also, even in the case of cross-CPU removal, the hardware has much more opportunity to parallelise cacheline transfers with N cachelines than with 1.
A worst-case test of 1 CPU allocating files subsequently being freed by N CPUs degenerates to contending on a single lock, which is no worse than before. When more than one CPU are allocating files, even if they are always freed by different CPUs, there will be more parallelism than the single-lock case.
Testing results:
On a 2 socket, 8 core opteron, I measure the number of times the lock is taken to remove the file, the number of times it is removed by the same CPU that added it, and the number of times it is removed by the same node that added it.
Booting: locks= 25049 cpu-hits= 23174 (92.5%) node-hits= 23945 (95.6%)
kbuild -j16 locks=2281913 cpu-hits=2208126 (96.8%) node-hits=2252674 (98.7%)
dbench 64 locks=4306582 cpu-hits=4287247 (99.6%) node-hits=4299527 (99.8%)
So a file is removed from the same CPU it was added by over 90% of the time. It remains within the same node 95% of the time.
Tim Chen run some numbers for a 64 thread Nehalem system performing a compile.
throughput
2.6.34-rc2 24.5
+patch 24.9
us sys idle IO wait (in %) 2.6.34-rc2 51.25 28.25 17.25 3.25 +patch 53.75 18.5 19 8.75
So significantly less CPU time spent in kernel code, higher idle time and slightly higher throughput.
Single threaded performance difference was within the noise of microbenchmarks. That is not to say one does not exist, the code is larger and more memory accesses required so it will be slightly slower.
--- fs/file_table.c | 108 ++++++++++++++++++++++++++++++++++++++++++++--------- fs/super.c | 18 ++++++++ include/linux/fs.h | 7 +++ 3 files changed, 115 insertions(+), 18 deletions(-)
fs/file_table.c +90 -18
@@ -20,7 +20,9 @@#include <linux/cdev.h> #include <linux/fsnotify.h> #include <linux/sysctl.h> +#include <linux/lglock.h> #include <linux/percpu_counter.h> +#include <linux/percpu.h> #include <linux/ima.h> #include <asm/atomic.h>
@@ -32,7 +34,8 @@ struct files_stat_struct files_stat = { .max_files = NR_FILE }; -static __cacheline_aligned_in_smp DEFINE_SPINLOCK (files_lock ); +DECLARE_LGLOCK (files_lglock); +DEFINE_LGLOCK (files_lglock);/* SLAB cache for file structures */ static struct kmem_cache *filp_cachep__read_mostly ;
@@ -327,30 +330,98 @@ void put_filp(struct file *file) } } +static inline int file_list_cpu (struct file *file) +{ +#ifdef CONFIG_SMP +return file->f_sb_list_cpu; +#else +return smp_processor_id (); +#endif +} + +/* helper for file_sb_list_add to reduce ifdefs */ +static inline void __file_sb_list_add (struct file *file,struct super_block *sb) +{ +struct list_head *list; +#ifdef CONFIG_SMP +int cpu; + cpu =smp_processor_id (); + file->f_sb_list_cpu = cpu; + list =per_cpu_ptr (sb->s_files, cpu); +#else + list = &sb->s_files; +#endif +list_add (&file->f_u.fu_list, list); +} + +/** +* file_sb_list_add - add a file to the sb's file list +* @file: file to add +* @sb: sb to add it to +* +* Use this function to associate a file with the superblock of the inode it +* refers to. +*/ void file_sb_list_add (struct file *file,struct super_block *sb) { -spin_lock (&files_lock); -BUG_ON (!list_empty (&file->f_u.fu_list)); -list_add (&file->f_u.fu_list, &sb->s_files); -spin_unlock (&files_lock); +lg_local_lock (files_lglock); +__file_sb_list_add (file, sb); +lg_local_unlock (files_lglock); } +/** +* file_sb_list_del - remove a file from the sb's file list +* @file: file to remove +* @sb: sb to remove it from +* +* Use this function to remove a file from its superblock. +*/ void file_sb_list_del (struct file *file) {if (!list_empty (&file->f_u.fu_list)) { -spin_lock (&files_lock); +lg_local_lock_cpu (files_lglock,file_list_cpu (file));list_del_init (&file->f_u.fu_list); -spin_unlock (&files_lock); +lg_local_unlock_cpu (files_lglock,file_list_cpu (file)); } } +#ifdef CONFIG_SMP + +/* +* These macros iterate all files on all CPUs for a given superblock. +* files_lglock must be held globally. +*/ +#define do_file_list_for_each_entry (__sb, __file) \ +{ \ + int i; \ + for_each_possible_cpu(i) { \ + struct list_head *list; \ + list = per_cpu_ptr((__sb)->s_files, i); \ + list_for_each_entry((__file), list, f_u.fu_list) + +#define while_file_list_for_each_entry \ + } \ +} + +#else + +#define do_file_list_for_each_entry (__sb, __file) \ +{ \ + struct list_head *list; \ + list = &(sb)->s_files; \ + list_for_each_entry((__file), list, f_u.fu_list) + +#define while_file_list_for_each_entry \ +} + +#endif +int fs_may_remount_ro (struct super_block *sb) {struct file *file; -/* Check that no files are currently opened for writing. */ -spin_lock (&files_lock); -list_for_each_entry (file, &sb->s_files, f_u.fu_list) { +lg_global_lock (files_lglock); +do_file_list_for_each_entry (sb, file) {struct inode *inode = file->f_path.dentry->d_inode;/* File with pending delete? */
@@ -360,11 +431,11 @@ int fs_may_remount_ro(struct super_block/* Writeable file? */ if (S_ISREG (inode->i_mode) && (file->f_mode &FMODE_WRITE )) goto too_bad; - } -spin_unlock (&files_lock); + } while_file_list_for_each_entry; +lg_global_unlock (files_lglock);return 1 ;/* Tis' cool bro. */ too_bad: -spin_unlock (&files_lock); +lg_global_unlock (files_lglock);return 0 ; }
@@ -380,8 +451,8 @@ void mark_files_ro(struct super_block *sstruct file *f; retry: -spin_lock (&files_lock); -list_for_each_entry (f, &sb->s_files, f_u.fu_list) { +lg_global_lock (files_lglock); +do_file_list_for_each_entry (sb, f) {struct vfsmount *mnt;if (!S_ISREG (f->f_path.dentry->d_inode->i_mode))continue ;
@@ -397,12 +468,12 @@ retry:file_release_write (f); mnt =mntget (f->f_path.mnt);/* This can sleep, so we can't hold the spinlock. */ -spin_unlock (&files_lock); +lg_global_unlock (files_lglock);mnt_drop_write (mnt);mntput (mnt); goto retry; - } -spin_unlock (&files_lock); + } while_file_list_for_each_entry; +lg_global_unlock (files_lglock); }void __init files_init (unsigned long mempages)
@@ -422,5 +493,6 @@ void __init files_init(unsigned long memif (files_stat.max_files <NR_FILE ) files_stat.max_files =NR_FILE ;files_defer_init (); +lg_lock_init (files_lglock);percpu_counter_init (&nr_files,0 ); }
fs/super.c +18 -0
@@ -54,7 +54,22 @@ static struct super_block *alloc_super(s s =NULL ; goto out; } +#ifdef CONFIG_SMP + s->s_files = alloc_percpu(struct list_head); +if (!s->s_files) { +security_sb_free (s); +kfree (s); + s =NULL ; + goto out; + }else { +int i; + +for_each_possible_cpu (i) +INIT_LIST_HEAD (per_cpu_ptr (s->s_files, i)); + } +#else INIT_LIST_HEAD (&s->s_files); +#endif INIT_LIST_HEAD (&s->s_instances);INIT_HLIST_HEAD (&s->s_anon);INIT_LIST_HEAD (&s->s_inodes);
@@ -108,6 +123,9 @@ out:*/ static inline void destroy_super (struct super_block *s) { +#ifdef CONFIG_SMP +free_percpu (s->s_files); +#endif security_sb_free (s);kfree (s->s_subtype);kfree (s->s_options);
include/linux/fs.h +7 -0
@@ -925,6 +925,9 @@ struct file {#define f_vfsmnt f_path.mntconst struct file_operations *f_op;spinlock_t f_lock;/* f_ep_links, f_flags, no IRQ */ +#ifdef CONFIG_SMP +int f_sb_list_cpu; +#endif atomic_long_t f_count;unsigned int f_flags;fmode_t f_mode;
@@ -1339,7 +1342,11 @@ struct super_block {struct list_head s_inodes;/* all inodes */ struct hlist_head s_anon;/* anonymous dentries for (nfs) exporting */ +#ifdef CONFIG_SMP +struct list_head __percpu *s_files; +#else struct list_head s_files; +#endif /* s_dentry_lru and s_nr_dentry_unused are protected by dcache_lock */ struct list_head s_dentry_lru;/* unused dentry lru */ int s_nr_dentry_unused;/* # of dentry on lru */
Re: [patch 01/52] kernel: add bl_list
In reply to [email protected]Quoted 49 lines · Le jeudi 24 juin 2010 à 13:02 +1000, [email protected] a écrit :
pièce jointe document texte brut (list-bitlock.patch)
Introduce a type of hlist that can support the use of the lowest bit in thehlist_head. This will be subsequently used to implement per-bucket bit spinlock for inode and dentry hashes.Signed-off-by Nick Piggin <[email protected]>--- include/linux/list_bl.h | 99 +++++++++++++++++++++++++++++++++++++ include/linux/rculist_bl.h | 120 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+)Index:
linux-2.6/include/linux/list_bl.h
===================================================================include/linux/list_bl.h new file +32
-0@@ -0,0 +1,99 @@ +#ifndef _LINUX_LIST_BL_H +#define _LINUX_LIST_BL_H + +#include <linux/list.h> + +/* +* Special version of lists, where head of the list has a bit spinlock +* in the lowest bit. This is useful for scalable hash tables without +* increasing memory footprint overhead. +*/ + +struct hlist_bl_head { +struct hlist_bl_node *first; +}; + +struct hlist_bl_node { +struct hlist_bl_node *next, **pprev; +}; +#define INIT_HLIST_BL_HEAD (ptr) \ + ((ptr)->first = NULL) + +static inline void INIT_HLIST_BL_NODE (struct hlist_bl_node *h) +{ + h->next =NULL ; + h->pprev =NULL ; +} + +#define hlist_bl_entry (ptr, type, member) container_of(ptr,type,member) + +static inline int hlist_bl_unhashed (const struct hlist_bl_node *h) +{ +return !h->pprev;
include/linux/list_bl.h line 42
Quoted 10 lines
include/linux/list_bl.h new file +10
-0+} + +static inline struct hlist_bl_node *hlist_bl_first (struct hlist_bl_head *h) +{ +return (struct hlist_bl_node *)((unsigned long )h->first & ~1UL ); +} + +static inline void hlist_bl_set_first (struct hlist_bl_head *h,struct hlist_bl_node *n) +{ + h->first = (struct hlist_bl_node *)((unsigned long )n | ((unsigned long )h->first &1UL ));
Hmm, shouldnt hlist_bl_set_first() be used only with bit lock held ?
h->first = (struct hlist_bl_node *)((unsigned long)n | 1UL);
include/linux/list_bl.h
Quoted 7 lines
include/linux/list_bl.h new file +6
-0+} + + +static inline void hlist_bl_set_first_rcu (struct hlist_bl_head *h,struct hlist_bl_node *n) +{ +rcu_assign_pointer (h->first, (struct hlist_bl_node *)((unsigned long )n | ((unsigned long )h->first &1UL )));
Same question here.
include/linux/list_bl.h
Quoted 6 lines
include/linux/list_bl.h new file +6
-0+} + +static inline struct hlist_bl_node *hlist_bl_first_rcu (struct hlist_bl_head *h) +{ +return (struct hlist_bl_node *)((unsigned long )rcu_dereference (h->first) & ~1UL ); +}
Looks really nice Nick, maybe we should push this so that other subsystem can start using it.
Thanks
Peter Zijlstra
maintainerRe: [patch 06/52] fs: scale files_lock
In reply to [email protected]Quoted 4 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
One difficulty with this approach is that a file can be removed from the list by another CPU. We must track which per-cpu list the file is on. Scalability could suffer if files are frequently removed from different cpu's list.
Is this really a lot less complex than what I did with my fine-grained locked list?
Peter Zijlstra
maintainerRe: [patch 14/52] fs: dcache scale subdirs
In reply to [email protected]Quoted 4 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
plain text document attachment (fs-dcache-scale-d_subdirs.patch) Protect
d_subdirsandd_childwithd_lock, except in filesystems that aren't usingdcache_lockfor these anyway (eg. usingi_mutex).
Quoted 8 lines
XXX: probably don't need parent lock in inotify (because child lock should stabilize parent). Also, possibly some filesystems don't need so much locking (eg. of child dentry when modifying
d_child, so long as parent is locked)... but be on the safe side. Hmm, maybe we should just sayd_childlist is protected byd_parent->d_lock.d_parentcould remain protected withd_lock.XXX: leave
dcache_lockin there until removedcache_lockpatch
This still suffers the problem John found, right?
Peter Zijlstra
maintainerRe: [patch 16/52] fs: dcache RCU for multi-step operaitons
In reply to [email protected]Quoted 9 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
plain text document attachment (fs-dcache_lock-multi-step.patch) The remaining usages for
dcache_lockis to allow atomic, multi-step read-side operations over the directory tree by excluding modifications to the tree. Also, to walk in theleaf->rootdirection in the tree where we don't have a naturald_lockordering.This could be accomplished by taking every
d_lock, but this would mean a huge number of locks and actually gets very tricky.
Quoted 7 lines
Solve this instead by using the rename seqlock for multi-step read-side operations. Insert operations are not serialised. Delete operations are tricky when walking up the directory our parent might have been deleted when dropping locks so also need to check and retry for that.
XXX: hmm, we could of course just take the rename lock if there is any worry about livelock. Most of these are slow paths.
Ah, does this address John's issue?
Peter Zijlstra
maintainerRe: [patch 24/52] fs: dcache reduce d_parent locking
In reply to [email protected]Quoted 4 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
Use RCU property of dcache to simplify locking in some places where we take
d_parentandd_lock.Comment: don't need
rcu_derefbecause we take the spinlock and recheck it.
But does the LOCK barrier imply a DATA DEPENDENCY barrier? (It does on x86, and the compiler barrier implied by spin_lock() suffices to replace ACCESS_ONCE()).
Peter Zijlstra
maintainerRe: [patch 30/52] fs: icache lock lru/writeback lists
In reply to [email protected]Quoted 1 line · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
+
assert_spin_locked(&wb_inode_list_lock);
There's also lockdep_assert_held() which also validates we're the owner.
Re: [patch 42/52] fs: icache per-cpu last_ino allocator
In reply to [email protected]Quoted 6 lines · [email protected] writes:
From: Eric Dumazet <[email protected]>
new_inode()dirties a contended cache line to get increasing inode numbers.Solve this problem by providing to each cpu a
per_cpuvariable, feeded by the sharedlast_ino, but once every 1024 allocations.
Most file systems don't even need this because they
allocate their own inode numbers, right?. So perhaps it could be turned off for all of those, e.g. with a superblock flag.
I guess the main customer is sockets only.
fs/inode.c __inode_add_to_lists(struct super_block · line 675
Quoted 9 lines
fs/inode.c +9
-0+#ifdef CONFIG_SMP +/* +* Each cpu owns a range of 1024 numbers. +* 'shared_last_ino' is dirtied only once out of 1024 allocations, +* to renew the exhausted range. +* +* On a 32bit, non LFS stat() call, glibc will generate an EOVERFLOW +* error if st_ino won't fit in target struct field. Use 32bit counter +* here to attempt to avoid that.
I don't understand how the 32bit counter should prevent that.
fs/inode.c __inode_add_to_lists(struct super_block · line 678
Quoted 3 lines
+ */
fs/inode.c +2
-0+static DEFINE_PER_CPU(int, last_ino); +static atomic_t shared_last_ino;
With the 1024 skip, isn't overflow much more likely, just scaling with the number of CPUs on a large CPU number systems, even if there aren't that many new inodes?
fs/inode.c __inode_add_to_lists(struct super_block · line 686
Quoted 7 lines
fs/inode.c +7
-0+static int last_ino_get (void ) +{ +int *p = &get_cpu_var (last_ino); +int res = *p; + +if (unlikely ((res &1023 ) ==0 )) + res =atomic_add_return (1024 , &shared_last_ino) -1024 ;
The magic numbers really want to be defines?
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [patch 14/52] fs: dcache scale subdirs
In reply to [email protected]Quoted 2 lines · [email protected] writes:
Protect
d_subdirsandd_childwithd_lock, except in filesystems that aren't usingdcache_lockfor these anyway (eg. usingi_mutex).
Different locking for different file systems seems a bit confusing. Could the be unified?
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [patch 37/52] fs: icache lazy lru
In reply to [email protected]Quoted 2 lines · [email protected] writes:
Impelemnt lazy inode lru similarly to dcache. This will reduce lock acquisition and will help to improve lock ordering subsequently.
Or just drop inode LRU completely and only rely on the dcache for that?
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [patch 50/52] mm: implement per-zone shrinker
In reply to [email protected]Quoted 3 lines · [email protected] writes:
Allow the shrinker to do per-zone shrinking. This means it is called for each zone scanned. The shrinker is now completely responsible for calculating and batching (given helpers), which provides better flexibility.
Beyond the scope of this patch, but at some point this probably needs to be even more fine grained. With large number of cores/threads in each socket a "zone" is actually shared by quite a large number of CPUs now and this can cause problems.
mm/vmscan.c void unregister_shrinker(struct shrinker · line 188
Quoted 9 lines
mm/vmscan.c +9
-0+void shrinker_add_scan (unsigned long *dst, +unsigned long scanned,unsigned long total, +unsigned long objects,unsigned int ratio) +{ +unsigned long long delta; + + delta = (unsigned long long )scanned * objects * ratio; +do_div (delta, total +1 ); + delta /= (128ULL /4ULL );
Again I object to the magic numbers ...
mm/vmscan.c unsigned long shrink_slab(unsigned long · line 260
Quoted 3 lines
mm/vmscan.c +3
-0+ nr +=shrink_slab (zone,1 ,1 ,1 ,GFP_KERNEL ); +if (nr >=10 ) + goto again;
And here.
Overall it seems good, but I have not read all the shrinker callback changes in all subsystems.
-Andi
Signature · 7 lines
[email protected] -- Speaking for myself only. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 01/52] kernel: add bl_list
In reply to Eric DumazetQuoted 9 lines · Eric Dumazet
include/linux/list_bl.h line 42
Quoted 3 lines · Le jeudi 24 juin 2010 à 13:02 +1000, [email protected] a écrit :
include/linux/list_bl.h new file +3
-0+static inline void hlist_bl_set_first (struct hlist_bl_head *h,struct hlist_bl_node *n) +{ + h->first = (struct hlist_bl_node *)((unsigned long )n | ((unsigned long )h->first &1UL ));Hmm, shouldnt
hlist_bl_set_first()be used only with bit lock held ?h->first = (struct hlist_bl_node *)((unsigned long)n | 1UL);Quoted 1 line
+}
I had it that way but changed it for some reason. Thinking about it again though, you're right I'm sure (it could have been some other bug in my code making me think I needed it).
Thanks.
Quoted 6 lines
include/linux/rculist_bl.h line 14
Quoted 3 lines
include/linux/rculist_bl.h new file +3
-0+static inline void hlist_bl_set_first_rcu (struct hlist_bl_head *h,struct hlist_bl_node *n) +{ +rcu_assign_pointer (h->first, (struct hlist_bl_node *)((unsigned long )n | ((unsigned long )h->first &1UL )));Same question here.
Quoted 10 lines
include/linux/rculist_bl.h line 20
Quoted 6 lines
include/linux/rculist_bl.h new file +6
-0+} + +static inline struct hlist_bl_node *hlist_bl_first_rcu (struct hlist_bl_head *h) +{ +return (struct hlist_bl_node *)((unsigned long )rcu_dereference (h->first) & ~1UL ); +}Looks really nice Nick, maybe we should push this so that other subsystem can start using it.
Sure, if you have an interest in using it, it will be trivial to send upstream. Should we merge it before any users appear? I don't know...
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [patch 06/52] fs: scale files_lock
In reply to Peter ZijlstraQuoted 9 lines · Peter Zijlstra
Quoted 4 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
One difficulty with this approach is that a file can be removed from the list by another CPU. We must track which per-cpu list the file is on. Scalability could suffer if files are frequently removed from different cpu's list.
Is this really a lot less complex than what I did with my fine-grained locked list?
http://www.mail-archive.com/[email protected]/msg115071.html
Honestly the filevec code seemed overkill to me, and yes it was a bit complex. The only reason to consider it AFAIKS would be if the space overhead of the per-cpu structures, or the slowpath cost of the brlock was unbearable.
filevecs probably dont perform as well in the fastpath. My patch doesn't add any atomics. The cost of adding or removing a file from its list are one atomic for the spinlock.
The cost of adding a file with filevecs is a spinlock to put it on the vec, a spinlock to take it off the vec, a spinlock to put it on the lock-list. 3 atomics. A heap more icache and branches.
Removing a file with filevecs is a spinlock to check the vec, and 1 or 2 spinlocks to take it off the list (common case).
Scalability will be improved, but it will hit the global list still 1/15th times (and there is even no lock batching on the list but I assume that could be fixed). Compared with never for my patch (unless there is a cross-CPU removal, in which case they both need to hit a remote-CPU cacheline).
But before we even get to scalability, I think filevecs from complexity and single threaded performance point already lose.
Re: [patch 16/52] fs: dcache RCU for multi-step operaitons
In reply to Peter ZijlstraQuoted 15 lines · Peter Zijlstra
Quoted 14 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
plain text document attachment (fs-dcache_lock-multi-step.patch) The remaining usages for
dcache_lockis to allow atomic, multi-step read-side operations over the directory tree by excluding modifications to the tree. Also, to walk in theleaf->rootdirection in the tree where we don't have a naturald_lockordering.This could be accomplished by taking every
d_lock, but this would mean a huge number of locks and actually gets very tricky.Solve this instead by using the rename seqlock for multi-step read-side operations. Insert operations are not serialised. Delete operations are tricky when walking up the directory our parent might have been deleted when dropping locks so also need to check and retry for that.
Quoted 5 lines
Quoted 2 lines
XXX: hmm, we could of course just take the rename lock if there is any worry about livelock. Most of these are slow paths.
Ah, does this address John's issue?
This is where John's issue is introduced. I actually again couldn't see the problem (thought I saw a problem, then lost it!).
Got to think about it and test more... I couldn't reproduce the problem mind you, but I was testing mainline wheras bug was seen on -rt.
Re: [patch 24/52] fs: dcache reduce d_parent locking
In reply to Peter ZijlstraQuoted 9 lines · Peter Zijlstra
Quoted 4 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
Use RCU property of dcache to simplify locking in some places where we take
d_parentandd_lock.Comment: don't need
rcu_derefbecause we take the spinlock and recheck it.But does the LOCK barrier imply a DATA DEPENDENCY barrier? (It does on x86, and the compiler barrier implied by
spin_lock()suffices to replaceACCESS_ONCE()).
Well the dependency we care about is from loading the parent pointer to acquiring its spinlock. But we can't possibly have stale data given to the spin lock operation itself because it is a RMW.
Re: [patch 30/52] fs: icache lock lru/writeback lists
In reply to Peter ZijlstraQuoted 4 lines · Peter Zijlstra
Quoted 1 line · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
+
assert_spin_locked(&wb_inode_list_lock);There's also
lockdep_assert_held()which also validates we're the owner.
These locks should have such miniscule contention now that they effectively mean the same thing :) But no that's a good suggestion thanks. I guess _most_ assert_spin_locked could be changed over.
Peter Zijlstra
maintainerRe: [patch 30/52] fs: icache lock lru/writeback lists
Quoted 9 lines · Nick Piggin
Quoted 4 lines · Peter Zijlstra
Quoted 1 line · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
+
assert_spin_locked(&wb_inode_list_lock);There's also
lockdep_assert_held()which also validates we're the owner.These locks should have such miniscule contention now that they effectively mean the same thing :) But no that's a good suggestion thanks. I guess _most_
assert_spin_lockedcould be changed over.
Probably, I just haven't felt like actually visiting all sites to check ;-)
Re: [patch 24/52] fs: dcache reduce d_parent locking
In reply to Nick PigginQuoted 7 lines · Nick Piggin
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
Use RCU property of dcache to simplify locking in some places where we take
d_parentandd_lock.Comment: don't need
rcu_derefbecause we take the spinlock and recheck it.
Quoted 7 lines
Quoted 3 lines
But does the LOCK barrier imply a DATA DEPENDENCY barrier? (It does on x86, and the compiler barrier implied by
spin_lock()suffices to replaceACCESS_ONCE()).Well the dependency we care about is from loading the parent pointer to acquiring its spinlock. But we can't possibly have stale data given to the spin lock operation itself because it is a RMW.
As long as you check for the structure being valid after acquiring the lock, I agree. Otherwise, I would be concerned about the following sequence of events:
1. CPU 0 picks up a pointer to a given data element.
2. CPU 1 removes this element from the list, drops any locks that
it might have, and starts waiting for a grace period to elapse.
3. CPU 0 acquires the lock, does some operation that would
be appropriate had the element not been removed, then releases the lock.
4. After the grace period, CPU 1 frees the element, negating
CPU 0's hard work.
The usual approach is to have a "deleted" flag or some such in the element that CPU 0 would set when removing the element and that CPU 1 would check after acquiring the lock. Which you might well already be doing! ;-)
Thanx, Paul
Re: [patch 42/52] fs: icache per-cpu last_ino allocator
In reply to Andi KleenQuoted 4 lines · Andi Kleen
Quoted 2 lines · [email protected] writes:
From: Eric Dumazet <[email protected]>
Quoted 8 lines
Quoted 4 lines
new_inode()dirties a contended cache line to get increasing inode numbers.Solve this problem by providing to each cpu a
per_cpuvariable, feeded by the sharedlast_ino, but once every 1024 allocations.Most file systems don't even need this because they
allocate their own inode numbers, right?. So perhaps it could be turned off for all of those, e.g. with a superblock flag.
That's right. More or less it just requires alloc_inode to be exported, adding more branches in new_inode would not be a good way to go.
But I didn't want to start microoptimisations in filesystems just yet.
Quoted 1 line
I guess the main customer is sockets only.
I guess. Sockets and ram based filesystems. Interestingly I don't know really what it's for (in socket code it's mostly for reporting and hashing it seems). It sure isn't guaranteed to be unique.
Anyway it's outside the scope of this patchset to change functionality at all.
Quoted 11 lines
fs/inode.c __inode_add_to_lists(struct super_block · line 675
Quoted 9 lines
fs/inode.c +9
-0+#ifdef CONFIG_SMP +/* +* Each cpu owns a range of 1024 numbers. +* 'shared_last_ino' is dirtied only once out of 1024 allocations, +* to renew the exhausted range. +* +* On a 32bit, non LFS stat() call, glibc will generate an EOVERFLOW +* error if st_ino won't fit in target struct field. Use 32bit counter +* here to attempt to avoid that. I don't understand how the 32bit counter should prevent that.
Well I think glibc will convert 64 bit stat struct to 32bit for old apps. It detects if the ino can't fit in 32 bits.
Quoted 6 lines
fs/inode.c __inode_add_to_lists(struct super_block · line 678
Quoted 2 lines
fs/inode.c +2
-0+static DEFINE_PER_CPU(int, last_ino); +static atomic_t shared_last_ino;With the 1024 skip, isn't overflow much more likely, just scaling with the number of CPUs on a large CPU number systems, even if there aren't that many new inodes?
Well EOVERFLOW should never happen with only the low 32 significant bits set in the inode. If you are worried about wrapping the counter, then no I don't think it is much more likely.
Because each CPU will only reserve another 1024 inode interval after it has already allocated 1024 numbers. So the most wastage you will get is (1024-1)*NR_CPUS -- somewhere around 1/1000th of the available range.
I guess overflow will be more common now because it will be possible to allocate inodes much faster on such a huge machine :)
Quoted 9 lines
fs/inode.c __inode_add_to_lists(struct super_block · line 686
Quoted 7 lines
fs/inode.c +7
-0+static int last_ino_get (void ) +{ +int *p = &get_cpu_var (last_ino); +int res = *p; + +if (unlikely ((res &1023 ) ==0 )) + res =atomic_add_return (1024 , &shared_last_ino) -1024 ;The magic numbers really want to be defines?
Sure OK.
Re: [patch 14/52] fs: dcache scale subdirs
In reply to Andi KleenQuoted 7 lines · Andi Kleen
Quoted 2 lines · [email protected] writes:
Protect
d_subdirsandd_childwithd_lock, except in filesystems that aren't usingdcache_lockfor these anyway (eg. usingi_mutex).Different locking for different file systems seems a bit confusing. Could the be unified?
Yes well it is a bit misleading. It should always be modified under spinlocks, but some filesystems are using i_mutex for read access, which should be fine (and not require knowledge of any other code).
Re: [patch 37/52] fs: icache lazy lru
In reply to Andi KleenQuoted 6 lines · Andi Kleen
Quoted 2 lines · [email protected] writes:
Impelemnt lazy inode lru similarly to dcache. This will reduce lock acquisition and will help to improve lock ordering subsequently.
Or just drop inode LRU completely and only rely on the dcache for that?
Possible, yes. There was some talking about it. I prefer not to do anything too controversial yet if possible :)
Re: [patch 50/52] mm: implement per-zone shrinker
In reply to Andi KleenQuoted 10 lines · Andi Kleen
Quoted 3 lines · [email protected] writes:
Allow the shrinker to do per-zone shrinking. This means it is called for each zone scanned. The shrinker is now completely responsible for calculating and batching (given helpers), which provides better flexibility.
Beyond the scope of this patch, but at some point this probably needs to be even more fine grained. With large number of cores/threads in each socket a "zone" is actually shared by quite a large number of CPUs now and this can cause problems.
Yes, possibly. At least it is a much better step than the big dumb global list.
Quoted 12 lines
mm/vmscan.c void unregister_shrinker(struct shrinker · line 188
Quoted 9 lines
mm/vmscan.c +9
-0+void shrinker_add_scan (unsigned long *dst, +unsigned long scanned,unsigned long total, +unsigned long objects,unsigned int ratio) +{ +unsigned long long delta; + + delta = (unsigned long long )scanned * objects * ratio; +do_div (delta, total +1 ); + delta /= (128ULL /4ULL );Again I object to the magic numbers ...
Quoted 5 lines
mm/vmscan.c unsigned long shrink_slab(unsigned long · line 260
Quoted 3 lines
mm/vmscan.c +3
-0+ nr +=shrink_slab (zone,1 ,1 ,1 ,GFP_KERNEL ); +if (nr >=10 ) + goto again;And here.
I don't like them either -- problem is they were inherited from the old code (actually 128 is the fixed point scale, I do have a define for it just forgot to use it).
I don't know where 4 came from. And 10 is just a random number someone picked out of a hat :P
Quoted 2 lines
Overall it seems good, but I have not read all the shrinker callback changes in all subsystems.
Thanks for looking over it Andi.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 01/52] kernel: add bl_list
In reply to Nick PigginQuoted 3 lines · Nick Piggin
Sure, if you have an interest in using it, it will be trivial to send upstream. Should we merge it before any users appear? I don't know...
I'll work on using this for ip route cache, as you suggested.
BTW, I think we could care about this 0 bit only if it could possibly set, ie :
#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
since bit_spin_lock() wont set it anyway if CONFIG_SMP=n and CONFIG_DEBUG_SPINLOCK=n
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [patch 24/52] fs: dcache reduce d_parent locking
In reply to Paul E. McKenneyQuoted 30 lines · Paul E. McKenney
Quoted 7 lines · Nick Piggin
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
Use RCU property of dcache to simplify locking in some places where we take
d_parentandd_lock.Comment: don't need
rcu_derefbecause we take the spinlock and recheck it.Quoted 7 lines
Quoted 3 lines
But does the LOCK barrier imply a DATA DEPENDENCY barrier? (It does on x86, and the compiler barrier implied by
spin_lock()suffices to replaceACCESS_ONCE()).Well the dependency we care about is from loading the parent pointer to acquiring its spinlock. But we can't possibly have stale data given to the spin lock operation itself because it is a RMW.
As long as you check for the structure being valid after acquiring the lock, I agree. Otherwise, I would be concerned about the following sequence of events:
1. CPU 0 picks up a pointer to a given data element.
2. CPU 1 removes this element from the list, drops any locks that
it might have, and starts waiting for a grace period to elapse.3. CPU 0 acquires the lock, does some operation that would
be appropriate had the element not been removed, then releases the lock.
Quoted 7 lines
4. After the grace period, CPU 1 frees the element, negating
CPU 0's hard work.The usual approach is to have a "deleted" flag or some such in the element that CPU 0 would set when removing the element and that CPU 1 would check after acquiring the lock. Which you might well already be doing! ;-)
Thanks, yep it's done under RCU, and after taking the lock it rechecks to see that it is still reachable by the same pointer (and if not, unlocks and retries) so it should be fine.
Thanks,
Nick
Re: [patch 42/52] fs: icache per-cpu last_ino allocator
In reply to Nick PigginQuoted 3 lines · Nick Piggin
That's right. More or less it just requires
alloc_inodeto be exported, adding more branches innew_inodewould not be a good way to go.
One test/branch shouldn't hurt much.
Quoted 5 lines
Quoted 1 line
I guess the main customer is sockets only.
I guess. Sockets and ram based filesystems. Interestingly I don't know really what it's for (in socket code it's mostly for reporting and hashing it seems). It sure isn't guaranteed to be unique.
Maybe it could be generated lazily on access for those? I suppose stat on a socket is relatively rare. The only problem is would need an accessor.
But ok out of scope.
Quoted 2 lines
Well I think glibc will convert 64 bit stat struct to 32bit for old apps. It detects if the ino can't fit in 32 bits.
... and will fail the stat.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [patch 50/52] mm: implement per-zone shrinker
In reply to Nick PigginQuoted 4 lines
Quoted 2 lines
Overall it seems good, but I have not read all the shrinker callback changes in all subsystems.
Thanks for looking over it Andi.
FWIW i skimmed over most of the patches and nothing stood out that I really disliked. But I have gone over the code in very deep detail.
-Andi
Signature · 7 lines
[email protected] -- Speaking for myself only. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 50/52] mm: implement per-zone shrinker
Quoted 7 lines · Andi Kleen
Quoted 4 lines
Quoted 2 lines
Overall it seems good, but I have not read all the shrinker callback changes in all subsystems.
Thanks for looking over it Andi.
FWIW i skimmed over most of the patches and nothing stood out that I really disliked. But I have gone over the code in very deep detail.
haven't
-Andi
Signature · 7 lines
[email protected] -- Speaking for myself only. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 50/52] mm: implement per-zone shrinker
In reply to Andi KleenQuoted 7 lines · Andi Kleen
Quoted 4 lines
Quoted 2 lines
Overall it seems good, but I have not read all the shrinker callback changes in all subsystems.
Thanks for looking over it Andi.
FWIW i skimmed over most of the patches and nothing stood out that I really disliked. But I have gone over the code in very deep detail.
s/have/haven't/
-Andi
Signature · 7 lines
[email protected] -- Speaking for myself only. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 42/52] fs: icache per-cpu last_ino allocator
In reply to Andi KleenQuoted 6 lines · Andi Kleen
Quoted 3 lines · Nick Piggin
That's right. More or less it just requires
alloc_inodeto be exported, adding more branches innew_inodewould not be a good way to go.One test/branch shouldn't hurt much.
If we go through filesystems anyway may as well just use alloc_inode.
Quoted 11 lines
Quoted 5 lines
Quoted 1 line
I guess the main customer is sockets only.
I guess. Sockets and ram based filesystems. Interestingly I don't know really what it's for (in socket code it's mostly for reporting and hashing it seems). It sure isn't guaranteed to be unique.
Maybe it could be generated lazily on access for those? I suppose stat on a socket is relatively rare. The only problem is would need an accessor.
But ok out of scope.
Yea that might work. sock_i_ino() and ->dname covers a lot.
Quoted 4 lines
Quoted 2 lines
Well I think glibc will convert 64 bit stat struct to 32bit for old apps. It detects if the ino can't fit in 32 bits.
... and will fail the stat.
Which is what we're trying to avoid, I guess.
Re: [patch 24/52] fs: dcache reduce d_parent locking
In reply to Nick PigginQuoted 34 lines · Nick Piggin
Quoted 33 lines · Paul E. McKenney
Quoted 7 lines · Nick Piggin
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
Use RCU property of dcache to simplify locking in some places where we take
d_parentandd_lock.Comment: don't need
rcu_derefbecause we take the spinlock and recheck it.Quoted 7 lines
Quoted 3 lines
But does the LOCK barrier imply a DATA DEPENDENCY barrier? (It does on x86, and the compiler barrier implied by
spin_lock()suffices to replaceACCESS_ONCE()).Well the dependency we care about is from loading the parent pointer to acquiring its spinlock. But we can't possibly have stale data given to the spin lock operation itself because it is a RMW.
As long as you check for the structure being valid after acquiring the lock, I agree. Otherwise, I would be concerned about the following sequence of events:
1. CPU 0 picks up a pointer to a given data element.
2. CPU 1 removes this element from the list, drops any locks that
it might have, and starts waiting for a grace period to elapse.3. CPU 0 acquires the lock, does some operation that would
be appropriate had the element not been removed, then releases the lock.4. After the grace period, CPU 1 frees the element, negating
CPU 0's hard work.
Quoted 8 lines
Quoted 4 lines
The usual approach is to have a "deleted" flag or some such in the element that CPU 0 would set when removing the element and that CPU 1 would check after acquiring the lock. Which you might well already be doing! ;-)
Thanks, yep it's done under RCU, and after taking the lock it rechecks to see that it is still reachable by the same pointer (and if not, unlocks and retries) so it should be fine.
Very good!!! ;-)
Thanx, Paul
Re: [patch 16/52] fs: dcache RCU for multi-step operaitons
In reply to Nick PigginQuoted 16 lines · Nick Piggin
Quoted 15 lines · Peter Zijlstra
Quoted 14 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
plain text document attachment (fs-dcache_lock-multi-step.patch) The remaining usages for
dcache_lockis to allow atomic, multi-step read-side operations over the directory tree by excluding modifications to the tree. Also, to walk in theleaf->rootdirection in the tree where we don't have a naturald_lockordering.This could be accomplished by taking every
d_lock, but this would mean a huge number of locks and actually gets very tricky.Solve this instead by using the rename seqlock for multi-step read-side operations. Insert operations are not serialised. Delete operations are tricky when walking up the directory our parent might have been deleted when dropping locks so also need to check and retry for that.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
XXX: hmm, we could of course just take the rename lock if there is any worry about livelock. Most of these are slow paths.
Ah, does this address John's issue?
This is where John's issue is introduced. I actually again couldn't see the problem (thought I saw a problem, then lost it!).
Ok. So I need to review this new set in full, but the issue we tripped with the patches in -rt was the following:
In select parent, when it does the dentry ascending, it has to release the current dentry lock so it can aquire the parents dentry (for proper ordering). At the point it released the lock, before it grabs the parent's lock, there is nothing that is preventing dput from being called on the next dentry, it grabbing the parent and dentry's d_lock and killing it. Then back in select_parent, when we try to lock the next entry, it no longer exists and we oops.
So I can't see anything that is protecting the dentry (or even the new parent dentry, should everything be killed under it) at this point. The dentries d_count might be zero, we don't hold the d_lock, and we don't hold the parent's d_lock. What am I missing here?
Quoted 2 lines
Got to think about it and test more... I couldn't reproduce the problem mind you, but I was testing mainline wheras bug was seen on -rt.
Yea, -rt may be allowing the race to more easily occur (I only found I could trigger it on a UP machine) since we can be preempted right after we released the dentry lock as we tried to grab the parent. Then dput would jump in and wreck things. I had some pretty clear trace logs that were easily repeated (well, took about an hour or two to trigger), that showed about the same order of operations every time.
I don't remember if there's another lock being held at the point select_parent is called, so on mainline it might be harder to trigger (having to actually get the dput race on another cpu timed right).
thanks
-john
Re: [patch 16/52] fs: dcache RCU for multi-step operaitons
In reply to [email protected]Quoted 9 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
plain text document attachment (fs-dcache_lock-multi-step.patch) The remaining usages for
dcache_lockis to allow atomic, multi-step read-side operations over the directory tree by excluding modifications to the tree. Also, to walk in theleaf->rootdirection in the tree where we don't have a naturald_lockordering.This could be accomplished by taking every
d_lock, but this would mean a huge number of locks and actually gets very tricky.
Quoted 7 lines
Solve this instead by using the rename seqlock for multi-step read-side operations. Insert operations are not serialised. Delete operations are tricky when walking up the directory our parent might have been deleted when dropping locks so also need to check and retry for that.
XXX: hmm, we could of course just take the rename lock if there is any worry about livelock. Most of these are slow paths.
I'll try to point out exactly the spot I think we were hitting in the -rt tree (once the dcache_lock is removed).
Quoted 29 lines
fs/dcache.c +8
-3@@ -1030,9 +1056,15 @@ EXPORT_SYMBOL(have_submounts);*/ static int select_parent (struct dentry * parent) { -struct dentry *this_parent = parent; +struct dentry *this_parent;struct list_head *next; -int found =0 ; +unsigned seq; +int found; + +rename_retry: + found =0 ; + this_parent = parent; + seq =read_seqbegin (&rename_lock);spin_lock (&dcache_lock);spin_lock (&this_parent->d_lock);@@ -1043,7 +1075,6 @@ resume:struct list_head *tmp = next; struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child); next = tmp->next; -BUG_ON (this_parent == dentry);spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED );dentry_lru_del_init (dentry);@@ -1084,17 +1115,33 @@ resume:*/ if (this_parent != parent) {
fs/dcache.c resume: · line 1124
Quoted 10 lines
fs/dcache.c +4
-2struct dentry *tmp; - next = this_parent->d_u.d_child.next; +struct dentry *child; + tmp = this_parent->d_parent; +rcu_read_lock ();spin_unlock (&this_parent->d_lock); -BUG_ON (tmp == this_parent); + child = this_parent; this_parent = tmp;
Ok. So right here, we get preempted, or dput() is called by another cpu on the child dentry, or the child->d_u.d_child.next dentry and its d_kill'ed.
fs/dcache.c resume: · line 1027
Quoted 13 lines
fs/dcache.c +12
-0spin_lock (&this_parent->d_lock); +/* might go back up the wrong parent if we have had a rename +* or deletion */ +if (this_parent != child->d_parent || +// d_unlinked(this_parent) || XXX +read_seqretry (&rename_lock, seq)) { +spin_unlock (&this_parent->d_lock); +spin_unlock (&dcache_lock); +rcu_read_unlock (); + goto rename_retry; + } +rcu_read_unlock (); + next = child->d_u.d_child.next;
Then at this point, next may point to junk.
fs/dcache.c resume: · line 1146
Quoted 9 lines
fs/dcache.c +2
-0goto resume; } out:spin_unlock (&this_parent->d_lock);spin_unlock (&dcache_lock); +if (read_seqretry (&rename_lock, seq)) + goto rename_retry;return found; }
thanks
-john
Re: [patch 05/52] lglock: introduce special lglock and brlock spin locks
In reply to [email protected]include/linux/lglock.h line 75
Quoted 3 lines · On Thu, 24 Jun 2010, [email protected] wrote:
include/linux/lglock.h new file +3
-0+#define DEFINE_LGLOCK (name) \ + \ + DEFINE_PER_CPU(arch_spinlock_t, name##_lock); \
Uuurgh. You want to make that an arch_spinlock ? Just to avoid the preempt_count overflow when you lock all cpu locks nested ?
I'm really not happy about that, it's going to be a complete nightmare for RT. If you wanted to make this a present for RT giving the scalability stuff massive testing, then you failed miserably :)
I know how to fix it, but can't we go for an approach which does not require massive RT patching again ?
struct percpu_lock {
spinlock_t lock;
unsigned global_state;
};And let the lock function do:
spin_lock(&pcp->lock);
while (pcp->global_state)
cpu_relax();So the global lock side can take each single lock, modify the percpu "global state" and release the lock. On unlock you just need to reset the global state w/o taking the percpu lock and be done.
I doubt that the extra conditional in the lock path is going to be relevant overhead, compared to the spin_lock it's noise.
Thanks,
tglx
Re: [patch 05/52] lglock: introduce special lglock and brlock spin locks
Quoted 8 lines · Thomas Gleixner
include/linux/lglock.h line 75
Quoted 3 lines · On Thu, 24 Jun 2010, [email protected] wrote:
include/linux/lglock.h new file +3
-0+#define DEFINE_LGLOCK (name) \ + \ + DEFINE_PER_CPU(arch_spinlock_t, name##_lock); \Uuurgh. You want to make that an
arch_spinlock? Just to avoid thepreempt_countoverflow when you lock all cpu locks nested ?
Yep, and the lockdep wreckage too :)
Actually it's nice to avoid the function call too (lglock/brlocks are already out of line). Calls aren't totally free, especially on small chips without RSBs. And even with RSBs it's helpful not to overflow them, although Nehalem seems to have 12-16 entries.
Quoted 3 lines
I'm really not happy about that, it's going to be a complete nightmare for RT. If you wanted to make this a present for RT giving the scalability stuff massive testing, then you failed miserably :)
Heh, it's a present for -rt because the locking is quite isolated (I did the same thing with hashtable bitlocks, added a new structure for them, in case you prefer spinlocks than bit spinlocks there).
-rt already changes locking primitives, so in the worst case you might have to tweak this. My previous patches were open coding these locks in fs/ so I can understand why that was a headache.
Quoted 14 lines
I know how to fix it, but can't we go for an approach which does not require massive RT patching again ?
struct percpu_lock { spinlock_t lock; unsigned global_state; };And let the lock function do:
spin_lock(&pcp->lock); while (pcp->global_state) cpu_relax();
Quoted 6 lines
So the global lock side can take each single lock, modify the percpu "global state" and release the lock. On unlock you just need to reset the global state w/o taking the percpu lock and be done.
I doubt that the extra conditional in the lock path is going to be relevant overhead, compared to the
spin_lockit's noise.
Hmm. We need a smp_rmb() which costs a bit (on non-x86). For -rt you would need to do priority boosting too.
reader lock:spin_lock(&pcp->rlock);
if (unlikely(pcp->global_state)) {
spin_unlock(&pcp->rlock);
spin_lock(&wlock);
spin_lock(&pcp->rlock);
spin_unlock(&wlock);
} else
smp_rmb();
I think I'll keep it as is for now, it's hard enough to keep single threaded performance up. But it should be much easier to override this in -rt and I'll be happy to try restructuring things to help rt if and when it's possible.
Re: [patch 16/52] fs: dcache RCU for multi-step operaitons
In reply to john stultzQuoted 66 lines · John Stultz
Quoted 9 lines · On Thu, 2010-06-24 at 13:02 +1000, [email protected] wrote:
plain text document attachment (fs-dcache_lock-multi-step.patch) The remaining usages for
dcache_lockis to allow atomic, multi-step read-side operations over the directory tree by excluding modifications to the tree. Also, to walk in theleaf->rootdirection in the tree where we don't have a naturald_lockordering.This could be accomplished by taking every
d_lock, but this would mean a huge number of locks and actually gets very tricky.Quoted 7 lines
Solve this instead by using the rename seqlock for multi-step read-side operations. Insert operations are not serialised. Delete operations are tricky when walking up the directory our parent might have been deleted when dropping locks so also need to check and retry for that.
XXX: hmm, we could of course just take the rename lock if there is any worry about livelock. Most of these are slow paths.
I'll try to point out exactly the spot I think we were hitting in the -rt tree (once the
dcache_lockis removed).Quoted 29 lines
fs/dcache.c +8
-3@@ -1030,9 +1056,15 @@ EXPORT_SYMBOL(have_submounts);*/ static int select_parent (struct dentry * parent) { -struct dentry *this_parent = parent; +struct dentry *this_parent;struct list_head *next; -int found =0 ; +unsigned seq; +int found; + +rename_retry: + found =0 ; + this_parent = parent; + seq =read_seqbegin (&rename_lock);spin_lock (&dcache_lock);spin_lock (&this_parent->d_lock);@@ -1043,7 +1075,6 @@ resume:struct list_head *tmp = next; struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child); next = tmp->next; -BUG_ON (this_parent == dentry);spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED );dentry_lru_del_init (dentry);@@ -1084,17 +1115,33 @@ resume:*/ if (this_parent != parent) {fs/dcache.c resume: · line 1124
Quoted 10 lines
fs/dcache.c +4
-2struct dentry *tmp; - next = this_parent->d_u.d_child.next; +struct dentry *child; + tmp = this_parent->d_parent; +rcu_read_lock ();spin_unlock (&this_parent->d_lock); -BUG_ON (tmp == this_parent); + child = this_parent; this_parent = tmp;Ok. So right here, we get preempted, or
dput()is called by another cpu on the child dentry, or thechild->d_u.d_child.nextdentry and its d_kill'ed.
Quoted 15 lines
fs/dcache.c resume: · line 1027
Quoted 13 lines
fs/dcache.c +12
-0spin_lock (&this_parent->d_lock); +/* might go back up the wrong parent if we have had a rename +* or deletion */ +if (this_parent != child->d_parent || +// d_unlinked(this_parent) || XXX +read_seqretry (&rename_lock, seq)) { +spin_unlock (&this_parent->d_lock); +spin_unlock (&dcache_lock); +rcu_read_unlock (); + goto rename_retry; + } +rcu_read_unlock (); + next = child->d_u.d_child.next;Then at this point, next may point to junk.
But see the test above it. We ensure that child->d_parent still points to this_parent with this_parent d_lock held. Oh, I'm not clearing d_parent! d_kill() should have
dentry->d_parent = NULL;
when it removes dentry from the list.
That should fix it I'd hope.
Thanks,
Nick
If you actuall want to get this work in reposting huge patchkit again and again probably doesn't help. Start to prioritize areas and work on small sets to get them ready.
files_lock and vfsmount_lock seem like rather easy targets to start with. But for files_lock I really want to see something to generalize the tty special case. If you touch that are in detail that wart needs to go. Al didn't seem to like my variant very much, so he might have a better idea for it - otherwise it really makes the VFS locking simple by removing any tty interaction with the superblock files list. The other suggestion would be to only open regular (maybe even just writeable) files to the list. In addition to reducing the number of list operations require it will also make the tty code a lot easier.
As for the other patches: I don't think the massive fine-grained locking in the hash tables is a good idea. I would recommend to defer them for now, and then look into better data structures for these caches instead of working around the inherent problems of global hash tables.
Quoted 3 lines · Christoph Hellwig
If you actuall want to get this work in reposting huge patchkit again and again probably doesn't help. Start to prioritize areas and work on small sets to get them ready.
Sure, I haven't been posting the same thing (haven't posted it for a long time). This simply had a lot of new stuff and improvements to all existing patches.
I didn't cc anyone in particular because it's only for interested people to take a look at. As you saw last time I cc'ed Al I exactly was just trying to get those easier targets merged.
Quoted 6 lines
files_lockandvfsmount_lockseem like rather easy targets to start with. But forfiles_lockI really want to see something to generalize the tty special case. If you touch that are in detail that wart needs to go. Al didn't seem to like my variant very much, so he might have a better idea for it - otherwise it really makes the VFS locking simple by removing any tty interaction with the superblock files list.
Actually I didn't like it because the error handling in the tty code was broken and difficult to fix properly. The concept was OK though.
But the fact is that today already tty "knows" that vfs doesn't need its files on the superblock list, and so it may take them off and use that list_head privately. Currently it is also using files lock to protect that private usage. These are two independent problems. My patch fixes the second, and anything that fixes the first also needs to fix the second in exactly the same way.
Quoted 4 lines
The
other suggestion would be to only open regular (maybe even just writeable) files to the list. In addition to reducing the number of list operations require it will also make the tty code a lot easier.
This was my suggestion, yes. Either way is conceptually the same, this one just avoids the memory allocation and error handling problems that yours had.
But again, locking change is still required and it would look exactly the same as my patch really.
Quoted 4 lines
As for the other patches: I don't think the massive fine-grained locking in the hash tables is a good idea. I would recommend to defer them for now, and then look into better data structures for these caches instead of working around the inherent problems of global hash tables.
I don't agree actually. I don't think there is any downside to fine grained locking the hash with bit spinlocks. Until I see one, I will keep them.
I agree that some other data structure may be better, but it should be compared with the best possible hash implementation, which is a scalable hash like this one.
Also, our big impending performance problem is SMP scalability, not hash lookup, AFAIKS.
Re: [patch 05/52] lglock: introduce special lglock and brlock spin locks
In reply to Nick PigginQuoted 18 lines · Nick Piggin
Quoted 8 lines · Thomas Gleixner
include/linux/lglock.h line 75
Quoted 3 lines · On Thu, 24 Jun 2010, [email protected] wrote:
include/linux/lglock.h new file +3
-0+#define DEFINE_LGLOCK (name) \ + \ + DEFINE_PER_CPU(arch_spinlock_t, name##_lock); \Uuurgh. You want to make that an
arch_spinlock? Just to avoid thepreempt_countoverflow when you lock all cpu locks nested ?Yep, and the lockdep wreckage too :)
Actually it's nice to avoid the function call too (lglock/brlocks are already out of line). Calls aren't totally free, especially on small chips without RSBs. And even with RSBs it's helpful not to overflow them, although Nehalem seems to have 12-16 entries.
Quoted 7 lines
Quoted 3 lines
I'm really not happy about that, it's going to be a complete nightmare for RT. If you wanted to make this a present for RT giving the scalability stuff massive testing, then you failed miserably :)
Heh, it's a present for -rt because the locking is quite isolated (I did the same thing with hashtable bitlocks, added a new structure for them, in case you prefer spinlocks than bit spinlocks there).
Sure, bitlocks are equally horrible.
Quoted 3 lines
-rt already changes locking primitives, so in the worst case you might have to tweak this. My previous patches were open coding these locks in
fs/so I can understand why that was a headache.
I agree that having the code isolated makes my life easier, but I'm a bit worried about the various new locking primitives which pop up in all corners of the kernel.
Quoted 4 lines
I think I'll keep it as is for now, it's hard enough to keep single threaded performance up. But it should be much easier to override this in -rt and I'll be happy to try restructuring things to help rt if and when it's possible.
Ok, lets see how bad it gets :)
Thanks,
tglx
Re: [patch 05/52] lglock: introduce special lglock and brlock spin locks
Quoted 29 lines · Thomas Gleixner
Quoted 18 lines · Nick Piggin
Quoted 8 lines · Thomas Gleixner
include/linux/lglock.h line 75
Quoted 3 lines · On Thu, 24 Jun 2010, [email protected] wrote:
include/linux/lglock.h new file +3
-0+#define DEFINE_LGLOCK (name) \ + \ + DEFINE_PER_CPU(arch_spinlock_t, name##_lock); \Uuurgh. You want to make that an
arch_spinlock? Just to avoid thepreempt_countoverflow when you lock all cpu locks nested ?Yep, and the lockdep wreckage too :)
Actually it's nice to avoid the function call too (lglock/brlocks are already out of line). Calls aren't totally free, especially on small chips without RSBs. And even with RSBs it's helpful not to overflow them, although Nehalem seems to have 12-16 entries.
Quoted 7 lines
Quoted 3 lines
I'm really not happy about that, it's going to be a complete nightmare for RT. If you wanted to make this a present for RT giving the scalability stuff massive testing, then you failed miserably :)
Heh, it's a present for -rt because the locking is quite isolated (I did the same thing with hashtable bitlocks, added a new structure for them, in case you prefer spinlocks than bit spinlocks there).
Sure, bitlocks are equally horrible.
Quoted 7 lines
Quoted 3 lines
-rt already changes locking primitives, so in the worst case you might have to tweak this. My previous patches were open coding these locks in
fs/so I can understand why that was a headache.I agree that having the code isolated makes my life easier, but I'm a bit worried about the various new locking primitives which pop up in all corners of the kernel.
Be sure to shout at people for it :). Locking primitives really need to be reviewed, and having them in common places lets other people use them too.
Quoted 6 lines
Quoted 4 lines
I think I'll keep it as is for now, it's hard enough to keep single threaded performance up. But it should be much easier to override this in -rt and I'll be happy to try restructuring things to help rt if and when it's possible.
Ok, lets see how bad it gets :)
Ok good.
Re: [patch 01/52] kernel: add bl_list
In reply to [email protected]Quoted 5 lines · On Thu, Jun 24, 2010 at 01:02:13PM +1000, [email protected] wrote:
Introduce a type of hlist that can support the use of the lowest bit in the
hlist_head. This will be subsequently used to implement per-bucket bit spinlock for inode and dentry hashes.Signed-off-by Nick Piggin <[email protected]>
Looks good! One question on non-RCU pointer poisoning and a typo. When these are addressed (perhaps by showing me the error of my ways):
Quoted 74 lines
--- include/linux/list_bl.h | 99 +++++++++++++++++++++++++++++++++++++ include/linux/rculist_bl.h | 120 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+)Index:
linux-2.6/include/linux/list_bl.h
===================================================================include/linux/list_bl.h new file +64
-0@@ -0,0 +1,99 @@ +#ifndef _LINUX_LIST_BL_H +#define _LINUX_LIST_BL_H + +#include <linux/list.h> + +/* +* Special version of lists, where head of the list has a bit spinlock +* in the lowest bit. This is useful for scalable hash tables without +* increasing memory footprint overhead. +*/ + +struct hlist_bl_head { +struct hlist_bl_node *first; +}; + +struct hlist_bl_node { +struct hlist_bl_node *next, **pprev; +}; +#define INIT_HLIST_BL_HEAD (ptr) \ + ((ptr)->first = NULL) + +static inline void INIT_HLIST_BL_NODE (struct hlist_bl_node *h) +{ + h->next =NULL ; + h->pprev =NULL ; +} + +#define hlist_bl_entry (ptr, type, member) container_of(ptr,type,member) + +static inline int hlist_bl_unhashed (const struct hlist_bl_node *h) +{ +return !h->pprev; +} + +static inline struct hlist_bl_node *hlist_bl_first (struct hlist_bl_head *h) +{ +return (struct hlist_bl_node *)((unsigned long )h->first & ~1UL ); +} + +static inline void hlist_bl_set_first (struct hlist_bl_head *h,struct hlist_bl_node *n) +{ + h->first = (struct hlist_bl_node *)((unsigned long )n | ((unsigned long )h->first &1UL )); +} + +static inline int hlist_bl_empty (const struct hlist_bl_head *h) +{ +return !((unsigned long )h->first & ~1UL ); +} + +static inline void hlist_bl_add_head (struct hlist_bl_node *n, +struct hlist_bl_head *h) +{ +struct hlist_bl_node *first =hlist_bl_first (h); + + n->next = first; +if (first) + first->pprev = &n->next; + n->pprev = &h->first; +hlist_bl_set_first (h, n); +} + +static inline void __hlist_bl_del (struct hlist_bl_node *n) +{ +struct hlist_bl_node *next = n->next;
include/linux/list_bl.h line 74
Quoted 10 lines
include/linux/list_bl.h new file +10
-0+struct hlist_bl_node **pprev = n->pprev; + *pprev = (struct hlist_bl_node *)((unsigned long )next | ((unsigned long )*pprev &1UL )); +if (next) + next->pprev = pprev; +} + +static inline void hlist_bl_del (struct hlist_bl_node *n) +{ +__hlist_bl_del (n); + n->pprev =LIST_POISON2 ;
OK, I'll bite... Why don't we poison the ->next pointer?
Quoted 46 lines
include/linux/list_bl.h new file +25
-0+} + +static inline void hlist_bl_del_init (struct hlist_bl_node *n) +{ +if (!hlist_bl_unhashed (n)) { +__hlist_bl_del (n); +INIT_HLIST_BL_NODE (n); + } +} + +/** +* hlist_bl_for_each_entry - iterate over list of given type +* @tpos: the type * to use as a loop cursor. +* @pos: the &struct hlist_node to use as a loop cursor. +* @head: the head for your list. +* @member: the name of the hlist_node within the struct. +* +*/ +#define hlist_bl_for_each_entry (tpos, pos, head, member) \ + for (pos = hlist_bl_first(head); \ + pos && \ + ({ tpos = hlist_bl_entry(pos, typeof(*tpos), member); 1;}); \ + pos = pos->next) + +#endif Index:
linux-2.6/include/linux/rculist_bl.h
===================================================================include/linux/rculist_bl.h new file +16
-0@@ -0,0 +1,120 @@ +#ifndef _LINUX_RCULIST_BL_H +#define _LINUX_RCULIST_BL_H + +#ifdef __KERNEL__ + +/* +* RCU-protected list version +*/ +#include <linux/list_bl.h> +#include <linux/rcupdate.h> + +static inline void hlist_bl_set_first_rcu (struct hlist_bl_head *h,struct hlist_bl_node *n) +{ +rcu_assign_pointer (h->first, (struct hlist_bl_node *)((unsigned long )n | ((unsigned long )h->first &1UL ))); +} +
include/linux/rculist_bl.h line 26
Quoted 10 lines
include/linux/rculist_bl.h new file +10
-0+static inline struct hlist_bl_node *hlist_bl_first_rcu (struct hlist_bl_head *h) +{ +return (struct hlist_bl_node *)((unsigned long )rcu_dereference (h->first) & ~1UL ); +} + +/** +* hlist_bl_del_init_rcu - deletes entry from hash list with re-initialization +* @n: the element to delete from the hash list. +* +* Note: hlist_bl_unhashed() on the node return true after this. It is
returns
Quoted 101 lines
include/linux/rculist_bl.h new file +94
-1+* useful for RCU based read lockfree traversal if the writer side +* must know if the list entry is still hashed or already unhashed. +* +* In particular, it means that we can not poison the forward pointers +* that may still be used for walking the hash list and we can only +* zero the pprev pointer so list_unhashed() will return true after +* this. +* +* The caller must take whatever precautions are necessary (such as +* holding appropriate locks) to avoid racing with another +* list-mutation primitive, such as hlist_bl_add_head_rcu() or +* hlist_bl_del_rcu(), running on this same list. However, it is +* perfectly legal to run concurrently with the _rcu list-traversal +* primitives, such as hlist_bl_for_each_entry_rcu(). +*/ +static inline void hlist_bl_del_init_rcu (struct hlist_bl_node *n) +{ +if (!hlist_bl_unhashed (n)) { +__hlist_bl_del (n); + n->pprev =NULL ; + } +} + +/** +* hlist_bl_del_rcu - deletes entry from hash list without re-initialization +* @n: the element to delete from the hash list. +* +* Note: hlist_bl_unhashed() on entry does not return true after this, +* the entry is in an undefined state. It is useful for RCU based +* lockfree traversal. +* +* In particular, it means that we can not poison the forward +* pointers that may still be used for walking the hash list. +* +* The caller must take whatever precautions are necessary +* (such as holding appropriate locks) to avoid racing +* with another list-mutation primitive, such as hlist_bl_add_head_rcu() +* or hlist_bl_del_rcu(), running on this same list. +* However, it is perfectly legal to run concurrently with +* the _rcu list-traversal primitives, such as +* hlist_bl_for_each_entry(). +*/ +static inline void hlist_bl_del_rcu (struct hlist_bl_node *n) +{ +__hlist_bl_del (n); + n->pprev =LIST_POISON2 ; +} + +/** +* hlist_bl_add_head_rcu +* @n: the element to add to the hash list. +* @h: the list to add to. +* +* Description: +* Adds the specified element to the specified hlist_bl, +* while permitting racing traversals. +* +* The caller must take whatever precautions are necessary +* (such as holding appropriate locks) to avoid racing +* with another list-mutation primitive, such as hlist_bl_add_head_rcu() +* or hlist_bl_del_rcu(), running on this same list. +* However, it is perfectly legal to run concurrently with +* the _rcu list-traversal primitives, such as +* hlist_bl_for_each_entry_rcu(), used to prevent memory-consistency +* problems on Alpha CPUs. Regardless of the type of CPU, the +* list-traversal primitive must be guarded by rcu_read_lock(). +*/ +static inline void hlist_bl_add_head_rcu (struct hlist_bl_node *n, +struct hlist_bl_head *h) +{ +struct hlist_bl_node *first =hlist_bl_first (h); + + n->next = first; +if (first) + first->pprev = &n->next; + n->pprev = &h->first; +hlist_bl_set_first_rcu (h, n); +} +/** +* hlist_bl_for_each_entry_rcu - iterate over rcu list of given type +* @tpos: the type * to use as a loop cursor. +* @pos: the &struct hlist_bl_node to use as a loop cursor. +* @head: the head for your list. +* @member: the name of the hlist_bl_node within the struct. +* +*/ +#define hlist_bl_for_each_entry_rcu (tpos, pos, head, member) \ + for (pos = hlist_bl_first_rcu(head); \ + pos && \ + ({ tpos = hlist_bl_entry(pos, typeof(*tpos), member); 1; }); \ + pos = rcu_dereference_raw(pos->next)) + +#endif +#endif --To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [patch 24/52] fs: dcache reduce d_parent locking
In reply to [email protected]Quoted 4 lines · On Thu, Jun 24, 2010 at 01:02:36PM +1000, [email protected] wrote:
Use RCU property of dcache to simplify locking in some places where we take
d_parentandd_lock.Comment: don't need
rcu_derefbecause we take the spinlock and recheck it.
Looks good other than one question below.
Thanx, Paul
Quoted 8 lines
Signed-off-by Nick Piggin <[email protected]>--
Index:
linux-2.6/fs/dcache.c
===================================================================
fs/dcache.c struct dentry *dget_parent(struct dentry · line 315
Quoted 6 lines
fs/dcache.c +1
-1@@ -311,23 +311,18 @@ struct dentry *dget_parent(struct dentrystruct dentry *ret; repeat: -spin_lock (&dentry->d_lock); +rcu_read_lock (); ret = dentry->d_parent;
Doesn't this need to be as follows?
ret = rcu_dereference(dentry)->d_parent;
Otherwise, couldn't we end up seeing pre-initialization value for ->d_parent for a newly inserted dentry?
fs/dcache.c struct dentry *dget_parent(struct dentry · line 316
Quoted 9 lines
fs/dcache.c +1
-8-if (!ret) - goto out; -if (dentry == ret) { - ret->d_count++; - goto out; - } -if (!spin_trylock (&ret->d_lock)) { -spin_unlock (&dentry->d_lock); +spin_lock (&ret->d_lock);
Once we do this, however, we are golden, at least for all dentry fields protected by ->lock. This does assume that the compiler does not speculate the fetch that initialized the argument dentry into the critical section, which I would sure hope would be a reasonable assumption.
Quoted 50 lines
fs/dcache.c +18
-9+if (unlikely (ret != dentry->d_parent)) { +spin_unlock (&ret->d_lock); +rcu_read_unlock (); goto repeat; } +rcu_read_unlock ();BUG_ON (!ret->d_count); ret->d_count++;spin_unlock (&ret->d_lock); -out: -spin_unlock (&dentry->d_lock);return ret; }EXPORT_SYMBOL (dget_parent);@@ -601,14 +596,22 @@ static void prune_one_dentry(struct dentif (inode)spin_lock (&inode->i_lock); again: -spin_lock (&dentry->d_lock); -if (dentry->d_parent && dentry != dentry->d_parent) { -if (!spin_trylock (&dentry->d_parent->d_lock)) { -spin_unlock (&dentry->d_lock); +rcu_read_lock (); + parent = dentry->d_parent; +if (parent) { +spin_lock (&parent->d_lock); +if (unlikely (parent != dentry->d_parent)) { +spin_unlock (&parent->d_lock); +rcu_read_unlock (); goto again; } - parent = dentry->d_parent; - } +if (parent != dentry) +spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED ); +else + parent =NULL ; + }else +spin_lock (&dentry->d_lock); +rcu_read_unlock (); dentry->d_count--;if (dentry->d_count) {if (parent) --To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [patch 01/52] kernel: add bl_list
In reply to Paul E. McKenneyQuoted 12 lines · Paul E. McKenney
Quoted 5 lines · On Thu, Jun 24, 2010 at 01:02:13PM +1000, [email protected] wrote:
Introduce a type of hlist that can support the use of the lowest bit in the
hlist_head. This will be subsequently used to implement per-bucket bit spinlock for inode and dentry hashes.Signed-off-by Nick Piggin <[email protected]>Looks good! One question on non-RCU pointer poisoning and a typo. When these are addressed (perhaps by showing me the error of my ways):
Reviewed-by Paul E. McKenney <[email protected]>
..
Quoted 6 lines
include/linux/list_bl.h line 74
Quoted 4 lines
include/linux/list_bl.h new file +4
-0+static inline void hlist_bl_del (struct hlist_bl_node *n) +{ +__hlist_bl_del (n); + n->pprev =LIST_POISON2 ;OK, I'll bite... Why don't we poison the ->next pointer?
Ah, I took the code from list_nulls.h, but actually, except for the hlist anchoring, the code is much more similar to the standard hlist. This can be poisoned, and I'll go through and look for other possible differences with hlists.
Quoted 6 lines
Quoted 5 lines
+/**
+ *hlist_bl_del_init_rcu- deletes entry from hash list with re-initialization
+ * @n: the element to delete from the hash list.
+ *
+ * Note:hlist_bl_unhashed()on the node return true after this. It isreturns
Yes, thanks!
Re: [patch 02/52] fs: fix superblock iteration race
In reply to [email protected]This should actually be on it's way to Linus for .35, shouldn't it?
Quoted 89 lines · On Thu, Jun 24, 2010 at 01:02:14PM +1000, [email protected] wrote:
list_for_each_entry_safeis not suitable to protect against concurrent modification of the list. 6754af6 introduced a race in sb walking.
list_for_each_entrycan use the trick of pinning the current entry in the list before we drop and retake the lock because it subsequently followscur->next. Howeverlist_for_each_entry_safesaves n=cur->next for following before entering the loop body, so when the lock is dropped, n may be deleted.Signed-off-by Nick Piggin <[email protected]>--- fs/dcache.c | 2 ++ fs/super.c | 6 ++++++ include/linux/list.h | 15 +++++++++++++++ 3 files changed, 23 insertions(+)Index:
linux-2.6/fs/dcache.c
===================================================================fs/dcache.c +2
-0@@ -590,6 +590,8 @@ static void prune_dcache(int count)up_read (&sb->s_umount); }spin_lock (&sb_lock); +/* lock was dropped, must reset next */ +list_safe_reset_next (sb, n, s_list); count -= pruned;__put_super (sb);/* more work left to do? */ Index:
linux-2.6/fs/super.c
===================================================================fs/super.c +6
-0@@ -374,6 +374,8 @@ void sync_supers(void)up_read (&sb->s_umount);spin_lock (&sb_lock); +/* lock was dropped, must reset next */ +list_safe_reset_next (sb, n, s_list);__put_super (sb); } }@@ -405,6 +407,8 @@ void iterate_supers(void (*f)(struct supup_read (&sb->s_umount);spin_lock (&sb_lock); +/* lock was dropped, must reset next */ +list_safe_reset_next (sb, n, s_list);__put_super (sb); }spin_unlock (&sb_lock);@@ -585,6 +589,8 @@ static void do_emergency_remount(struct }up_write (&sb->s_umount);spin_lock (&sb_lock); +/* lock was dropped, must reset next */ +list_safe_reset_next (sb, n, s_list);__put_super (sb); }spin_unlock (&sb_lock);Index:
linux-2.6/include/linux/list.h
===================================================================include/linux/list.h +15
-1@@ -544,6 +544,21 @@ static inline void list_splice_tail_init &pos->member != (head); \ pos = n, n = list_entry(n->member.prev, typeof(*n), member)) +/** +* list_safe_reset_next - reset a stale list_for_each_entry_safe loop +* @pos: the loop cursor used in the list_for_each_entry_safe loop +* @n: temporary storage used in list_for_each_entry_safe +* @member: the name of the list_struct within the struct. +* +* list_safe_reset_next is not safe to use in general if the list may be +* modified concurrently (eg. the lock is dropped in the loop body). An +* exception to this is if the cursor element (pos) is pinned in the list, +* and list_safe_reset_next is called after re-taking the lock and before +* completing the current iteration of the loop body. +*/ +#define list_safe_reset_next (pos, n, member) \ + n = list_entry(pos->member.next, typeof(*pos), member) +/* * Double linked lists with a single pointer list head. * Mostly useful for hash tables where the two pointer list head is --
Quoted 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
---end quoted text---
Re: [patch 02/52] fs: fix superblock iteration race
Quoted 1 line · Christoph Hellwig
This should actually be on it's way to Linus for .35, shouldn't it?
Yeah, I was waiting for Al to reappear, but I think this is probably the nicest way to solve the problem. Linus? --
fs: fix superblock iteration race
list_for_each_entry_safe is not suitable to protect against concurrent modification of the list. 6754af6 introduced a race in sb walking.
list_for_each_entry can use the trick of pinning the current entry in the list before we drop and retake the lock because it subsequently follows cur->next. However list_for_each_entry_safe saves n=cur->next for following before entering the loop body, so when the lock is dropped, n may be deleted.
--- fs/dcache.c | 2 ++ fs/super.c | 6 ++++++ include/linux/list.h | 15 +++++++++++++++ 3 files changed, 23 insertions(+)
fs/dcache.c +2 -0
@@ -590,6 +590,8 @@ static void prune_dcache(int count)up_read (&sb->s_umount); }spin_lock (&sb_lock); +/* lock was dropped, must reset next */ +list_safe_reset_next (sb, n, s_list); count -= pruned;__put_super (sb);/* more work left to do? */
fs/super.c +6 -0
@@ -374,6 +374,8 @@ void sync_supers(void)up_read (&sb->s_umount);spin_lock (&sb_lock); +/* lock was dropped, must reset next */ +list_safe_reset_next (sb, n, s_list);__put_super (sb); } }
@@ -405,6 +407,8 @@ void iterate_supers(void (*f)(struct supup_read (&sb->s_umount);spin_lock (&sb_lock); +/* lock was dropped, must reset next */ +list_safe_reset_next (sb, n, s_list);__put_super (sb); }spin_unlock (&sb_lock);
@@ -585,6 +589,8 @@ static void do_emergency_remount(struct }up_write (&sb->s_umount);spin_lock (&sb_lock); +/* lock was dropped, must reset next */ +list_safe_reset_next (sb, n, s_list);__put_super (sb); }spin_unlock (&sb_lock);
include/linux/list.h +15 -0
@@ -544,6 +544,21 @@ static inline void list_splice_tail_init &pos->member != (head); \ pos = n, n = list_entry(n->member.prev, typeof(*n), member)) +/** +* list_safe_reset_next - reset a stale list_for_each_entry_safe loop +* @pos: the loop cursor used in the list_for_each_entry_safe loop +* @n: temporary storage used in list_for_each_entry_safe +* @member: the name of the list_struct within the struct. +* +* list_safe_reset_next is not safe to use in general if the list may be +* modified concurrently (eg. the lock is dropped in the loop body). An +* exception to this is if the cursor element (pos) is pinned in the list, +* and list_safe_reset_next is called after re-taking the lock and before +* completing the current iteration of the loop body. +*/ +#define list_safe_reset_next (pos, n, member) \ + n = list_entry(pos->member.next, typeof(*pos), member) +/* * Double linked lists with a single pointer list head. * Mostly useful for hash tables where the two pointer list head is
Re: [patch 02/52] fs: fix superblock iteration race
Quoted 5 lines · Nick Piggin
Quoted 1 line · Christoph Hellwig
This should actually be on it's way to Linus for .35, shouldn't it?
Yeah, I was waiting for Al to reappear, but I think this is probably the nicest way to solve the problem. Linus?
I'll apply it. We have a couple of oopses listed for the superblock iterator, and I haven't heard from Al. And the patch looks obviously fine, whether it's actually the cause of some of the bugs or not.
Linus
Re: [patch 02/52] fs: fix superblock iteration race
Quoted 10 lines · Linus Torvalds
Quoted 5 lines · Nick Piggin
Quoted 1 line · Christoph Hellwig
This should actually be on it's way to Linus for .35, shouldn't it?
Yeah, I was waiting for Al to reappear, but I think this is probably the nicest way to solve the problem. Linus?
I'll apply it. We have a couple of oopses listed for the superblock iterator, and I haven't heard from Al. And the patch looks obviously fine, whether it's actually the cause of some of the bugs or not.
OK. I only have managed to get it into an infininte loop but I think it would be surely possible to oops it because the next pointer can be uninitialised memory at that point.
Re: [patch 02/52] fs: fix superblock iteration race
Quoted 9 lines · Nick Piggin
Quoted 4 lines · Linus Torvalds
I'll apply it. We have a couple of oopses listed for the superblock iterator, and I haven't heard from Al. And the patch looks obviously fine, whether it's actually the cause of some of the bugs or not.
OK. I only have managed to get it into an infininte loop but I think it would be surely possible to oops it because the next pointer can be uninitialised memory at that point.
Look for "2.6.35-rc3 oops trying to suspend" on lkml, for example. No guarantee that it's the same thing, but it's "iterate_supers()" getting an oops when it does "down_read(&sb->s_umount)". Which really looks suspiciously like "sb" just being totally bogus, most likely because of this same issue.
So I dunno, but I asked Al to look at it, and haven't heard back.
Regardless, I think your patch is the right thing to do (modulo any syntactic issues - and I think your final version was the best of the lot).
Linus
Re: [patch 02/52] fs: fix superblock iteration race
Quoted 4 lines · Linus Torvalds
Look for "2.6.35-rc3 oops trying to suspend" on lkml, for example. No guarantee that it's the same thing, but it's "
iterate_supers()" getting an oops [..]
Also, "Oops during closedown with 2.6.35-rc3-git3" is an iterate_supers oops (in the jpg) and Chris says it's repeatable for him.
Chris - you could try testing current -git now that I've merged Nick's patch. It's commit 57439f878af ("fs: fix superblock iteration race"), and I just pushed it out (so it might take a few minutes to mirror out to the public git trees, but it should be there shortly).
Linus
Re: [patch 02/52] fs: fix superblock iteration race
Quoted 7 lines · Linus Torvalds
On Tue, Jun 29, 2010 at 10:52 AM, Linus Torvalds
Quoted 3 lines · <[email protected]> wrote:
Look for "2.6.35-rc3 oops trying to suspend" on lkml, for example. No guarantee that it's the same thing, but it's "
iterate_supers()" getting an oops [..]
Quoted 9 lines
Also, "Oops during closedown with 2.6.35-rc3-git3" is an
iterate_supersoops (in the jpg) and Chris says it's repeatable for him.Chris - you could try testing current -git now that I've merged Nick's patch. It's commit
57439f878af("fs: fix superblock iteration race"), and I just pushed it out (so it might take a few minutes to mirror out to the public git trees, but it should be there shortly).
Well, it was repeatable this morning, but despite 30+ shutdowns this evening, I haven't had a single oops. Perhaps I'm just not doing enough computing stuff between startup and shutdown to create the conditions under which I got the oopses this morning. Moreover, I've been using this kernel every day with, maybe two or three shutdowns a day, for two weeks or so now (since just after Linus went on vacation) with no oopses. (The kernel is -rc3 + John Fastabend's "net: fix deliver_no_wcard regression on loopback device" patch).
I'll spend a couple of hours doing stuff and see if I can generate an oops. Trouble is, of course, that when I pull and build the latest and greatest, I won't know why I'm not getting oopses, assuming I don't.
I'll update y'all later.
Chris
Quoted 1 line
Linus
Signature · 2 lines
The more I see, the more I know. The more I know, the less I understand. Changing Man - Paul Weller
Re: [patch 02/52] fs: fix superblock iteration race
Quoted 26 lines · Chris Clayton
Quoted 7 lines · Linus Torvalds
On Tue, Jun 29, 2010 at 10:52 AM, Linus Torvalds
Quoted 3 lines · <[email protected]> wrote:
Look for "2.6.35-rc3 oops trying to suspend" on lkml, for example. No guarantee that it's the same thing, but it's "
iterate_supers()" getting an oops [..]Quoted 9 lines
Also, "Oops during closedown with 2.6.35-rc3-git3" is an
iterate_supersoops (in the jpg) and Chris says it's repeatable for him.Chris - you could try testing current -git now that I've merged Nick's patch. It's commit
57439f878af("fs: fix superblock iteration race"), and I just pushed it out (so it might take a few minutes to mirror out to the public git trees, but it should be there shortly).Well, it was repeatable this morning, but despite 30+ shutdowns this evening, I haven't had a single oops. Perhaps I'm just not doing enough computing stuff between startup and shutdown to create the conditions under which I got the oopses this morning. Moreover, I've been using this kernel every day with, maybe two or three shutdowns a day, for two weeks or so now (since just after Linus went on vacation) with no oopses. (The kernel is -rc3 + John Fastabend's "net: fix
deliver_no_wcardregression on loopback device" patch).
Quoted 3 lines
I'll spend a couple of hours doing stuff and see if I can generate an oops. Trouble is, of course, that when I pull and build the latest and greatest, I won't know why I'm not getting oopses, assuming I don't.
Don't worry too much if you can't reproduce. I'd say it is likely to be this bug, and if so, it is going to depend significantly on timing and ordering of mounts/umounts.
Re: [patch 02/52] fs: fix superblock iteration race
Quoted 27 lines · Nick Piggin
Quoted 26 lines · Chris Clayton
Quoted 7 lines · Linus Torvalds
On Tue, Jun 29, 2010 at 10:52 AM, Linus Torvalds
Quoted 3 lines · <[email protected]> wrote:
Look for "2.6.35-rc3 oops trying to suspend" on lkml, for example. No guarantee that it's the same thing, but it's "
iterate_supers()" getting an oops [..]Quoted 8 lines
Also, "Oops during closedown with 2.6.35-rc3-git3" is an
iterate_supersoops (in the jpg) and Chris says it's repeatable for him.Chris - you could try testing current -git now that I've merged Nick's patch. It's commit
57439f878af("fs: fix superblock iteration race"), and I just pushed it out (so it might take a few minutes to mirror out to the public git trees, but it should be there shortly).Well, it was repeatable this morning, but despite 30+ shutdowns this evening, I haven't had a single oops. Perhaps I'm just not doing enough computing stuff between startup and shutdown to create the conditions under which I got the oopses this morning. Moreover, I've been using this kernel every day with, maybe two or three shutdowns a day, for two weeks or so now (since just after Linus went on vacation) with no oopses. (The kernel is -rc3 + John Fastabend's "net: fix
deliver_no_wcardregression on loopback device" patch).
Quoted 7 lines
Quoted 3 lines
I'll spend a couple of hours doing stuff and see if I can generate an oops. Trouble is, of course, that when I pull and build the latest and greatest, I won't know why I'm not getting oopses, assuming I don't.
Don't worry too much if you can't reproduce. I'd say it is likely to be this bug, and if so, it is going to depend significantly on timing and ordering of mounts/umounts.
Yes, that makes sense. I did quite a bit of copying files to and from USB storage devices this morning. I've got some more to do, so I'll see what that produces.
Signature · 2 lines
The more I see, the more I know. The more I know, the less I understand. Changing Man - Paul Weller
Re: [patch 50/52] mm: implement per-zone shrinker
In reply to [email protected]Quoted 11 lines · On Thu, Jun 24, 2010 at 01:03:02PM +1000, [email protected] wrote:
Allow the shrinker to do per-zone shrinking. This means it is called for each zone scanned. The shrinker is now completely responsible for calculating and batching (given helpers), which provides better flexibility.
Finding the ratio of objects to scan requires scaling the ratio of pagecache objects scanned. By passing down both the per-zone and the global reclaimable pages, per-zone caches and global caches can be calculated correctly.
Finally, add some fixed-point scaling to the ratio, which helps calculations.
Signed-off-by Nick Piggin <[email protected]>
Quoted 11 lines
--- fs/dcache.c | 2 fs/drop_caches.c | 2 fs/inode.c | 2 fs/mbcache.c | 4 - fs/nfs/dir.c | 2 fs/nfs/internal.h | 2 fs/quota/dquot.c | 2 include/linux/mm.h | 6 +- mm/vmscan.c | 131 ++++++++++++++--------------------------------------- 9 files changed, 47 insertions(+), 106 deletions(-)
The diffstat doesn't match the patch ;)
include/linux/mm.h static inline void sync_mm_rss(struct ta · line 1003
Quoted 13 lines
Index:
linux-2.6/include/linux/mm.h
===================================================================include/linux/mm.h +2
-3@@ -999,16 +999,19 @@ static inline void sync_mm_rss(struct ta* querying the cache size, so a fastpath for that case is appropriate. */ struct shrinker { -int (*shrink)(int nr_to_scan,gfp_t gfp_mask); -int seeks;/* seeks to recreate an obj */ - +int (*shrink)(struct zone *zone,unsigned long scanned,unsigned long total, +unsigned long global,gfp_t gfp_mask);
Can we add the shrinker structure to taht callback, too, so that we can get away from needing global context for the shrinker?
include/linux/mm.h static inline void sync_mm_rss(struct ta · line 1006
Quoted 3 lines
include/linux/mm.h +3
-0+unsigned long shrinker_do_scan (unsigned long *dst,unsigned long batch) +{ +unsigned long nr =ACCESS_ONCE (*dst);
What's the point of ACCESS_ONCE() here?
/me gets most of the way into the patch
Oh, it's because you are using static variables for nr_to_scan and hence when concurrent shrinkers are running they are all incrementing and decrementing the same variable. That doesn't sound like a good idea to me - concurrent shrinkers are much more likely with per-zone shrinker callouts. It seems to me that a reclaim thread could be kept in a shrinker long after it has run it's scan count if new shrinker calls from a different reclaim context occur before the first has finished....
As a further question - why do some shrinkerѕ get converted to a single global nr_to_scan, and others get converted to a private nr_to_scan? Shouldn't they all use the same method? The static variable method looks to me to be full of races - concurrent callers to shrinker_add_scan() does not look at all thread safe to me.
include/linux/mm.h static inline void sync_mm_rss(struct ta · line 1008
Quoted 2 lines
include/linux/mm.h +2
-0+if (nr < batch) +return 0 ;
Why wouldn't we return nr here to drain the remaining objects? Doesn't this mean we can't shrink caches that have a scan count of less than SHRINK_BATCH?
include/linux/mm.h static inline void sync_mm_rss(struct ta · line 1009
Quoted 1 line
include/linux/mm.h +1
-0+ *dst = nr - batch;
Similarly, that is not a threadsafe update.
Quoted 53 lines
include/linux/mm.h +6
-33+return batch; +} +EXPORT_SYMBOL (shrinker_do_scan); +/* * Call the shrink functions to age shrinkable caches * @@ -198,8 +228,8 @@ EXPORT_SYMBOL(unregister_shrinker);* * Returns the number of slab objects which we shrunk. */ -unsigned long shrink_slab (unsigned long scanned,gfp_t gfp_mask, -unsigned long lru_pages) +static unsigned long shrink_slab (struct zone *zone,unsigned long scanned,unsigned long total, +unsigned long global,gfp_t gfp_mask) {struct shrinker *shrinker;unsigned long ret =0 ;@@ -211,55 +241,25 @@ unsigned long shrink_slab(unsigned longreturn 1 ;/* Assume we'll be able to shrink next time */ list_for_each_entry (shrinker, &shrinker_list, list) { -unsigned long long delta; -unsigned long total_scan; -unsigned long max_pass = (*shrinker->shrink)(0 , gfp_mask); - - delta = (4 * scanned) / shrinker->seeks; - delta *= max_pass; -do_div (delta, lru_pages +1 ); - shrinker->nr += delta; -if (shrinker->nr <0 ) { -printk (KERN_ERR "shrink_slab: %pF negative objects to " -"delete nr=%ld\n" , - shrinker->shrink, shrinker->nr); - shrinker->nr = max_pass; - } - -/* -* Avoid risking looping forever due to too large nr value: -* never try to free more than twice the estimate number of -* freeable entries. -*/ -if (shrinker->nr > max_pass *2 ) - shrinker->nr = max_pass *2 ; - - total_scan = shrinker->nr; - shrinker->nr =0 ; - -while (total_scan >=SHRINK_BATCH ) { -long this_scan =SHRINK_BATCH ; -int shrink_ret; -int nr_before; -
include/linux/mm.h unsigned long shrink_slab(unsigned long · line 254
Quoted 10 lines
include/linux/mm.h +0
-10- nr_before = (*shrinker->shrink)(0 , gfp_mask); - shrink_ret = (*shrinker->shrink)(this_scan, gfp_mask); -if (shrink_ret ==-1 ) -break ; -if (shrink_ret < nr_before) - ret += nr_before - shrink_ret; -count_vm_events (SLABS_SCANNED , this_scan); - total_scan -= this_scan; - -cond_resched ();
Removing this means we need cond_resched() in all shrinker loops now to maintain the same latencies as we currently have. I note that you've done this for most of the shrinkers, but the documentation needs to be updated to mention this...
include/linux/mm.h unsigned long shrink_slab(unsigned long · line 257
Quoted 3 lines
include/linux/mm.h +0
-3- } - - shrinker->nr += total_scan;
And dropping this means we do not carry over the remainder of the previous scan into the next scan. This means we could be scanning a lot less with this new code.
Quoted 7 lines
include/linux/mm.h +2
-0+ (*shrinker->shrink)(zone, scanned, total, global, gfp_mask); }up_read (&shrinker_rwsem);return ret; } +void shrink_all_slab (void )
include/linux/mm.h unsigned long shrink_slab(unsigned long · line 260
Quoted 10 lines
include/linux/mm.h +10
-0+{ +struct zone *zone; +unsigned long nr; + +again: + nr =0 ; +for_each_zone (zone) + nr +=shrink_slab (zone,1 ,1 ,1 ,GFP_KERNEL ); +if (nr >=10 ) + goto again;
do {
nr = 0;
for_each_zone(zone)
nr += shrink_slab(zone, 1, 1, 1, GFP_KERNEL);
} while (nr >= 10);Quoted 8 lines
include/linux/mm.h +4
-0@@ -1705,6 +1708,23 @@ static void shrink_zone(int priority, stif (inactive_anon_is_low (zone, sc) && nr_swap_pages >0 )shrink_active_list (SWAP_CLUSTER_MAX , zone, sc, priority,0 ); +/* +* Don't shrink slabs when reclaiming memory from +* over limit cgroups +*/
include/linux/mm.h static void shrink_zone(int priority, st · line 1724
Quoted 10 lines
include/linux/mm.h +10
-0+if (scanning_global_lru (sc)) { +struct reclaim_state *reclaim_state = current->reclaim_state; + +shrink_slab (zone, sc->nr_scanned - nr_scanned, + lru_pages, global_lru_pages, sc->gfp_mask); +if (reclaim_state) { + nr_reclaimed += reclaim_state->reclaimed_slab; + reclaim_state->reclaimed_slab =0 ; + } + }
So effectively we are going to be calling shrink_slab() once per zone instead of once per priority loop, right? That means we are going to be doing a lot more concurrent shrink_slab() calls that the current code. Combine that with the removal of residual aggregation, I think this will alter the reclaim balance somewhat. Have you tried to quantify this?
Quoted 55 lines
Index:
linux-2.6/fs/dcache.c
===================================================================fs/dcache.c +18
-7@@ -748,20 +748,26 @@ again2:* * This function may fail to free any resources if all the dentries are in use. */ -static void prune_dcache (int count) +static void prune_dcache (struct zone *zone,unsigned long scanned, +unsigned long total,gfp_t gfp_mask) + { +unsigned long nr_to_scan;struct super_block *sb, *n;int w_count; -int unused = dentry_stat.nr_unused;int prune_ratio; -int pruned; +int count, pruned; -if (unused ==0 || count ==0 ) +shrinker_add_scan (&nr_to_scan, scanned, total, dentry_stat.nr_unused, +DEFAULT_SEEKS * sysctl_vfs_cache_pressure /100 ); +done: + count =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH ); +if (dentry_stat.nr_unused ==0 || count ==0 )return ; -if (count >= unused) +if (count >= dentry_stat.nr_unused) prune_ratio =1 ;else - prune_ratio = unused / count; + prune_ratio = dentry_stat.nr_unused / count;spin_lock (&sb_lock);list_for_each_entry_safe (sb, n, &super_blocks, s_list) {if (list_empty (&sb->s_instances))@@ -810,6 +816,10 @@ static void prune_dcache(int count)break ; }spin_unlock (&sb_lock); +if (count <=0 ) { +cond_resched (); + goto done; + } }/** @@ -1176,19 +1186,15 @@ EXPORT_SYMBOL(shrink_dcache_parent);* * In this case we return -1 to tell the caller that we baled. */ -static int shrink_dcache_memory (int nr,gfp_t gfp_mask) +static int shrink_dcache_memory (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask)
fs/dcache.c EXPORT_SYMBOL(shrink_dcache_parent); · line 1194
Quoted 10 lines
fs/dcache.c +2
-6{ -if (nr) { -if (!(gfp_mask & __GFP_FS)) -return -1 ; -prune_dcache (nr); - } -return (dentry_stat.nr_unused /100 ) * sysctl_vfs_cache_pressure; +prune_dcache (zone, scanned, global, gfp_mask); +return 0 ; }
I would have thought that putting the shrinker_add_scan/ shrinker_do_scan loop in shrink_dcache_memory() and leaving prune_dcache untouched would have been a better separation. I note that this is what you did with prune_icache(), so consistency between the two would be good ;)
Also, this patch drops the __GFP_FS check from the dcache shrinker - not intentional, right?
Quoted 28 lines
fs/dcache.c +11
-3@@ -211,28 +215,38 @@ mb_cache_shrink_fn(int nr_to_scan, gfp_t atomic_read(&cache->c_entry_count)); count +=atomic_read (&cache->c_entry_count); } +shrinker_add_scan (&nr_to_scan, scanned, global, count, +DEFAULT_SEEKS * sysctl_vfs_cache_pressure /100 );mb_debug ("trying to free %d entries" , nr_to_scan); -if (nr_to_scan ==0 ) { + +again: + nr =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH ); +if (!nr) {spin_unlock (&mb_cache_spinlock); - goto out; +return 0 ; } -while (nr_to_scan-- && !list_empty (&mb_cache_lru_list)) { +while (!list_empty (&mb_cache_lru_list)) {struct mb_cache_entry *ce =list_entry (mb_cache_lru_list.next, struct mb_cache_entry, e_lru_list);list_move_tail (&ce->e_lru_list, &free_list);__mb_cache_entry_unhash (ce); +cond_resched_lock (&mb_cache_spinlock); +if (!--nr) +break ; }spin_unlock (&mb_cache_spinlock);
fs/dcache.c mb_cache_shrink_fn(int nr_to_scan, gfp_t · line 246
Quoted 10 lines
fs/dcache.c +4
-2list_for_each_safe (l, ltmp, &free_list) { __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry, e_lru_list), gfp_mask); } -out: -return (count /100 ) * sysctl_vfs_cache_pressure; +if (!nr) { +spin_lock (&mb_cache_spinlock); + goto again; + }
Another candidate for a do-while loop.
Quoted 29 lines
fs/dcache.c +1
-1+return 0 ; } -/* * mb_cache_create() create a new cache * Index:
linux-2.6/fs/nfs/dir.c
===================================================================fs/nfs/dir.c +4
-5@@ -1709,21 +1709,31 @@ static void nfs_access_free_list(struct } } -int nfs_access_cache_shrinker (int nr_to_scan,gfp_t gfp_mask) +int nfs_access_cache_shrinker (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask) { +static unsigned long nr_to_scan;LIST_HEAD (head); -struct nfs_inode *nfsi;struct nfs_access_entry *cache; - -if ((gfp_mask &GFP_KERNEL ) !=GFP_KERNEL ) -return (nr_to_scan ==0 ) ?0 :-1 ; +unsigned long nr;spin_lock (&nfs_access_lru_lock);
fs/nfs/dir.c static void nfs_access_free_list(struct · line 1729
Quoted 10 lines
fs/nfs/dir.c +9
-1-list_for_each_entry (nfsi, &nfs_access_lru_list, access_cache_inode_lru) { +shrinker_add_scan (&nr_to_scan, scanned, global, +atomic_long_read (&nfs_access_nr_entries), +DEFAULT_SEEKS * sysctl_vfs_cache_pressure /100 ); +if (!(gfp_mask & __GFP_FS) || nr_to_scan <SHRINK_BATCH ) { +spin_unlock (&nfs_access_lru_lock); +return 0 ; + } + nr =ACCESS_ONCE (nr_to_scan); + nr_to_scan =0 ;
That's not safe for concurrent callers. Both could get nr = nr_to_scan rather than nr(1) = nr_to_scan and nr(2) = 0 which I think is the intent....
Quoted 23 lines
Index:
linux-2.6/arch/x86/kvm/mmu.c
===================================================================arch/x86/kvm/mmu.c +8
-2@@ -2924,14 +2924,29 @@ static int kvm_mmu_remove_some_alloc_mmureturn kvm_mmu_zap_page (kvm, page) +1 ; } -static int mmu_shrink (int nr_to_scan,gfp_t gfp_mask) +static int mmu_shrink (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask) { +static unsigned long nr_to_scan;struct kvm *kvm;struct kvm *kvm_freed =NULL ; -int cache_count =0 ; +unsigned long cache_count =0 ;spin_lock (&kvm_lock); +list_for_each_entry (kvm, &vm_list, vm_list) { + cache_count += kvm->arch.n_alloc_mmu_pages - + kvm->arch.n_free_mmu_pages; + }
arch/x86/kvm/mmu.c static int kvm_mmu_remove_some_alloc_mmu · line 2949
Quoted 10 lines
arch/x86/kvm/mmu.c +9
-0+shrinker_add_scan (&nr_to_scan, scanned, global, cache_count, +DEFAULT_SEEKS *10 ); + +done: + cache_count =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH ); +if (!cache_count) { +spin_unlock (&kvm_lock); +return 0 ; + }
I note that this use of a static scan count is thread safe because all the calculations are done under the kvm_lock. THat's three different ways the shrinkers implement the same functionality now....
Quoted 38 lines
Index:
linux-2.6/fs/xfs/linux-2.6/xfs_sync.c
===================================================================fs/xfs/linux-2.6/xfs_sync.c +7
-16@@ -838,43 +838,52 @@ static struct rw_semaphore xfs_mount_lisstatic int xfs_reclaim_inode_shrink ( -int nr_to_scan, +struct zone *zone, +unsigned long scanned, +unsigned long total, +unsigned long global,gfp_t gfp_mask) { +static unsigned long nr_to_scan; +int nr;struct xfs_mount *mp;struct xfs_perag *pag;xfs_agnumber_t ag; -int reclaimable =0 ; - -if (nr_to_scan) { -if (!(gfp_mask & __GFP_FS)) -return -1 ; - -down_read (&xfs_mount_list_lock); -list_for_each_entry (mp, &xfs_mount_list, m_mplist) { -xfs_inode_ag_iterator (mp, xfs_reclaim_inode,0 , -XFS_ICI_RECLAIM_TAG ,1 , &nr_to_scan); -if (nr_to_scan <=0 ) -break ; - } -up_read (&xfs_mount_list_lock); - } +unsigned long nr_reclaimable =0 ;down_read (&xfs_mount_list_lock);
fs/xfs/linux-2.6/xfs_sync.c static struct rw_semaphore xfs_mount_lis · line 863
Quoted 10 lines
fs/xfs/linux-2.6/xfs_sync.c +3
-1list_for_each_entry (mp, &xfs_mount_list, m_mplist) {for (ag =0 ; ag < mp->m_sb.sb_agcount; ag++) { pag =xfs_perag_get (mp, ag); - reclaimable += pag->pag_ici_reclaimable; + nr_reclaimable += pag->pag_ici_reclaimable;xfs_perag_put (pag); } } +shrinker_add_scan (&nr_to_scan, scanned, global, nr_reclaimable, +DEFAULT_SEEKS );
That's not thread safe - it's under a read lock. This code really needs a shrinker context....
Quoted 7 lines
fs/xfs/linux-2.6/xfs_sync.c +7
-0+if (!(gfp_mask & __GFP_FS)) { +up_read (&xfs_mount_list_lock); +return 0 ; + } + +done: + nr =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH );
fs/xfs/linux-2.6/xfs_sync.c static struct rw_semaphore xfs_mount_lis · line 880
Quoted 10 lines
fs/xfs/linux-2.6/xfs_sync.c +10
-0+if (!nr) { +up_read (&xfs_mount_list_lock); +return 0 ; + } +list_for_each_entry (mp, &xfs_mount_list, m_mplist) { +xfs_inode_ag_iterator (mp, xfs_reclaim_inode,0 , +XFS_ICI_RECLAIM_TAG ,1 , &nr); +if (nr <=0 ) + goto done; + }
That's missing conditional reschedules....
Cheers,
Dave.
Signature · 8 lines
Dave Chinner [email protected] -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 02/52] fs: fix superblock iteration race
In reply to Chris ClaytonQuoted 8 lines · Chris Clayton
Quoted 7 lines · Nick Piggin
Quoted 4 lines · Chris Clayton
I'll spend a couple of hours doing stuff and see if I can generate an oops. Trouble is, of course, that when I pull and build the latest and greatest, I won't know why I'm not getting oopses, assuming I don't.
Quoted 7 lines
Quoted 3 lines
Don't worry too much if you can't reproduce. I'd say it is likely to be this bug, and if so, it is going to depend significantly on timing and ordering of mounts/umounts.
Yes, that makes sense. I did quite a bit of copying files to and from USB storage devices this morning. I've got some more to do, so I'll see what that produces.
Well, try as I may, these oopses are like London buses - firstly you get three in quick succession when you don't need them and then when you do, none turn up. Oh well!
Chris
Signature · 2 lines
The more I see, the more I know. The more I know, the less I understand. Changing Man - Paul Weller
Re: [patch 29/52] fs: icache lock i_count
In reply to [email protected]Quoted 3 lines · On Thu, Jun 24, 2010 at 01:02:41PM +1000, [email protected] wrote:
Protect
inode->i_countwithi_lock, rather than having it atomic. Next step should also be to move things together (eg. the refcount increment intod_instantiate, which will remove a lock/unlock cycle oni_lock).
.....
Quoted 9 lines
Index:
linux-2.6/fs/inode.c
===================================================================fs/inode.c +0
-1@@ -33,14 +33,13 @@* inode_hash_lock protects: * inode hash table, i_hash * inode->i_lock protects: -* i_state
fs/inode.c line 43
Quoted 10 lines
fs/inode.c +2
-2+* i_state, i_count * * Ordering: * inode_lock * sb_inode_list_lock * inode->i_lock -* inode_lock -* inode_hash_lock +* inode_hash_lock */
I thought that the rule governing the use of inode->i_lock was that it can be used anywhere as long as it is the innermost lock.
Hmmm, no references in the code or documentation. Google gives a pretty good reference:
http://www.mail-archive.com/[email protected]/msg02584.html
Perhaps a different/new lock needs to be used here?
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [patch 37/52] fs: icache lazy lru
In reply to [email protected]Quoted 2 lines · On Thu, Jun 24, 2010 at 01:02:49PM +1000, [email protected] wrote:
Impelemnt lazy inode lru similarly to dcache. This will reduce lock acquisition and will help to improve lock ordering subsequently.
I'm not sure we want the I_REFERENCED reclaim free pass for a clean inode that has been put on the LRU directly. I can see exactly how it is benficial to delay reclaim of dirty inodes (XFS uses that trick), but in terms of aging the cache we've already done this free pass trick at the dentry level. Hence I think the frequent separate access patterns tend to be filtered out at the dcache level and hence we don't need to handle that in the inode cache.
Perhaps we only need the I_REFERENCED flag to give dirty inodes a chance to be flushed by other means before forcing reclaim to do inode writeback?
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [patch 38/52] fs: icache RCU free inodes
In reply to [email protected]Quoted 1 line · On Thu, Jun 24, 2010 at 01:02:50PM +1000, [email protected] wrote:
RCU free the struct inode. This will allow:
Rather than what it will allow, what are the constraints this imposes on allocating and freeing a struct inode? e.g. XFS embeds the struct inode in a larger inode structure and does it's own allocation, caching and freeing of the larger structure outside of the VFS functionality.
Does this need to be converted to RCU? Do we need to do more initialisation of the struct inode than we currently do? What functions/call chains now implicitly require RCU freeing semantics on the struct inode for safe operation? What else do we need to be aware of?
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [patch 44/52] fs: icache per-CPU sb inode lists and locks
In reply to [email protected]Quoted 1 line · On Thu, Jun 24, 2010 at 01:02:56PM +1000, [email protected] wrote:
Signed-off-by Nick Piggin <[email protected]>
.....
Quoted 43 lines
include/linux/fs.h +39
-0@@ -2194,6 +2198,58 @@ static inline void insert_inode_hash(strextern void file_sb_list_add (struct file *f,struct super_block *sb);extern void file_sb_list_del (struct file *f); +#ifdef CONFIG_SMP + +/* +* These macros iterate all inodes on all CPUs for a given superblock. +* rcu_read_lock must be held. +*/ +#define do_inode_list_for_each_entry_rcu (__sb, __inode) \ +{ \ + int i; \ + for_each_possible_cpu(i) { \ + struct list_head *list; \ + list = per_cpu_ptr((__sb)->s_inodes, i); \ + list_for_each_entry_rcu((__inode), list, i_sb_list) + +#define while_inode_list_for_each_entry_rcu \ + } \ +} + +#define do_inode_list_for_each_entry_safe (__sb, __inode, __tmp) \ +{ \ + int i; \ + for_each_possible_cpu(i) { \ + struct list_head *list; \ + list = per_cpu_ptr((__sb)->s_inodes, i); \ + list_for_each_entry_safe((__inode), (__tmp), list, i_sb_list) + +#define while_inode_list_for_each_entry_safe \ + } \ +} + +#else + +#define do_inode_list_for_each_entry_rcu (__sb, __inode) \ +{ \ + struct list_head *list; \ + list = &(sb)->s_inodes; \ + list_for_each_entry_rcu((__inode), list, i_sb_list) + +#define while_inode_list_for_each_entry_rcu \
include/linux/fs.h static inline void insert_inode_hash(str · line 2249
Quoted 10 lines
include/linux/fs.h +10
-0+} + +#define do_inode_list_for_each_entry_safe (__sb, __inode, __tmp) \ +{ \ + struct list_head *list; \ + list = &(sb)->s_inodes; \ + list_for_each_entry_rcu((__inode), (__tmp), list, i_sb_list) + +#define while_inode_list_for_each_entry_safe \ +}
I can't say that I'm a great fan of hiding loop context in defines like this. It reminds far too much of how parts of Irix slowly ossified because they ended up mess of complex, fragile macros that nobody fully understood...
Cheers.
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [patch 51/52] fs: per-zone dentry and inode LRU
In reply to [email protected]Quoted 3 lines · On Thu, Jun 24, 2010 at 01:03:03PM +1000, [email protected] wrote:
Per-zone LRUs and shrinkers for dentry and inode caches.
Signed-off-by Nick Piggin <[email protected]>
This destroys any notion we have of global LRU-ness of inode and dentry caches, doesn't it? Can you outline in more detail what sort of reclaim pattern this results in. e.g. is a workload running on a single node now effectively limited to a dentry/icache size within the local node because of local node slab allocation and per-zone reclaim?
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [patch 52/52] fs: icache less I_FREEING time
In reply to [email protected]Quoted 4 lines · On Thu, Jun 24, 2010 at 01:03:04PM +1000, [email protected] wrote:
Problem with inode reclaim is that it puts inodes into
I_FREEINGstate and then continues to gather more, during which it may iput,invalidate_mapping_pages, be preempted, etc. Holding these inodes inI_FREEINGcan cause pauses.
What sort of pauses? I can't see how holding a few inodes in I_FREEING state would cause any serious sort of holdoff...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 1 line · On Thu, Jun 24, 2010 at 01:02:12PM +1000, [email protected] wrote:
http://www.kernel.org/pub/linux/kernel/people/npiggin/patches/fs-scale/
Can you put a git tree up somewhere?
Quoted 1 line
Update to vfs scalability patches:
....
Now that I've had a look at the whole series, I'll make an overall
comment: I suspect that the locking is sufficiently complex that we can count the number of people that will be able to debug it on one hand. This patch set didn't just fall off the locking cliff, it fell into a bottomless pit...
Quoted 6 lines
Performance:
Last time I was testing on a 32-node Altix which could be considered as not a sweet-spot for Linux performance target (ie. improvements there may not justify complexity). So recently I've been testing with a tightly interconnected 4-socket Nehalem (4s/32c/64t). Linux needs to perform well on this size of system.
Sure, but I have to question how much of this is actually necessary? A lot of it looks like scalability for scalabilities sake, not because there is a demonstrated need...
Quoted 7 lines
*** Single-thread microbenchmark (simple syscall loops, lower is better):
Test Difference at 95.0% confidence (50 runs) open/close -6.07% +/- 1.075% creat/unlink 27.83% +/- 0.522%Open/close is a little faster, which should be due to one less atomic in the dput common case. Creat/unlink is significantly slower, which is due to RCU freeing inodes.
That's a pretty big ouch. Why does RCU freeing of inodes cause that much regression? The RCU freeing is out of line, so where does the big impact come from?
Quoted 8 lines
*** 64 parallel git diff on 64 kernel trees fully cached (avg of 5 runs):
vanilla vfs real 0m4.911s 0m0.183s user 0m1.920s 0m1.610s sys 4m58.670s 0m5.770sAfter vfs patches, 26x increase in throughput, however parallelism is limited by test spawning and exit phases. sys time improvement shows closer to 50x improvement. vanilla is bottlenecked on
dcache_lock.
So if we cherry pick patches out of the series, what is the bare minimum set needed to obtain a result in this ballpark? Same for the other tests?
Quoted 6 lines
*** Reclaim
I have not done much reclaim testing yet. It should be more scalable and lower latency due to significant reduction in lru locks interfering with other critical sections in inode/dentry code, and because we have per-zone locks. Per-zone LRUs mean that reclaim is targetted to the correct zone, and that kswapd will operate on lists of node-local memory objects.
This means we no longer have any global LRUness to inode or dentry reclaim, which is going to significantly change caching behaviour. It's also got interesting corner cases like a workload running on a single node with a dentry/icache working set larger than the VM wants to hold on a single node.
We went through these sorts of problems with cpusets a few years back, and the workaround for it was not to limit the slab cache to the cpuset's nodes. Handling this sort of problem correctly seems distinctly non-trivial, so I'm really very reluctant to move in this direction without clear evidence that we have no other alternative....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [patch 50/52] mm: implement per-zone shrinker
In reply to Dave ChinnerWow, some reviewing! Thanks Dave.
Quoted 4 lines · Dave Chinner
Quoted 1 line · On Thu, Jun 24, 2010 at 01:03:02PM +1000, [email protected] wrote:
9 files changed, 47 insertions(+), 106 deletions(-)The diffstat doesn't match the patch ;)
Bah, sorry.
Quoted 8 lines
Quoted 8 lines
Index:
linux-2.6/include/linux/mm.h
===================================================================include/linux/mm.h +0
-0@@ -999,16 +999,19 @@ static inline void sync_mm_rss(struct ta* querying the cache size, so a fastpath for that case is appropriate. */ struct shrinker {
Quoted 8 lines
include/linux/mm.h static inline void sync_mm_rss(struct ta · line 1003
Quoted 5 lines
include/linux/mm.h +2
-3-int (*shrink)(int nr_to_scan,gfp_t gfp_mask); -int seeks;/* seeks to recreate an obj */ - +int (*shrink)(struct zone *zone,unsigned long scanned,unsigned long total, +unsigned long global,gfp_t gfp_mask);Can we add the shrinker structure to taht callback, too, so that we can get away from needing global context for the shrinker?
I was planning to merge this on top of your shrinker change (which I like how the locking / refcounting worked out). So I was just going to leave that part for you :)
Quoted 8 lines
include/linux/mm.h static inline void sync_mm_rss(struct ta · line 1006
Quoted 3 lines
include/linux/mm.h +3
-0+unsigned long shrinker_do_scan (unsigned long *dst,unsigned long batch) +{ +unsigned long nr =ACCESS_ONCE (*dst);What's the point of
ACCESS_ONCE()here?/me gets most of the way into the patch
Quoted 8 lines
Oh, it's because you are using static variables for
nr_to_scanand hence when concurrent shrinkers are running they are all incrementing and decrementing the same variable. That doesn't sound like a good idea to me - concurrent shrinkers are much more likely with per-zone shrinker callouts. It seems to me that a reclaim thread could be kept in a shrinker long after it has run it's scan count if new shrinker calls from a different reclaim context occur before the first has finished....
I don't think parallelism will be much changed. The existing shrinker didn't provide any serialisation. It likewise did not serialise any updates to shrinker->nr accumulator (reclaim is a crappy heuristic anyway so it apparently doesn't matter too much that it is racy). So a lot of your criticism of racy access to the accumulators isn't really inherent to this patch
(where it's easy, I did put them under locks, but I didn't go out of my way -- a subsequent patch could do that if we really wanted)
Quoted 5 lines
As a further question - why do some shrinkerѕ get converted to a single global
nr_to_scan, and others get converted to a privatenr_to_scan? Shouldn't they all use the same method? The static variable method looks to me to be full of races - concurrent callers toshrinker_add_scan()does not look at all thread safe to me.
Hmm, they should all have their own nr_to_scan.
Quoted 4 lines
include/linux/mm.h static inline void sync_mm_rss(struct ta · line 1008
Quoted 2 lines
include/linux/mm.h +2
-0+if (nr < batch) +return 0 ;Why wouldn't we return nr here to drain the remaining objects?
I was thinking, because it's not worth taking locks for a small number of objects.
Quoted 2 lines
Doesn't this mean we can't shrink caches that have a scan count of less than
SHRINK_BATCH?
No, they just accumulate slowly until hitting the batch size.
Quoted 9 lines
include/linux/mm.h static inline void sync_mm_rss(struct ta · line 1008
Quoted 4 lines
include/linux/mm.h +0
-4-count_vm_events (SLABS_SCANNED , this_scan); - total_scan -= this_scan; - -cond_resched ();Removing this means we need
cond_resched()in all shrinker loops now to maintain the same latencies as we currently have. I note that you've done this for most of the shrinkers, but the documentation needs to be updated to mention this...
That's true, yes.
Quoted 7 lines
include/linux/mm.h static inline void sync_mm_rss(struct ta · line 1011
Quoted 3 lines
include/linux/mm.h +0
-3- } - - shrinker->nr += total_scan;And dropping this means we do not carry over the remainder of the previous scan into the next scan. This means we could be scanning a lot less with this new code.
We do because they accumulate to static variables. It's effectively the same as accumulating to shrinker->nr, but it allows the per-zone patches to change to accumulate to per-zone counters.
Quoted 4 lines
Quoted 4 lines
include/linux/mm.h +4
-0+again: + nr =0 ; +for_each_zone (zone) + nr +=shrink_slab (zone,1 ,1 ,1 ,GFP_KERNEL );
Quoted 8 lines
include/linux/mm.h static inline void sync_mm_rss(struct ta · line 1014
Quoted 2 lines
include/linux/mm.h +2
-0+if (nr >=10 ) + goto again;do { nr = 0; for_each_zone(zone) nr += shrink_slab(zone, 1, 1, 1, GFP_KERNEL); } while (nr >= 10);
OK.
Quoted 13 lines
Quoted 13 lines
include/linux/mm.h +9
-0@@ -1705,6 +1708,23 @@ static void shrink_zone(int priority, stif (inactive_anon_is_low (zone, sc) && nr_swap_pages >0 )shrink_active_list (SWAP_CLUSTER_MAX , zone, sc, priority,0 ); +/* +* Don't shrink slabs when reclaiming memory from +* over limit cgroups +*/ +if (scanning_global_lru (sc)) { +struct reclaim_state *reclaim_state = current->reclaim_state; + +shrink_slab (zone, sc->nr_scanned - nr_scanned, + lru_pages, global_lru_pages, sc->gfp_mask);
Quoted 8 lines
include/linux/mm.h static void shrink_zone(int priority, st · line 1724
Quoted 5 lines
include/linux/mm.h +5
-0+if (reclaim_state) { + nr_reclaimed += reclaim_state->reclaimed_slab; + reclaim_state->reclaimed_slab =0 ; + } + }So effectively we are going to be calling
shrink_slab()once per zone instead of once per priority loop, right? That means we are
Yes.
Quoted 4 lines
going to be doing a lot more concurrent
shrink_slab()calls that the current code. Combine that with the removal of residual aggregation, I think this will alter the reclaim balance somewhat. Have you tried to quantify this?
It will alter reclaim a bit. I don't think it will change the concurrency too much (per-prio which gets chopped into batch size calls into shrinker versus per-zone call which the shrinker chops up itself).
Basically, the number of items to scan should be about the same, and chopped into the same number of batches. It just depends on exactly when it gets done.
Quoted 11 lines
Quoted 11 lines
include/linux/mm.h +3
-7-static int shrink_dcache_memory (int nr,gfp_t gfp_mask) +static int shrink_dcache_memory (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask) { -if (nr) { -if (!(gfp_mask & __GFP_FS)) -return -1 ; -prune_dcache (nr); - } -return (dentry_stat.nr_unused /100 ) * sysctl_vfs_cache_pressure; +prune_dcache (zone, scanned, global, gfp_mask);
Quoted 8 lines
include/linux/mm.h
Quoted 2 lines
include/linux/mm.h +1
-0+return 0 ; }I would have thought that putting the shrinker_add_scan/
shrinker_do_scanloop inshrink_dcache_memory()and leavingprune_dcacheuntouched would have been a better separation. I note that this is what you did withprune_icache(), so consistency between the two would be good ;)
You're probably right, I'll go back and take a look.
Quoted 2 lines
Also, this patch drops the
__GFP_FScheck from the dcache shrinker - not intentional, right?
Right, thanks.
Quoted 23 lines
Quoted 23 lines
include/linux/mm.h +8
-2+again: + nr =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH ); +if (!nr) {spin_unlock (&mb_cache_spinlock); - goto out; +return 0 ; } -while (nr_to_scan-- && !list_empty (&mb_cache_lru_list)) { +while (!list_empty (&mb_cache_lru_list)) {struct mb_cache_entry *ce =list_entry (mb_cache_lru_list.next, struct mb_cache_entry, e_lru_list);list_move_tail (&ce->e_lru_list, &free_list);__mb_cache_entry_unhash (ce); +cond_resched_lock (&mb_cache_spinlock); +if (!--nr) +break ; }spin_unlock (&mb_cache_spinlock);list_for_each_safe (l, ltmp, &free_list) { __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry, e_lru_list), gfp_mask); }
Quoted 8 lines
include/linux/mm.h
Quoted 6 lines
include/linux/mm.h +4
-2-out: -return (count /100 ) * sysctl_vfs_cache_pressure; +if (!nr) { +spin_lock (&mb_cache_spinlock); + goto again; + }Another candidate for a do-while loop.
Maybe. I prefer not to indent so much (then one would argue to put the body in a seperate function :), but meh)
Quoted 6 lines
include/linux/mm.h
Quoted 2 lines
include/linux/mm.h +2
-0+ nr =ACCESS_ONCE (nr_to_scan); + nr_to_scan =0 ;That's not safe for concurrent callers. Both could get nr =
nr_to_scanrather than nr(1) =nr_to_scanand nr(2) = 0 which I think is the intent....
...
Quoted 4 lines
I note that this use of a static scan count is thread safe because all the calculations are done under the
kvm_lock. THat's three different ways the shrinkers implement the same functionality now....
...
Quoted 2 lines
That's not thread safe - it's under a read lock. This code really needs a shrinker context....
So as I said above, lost updates are not cared about.
Quoted 11 lines
Quoted 11 lines
include/linux/mm.h +11
-0+if (!(gfp_mask & __GFP_FS)) { +up_read (&xfs_mount_list_lock); +return 0 ; + } + +done: + nr =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH ); +if (!nr) { +up_read (&xfs_mount_list_lock); +return 0 ; + }
Quoted 8 lines
include/linux/mm.h
Quoted 6 lines
include/linux/mm.h +6
-0+list_for_each_entry (mp, &xfs_mount_list, m_mplist) { +xfs_inode_ag_iterator (mp, xfs_reclaim_inode,0 , +XFS_ICI_RECLAIM_TAG ,1 , &nr); +if (nr <=0 ) + goto done; + }That's missing conditional reschedules....
Thanks
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 29/52] fs: icache lock i_count
In reply to Dave ChinnerQuoted 28 lines · Dave Chinner
Quoted 3 lines · On Thu, Jun 24, 2010 at 01:02:41PM +1000, [email protected] wrote:
Protect
inode->i_countwithi_lock, rather than having it atomic. Next step should also be to move things together (eg. the refcount increment intod_instantiate, which will remove a lock/unlock cycle oni_lock)......
Quoted 9 lines
Index:
linux-2.6/fs/inode.c
===================================================================fs/inode.c +0
-1@@ -33,14 +33,13 @@* inode_hash_lock protects: * inode hash table, i_hash * inode->i_lock protects: -* i_state fs/inode.c line 43
Quoted 10 lines
fs/inode.c +2
-2+* i_state, i_count * * Ordering: * inode_lock * sb_inode_list_lock * inode->i_lock -* inode_lock -* inode_hash_lock +* inode_hash_lock */ I thought that the rule governing the use of
inode->i_lockwas that it can be used anywhere as long as it is the innermost lock.
Quoted 6 lines
Hmmm, no references in the code or documentation. Google gives a pretty good reference:
http://www.mail-archive.com/[email protected]/msg02584.html
Perhaps a different/new lock needs to be used here?
Well I just changed the order (and documented it to boot :)). It's pretty easy to verify that LOR is no problem. inode hash is only taken in a very few places so other code outside inode.c is fine to use i_lock as an innermost lock.
Re: [patch 37/52] fs: icache lazy lru
In reply to Dave ChinnerQuoted 12 lines · Dave Chinner
Quoted 2 lines · On Thu, Jun 24, 2010 at 01:02:49PM +1000, [email protected] wrote:
Impelemnt lazy inode lru similarly to dcache. This will reduce lock acquisition and will help to improve lock ordering subsequently.
I'm not sure we want the
I_REFERENCEDreclaim free pass for a clean inode that has been put on the LRU directly. I can see exactly how it is benficial to delay reclaim of dirty inodes (XFS uses that trick), but in terms of aging the cache we've already done this free pass trick at the dentry level. Hence I think the frequent separate access patterns tend to be filtered out at the dcache level and hence we don't need to handle that in the inode cache.
Quoted 3 lines
Perhaps we only need the
I_REFERENCEDflag to give dirty inodes a chance to be flushed by other means before forcing reclaim to do inode writeback?
It doesn't force flush, but it force invalidates pagecache.
Re: [patch 38/52] fs: icache RCU free inodes
In reply to Dave ChinnerQuoted 9 lines · Dave Chinner
Quoted 1 line · On Thu, Jun 24, 2010 at 01:02:50PM +1000, [email protected] wrote:
RCU free the struct inode. This will allow:
Rather than what it will allow, what are the constraints this imposes on allocating and freeing a struct inode? e.g. XFS embeds the struct inode in a larger inode structure and does it's own allocation, caching and freeing of the larger structure outside of the VFS functionality.
Quoted 5 lines
Does this need to be converted to RCU? Do we need to do more initialisation of the struct inode than we currently do? What functions/call chains now implicitly require RCU freeing semantics on the struct inode for safe operation? What else do we need to be aware of?
Yeah, filesystems with their own freeing functions will need to do a call_rcu to free it (many are not converted). Otherwise, there is nothing else to know. They could take advantage of RCU if they would like though.
Re: [patch 44/52] fs: icache per-CPU sb inode lists and locks
In reply to Dave ChinnerQuoted 53 lines · Dave Chinner
Quoted 1 line · On Thu, Jun 24, 2010 at 01:02:56PM +1000, [email protected] wrote:
Signed-off-by Nick Piggin <[email protected]>.....
Quoted 50 lines
include/linux/fs.h +46
-0@@ -2194,6 +2198,58 @@ static inline void insert_inode_hash(strextern void file_sb_list_add (struct file *f,struct super_block *sb);extern void file_sb_list_del (struct file *f); +#ifdef CONFIG_SMP + +/* +* These macros iterate all inodes on all CPUs for a given superblock. +* rcu_read_lock must be held. +*/ +#define do_inode_list_for_each_entry_rcu (__sb, __inode) \ +{ \ + int i; \ + for_each_possible_cpu(i) { \ + struct list_head *list; \ + list = per_cpu_ptr((__sb)->s_inodes, i); \ + list_for_each_entry_rcu((__inode), list, i_sb_list) + +#define while_inode_list_for_each_entry_rcu \ + } \ +} + +#define do_inode_list_for_each_entry_safe (__sb, __inode, __tmp) \ +{ \ + int i; \ + for_each_possible_cpu(i) { \ + struct list_head *list; \ + list = per_cpu_ptr((__sb)->s_inodes, i); \ + list_for_each_entry_safe((__inode), (__tmp), list, i_sb_list) + +#define while_inode_list_for_each_entry_safe \ + } \ +} + +#else + +#define do_inode_list_for_each_entry_rcu (__sb, __inode) \ +{ \ + struct list_head *list; \ + list = &(sb)->s_inodes; \ + list_for_each_entry_rcu((__inode), list, i_sb_list) + +#define while_inode_list_for_each_entry_rcu \ +} + +#define do_inode_list_for_each_entry_safe (__sb, __inode, __tmp) \ +{ \ + struct list_head *list; \ + list = &(sb)->s_inodes; \ + list_for_each_entry_rcu((__inode), (__tmp), list, i_sb_list)
Quoted 8 lines
include/linux/fs.h static inline void insert_inode_hash(str · line 2229
Quoted 3 lines
include/linux/fs.h +3
-0+ +#define while_inode_list_for_each_entry_safe \ +}I can't say that I'm a great fan of hiding loop context in defines like this. It reminds far too much of how parts of Irix slowly ossified because they ended up mess of complex, fragile macros that nobody fully understood...
It's not perfect. I think it is a lot better than open coding (which I tried before) because that really muddies up the intention of the loop body.
Re: [patch 51/52] fs: per-zone dentry and inode LRU
In reply to Dave ChinnerQuoted 7 lines · Dave Chinner
Quoted 3 lines · On Thu, Jun 24, 2010 at 01:03:03PM +1000, [email protected] wrote:
Per-zone LRUs and shrinkers for dentry and inode caches.
Signed-off-by Nick Piggin <[email protected]>This destroys any notion we have of global LRU-ness of inode and dentry caches, doesn't it?
Yes.
Quoted 5 lines
Can you outline in more detail what sort
of reclaim pattern this results in. e.g. is a workload running on a single node now effectively limited to a dentry/icache size within the local node because of local node slab allocation and per-zone reclaim?
No, it will just make the vfs cache reclaim work similarly to pagecache reclaim. Reclaimers (kswapd) can work on node local memory; memory pressure in a particular zone can be targetted specifically instead of shrinking all zones until it is OK; zone reclaim will work properly for vfs caches; partitioning of workloads can be better.
Workload on a single node can certainly still use up all global memory if that is how the policy is configured.
Global LRU ordering is lost, but it is approximated when there is a global memory shortage by scanning a little from each zone head. When there is a local memory shortage it should be superior because that can be resolved without reclaiming so much memory.
Thanks,
Nick
Re: [patch 52/52] fs: icache less I_FREEING time
In reply to Dave ChinnerQuoted 8 lines · Dave Chinner
Quoted 4 lines · On Thu, Jun 24, 2010 at 01:03:04PM +1000, [email protected] wrote:
Problem with inode reclaim is that it puts inodes into
I_FREEINGstate and then continues to gather more, during which it may iput,invalidate_mapping_pages, be preempted, etc. Holding these inodes inI_FREEINGcan cause pauses.What sort of pauses? I can't see how holding a few inodes in
I_FREEINGstate would cause any serious sort of holdoff...
Well if the inode is accessed again, it has to wait for potentially hundreds of inodes to be found from the LRU, pagecache invalidated, and destroyed.
Al Viro
maintainerRe: [patch 02/52] fs: fix superblock iteration race
In reply to Linus TorvaldsQuoted 7 lines · Linus Torvalds
Quoted 4 lines · Linus Torvalds
Look for "2.6.35-rc3 oops trying to suspend" on lkml, for example. No guarantee that it's the same thing, but it's "
iterate_supers()" getting an oops [..]
Quoted 8 lines
Also, "Oops during closedown with 2.6.35-rc3-git3" is an
iterate_supersoops (in the jpg) and Chris says it's repeatable for him.Chris - you could try testing current -git now that I've merged Nick's patch. It's commit
57439f878af("fs: fix superblock iteration race"), and I just pushed it out (so it might take a few minutes to mirror out to the public git trees, but it should be there shortly).
ACK. I've several cleanups on top of that, but that's not a .35 fodder. I'll put them into for-next tonight. But yes, the hole caught by Nick is definitely real and very likely to be responsible for all that pile of reports. Mea culpa.
Quoted 4 lines · Dave Chinner
Quoted 1 line · On Thu, Jun 24, 2010 at 01:02:12PM +1000, [email protected] wrote:
http://www.kernel.org/pub/linux/kernel/people/npiggin/patches/fs-scale/
Can you put a git tree up somewhere?
I suppose I should. I'll try to set one up.
Quoted 8 lines
Quoted 1 line
Update to vfs scalability patches:
....
Now that I've had a look at the whole series, I'll make an overall
comment: I suspect that the locking is sufficiently complex that we can count the number of people that will be able to debug it on one hand.
As opposed to everyone who understood it beforehand? :)
Quoted 2 lines
This patch set didn't just fall off the locking cliff, it
fell into a bottomless pit...
I actually think it's simpler in ways. It has more locks, but a lot of those protect small, well defined data.
Filesystems have required surprisingly minimal changes (except autofs4, but that's fairly special case).
Quoted 10 lines
Quoted 6 lines
Performance:
Last time I was testing on a 32-node Altix which could be considered as not a sweet-spot for Linux performance target (ie. improvements there may not justify complexity). So recently I've been testing with a tightly interconnected 4-socket Nehalem (4s/32c/64t). Linux needs to perform well on this size of system.Sure, but I have to question how much of this is actually necessary? A lot of it looks like scalability for scalabilities sake, not because there is a demonstrated need...
People are complaining about vfs scalability already (at least Intel, Google, IBM, and networking people). By the time people start shouting, it's too late because it will take years to get the patches merged. I'm not counting -rt people who have a bad time with global vfs locks.
You saw the "batched dput+iput" hacks that google posted a couple of years ago. Those were in the days of 4 core Core2 CPUs, long before 16 thread Nehalems that will scale well to 4/8 sockets at low cost.
At the high end, vaguely extrapolating from my numbers, a big POWER7 may do under 100 open/close operations per second per hw thread. A big UV probably under 10 per core.
But actually it's not all for scalability. I have some follow on patches (that require RCU inodes, among other things) that actually improve single threaded performance significnatly. git diff workload IIRC was several % improved from speeding up stat(2).
Quoted 11 lines
Quoted 7 lines
*** Single-thread microbenchmark (simple syscall loops, lower is better):
Test Difference at 95.0% confidence (50 runs) open/close -6.07% +/- 1.075% creat/unlink 27.83% +/- 0.522%Open/close is a little faster, which should be due to one less atomic in the dput common case. Creat/unlink is significantly slower, which is due to RCU freeing inodes.
That's a pretty big ouch. Why does RCU freeing of inodes cause that much regression? The RCU freeing is out of line, so where does the big impact come from?
That comes mostly from inability to reuse the cache-hot inode structure, and the cost to go over the deferred RCU list and free them after they get cache cold.
Quoted 9 lines
Quoted 8 lines
*** 64 parallel git diff on 64 kernel trees fully cached (avg of 5 runs):
vanilla vfs real 0m4.911s 0m0.183s user 0m1.920s 0m1.610s sys 4m58.670s 0m5.770sAfter vfs patches, 26x increase in throughput, however parallelism is limited by test spawning and exit phases. sys time improvement shows closer to 50x improvement. vanilla is bottlenecked on
dcache_lock.
Quoted 3 lines
So if we cherry pick patches out of the series, what is the bare minimum set needed to obtain a result in this ballpark? Same for the other tests?
Well it's very hard to just scale up bits and pieces because the dcache_lock is currently basically global (except for d_flags and some cases of d_count manipulations).
Start chipping away at bits and pieces of it as people hit bottlenecks and I think it will end in a bigger mess than we have now.
I don't think this should be done lightly, but I think it is going to be required soon.
Quoted 13 lines
Quoted 6 lines
*** Reclaim
I have not done much reclaim testing yet. It should be more scalable and lower latency due to significant reduction in lru locks interfering with other critical sections in inode/dentry code, and because we have per-zone locks. Per-zone LRUs mean that reclaim is targetted to the correct zone, and that kswapd will operate on lists of node-local memory objects.This means we no longer have any global LRUness to inode or dentry reclaim, which is going to significantly change caching behaviour. It's also got interesting corner cases like a workload running on a single node with a dentry/icache working set larger than the VM wants to hold on a single node.
Quoted 6 lines
We went through these sorts of problems with cpusets a few years back, and the workaround for it was not to limit the slab cache to the cpuset's nodes. Handling this sort of problem correctly seems distinctly non-trivial, so I'm really very reluctant to move in this direction without clear evidence that we have no other alternative....
As I explained in the other mail, that's not actaully how the per-zone reclaim works.
Thanks,
Nick
Quoted 3 lines · Dave Chinner
Sure, but I have to question how much of this is actually necessary? A lot of it looks like scalability for scalabilities sake, not because there is a demonstrated need...
Well, we've repeatedly run into problems with contention on the dcache_lock as well as the inode_lock; changes that improve those paths are extremely interesting to us. I've also seen numbers from systems with large (i.e. 32 to 64) numbers of cores that clearly show serious problems in this area.
Further, while this seems like a bunch of patches, a close look shows that it basically just pushes the dcache and inode locks down as far as possible, making other improvements (such as removal of a few atomics and no longer batching inode reclaims, among other things) based on that work. I would be hard-pressed to find much to cherry-pick from this patch set.
One interesting thing might be to do a set of performance tests for kernels with increasingly more of the patchset, just to see the effect of the earlier patches against a vanilla kernel and to measure the cumulative effect of the later patches. (I'm not volunteering, however:
ENOTIME.)
Signature · 2 lines
Frank Mayhar <[email protected]> Google, Inc.
Quoted 7 lines · Nick Piggin
Quoted 4 lines · Dave Chinner
Quoted 1 line · On Thu, Jun 24, 2010 at 01:02:12PM +1000, [email protected] wrote:
http://www.kernel.org/pub/linux/kernel/people/npiggin/patches/fs-scale/
Can you put a git tree up somewhere?
I suppose I should. I'll try to set one up.
Please! I was going to ask you this myself, in fact.
Signature · 2 lines
Frank Mayhar <[email protected]> Google, Inc.
Re: [patch 29/52] fs: icache lock i_count
In reply to Nick PigginQuoted 32 lines · Nick Piggin
Quoted 31 lines · Dave Chinner
Quoted 3 lines · On Thu, Jun 24, 2010 at 01:02:41PM +1000, [email protected] wrote:
Protect
inode->i_countwithi_lock, rather than having it atomic. Next step should also be to move things together (eg. the refcount increment intod_instantiate, which will remove a lock/unlock cycle oni_lock)......
Quoted 9 lines
Index:
linux-2.6/fs/inode.c
===================================================================fs/inode.c +0
-1@@ -33,14 +33,13 @@* inode_hash_lock protects: * inode hash table, i_hash * inode->i_lock protects: -* i_state fs/inode.c line 43
Quoted 10 lines
fs/inode.c +2
-2+* i_state, i_count * * Ordering: * inode_lock * sb_inode_list_lock * inode->i_lock -* inode_lock -* inode_hash_lock +* inode_hash_lock */ I thought that the rule governing the use of
inode->i_lockwas that it can be used anywhere as long as it is the innermost lock.Hmmm, no references in the code or documentation. Google gives a pretty good reference:
Quoted 8 lines
Quoted 3 lines
http://www.mail-archive.com/[email protected]/msg02584.html
Perhaps a different/new lock needs to be used here?
Well I just changed the order (and documented it to boot :)). It's pretty easy to verify that LOR is no problem. inode hash is only taken in a very few places so other code outside
inode.cis fine to usei_lockas an innermost lock.
It's not just the inode_hash_lock - you move four or five other locks under inode->i_lock as the series progresses. IOWs, there's now many paths and locking orders where the i_lock is not innermost. If we go forward with this, it's only going to get more complex and eventually somewhere we'll need a new lock for an innermost operation because inode->i_lock is no longer safe to use....
Seriously: use a new lock for high level inode operations you are optimising - don't repurpose an existing lock with different usage rules just because it's convenient.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [patch 37/52] fs: icache lazy lru
In reply to Nick PigginQuoted 13 lines · Nick Piggin
Quoted 12 lines · Dave Chinner
Quoted 2 lines · On Thu, Jun 24, 2010 at 01:02:49PM +1000, [email protected] wrote:
Impelemnt lazy inode lru similarly to dcache. This will reduce lock acquisition and will help to improve lock ordering subsequently.
I'm not sure we want the
I_REFERENCEDreclaim free pass for a clean inode that has been put on the LRU directly. I can see exactly how it is benficial to delay reclaim of dirty inodes (XFS uses that trick), but in terms of aging the cache we've already done this free pass trick at the dentry level. Hence I think the frequent separate access patterns tend to be filtered out at the dcache level and hence we don't need to handle that in the inode cache.
Quoted 5 lines
Quoted 3 lines
Perhaps we only need the
I_REFERENCEDflag to give dirty inodes a chance to be flushed by other means before forcing reclaim to do inode writeback?It doesn't force flush, but it force invalidates pagecache.
Sorry, bad choice of words - I should have said "forcing reclaim to wait on inode writeback". That is what will happen in the case of delayed allocation - the page cache will be clean, but the inode can be dirty, so reclaiming such an inode would cause the shrinker to block in clear_inode() waiting for inode writeback to complete.
However, that is mostly irrelevant - you haven't comented at all on whether the I_REFERENCED flag is too broad or even needed which is what really needs to be discussed about this patch....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [patch 44/52] fs: icache per-CPU sb inode lists and locks
In reply to Nick PigginQuoted 63 lines · Nick Piggin
Quoted 53 lines · Dave Chinner
Quoted 1 line · On Thu, Jun 24, 2010 at 01:02:56PM +1000, [email protected] wrote:
Signed-off-by Nick Piggin <[email protected]>.....
Quoted 50 lines
include/linux/fs.h +46
-0@@ -2194,6 +2198,58 @@ static inline void insert_inode_hash(strextern void file_sb_list_add (struct file *f,struct super_block *sb);extern void file_sb_list_del (struct file *f); +#ifdef CONFIG_SMP + +/* +* These macros iterate all inodes on all CPUs for a given superblock. +* rcu_read_lock must be held. +*/ +#define do_inode_list_for_each_entry_rcu (__sb, __inode) \ +{ \ + int i; \ + for_each_possible_cpu(i) { \ + struct list_head *list; \ + list = per_cpu_ptr((__sb)->s_inodes, i); \ + list_for_each_entry_rcu((__inode), list, i_sb_list) + +#define while_inode_list_for_each_entry_rcu \ + } \ +} + +#define do_inode_list_for_each_entry_safe (__sb, __inode, __tmp) \ +{ \ + int i; \ + for_each_possible_cpu(i) { \ + struct list_head *list; \ + list = per_cpu_ptr((__sb)->s_inodes, i); \ + list_for_each_entry_safe((__inode), (__tmp), list, i_sb_list) + +#define while_inode_list_for_each_entry_safe \ + } \ +} + +#else + +#define do_inode_list_for_each_entry_rcu (__sb, __inode) \ +{ \ + struct list_head *list; \ + list = &(sb)->s_inodes; \ + list_for_each_entry_rcu((__inode), list, i_sb_list) + +#define while_inode_list_for_each_entry_rcu \ +} + +#define do_inode_list_for_each_entry_safe (__sb, __inode, __tmp) \ +{ \ + struct list_head *list; \ + list = &(sb)->s_inodes; \ + list_for_each_entry_rcu((__inode), (__tmp), list, i_sb_list)Quoted 8 lines
include/linux/fs.h static inline void insert_inode_hash(str · line 2229
Quoted 3 lines
include/linux/fs.h +3
-0+ +#define while_inode_list_for_each_entry_safe \ +}I can't say that I'm a great fan of hiding loop context in defines like this. It reminds far too much of how parts of Irix slowly ossified because they ended up mess of complex, fragile macros that nobody fully understood...
Quoted 3 lines
It's not perfect. I think it is a lot better than open coding (which I tried before) because that really muddies up the intention of the loop body.
Something like this doesn't seem particularly bad:
static inline struct list_head *inode_get_sb_list(struct super_block *sb, int *i)
{
int cpu;
cpu = cpumask_next(i, cpu_possible_mask);
if (cpu >= nr_cpu_ids)
return NULL;
*i = cpu;
#ifdef CONFIG_SMP
return per_cpu_ptr(sb->s_inodes, cpu);
#else
return &sb->s_inodes;#endif
}
and:
struct list_head *list;
int i;
....
i = -1;
while ((list = inode_get_sb_list(sb, &i))) {
list_for_each_entry_rcu(inode, tmp, list, i_sb_list) {
.....
}
}I'd much prefer this to hiding the outer loop in macros...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [patch 52/52] fs: icache less I_FREEING time
In reply to Nick PigginQuoted 7 lines · Nick Piggin
Quoted 6 lines · Dave Chinner
Quoted 4 lines · On Thu, Jun 24, 2010 at 01:03:04PM +1000, [email protected] wrote:
Problem with inode reclaim is that it puts inodes into
I_FREEINGstate and then continues to gather more, during which it may iput,invalidate_mapping_pages, be preempted, etc. Holding these inodes inI_FREEINGcan cause pauses.
Quoted 6 lines
Quoted 2 lines
What sort of pauses? I can't see how holding a few inodes in
I_FREEINGstate would cause any serious sort of holdoff...Well if the inode is accessed again, it has to wait for potentially hundreds of inodes to be found from the LRU, pagecache invalidated, and destroyed.
So it's a theoretical concern you have, not something that's actually been demonstrated as a problem?
As it is, If the inode is accessed immediately after teardown has started, then we failed to hold on to the inode at a higher level for long enough. Changing the I_FREEING behaviour is trying to address the issue at the wrong level...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 9 lines · Nick Piggin
Quoted 8 lines · Dave Chinner
Quoted 6 lines · On Thu, Jun 24, 2010 at 01:02:12PM +1000, [email protected] wrote:
Performance:
Last time I was testing on a 32-node Altix which could be considered as not a sweet-spot for Linux performance target (ie. improvements there may not justify complexity). So recently I've been testing with a tightly interconnected 4-socket Nehalem (4s/32c/64t). Linux needs to perform well on this size of system.
Quoted 8 lines
Quoted 3 lines
Sure, but I have to question how much of this is actually necessary? A lot of it looks like scalability for scalabilities sake, not because there is a demonstrated need...
People are complaining about vfs scalability already (at least Intel, Google, IBM, and networking people). By the time people start shouting, it's too late because it will take years to get the patches merged. I'm not counting -rt people who have a bad time with global vfs locks.
I'm not denying it that we need to do work here - I'm questioning the "change everything at once" approach this patch set takes. You've started from the assumption that everything the dcache_lock and inode_lock protect are a problem and goes from there.
However, if we move some things out fom under the dcache lock, then the pressure on the lock goes down and the remaining operations may not hinder scalability. That's what I'm trying to understand, and why I'm suggesting that you need to break this down into smaller, more easily verifable, benchamrked patch sets. IMO, I have no way of verifying if any of these patches are necessary or not, and I need to understand that as part of reviewing them...
Quoted 13 lines
Quoted 9 lines
Quoted 8 lines
*** 64 parallel git diff on 64 kernel trees fully cached (avg of 5 runs):
vanilla vfs real 0m4.911s 0m0.183s user 0m1.920s 0m1.610s sys 4m58.670s 0m5.770sAfter vfs patches, 26x increase in throughput, however parallelism is limited by test spawning and exit phases. sys time improvement shows closer to 50x improvement. vanilla is bottlenecked on
dcache_lock.Quoted 3 lines
So if we cherry pick patches out of the series, what is the bare minimum set needed to obtain a result in this ballpark? Same for the other tests?
Quoted 6 lines
Well it's very hard to just scale up bits and pieces because the
dcache_lockis currently basically global (except ford_flagsand some cases ofd_countmanipulations).Start chipping away at bits and pieces of it as people hit bottlenecks and I think it will end in a bigger mess than we have now.
I'm not suggesting that we should do this randomly. A more structured approach that demonstrates the improvement as groups of changes are made will help us evaluate the changes more effectively. It may be that we need every single change in the patch series, but there is no way we can verify that with the information that has been provided.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [patch 29/52] fs: icache lock i_count
In reply to Dave ChinnerQuoted 42 lines · Dave Chinner
Quoted 32 lines · Nick Piggin
Quoted 31 lines · Dave Chinner
Quoted 3 lines · On Thu, Jun 24, 2010 at 01:02:41PM +1000, [email protected] wrote:
Protect
inode->i_countwithi_lock, rather than having it atomic. Next step should also be to move things together (eg. the refcount increment intod_instantiate, which will remove a lock/unlock cycle oni_lock)......
Quoted 9 lines
Index:
linux-2.6/fs/inode.c
===================================================================fs/inode.c +0
-1@@ -33,14 +33,13 @@* inode_hash_lock protects: * inode hash table, i_hash * inode->i_lock protects: -* i_state fs/inode.c line 43
Quoted 10 lines
fs/inode.c +2
-2+* i_state, i_count * * Ordering: * inode_lock * sb_inode_list_lock * inode->i_lock -* inode_lock -* inode_hash_lock +* inode_hash_lock */ I thought that the rule governing the use of
inode->i_lockwas that it can be used anywhere as long as it is the innermost lock.Hmmm, no references in the code or documentation. Google gives a pretty good reference:
Quoted 8 lines
Quoted 3 lines
http://www.mail-archive.com/[email protected]/msg02584.html
Perhaps a different/new lock needs to be used here?
Well I just changed the order (and documented it to boot :)). It's pretty easy to verify that LOR is no problem. inode hash is only taken in a very few places so other code outside
inode.cis fine to usei_lockas an innermost lock.
Quoted 6 lines
It's not just the
inode_hash_lock- you move four or five other locks underinode->i_lockas the series progresses. IOWs, there's now many paths and locking orders where thei_lockis not innermost. If we go forward with this, it's only going to get more complex and eventually somewhere we'll need a new lock for an innermost operation becauseinode->i_lockis no longer safe to use....
OK yes it's more than one lock, but I don't quite see the problem. The locks are mostly confined to inode.c and fs-writeback.c, and filesystems can basically use i_lock as inner most for their purposes. If they get it wrong, lockdep will tell them pretty quick. And it's documented to boot.
Quoted 3 lines
Seriously: use a new lock for high level inode operations you are optimising - don't repurpose an existing lock with different usage rules just because it's convenient.
That's what scalability development is all about, I'm afraid. Just adding more and more locks is what makes things more complex, so you have to juggle around or change locks when possible. If there is a difficulty with locking pops up in future, I'd prefer to look at it then.
I don't think any filesystems cared at all when I converted them.
Re: [patch 37/52] fs: icache lazy lru
In reply to Dave ChinnerQuoted 18 lines · Dave Chinner
Quoted 17 lines · Nick Piggin
Quoted 15 lines · Dave Chinner
Quoted 2 lines · On Thu, Jun 24, 2010 at 01:02:49PM +1000, [email protected] wrote:
Impelemnt lazy inode lru similarly to dcache. This will reduce lock acquisition and will help to improve lock ordering subsequently.
I'm not sure we want the
I_REFERENCEDreclaim free pass for a clean inode that has been put on the LRU directly. I can see exactly how it is benficial to delay reclaim of dirty inodes (XFS uses that trick), but in terms of aging the cache we've already done this free pass trick at the dentry level. Hence I think the frequent separate access patterns tend to be filtered out at the dcache level and hence we don't need to handle that in the inode cache.Perhaps we only need the
I_REFERENCEDflag to give dirty inodes a chance to be flushed by other means before forcing reclaim to do inode writeback?
Quoted 8 lines
Quoted 1 line
It doesn't force flush, but it force invalidates pagecache.
Sorry, bad choice of words - I should have said "forcing reclaim to wait on inode writeback". That is what will happen in the case of delayed allocation - the page cache will be clean, but the inode can be dirty, so reclaiming such an inode would cause the shrinker to block in
clear_inode()waiting for inode writeback to complete.
OK.
Quoted 3 lines
However, that is mostly irrelevant - you haven't comented at all on whether the
I_REFERENCEDflag is too broad or even needed which is what really needs to be discussed about this patch....
Well when moving from non-lazy to lazy, I think I_REFERENCED makes sense, and matched what dcache did when it went to lazy LRU. Otherwise inodes on the LRU list stay basically in the order that they were added to the list, and have no relation to when they were last used, I don't think that's a good idea.
Re: [patch 44/52] fs: icache per-CPU sb inode lists and locks
In reply to Dave ChinnerQuoted 40 lines · Dave Chinner
Quoted 8 lines · Nick Piggin
Quoted 4 lines
I can't say that I'm a great fan of hiding loop context in defines like this. It reminds far too much of how parts of Irix slowly ossified because they ended up mess of complex, fragile macros that nobody fully understood...
It's not perfect. I think it is a lot better than open coding (which I tried before) because that really muddies up the intention of the loop body.
Something like this doesn't seem particularly bad:
static inline struct
list_head*inode_get_sb_list(struct super_block *sb, int *i){ int cpu; cpu = cpumask_next(i, cpu_possible_mask); if (cpu >= nr_cpu_ids) return NULL; *i = cpu; #ifdef CONFIG_SMP return per_cpu_ptr(sb->s_inodes, cpu); #else return &sb->s_inodes;#endif
}and:
struct list_head *list; int i; .... i = -1; while ((list = inode_get_sb_list(sb, &i))) { list_for_each_entry_rcu(inode, tmp, list, i_sb_list) { ..... } }
Quoted 1 line
I'd much prefer this to hiding the outer loop in macros...
I don't see it as an improvement. A macro called inode_sb_list_for_each_entry is rather obvious and idiomatic as to what it does. You don't need to look at the implementation if you just need to walk the inode sb list.
Re: [patch 52/52] fs: icache less I_FREEING time
In reply to Dave ChinnerQuoted 11 lines · Dave Chinner
Quoted 10 lines · Nick Piggin
Quoted 8 lines · Dave Chinner
Quoted 4 lines · On Thu, Jun 24, 2010 at 01:03:04PM +1000, [email protected] wrote:
Problem with inode reclaim is that it puts inodes into
I_FREEINGstate and then continues to gather more, during which it may iput,invalidate_mapping_pages, be preempted, etc. Holding these inodes inI_FREEINGcan cause pauses.What sort of pauses? I can't see how holding a few inodes in
I_FREEINGstate would cause any serious sort of holdoff...
Quoted 6 lines
Quoted 3 lines
Well if the inode is accessed again, it has to wait for potentially hundreds of inodes to be found from the LRU, pagecache invalidated, and destroyed.
So it's a theoretical concern you have, not something that's actually been demonstrated as a problem?
Yes it causes holdoffs. I actually started visibly seeing the problem badly in my parallel git diff workload as I started experimenting with increasing batch size.
But even smaller batches could have a problem if the wrong inode is hit. I didn't add instrumentation in there, but I just didn't see such a benefit from batching after the lock breakups, so I prefer to go the other way and add back batching and its downsides IF that proves to be an improvement.
Is this of any consequence for the filesystem?
Quoted 3 lines
As it is, If the inode is accessed immediately after teardown has started, then we failed to hold on to the inode at a higher level for long enough.
Or simply didn't anticpate userspace access pattern.
Quoted 2 lines
Changing the
I_FREEINGbehaviour is trying to
address the issue at the wrong level...
Reclaim should of course be as good as possible. But it is inherntly going to have problems. You need to design everything around reclaim thinking about the possibility that it will go wrong. Because it will, in unreproducable ways, on a customer's machine.
Quoted 24 lines · Dave Chinner
Quoted 9 lines · Nick Piggin
Quoted 8 lines · Dave Chinner
Quoted 6 lines · On Thu, Jun 24, 2010 at 01:02:12PM +1000, [email protected] wrote:
Performance:
Last time I was testing on a 32-node Altix which could be considered as not a sweet-spot for Linux performance target (ie. improvements there may not justify complexity). So recently I've been testing with a tightly interconnected 4-socket Nehalem (4s/32c/64t). Linux needs to perform well on this size of system.Quoted 8 lines
Quoted 3 lines
Sure, but I have to question how much of this is actually necessary? A lot of it looks like scalability for scalabilities sake, not because there is a demonstrated need...
People are complaining about vfs scalability already (at least Intel, Google, IBM, and networking people). By the time people start shouting, it's too late because it will take years to get the patches merged. I'm not counting -rt people who have a bad time with global vfs locks.
I'm not denying it that we need to do work here - I'm questioning the "change everything at once" approach this patch set takes. You've started from the assumption that everything the
dcache_lockandinode_lockprotect are a problem and goes from there.
Quoted 7 lines
However, if we move some things out fom under the dcache lock, then the pressure on the lock goes down and the remaining operations may not hinder scalability. That's what I'm trying to understand, and why I'm suggesting that you need to break this down into smaller, more easily verifable, benchamrked patch sets. IMO, I have no way of verifying if any of these patches are necessary or not, and I need to understand that as part of reviewing them...
I can see where you're coming from, and I tried to do that, but it got pretty hard and messy. Also, it was pretty difficult to lift dcache and inode lock out of many paths unless *everything* else was protected by other locks. It is also hard not to introduce more atomic operations and slow down single thread performance.
It's not so much the lock hold times as the cacheline bouncing that hurts most. So when adding or removing a dentry for example, we manipulate hash, lru, inode alias, parent, and the fields in the dentry itself. If you have to take the dcache_lock for any of those manipulations, you incur the global cacheline bounce for that operation.
Honestly, I like the way the locking turned out. In dcache.c, inode.c and fs-writeback.c it is complex, but it always has been. For filesystems I would say it is simpler.
Need to stabilize a dentry? Take dentry->d_lock. This freezes all its fields, its refcount, pins it in (or out of) data structures, and pins its immediate parent and children, and inode we point to. Same for inodes.
The rest of the data structures (hash, lru, io lists, inode alias lists etc) that they may belong to, are protected by individual, narrow locks.
Quoted 20 lines
Quoted 13 lines
Quoted 9 lines
Quoted 8 lines
*** 64 parallel git diff on 64 kernel trees fully cached (avg of 5 runs):
vanilla vfs real 0m4.911s 0m0.183s user 0m1.920s 0m1.610s sys 4m58.670s 0m5.770sAfter vfs patches, 26x increase in throughput, however parallelism is limited by test spawning and exit phases. sys time improvement shows closer to 50x improvement. vanilla is bottlenecked on
dcache_lock.Quoted 3 lines
So if we cherry pick patches out of the series, what is the bare minimum set needed to obtain a result in this ballpark? Same for the other tests?
Quoted 6 lines
Well it's very hard to just scale up bits and pieces because the
dcache_lockis currently basically global (except ford_flagsand some cases ofd_countmanipulations).Start chipping away at bits and pieces of it as people hit bottlenecks and I think it will end in a bigger mess than we have now.
Quoted 6 lines
I'm not suggesting that we should do this randomly. A more structured approach that demonstrates the improvement as groups of changes are made will help us evaluate the changes more effectively. It may be that we need every single change in the patch series, but there is no way we can verify that with the information that has been provided.
I didn't say randomly, but piece-wise, reducing locks bit by bit as problems are quantified. Doing that means that all the code has to go *far more* locking-scheme transitions and it's harder to come to a clean overall end result.
Re: [patch 29/52] fs: icache lock i_count
In reply to Nick PigginQuoted 6 lines · Nick Piggin
On Thu, Jul 01, 2010 at 12:36:18PM +1000, Dave Chinner wrote:
If there is a
difficulty with locking pops up in future, I'd prefer to look at it then.I don't think any filesystems cared at all when I converted them.
What I mean by this is that _today_ no filesystems seemed to have any problems with how I did it. I did touch quota and notify code, which iterates inode sb lists, but it was pretty trivial. Not many others are about inode locking details enough to care about any of the locks in fs/inode.c.
And so instead of adding another lock now when I already have a (IMO) nice and working code, I will prefer to wait until some fs development runs into problem with locking.
There are several things that can be done. Using RCU for more of the inode lists is a possibility, and can improve lock order problems while actually reducing the amount of locking rather than adding locks.
Re: [patch 29/52] fs: icache lock i_count
In reply to Nick PigginQuoted 10 lines · Nick Piggin
Quoted 3 lines · Dave Chinner
Seriously: use a new lock for high level inode operations you are optimising - don't repurpose an existing lock with different usage rules just because it's convenient.
That's what scalability development is all about, I'm afraid. Just adding more and more locks is what makes things more complex, so you have to juggle around or change locks when possible. If there is a difficulty with locking pops up in future, I'd prefer to look at it then.
I must agree strongly with Nick here. Lock proliferation is a Bad Thing; adding a new lock here just adds complexity without really improving anything, since you still have to deal with lock ordering _and_ add a new one to the mix. It also makes struct inode bigger for no real gain. Since i_lock is already well understood and its use is pretty isolated, it seems ideal to extend it to more general use while keeping the isolation intact as much as possible. Hell, if the code were designed with this kind of scalability in mind, i_lock would be doing all the locking directly related to struct inode. Much as it is after Nick's work.
My argument here is that it's not just convenient, it makes the implementation simpler since instead of dealing with two locks there's just one.
Signature · 2 lines
Frank Mayhar <[email protected]> Google, Inc.
Quoted 4 lines · Nick Piggin
But actually it's not all for scalability. I have some follow on patches (that require RCU inodes, among other things) that actually improve single threaded performance significnatly. git diff workload IIRC was several % improved from speeding up stat(2).
I rewrote the store-free path walk patch that goes on top of this patchset (it's now much cleaner and more optimised, I'll post a patch soonish). It is quicker than I remembered.
A single thread running stat(2) in a loop on a file "./file" has the following cost (on an 2s8c Barcelona):
2.6.35-rc3 595 ns/op
patched 336 ns/op
stat(2) takes 56% the time with patches. It's something like 13 fewer atomic operations per syscall.
What's that good for? A single threaded, cached git diff on the linux kernel tree takes just 81% of the time after the vfs patches (0.27s vs 0.33s).
Quoted 4 lines · Nick Piggin
What's that good for? A single threaded, cached
git diffon the linux kernel tree takes just 81% of the time after the vfs patches (0.27s vs 0.33s).
That's very cool!
Hopefully we can make some progress on the whole patchkit now.
-Andi
Quoted 8 lines · Nick Piggin
Quoted 4 lines
That's a pretty big ouch. Why does RCU freeing of inodes cause that much regression? The RCU freeing is out of line, so where does the big impact come from?
That comes mostly from inability to reuse the cache-hot inode structure, and the cost to go over the deferred RCU list and free them after they get cache cold.
I do wonder if this isn't a big design bug.
Most of the time with RCU, we don't need to wait to actually do the _freeing_ of the individual data structure, we only need to make sure that the data structure remains of the same _type_. IOW, we can free it (and re-use it), but the backing storage cannot be released to the page cache. That's what SLAB_DESTROY_BY_RCU should give us.
Is that not possible in this situation? Do we really need to keep the inode _identity_ around for RCU?
If you use just SLAB_DESTROY_BY_RCU, then inode re-use remains, and cache behavior would be much improved. The usual requirement for SLAB_DESTROY_BY_RCU is that you only touch a lock (and perhaps re-validate the identity) in the RCU-reader paths. Could that be made to work?
Because that 27% drop really is pretty distressing.
That said, open (of the non-creating kind), close, and stat are certainly more important than creating and freeing files. So as a trade-off, it's probably the right thing to do. But if we can get all the improvement _without_ that big downside, that would obviously be better yet.
Linus
Quoted 5 lines · Dave Chinner
I'm not denying it that we need to do work here - I'm questioning the "change everything at once" approach this patch set takes. You've started from the assumption that everything the
dcache_lockandinode_lockprotect are a problem and goes from there.
Global code locks in a core subsystem are definitely a problem.
In many ways they're as bad a a BKL. There will be always workloads where they hurt. They are bad coding style. They just have to go.
I don't understand how anyone can even defend them.
Especially bad are code locks that protect lots of different things. Those are not only bad for scalability, but also bad for maintainability, because few people can really understand them even. With smaller well defined locks that's usually easier.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Quoted 11 lines · Linus Torvalds
Quoted 8 lines · Nick Piggin
Quoted 4 lines
That's a pretty big ouch. Why does RCU freeing of inodes cause that much regression? The RCU freeing is out of line, so where does the big impact come from?
That comes mostly from inability to reuse the cache-hot inode structure, and the cost to go over the deferred RCU list and free them after they get cache cold.
I do wonder if this isn't a big design bug.
It's possible, yes. Although a lot of that drop does come from hitting RCU and overruning slab allocator queues. It was what, closer to 10% when doing small numbers of creat/unlink loops.
Quoted 6 lines
Most of the time with RCU, we don't need to wait to actually do the _freeing_ of the individual data structure, we only need to make sure that the data structure remains of the same _type_. IOW, we can free it (and re-use it), but the backing storage cannot be released to the page cache. That's what
SLAB_DESTROY_BY_RCUshould give us.
Quoted 8 lines
Is that not possible in this situation? Do we really need to keep the inode _identity_ around for RCU?
If you use just
SLAB_DESTROY_BY_RCU, then inode re-use remains, and cache behavior would be much improved. The usual requirement forSLAB_DESTROY_BY_RCUis that you only touch a lock (and perhaps re-validate the identity) in the RCU-reader paths. Could that be made to work?
I definitely thought of that. I actually thought it would not be possible with the store-free path walk patches though, because we need to check some inode properties (eg. permission). So I was thinking the usual approach of taking a per-entry lock defeats the whole purpose of store-free path walk.
But you've got me to think about it again and it should be possible to do just using the dentry seqlock. IOW, if the inode gets disconnected from the dentry (and then can get possibly freed and reused) then just retry the lookup.
It may be a little tricky. I'll wait until the path-walk code is more polished first.
Quoted 8 lines
Because that 27% drop really is pretty distressing.
That said, open (of the non-creating kind), close, and stat are certainly more important than creating and freeing files. So as a trade-off, it's probably the right thing to do. But if we can get all the improvement _without_ that big downside, that would obviously be better yet.
We have actually bigger regressions than that for other code paths. The RCU freeing for files structs causes similar, about 20-30% regression in open/close.
I actually have a (proper) patch to make that use DESTROY_BY_RCU too. It actually slows down fd lookup by a tiny bit, though (lock, load, branch, increment, unlock versus atomic inc). But same number of atomic ops.
Quoted 12 lines · Linus Torvalds
Quoted 8 lines · Nick Piggin
Quoted 4 lines
That's a pretty big ouch. Why does RCU freeing of inodes cause that much regression? The RCU freeing is out of line, so where does the big impact come from?
That comes mostly from inability to reuse the cache-hot inode structure, and the cost to go over the deferred RCU list and free them after they get cache cold.
I do wonder if this isn't a big design bug.
Quoted 8 lines
Most of the time with RCU, we don't need to wait to actually do the _freeing_ of the individual data structure, we only need to make sure that the data structure remains of the same _type_. IOW, we can free it (and re-use it), but the backing storage cannot be released to the page cache. That's what
SLAB_DESTROY_BY_RCUshould give us.Is that not possible in this situation? Do we really need to keep the inode _identity_ around for RCU?
In this case, the workload can be very update-heavy, so this type-safe (vs. identity-safe) approach indeed makes a lot of sense. But if this was a read-heavy situation (think SELinux or many areas in networking), the read-side simplifications and speedups that often come with identity safety would probably more than make up for the occasional grace-period-induced cache miss.
So, as a -very- rough rule of thumb, when less than a few percent of the accesses are updates, you most likely want identity safety. If more than half of the accesses can be updates, you probably want SLAB_DESTROY_BY_RCU-style type safety instead -- or maybe just straight locking. If you are somewhere in between, pick one randomly, if it works, go with it, otherwise try something else. ;-)
In this situation, a create/rename/delete workload would be quite update heavy, so, as you say, SLAB_DESTROY_BY_RCU is well worth looking into.
Thanx, Paul
Quoted 20 lines
If you use just
SLAB_DESTROY_BY_RCU, then inode re-use remains, and cache behavior would be much improved. The usual requirement forSLAB_DESTROY_BY_RCUis that you only touch a lock (and perhaps re-validate the identity) in the RCU-reader paths. Could that be made to work?Because that 27% drop really is pretty distressing.
That said, open (of the non-creating kind), close, and stat are certainly more important than creating and freeing files. So as a trade-off, it's probably the right thing to do. But if we can get all the improvement _without_ that big downside, that would obviously be better yet.
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Andrew Morton
maintainerRe: [patch 29/52] fs: icache lock i_count
In reply to Nick PigginQuoted 32 lines · On Wed, 30 Jun 2010 22:05:02 +1000 Nick Piggin <[email protected]> wrote:
Quoted 31 lines · Dave Chinner
Quoted 3 lines · On Thu, Jun 24, 2010 at 01:02:41PM +1000, [email protected] wrote:
Protect
inode->i_countwithi_lock, rather than having it atomic. Next step should also be to move things together (eg. the refcount increment intod_instantiate, which will remove a lock/unlock cycle oni_lock)......
Quoted 9 lines
Index:
linux-2.6/fs/inode.c
===================================================================fs/inode.c +0
-1@@ -33,14 +33,13 @@* inode_hash_lock protects: * inode hash table, i_hash * inode->i_lock protects: -* i_state fs/inode.c line 43
Quoted 10 lines
fs/inode.c +2
-2+* i_state, i_count * * Ordering: * inode_lock * sb_inode_list_lock * inode->i_lock -* inode_lock -* inode_hash_lock +* inode_hash_lock */ I thought that the rule governing the use of
inode->i_lockwas that it can be used anywhere as long as it is the innermost lock.Hmmm, no references in the code or documentation. Google gives a pretty good reference:
Quoted 8 lines
Quoted 3 lines
http://www.mail-archive.com/[email protected]/msg02584.html
Perhaps a different/new lock needs to be used here?
Well I just changed the order (and documented it to boot :)). It's pretty easy to verify that LOR is no problem. inode hash is only taken in a very few places so other code outside
inode.cis fine to usei_lockas an innermost lock.
um, nesting a kernel-wide singleton lock inside a per-inode lock is plain nutty.
Re: [patch 29/52] fs: icache lock i_count
Quoted 38 lines · Andrew Morton
Quoted 36 lines · On Wed, 30 Jun 2010 22:05:02 +1000 Nick Piggin <[email protected]> wrote:
Quoted 34 lines · Dave Chinner
Quoted 3 lines · On Thu, Jun 24, 2010 at 01:02:41PM +1000, [email protected] wrote:
Protect
inode->i_countwithi_lock, rather than having it atomic. Next step should also be to move things together (eg. the refcount increment intod_instantiate, which will remove a lock/unlock cycle oni_lock)......
Quoted 9 lines
Index:
linux-2.6/fs/inode.c
===================================================================fs/inode.c +0
-1@@ -33,14 +33,13 @@* inode_hash_lock protects: * inode hash table, i_hash * inode->i_lock protects: -* i_state fs/inode.c line 43
Quoted 10 lines
fs/inode.c +2
-2+* i_state, i_count * * Ordering: * inode_lock * sb_inode_list_lock * inode->i_lock -* inode_lock -* inode_hash_lock +* inode_hash_lock */ I thought that the rule governing the use of
inode->i_lockwas that it can be used anywhere as long as it is the innermost lock.Hmmm, no references in the code or documentation. Google gives a pretty good reference:
http://www.mail-archive.com/[email protected]/msg02584.html
Perhaps a different/new lock needs to be used here?
Quoted 7 lines
Quoted 4 lines
Well I just changed the order (and documented it to boot :)). It's pretty easy to verify that LOR is no problem. inode hash is only taken in a very few places so other code outside
inode.cis fine to usei_lockas an innermost lock.um, nesting a kernel-wide singleton lock inside a per-inode lock is plain nutty.
I think it worked out OK. Because the kernel-wide locks are really restricted in where they are to be used (ie. not in filesystems). So they're really pretty constrained to the inode management subsystem. So filesystems still get to really use i_lock as an inner most lock for their purposes.
And filesystems get to take i_lock and stop all manipulation of inode now. No changing of flags, moving it on/off lists etc behind its back. It really is about locking the data rather than the code.
The final ordering outcome looks like this:
* inode->i_lock
* inode_list_lglock * zone->inode_lru_lock * wb->b_lock * inode_hash_bucket lock
And it works like that because when you want to add or remove an inode from various data structures, you take the i_lock and then take each of these locks in turn, inside it. The alternative is to build a bigger lock ordering graph, and take all the locks up-front before taking i_lock. I did actaully try that and it ended up being worse, so I went this route.
I think taking a global lock in mark_inode_dirty is nutty (especially when that global lock is shared with hash management, LRU scanning, writeback, i_flags access... :) It's just a question of which is less nutty.
Andrew Morton
maintainerRe: [patch 29/52] fs: icache lock i_count
Quoted 57 lines · On Sat, 3 Jul 2010 13:41:23 +1000 Nick Piggin <[email protected]> wrote:
Quoted 38 lines · Andrew Morton
Quoted 36 lines · On Wed, 30 Jun 2010 22:05:02 +1000 Nick Piggin <[email protected]> wrote:
Quoted 34 lines · Dave Chinner
Quoted 3 lines · On Thu, Jun 24, 2010 at 01:02:41PM +1000, [email protected] wrote:
Protect
inode->i_countwithi_lock, rather than having it atomic. Next step should also be to move things together (eg. the refcount increment intod_instantiate, which will remove a lock/unlock cycle oni_lock)......
Quoted 9 lines
Index:
linux-2.6/fs/inode.c
===================================================================fs/inode.c +0
-1@@ -33,14 +33,13 @@* inode_hash_lock protects: * inode hash table, i_hash * inode->i_lock protects: -* i_state fs/inode.c line 43
Quoted 10 lines
fs/inode.c +2
-2+* i_state, i_count * * Ordering: * inode_lock * sb_inode_list_lock * inode->i_lock -* inode_lock -* inode_hash_lock +* inode_hash_lock */ I thought that the rule governing the use of
inode->i_lockwas that it can be used anywhere as long as it is the innermost lock.Hmmm, no references in the code or documentation. Google gives a pretty good reference:
http://www.mail-archive.com/[email protected]/msg02584.html
Perhaps a different/new lock needs to be used here?
Quoted 7 lines
Quoted 4 lines
Well I just changed the order (and documented it to boot :)). It's pretty easy to verify that LOR is no problem. inode hash is only taken in a very few places so other code outside
inode.cis fine to usei_lockas an innermost lock.um, nesting a kernel-wide singleton lock inside a per-inode lock is plain nutty.
I think it worked out OK. Because the kernel-wide locks are really restricted in where they are to be used (ie. not in filesystems). So they're really pretty constrained to the inode management subsystem. So filesystems still get to really use
i_lockas an inner most lock for their purposes.And filesystems get to take
i_lockand stop all manipulation of inode now. No changing of flags, moving it on/off lists etc behind its back. It really is about locking the data rather than the code.
Quoted 7 lines
The final ordering outcome looks like this:
*
inode->i_lock* inode_list_lglock * zone->inode_lru_lock * wb->b_lock * inode_hash_bucket lock
Apart from the conceptual vandalism, it means that any contention times and cache transfer times on those singleton locks will increase worst-case hold times of our nice, fine-grained i_lock.
Quoted 2 lines
And it works like that because when you want to add or remove an inode from various data structures, you take the
i_lock
Well that would be wrong. i_lock protects things *within* its inode. It's nonsensical to take i_lock when the inode is being added to or removed from external containers because i_lock doesn't protect those containers!
Quoted 10 lines
and then take each
of these locks in turn, inside it. The alternative is to build a bigger lock ordering graph, and take all the locks up-front before takingi_lock. I did actaully try that and it ended up being worse, so I went this route.I think taking a global lock in
mark_inode_dirtyis nutty (especially when that global lock is shared with hash management, LRU scanning, writeback,i_flagsaccess... :) It's just a question of which is less nutty.
Yes, inode_lock is bad news.
Re: [patch 29/52] fs: icache lock i_count
Quoted 23 lines · Andrew Morton
Quoted 14 lines · On Sat, 3 Jul 2010 13:41:23 +1000 Nick Piggin <[email protected]> wrote:
Quoted 2 lines · Andrew Morton
um, nesting a kernel-wide singleton lock inside a per-inode lock is plain nutty.
I think it worked out OK. Because the kernel-wide locks are really restricted in where they are to be used (ie. not in filesystems). So they're really pretty constrained to the inode management subsystem. So filesystems still get to really use
i_lockas an inner most lock for their purposes.And filesystems get to take
i_lockand stop all manipulation of inode now. No changing of flags, moving it on/off lists etc behind its back. It really is about locking the data rather than the code.Quoted 7 lines
The final ordering outcome looks like this:
*
inode->i_lock* inode_list_lglock * zone->inode_lru_lock * wb->b_lock * inode_hash_bucket lock
Quoted 3 lines
Apart from the conceptual vandalism, it means that any contention times and cache transfer times on those singleton locks will increase worst-case hold times of our nice, fine-grained
i_lock.
Yes you are quite right about contention times. I'll answer in two parts. First, why I don't think it should prove to be a big problem; second, what we can do to improve it if it does.
So a lot of things that previously required the much worse inode_lock now can use the i_lock (or other fine grained locks above). Also, the the contention only comes into play if we actually happen to hit the same i_lock at the same time, so the throughput oriented mainline should generally be OK, and -rt has priority inheretance that improves that situation.
IF this proves to be a problem -- I doubt it will, in fact I think that worst case contention experienced by filesystems and vfs will go down, significantly -- but if it is a problem, we can easily fix it up.
Because all of those above data structures can be traversed using RCU (hash list already is). That would make all the locks really only taken to put an inode on or off a list.
The other thing that can be trivially done is to introduce different locks. I don't have a problem with that, but like any other data structure, I just would like to wait and see where we have problems. The same argument applies to a lot of places that we use a single lock to lock different properties of an object. We use page_lock to protect page membership on or off LRU and pagecache lists for example, as well as various state transitions (eg. to writeback).
In summary, if there is a lock hold problem, it is easy to use RCU to reduce lock widths, or introduce a new per-inode lock to protect different parts of the inode structure.
Quoted 7 lines
Quoted 2 lines
And it works like that because when you want to add or remove an inode from various data structures, you take the
i_lockWell that would be wrong.
i_lockprotects things *within* its inode. It's nonsensical to takei_lockwhen the inode is being added to or removed from external containers becausei_lockdoesn't protect those containers!
Membership in a data structure is a property of the item, conceptually and literally when you're messing with list entries and such. There is no conceptual vandalism that I can tell.
And it just works better this way when lifting inode_lock (and dcache_lock). Currently, we do things like:
spin_lock(&inode_lock);add_to_list1add_to_list2inode->blah = somethingspin_unlock(&inode_lock);
If you lock list1, list2, and blah seperately, it is no longer an equivalent transformation: other code could find an inode on list1 that is now not on list2 and blah is not set.
The real data object of interest in all cases is the inode object. Other structures are just in aid of finding inode objects that have a particular property.
So it makes a lot of sense to have a lock to rule the inode (as opposed to now we have a lock to rule *all* inodes).
It is possible that locking can be reduced if some things are verified and carefully shown not to matter. I just don't see the need yet and it would make things overly complicated I think. Introducing any more complexity will sink this patchset.
Quoted 6 lines
Quoted 6 lines
and then take each
of these locks in turn, inside it. The alternative is to build a bigger lock ordering graph, and take all the locks up-front before takingi_lock. I did actaully try that and it ended up being worse, so I went this route.
Quoted 6 lines
Quoted 4 lines
I think taking a global lock in
mark_inode_dirtyis nutty (especially when that global lock is shared with hash management, LRU scanning, writeback,i_flagsaccess... :) It's just a question of which is less nutty.Yes,
inode_lockis bad news.
Hopefully not for long :)
Re: [patch 29/52] fs: icache lock i_count
Quoted 4 lines · Nick Piggin
It is possible that locking can be reduced if some things are verified and carefully shown not to matter. I just don't see the need yet and it would make things overly complicated I think. Introducing any more complexity will sink this patchset.
By overly complicated, I mean, for this patchset where locking is already been rewritten. It would then be no more complicated (actually far less) than equivalently trying to lift inode_lock from parts of the code where it is causing contention times.
Re: [patch 29/52] fs: icache lock i_count
In reply to Nick PigginQuoted 2 lines · Nick Piggin
So it makes a lot of sense to have a lock to rule the inode (as opposed to now we have a lock to rule *all* inodes).
I don't disagree with this approach - I object to the fact that you repurpose an existing lock and change it's locking rules to "rule the inode". We don't have any one lock that "rules the inode", anyway, so adding a new "i_list_lock" for the new VFS level locking strategies makes it a lot more self-contained. Fundamentally I'm less concerned about the additional memory usage than I am about having landmines planted around i_lock...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [patch 29/52] fs: icache lock i_count
Quoted 7 lines · Dave Chinner
Quoted 2 lines · Nick Piggin
So it makes a lot of sense to have a lock to rule the inode (as opposed to now we have a lock to rule *all* inodes).
I don't disagree with this approach - I object to the fact that you repurpose an existing lock and change it's locking rules to "rule the inode". We don't have any one lock that "rules the inode",
"rule the inode" was in regard to the inode cache / dirty / writeout handling; ie. what inode_lock is currently for. The idea is that in these code paths, we tend to want to take an inode, lock it, and then manipulate it (including putting it on or taking it off data structures).
Quoted 4 lines
anyway, so adding a new "
i_list_lock" for the new VFS level locking strategies makes it a lot more self-contained. Fundamentally I'm less concerned about the additional memory usage than I am about having landmines planted aroundi_lock...
(it's not just lists, its refcount and i_state too)
I just don't see a problem. _No_ filesystem takes any of the locks that nest inside i_lock. They may call some inode.c functions, but shouldn't do so while holding i_lock if they are treating i_lock as an innermost lock. So they can keep using i_lock. I did go through and attempt to look at all filesystems.
Within inode.c, lock ordering is 2 levels deep, same as it was when we had inode_lock and i_lock.
If some filesystem introduces a lock ordering problem from not reading the newly added documentation, lockdep should catch it pretty quick.
So I don't see a landmine they don't have (in much larger doses) with i_mutex, reentrant reclaim, page lock, buffer lock, mmap_sem etc already.
Theodore Tso
maintainerRe: [patch 29/52] fs: icache lock i_count
Quoted 11 lines · Nick Piggin
Quoted 9 lines · Dave Chinner
I don't disagree with this approach - I object to the fact that you repurpose an existing lock and change it's locking rules to "rule the inode". We don't have any one lock that "rules the inode", anyway, so adding a new "
i_list_lock" for the new VFS level locking strategies makes it a lot more self-contained. Fundamentally I'm less concerned about the additional memory usage than I am about having landmines planted aroundi_lock...
Quoted 3 lines
If some filesystem introduces a lock ordering problem from not reading the newly added documentation, lockdep should catch it pretty quick.
I assume you mean inline documentation in the source, because I quickly scanned the source and couldn't find any significant changes to any files in Documentation.
It would be nice if the new state of affairs is documented in a single file, so that people who want to understand this new locking system don't have to go crawling through the code, or searching mailing list archives to figure out what's going on.
A lot of the text in this mail thread, including your discussion of the new locking hierarchy, and why things are the way they are, would be good
fodder for a new documentation file. And if you don't want to renamei_lock, because no better name can be found, we should at least document that starting as of 2.6.35/36 the meaning of i_lock changed.
-- Ted
Re: [patch 29/52] fs: icache lock i_count
Quoted 17 lines · Theodore Tso
Quoted 11 lines · Nick Piggin
Quoted 9 lines · Dave Chinner
I don't disagree with this approach - I object to the fact that you repurpose an existing lock and change it's locking rules to "rule the inode". We don't have any one lock that "rules the inode", anyway, so adding a new "
i_list_lock" for the new VFS level locking strategies makes it a lot more self-contained. Fundamentally I'm less concerned about the additional memory usage than I am about having landmines planted aroundi_lock...Quoted 3 lines
If some filesystem introduces a lock ordering problem from not reading the newly added documentation, lockdep should catch it pretty quick.
Quoted 8 lines
I assume you mean inline documentation in the source, because I quickly scanned the source and couldn't find any significant changes to any files in Documentation.
It would be nice if the new state of affairs is documented in a single file, so that people who want to understand this new locking system don't have to go crawling through the code, or searching mailing list archives to figure out what's going on.
These type of internal details of lock ordering I think work best in source files (see rmap.c and filemap.c) so it's a little closer to the source code. That's in inode.c and dcache.c.
Locking for filesystem callback APIs I agree is just as good to be in Documentation/filesystems/Locking (which I need to update a bit), but it's never been used for this stuff before. I'm always open to suggestions of how to document it better though.
Quoted 5 lines
A lot of the text in this mail thread, including your discussion of the new locking hierarchy, and why things are the way they are, would be good
fodder for a new documentation file. And if you don't want to renamei_lock, because no better name can be found, we should at least document that starting as of 2.6.35/36 the meaning ofi_lockchanged.
Well there is not much definition of what i_lock is. It is really not an "innermost" lock anyway (whatever that exactly means). CEPH even takes dcache_lock inside i_lock. NFS uses it pretty extensively too.
So it really is *the* non sleeping lock to protect inode fields that I can see.
As far as filesystems go, inode changes matter very little really, but the best I can do is just to comment and document the locking and try to audit each filesystem.
Quoted 16 lines · Nick Piggin
Quoted 4 lines · Nick Piggin
But actually it's not all for scalability. I have some follow on patches (that require RCU inodes, among other things) that actually improve single threaded performance significnatly. git diff workload IIRC was several % improved from speeding up stat(2).
I rewrote the store-free path walk patch that goes on top of this patchset (it's now much cleaner and more optimised, I'll post a patch soonish). It is quicker than I remembered.
A single thread running stat(2) in a loop on a file "./file" has the following cost (on an 2s8c Barcelona):
2.6.35-rc3 595 ns/op
patched 336 ns/op
Quoted 6 lines
stat(2) takes 56% the time with patches. It's something like 13 fewer atomic operations per syscall.
What's that good for? A single threaded, cached
git diffon the linux kernel tree takes just 81% of the time after the vfs patches (0.27s vs 0.33s).
At the other end of the scale, I tried dbench on ramfs on the little 32n64c Altix. Dbench actually has statfs() call completely removed from the workload -- it's still a little problematic and patched kernel throughput is ~halved with statfs().
dbench procs 1 64
2.6.35-rc3 235MB/s 95MB/s ( 0.6% scaling)
patched 245MB/s 14870MB/s (94.8% scaling)
(note all these numbers are with store-free path walking patches on top of the posted patchset -- dbench procs do path walking from common cwds so it will never scale this well if we have to take refcounts on common dentries)
Thanks,
Nick
Re: [patch 24/52] fs: dcache reduce d_parent locking
In reply to Paul E. McKenneyHi Paul,
Sorry I had left this in my postponed folder while rechecking your questions and forgot about it :P
Quoted 27 lines · Paul E. McKenney
Quoted 4 lines · On Thu, Jun 24, 2010 at 01:02:36PM +1000, [email protected] wrote:
Use RCU property of dcache to simplify locking in some places where we take
d_parentandd_lock.Comment: don't need
rcu_derefbecause we take the spinlock and recheck it.Looks good other than one question below.
Thanx, Paul
Quoted 8 lines
Signed-off-by Nick Piggin <[email protected]>--
Index:
linux-2.6/fs/dcache.c
===================================================================fs/dcache.c struct dentry *dget_parent(struct dentry · line 315
Quoted 6 lines
fs/dcache.c +1
-1@@ -311,23 +311,18 @@ struct dentry *dget_parent(struct dentrystruct dentry *ret; repeat: -spin_lock (&dentry->d_lock); +rcu_read_lock (); ret = dentry->d_parent;Doesn't this need to be as follows?
Quoted 4 lines
ret = rcu_dereference(dentry)->d_parent;Otherwise, couldn't we end up seeing pre-initialization value for ->d_parent for a newly inserted dentry?
I don't think so. The child's dentry memory should be guaranteed to be post-initialized at the point it is passed to dget_parent, becase we've to have a stable refcount on it at that point. Ie. if it was pulled from an RCU list, it should already have been rcu dereferenced by now.
So ->d_parent should be a valid pointer with lifetime guarantee provided by RCU -- so enough to take the spinlock and recheck.
Quoted 15 lines
fs/dcache.c struct dentry *dget_parent(struct dentry · line 316
Quoted 10 lines
fs/dcache.c +1
-8-if (!ret) - goto out; -if (dentry == ret) { - ret->d_count++; - goto out; - } -if (!spin_trylock (&ret->d_lock)) { -spin_unlock (&dentry->d_lock); +spin_lock (&ret->d_lock);Once we do this, however, we are golden, at least for all dentry fields protected by ->lock. This does assume that the compiler does not speculate the fetch that initialized the argument dentry into the critical section, which I would sure hope would be a reasonable assumption.
Yes I think the above fact that we have a "good" ref on the dentry should prevent this.
Thanks,
Nick
Re: [patch 29/52] fs: icache lock i_count
In reply to Theodore TsoQuoted 5 lines · Theodore Tso
A lot of the text in this mail thread, including your discussion of the new locking hierarchy, and why things are the way they are, would be good
fodder for a new documentation file. And if you don't want to renamei_lock, because no better name can be found, we should at least document that starting as of 2.6.35/36 the meaning ofi_lockchanged.
Actually I like the idea of renaming i_lock. It adds a bit of code churn but renaming it to more clearly reflect its function makes sense to me and might catch uses of it that might have been missed earlier.
Signature · 2 lines
Frank Mayhar <[email protected]> Google, Inc.