vfs scalability patches updated
Subsystems (70)
cover vfs scalability patches updated
http://www.kernel.org/pub/linux/kernel/people/npiggin/patches/fs-scale/
Update to vfs scalability patches:
- Lots of fixes, particularly RCU inode stuff
- Lots of cleanups and aesthetic to the code, ifdef reduction etc
- Use bit locks for inode and dentry hashes
- Small improvements to single-threaded performance
- Split inode LRU and writeback list locking
- Per-bdi inode writeback list locking
- Per-zone mm shrinker
- Per-zone dentry and inode LRU lists
- Several fixes brought in from -rt tree testing
- No global locks remain in any fastpaths (arguably, rename)
I have not included the store-free path walk patches in this posting. They require a bit more work and they will need to be reworked after ->d_revalidate/->follow_mount changes that Al wants to do. I prefer to concentrate on these locking patches first.
Autofs4 is sadly missing. It's a bit tricky, patches have to be reworked.
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.
*** 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. We have have made the same magnitude of performance regression tradeoff when going to RCU freed dentries and files as well. Inode RCU is required for reducing inode hash lookup locking and improve lock ordering, also for store-free path-walk.
*** Let's take a look at this creat/unlink regression more closely. If we call rdtsc around the creat/unlink loop, and just run it once (so as to avoid much of the RCU induced problems):
vanilla: 5328 cycles
vfs: 5960 cycles (+11.8%)
Not so bad when RCU is not being stressed.
*** 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.770s
After 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.
*** Google sockets (http://marc.info/?l=linux-kernel&m=123215942507568&w=2):
vanilla vfs real 1m 7.774s 0m 3.245s user 0m19.230s 0m36.750s sys 71m41.310s 2m47.320s
do_exit path for
the run took 24.755s 1.219s
After vfs patches, 20x increase in throughput for both the total duration and the do_exit (teardown) time.
*** file-ops test (people.redhat.com/mingo/file-ops-test/file-ops-test.c) Parallel open/close or creat/unlink in same or different cwds within the same ramfs mount. Relative throughput percentages are given at each parallelism point (higher is better):
open/close vanilla vfs
same cwd
1 100.0 119.1
2 74.2 187.4 4 38.4 40.9 8 18.7 27.0 16 9.0 24.9 32 5.9 24.2 64 6.0 27.7 different cwd 1 100.0 119.1 2 133.0 238.6 4 21.2 488.6 8 19.7 932.6 16 18.8 1784.1 32 18.7 3469.5 64 19.0 2858.0
creat/unlink vanilla vfs
same cwd
1 100.0 75.0 2 44.1 41.8 4 28.7 24.6 8 16.5 14.2 16 8.7 8.9 32 5.5 7.8 64 5.9 7.4 different cwd 1 100.0 75.0 2 89.8 137.2 4 20.1 267.4 8 17.2 513.0 16 16.2 901.9 32 15.8 1724.0 64 17.3 1161.8
Note that at 64, we start using sibling threads on the CPU, making results jump around a bit. The drop at 64 in different-cwd cases seems to be hitting an RCU or slab allocator issue (or maybe it's just the SMT).
The scalability regression I was seeing in same-cwd tests is no longer there (is even improved now). It may still be present in some workloads doing common-element path lookups. This can be solved by making d_count atomic again, at the cost of more atomic ops in some cases, but scalability is still limited. So I prefer to do store-free path walking which is much more scalable.
In the different cwd open/close case, cost to bounce cachelines over the interconnect is putting absolute upper limit of 162K open/closes per second over the entire machine in vanilla kernel. After vfs patches, it is around 30M. On larger and less well connected machines, the lower limit will only get lower while the vfs case should continue to keep going up (assuming mm subsystem can keep up).
*** 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.
PATCH 3/52 fs: fs_struct rwlock to spinlock
struct fs_struct.lock is an rwlock with the read-side used to protect root and pwd members while taking references to them. Taking a reference to a path typically requires just 2 atomic ops, so the critical section is very small. Parallel read-side operations would have cacheline contention on the lock, the dentry, and the vfsmount cachelines, so the rwlock is unlikely to ever give a real parallelism increase.
Replace it with a spinlock to avoid one or two atomic operations in typical path lookup fastpath.
--- drivers/staging/pohmelfs/path_entry.c | 8 +++---- fs/cachefiles/daemon.c | 8 +++---- fs/dcache.c | 8 +++---- fs/exec.c | 4 +-- fs/fs_struct.c | 36 +++++++++++++++++----------------- fs/namei.c | 8 +++---- fs/namespace.c | 4 +-- fs/proc/base.c | 4 +-- include/linux/fs_struct.h | 2 - kernel/auditsc.c | 4 +-- kernel/fork.c | 10 ++++----- 11 files changed, 48 insertions(+), 48 deletions(-)
fs/dcache.c +4 -4
@@ -2012,10 +2012,10 @@ char *d_path(const struct path *path, chif (path->dentry->d_op && path->dentry->d_op->d_dname)return path->dentry->d_op->d_dname (path->dentry, buf, buflen); -read_lock (¤t->fs->lock); +spin_lock (¤t->fs->lock); root = current->fs->root;path_get (&root); -read_unlock (¤t->fs->lock); +spin_unlock (¤t->fs->lock);spin_lock (&dcache_lock); tmp = root; res =__d_path (path, &tmp, buf, buflen);
@@ -2110,12 +2110,12 @@ SYSCALL_DEFINE2(getcwd, char __user *, bif (!page)return -ENOMEM ; -read_lock (¤t->fs->lock); +spin_lock (¤t->fs->lock); pwd = current->fs->pwd;path_get (&pwd); root = current->fs->root;path_get (&root); -read_unlock (¤t->fs->lock); +spin_unlock (¤t->fs->lock); error = -ENOENT ;spin_lock (&dcache_lock);
fs/fs_struct.c +18 -18
@@ -13,11 +13,11 @@ void set_fs_root(struct fs_struct *fs, s {struct path old_root; -write_lock (&fs->lock); +spin_lock (&fs->lock); old_root = fs->root; fs->root = *path;path_get (path); -write_unlock (&fs->lock); +spin_unlock (&fs->lock);if (old_root.dentry)path_put (&old_root); }
@@ -30,11 +30,11 @@ void set_fs_pwd(struct fs_struct *fs, st {struct path old_pwd; -write_lock (&fs->lock); +spin_lock (&fs->lock); old_pwd = fs->pwd; fs->pwd = *path;path_get (path); -write_unlock (&fs->lock); +spin_unlock (&fs->lock);if (old_pwd.dentry)path_put (&old_pwd);
@@ -51,7 +51,7 @@ void chroot_fs_refs(struct path *old_rootask_lock (p); fs = p->fs;if (fs) { -write_lock (&fs->lock); +spin_lock (&fs->lock);if (fs->root.dentry == old_root->dentry && fs->root.mnt == old_root->mnt) {path_get (new_root);
@@ -64,7 +64,7 @@ void chroot_fs_refs(struct path *old_roo fs->pwd = *new_root; count++; } -write_unlock (&fs->lock); +spin_unlock (&fs->lock); }task_unlock (p); }while_each_thread (g, p);
@@ -87,10 +87,10 @@ void exit_fs(struct task_struct *tsk)if (fs) {int kill;task_lock (tsk); -write_lock (&fs->lock); +spin_lock (&fs->lock); tsk->fs =NULL ; kill = !--fs->users; -write_unlock (&fs->lock); +spin_unlock (&fs->lock);task_unlock (tsk);if (kill)free_fs_struct (fs);
@@ -104,14 +104,14 @@ struct fs_struct *copy_fs_struct(structif (fs) { fs->users =1 ; fs->in_exec =0 ; -rwlock_init (&fs->lock); +spin_lock_init (&fs->lock); fs->umask = old->umask; -read_lock (&old->lock); +spin_lock (&old->lock); fs->root = old->root;path_get (&old->root); fs->pwd = old->pwd;path_get (&old->pwd); -read_unlock (&old->lock); +spin_unlock (&old->lock); }return fs; }
@@ -126,10 +126,10 @@ int unshare_fs_struct(void)return -ENOMEM ;task_lock (current); -write_lock (&fs->lock); +spin_lock (&fs->lock); kill = !--fs->users; current->fs = new_fs; -write_unlock (&fs->lock); +spin_unlock (&fs->lock);task_unlock (current);if (kill)
@@ -148,7 +148,7 @@ EXPORT_SYMBOL(current_umask);/* to be mentioned only in INIT_TASK */ struct fs_struct init_fs = { .users =1 , - .lock =__RW_LOCK_UNLOCKED (init_fs.lock), + .lock =__SPIN_LOCK_UNLOCKED (init_fs.lock), .umask =0022 , };
@@ -161,14 +161,14 @@ void daemonize_fs_struct(void)task_lock (current); -write_lock (&init_fs.lock); +spin_lock (&init_fs.lock); init_fs.users++; -write_unlock (&init_fs.lock); +spin_unlock (&init_fs.lock); -write_lock (&fs->lock); +spin_lock (&fs->lock); current->fs = &init_fs; kill = !--fs->users; -write_unlock (&fs->lock); +spin_unlock (&fs->lock);task_unlock (current);if (kill)
fs/namei.c +4 -4
@@ -486,10 +486,10 @@ static __always_inline void set_root(str {if (!nd->root.mnt) {struct fs_struct *fs = current->fs; -read_lock (&fs->lock); +spin_lock (&fs->lock); nd->root = fs->root;path_get (&nd->root); -read_unlock (&fs->lock); +spin_unlock (&fs->lock); } }
@@ -1017,10 +1017,10 @@ static int path_init(int dfd, const charpath_get (&nd->root); }else if (dfd ==AT_FDCWD ) {struct fs_struct *fs = current->fs; -read_lock (&fs->lock); +spin_lock (&fs->lock); nd->path = fs->pwd;path_get (&fs->pwd); -read_unlock (&fs->lock); +spin_unlock (&fs->lock); }else {struct dentry *dentry;
fs/namespace.c +2 -2
@@ -2208,10 +2208,10 @@ SYSCALL_DEFINE2(pivot_root, const char _ goto out1; } -read_lock (¤t->fs->lock); +spin_lock (¤t->fs->lock); root = current->fs->root;path_get (¤t->fs->root); -read_unlock (¤t->fs->lock); +spin_unlock (¤t->fs->lock);down_write (&namespace_sem);mutex_lock (&old.dentry->d_inode->i_mutex); error = -EINVAL ;
include/linux/fs_struct.h +1 -1
@@ -5,7 +5,7 @@struct fs_struct {int users; -rwlock_t lock; +spinlock_t lock;int umask;int in_exec;struct path root, pwd;
fs/exec.c +2 -2
@@ -1117,7 +1117,7 @@ int check_unsafe_exec(struct linux_binpr bprm->unsafe =tracehook_unsafe_exec (p); n_fs =1 ; -write_lock (&p->fs->lock); +spin_lock (&p->fs->lock);rcu_read_lock ();for (t =next_thread (p); t != p; t =next_thread (t)) {if (t->fs == p->fs)
@@ -1134,7 +1134,7 @@ int check_unsafe_exec(struct linux_binpr res =1 ; } } -write_unlock (&p->fs->lock); +spin_unlock (&p->fs->lock);return res; }
fs/proc/base.c +2 -2
@@ -156,10 +156,10 @@ static int get_fs_path(struct task_structask_lock (task); fs = task->fs;if (fs) { -read_lock (&fs->lock); +spin_lock (&fs->lock); *path = root ? fs->root : fs->pwd;path_get (path); -read_unlock (&fs->lock); +spin_unlock (&fs->lock); result =0 ; }task_unlock (task);
kernel/fork.c +5 -5
@@ -752,13 +752,13 @@ static int copy_fs(unsigned long clone_fstruct fs_struct *fs = current->fs;if (clone_flags &CLONE_FS ) {/* tsk->fs is already what we want */ -write_lock (&fs->lock); +spin_lock (&fs->lock);if (fs->in_exec) { -write_unlock (&fs->lock); +spin_unlock (&fs->lock);return -EAGAIN ; } fs->users++; -write_unlock (&fs->lock); +spin_unlock (&fs->lock);return 0 ; } tsk->fs =copy_fs_struct (fs);
@@ -1675,13 +1675,13 @@ SYSCALL_DEFINE1(unshare, unsigned long,if (new_fs) { fs = current->fs; -write_lock (&fs->lock); +spin_lock (&fs->lock); current->fs = new_fs;if (--fs->users) new_fs =NULL ;else new_fs = fs; -write_unlock (&fs->lock); +spin_unlock (&fs->lock); }if (new_mm) {
drivers/staging/pohmelfs/path_entry.c +4 -4
@@ -44,9 +44,9 @@ int pohmelfs_construct_path_string(strucreturn -ENOENT ; } -read_lock (¤t->fs->lock); +spin_lock (¤t->fs->lock); path.mnt =mntget (current->fs->root.mnt); -read_unlock (¤t->fs->lock); +spin_unlock (¤t->fs->lock); path.dentry = d;
@@ -91,9 +91,9 @@ int pohmelfs_path_length(struct pohmelfsreturn -ENOENT ; } -read_lock (¤t->fs->lock); +spin_lock (¤t->fs->lock); root =dget (current->fs->root.dentry); -read_unlock (¤t->fs->lock); +spin_unlock (¤t->fs->lock);spin_lock (&dcache_lock);
fs/cachefiles/daemon.c +4 -4
@@ -574,9 +574,9 @@ static int cachefiles_daemon_cull(struct/* extract the directory dentry from the cwd */ fs = current->fs; -read_lock (&fs->lock); +spin_lock (&fs->lock); dir =dget (fs->pwd.dentry); -read_unlock (&fs->lock); +spin_unlock (&fs->lock);if (!S_ISDIR (dir->d_inode->i_mode)) goto notdir;
@@ -650,9 +650,9 @@ static int cachefiles_daemon_inuse(struc/* extract the directory dentry from the cwd */ fs = current->fs; -read_lock (&fs->lock); +spin_lock (&fs->lock); dir =dget (fs->pwd.dentry); -read_unlock (&fs->lock); +spin_unlock (&fs->lock);if (!S_ISDIR (dir->d_inode->i_mode)) goto notdir;
kernel/auditsc.c +2 -2
@@ -1838,10 +1838,10 @@ void __audit_getname(const char *name) context->names[context->name_count].osid =0 ; ++context->name_count;if (!context->pwd.dentry) { -read_lock (¤t->fs->lock); +spin_lock (¤t->fs->lock); context->pwd = current->fs->pwd;path_get (¤t->fs->pwd); -read_unlock (¤t->fs->lock); +spin_unlock (¤t->fs->lock); } }
PATCH 4/52 fs: cleanup files_lock
In reply to [email protected]Lock tty_files with a new spinlock, tty_files_lock; provide helpers to manipulate the per-sb files list; unexport the files_lock spinlock.
--- drivers/char/pty.c | 6 +++++- drivers/char/tty_io.c | 26 ++++++++++++++++++-------- fs/file_table.c | 42 ++++++++++++++++++------------------------ fs/open.c | 4 ++-- include/linux/fs.h | 7 ++----- include/linux/tty.h | 1 + security/selinux/hooks.c | 4 ++-- 7 files changed, 48 insertions(+), 42 deletions(-)
security/selinux/hooks.c +2 -2
@@ -2219,7 +2219,7 @@ static inline void flush_unauthorized_fi tty =get_current_tty ();if (tty) { -file_list_lock (); +spin_lock (&tty_files_lock);if (!list_empty (&tty->tty_files)) {struct inode *inode;
@@ -2235,7 +2235,7 @@ static inline void flush_unauthorized_fi drop_tty =1 ; } } -file_list_unlock (); +spin_unlock (&tty_files_lock);tty_kref_put (tty); }/* Reset controlling tty. */
drivers/char/pty.c +5 -1
@@ -650,7 +650,11 @@ static int __ptmx_open(struct inode *inoset_bit (TTY_PTY_LOCK , &tty->flags);/* LOCK THE SLAVE */ filp->private_data = tty; -file_move (filp, &tty->tty_files); + +file_sb_list_del (filp);/* __dentry_open has put it on the sb list */ +spin_lock (&tty_files_lock); +list_add (&filp->f_u.fu_list, &tty->tty_files); +spin_unlock (&tty_files_lock); retval =devpts_pty_new (inode, tty->link);if (retval)
drivers/char/tty_io.c +18 -8
@@ -136,6 +136,9 @@ LIST_HEAD(tty_drivers); /* linked listDEFINE_MUTEX (tty_mutex);EXPORT_SYMBOL (tty_mutex); +/* Spinlock to protect the tty->tty_files list */ +DEFINE_SPINLOCK (tty_files_lock); +static ssize_t tty_read (struct file *,char __user *,size_t ,loff_t *);static ssize_t tty_write (struct file *,const char __user *,size_t ,loff_t *); ssize_t redirected_tty_write(struct file *, const char __user *,
@@ -234,11 +237,11 @@ static int check_tty_count(struct tty_ststruct list_head *p;int count =0 ; -file_list_lock (); +spin_lock (&tty_files_lock);list_for_each (p, &tty->tty_files) { count++; } -file_list_unlock (); +spin_unlock (&tty_files_lock);if (tty->driver->type ==TTY_DRIVER_TYPE_PTY && tty->driver->subtype ==PTY_TYPE_SLAVE && tty->link && tty->link->count)
@@ -517,7 +520,7 @@ static void do_tty_hangup(struct work_stlock_kernel ();check_tty_count (tty,"do_tty_hangup" ); -file_list_lock (); +spin_lock (&tty_files_lock);/* This breaks for file handles being sent over AF_UNIX sockets ? */ list_for_each_entry (filp, &tty->tty_files, f_u.fu_list) {if (filp->f_op->write == redirected_tty_write)
@@ -528,7 +531,7 @@ static void do_tty_hangup(struct work_sttty_fasync (-1 , filp,0 );/* can't block */ filp->f_op = &hung_up_tty_fops; } -file_list_unlock (); +spin_unlock (&tty_files_lock);tty_ldisc_hangup (tty);
@@ -1419,9 +1422,9 @@ static void release_one_tty(struct work_tty_driver_kref_put (driver);module_put (driver->owner); -file_list_lock (); +spin_lock (&tty_files_lock);list_del_init (&tty->tty_files); -file_list_unlock (); +spin_unlock (&tty_files_lock);put_pid (tty->pgrp);put_pid (tty->session);
@@ -1666,7 +1669,10 @@ int tty_release(struct inode *inode, str* - do_tty_hangup no longer sees this file descriptor as * something that needs to be handled for hangups. */ -file_kill (filp); +spin_lock (&tty_files_lock); +BUG_ON (list_empty (&filp->f_u.fu_list)); +list_del_init (&filp->f_u.fu_list); +spin_unlock (&tty_files_lock); filp->private_data =NULL ;/*
@@ -1835,7 +1841,11 @@ got_driver: } filp->private_data = tty; -file_move (filp, &tty->tty_files); +BUG_ON (list_empty (&filp->f_u.fu_list)); +file_sb_list_del (filp);/* __dentry_open has put it on the sb list */ +spin_lock (&tty_files_lock); +list_add (&filp->f_u.fu_list, &tty->tty_files); +spin_unlock (&tty_files_lock);check_tty_count (tty,"tty_open" );if (tty->driver->type ==TTY_DRIVER_TYPE_PTY && tty->driver->subtype ==PTY_TYPE_MASTER )
fs/file_table.c +18 -24
104 lines not on this page · raw message
fs/open.c +2 -2
@@ -675,7 +675,7 @@ static struct file *__dentry_open(struct f->f_path.mnt = mnt; f->f_pos =0 ; f->f_op =fops_get (inode->i_fop); -file_move (f, &inode->i_sb->s_files); +file_sb_list_add (f, inode->i_sb); error =security_dentry_open (f, cred);if (error)
@@ -721,7 +721,7 @@ cleanup_all:mnt_drop_write (mnt); } } -file_kill (f); +file_sb_list_del (f); f->f_path.dentry =NULL ; f->f_path.mnt =NULL ; cleanup_file:
include/linux/fs.h +2 -5
@@ -949,9 +949,6 @@ struct file {unsigned long f_mnt_write_state;#endif }; -extern spinlock_t files_lock; -#define file_list_lock () spin_lock(&files_lock); -#define file_list_unlock () spin_unlock(&files_lock);#define get_file (x) atomic_long_inc(&(x)->f_count)#define fput_atomic (x) atomic_long_add_unless(&(x)->f_count, -1, 1)
@@ -2182,8 +2179,8 @@ static inline void insert_inode_hash(str__insert_inode_hash (inode, inode->i_ino); } -extern void file_move (struct file *f,struct list_head *list); -extern void file_kill (struct file *f); +extern void file_sb_list_add (struct file *f,struct super_block *sb); +extern void file_sb_list_del (struct file *f);#ifdef CONFIG_BLOCK struct bio ;extern void submit_bio (int ,struct bio *);
include/linux/tty.h +1 -0
@@ -467,6 +467,7 @@ extern struct tty_struct *tty_pair_get_textern struct tty_struct *tty_pair_get_pty (struct tty_struct *tty);extern struct mutex tty_mutex; +extern spinlock_t tty_files_lock;extern void tty_write_unlock (struct tty_struct *tty);extern int tty_write_lock (struct tty_struct *tty,int ndelay);
PATCH 5/52 lglock: introduce special lglock and brlock spin locks
In reply to [email protected]This patch introduces "local-global" locks (lglocks). These can be used to:
- Provide fast exclusive access to per-CPU data, with exclusive access to another CPU's data allowed but possibly subject to contention, and to provide very slow exclusive access to all per-CPU data.
- Or to provide very fast and scalable read serialisation, and to provide very slow exclusive serialisation of data (not necessarily per-CPU data).
Brlocks are also implemented as a short-hand notation for the latter use case.
Thanks to Paul for local/global naming convention.
--- include/linux/lglock.h | 172 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+)
include/linux/lglock.h new file +172 -0
@@ -0,0 +1,172 @@ +/* +* Specialised local-global spinlock. Can only be declared as global variables +* to avoid overhead and keep things simple (and we don't want to start using +* these inside dynamically allocated structures). +* +* "local/global locks" (lglocks) can be used to: +* +* - Provide fast exclusive access to per-CPU data, with exclusive access to +* another CPU's data allowed but possibly subject to contention, and to +* provide very slow exclusive access to all per-CPU data. +* - Or to provide very fast and scalable read serialisation, and to provide +* very slow exclusive serialisation of data (not necessarily per-CPU data). +* +* Brlocks are also implemented as a short-hand notation for the latter use +* case. +* +* Copyright 2009, 2010, Nick Piggin, Novell Inc. +*/ +#ifndef __LINUX_LGLOCK_H +#define __LINUX_LGLOCK_H + +#include <linux/spinlock.h> +#include <linux/lockdep.h> +#include <linux/percpu.h> + +/* can make br locks by using local lock for read side, global lock for write */ +#define br_lock_init (name) name##_lock_init() +#define br_read_lock (name) name##_local_lock() +#define br_read_unlock (name) name##_local_unlock() +#define br_write_lock (name) name##_global_lock_online() +#define br_write_unlock (name) name##_global_unlock_online() + +#define DECLARE_BRLOCK (name) DECLARE_LGLOCK(name) +#define DEFINE_BRLOCK (name) DEFINE_LGLOCK(name) + + +#define lg_lock_init (name) name##_lock_init() +#define lg_local_lock (name) name##_local_lock() +#define lg_local_unlock (name) name##_local_unlock() +#define lg_local_lock_cpu (name, cpu) name##_local_lock_cpu(cpu) +#define lg_local_unlock_cpu (name, cpu) name##_local_unlock_cpu(cpu) +#define lg_global_lock (name) name##_global_lock() +#define lg_global_unlock (name) name##_global_unlock() +#define lg_global_lock_online (name) name##_global_lock_online() +#define lg_global_unlock_online (name) name##_global_unlock_online() + +#ifdef CONFIG_DEBUG_LOCK_ALLOC +#define LOCKDEP_INIT_MAP lockdep_init_map + +#define DEFINE_LGLOCK_LOCKDEP (name) \ + struct lock_class_key name##_lock_key; \ + struct lockdep_map name##_lock_dep_map; \ + EXPORT_SYMBOL(name##_lock_dep_map) + +#else +#define LOCKDEP_INIT_MAP (a, b, c, d) + +#define DEFINE_LGLOCK_LOCKDEP (name) +#endif + + +#define DECLARE_LGLOCK (name) \ + extern void name##_lock_init(void); \ + extern void name##_local_lock(void); \ + extern void name##_local_unlock(void); \ + extern void name##_local_lock_cpu(int cpu); \ + extern void name##_local_unlock_cpu(int cpu); \ + extern void name##_global_lock(void); \ + extern void name##_global_unlock(void); \ + extern void name##_global_lock_online(void); \ + extern void name##_global_unlock_online(void); \ + +#define DEFINE_LGLOCK (name) \ + \ + DEFINE_PER_CPU(arch_spinlock_t, name##_lock); \ + DEFINE_LGLOCK_LOCKDEP(name); \ + \ + void name##_lock_init(void) { \ + int i; \ + LOCKDEP_INIT_MAP(&name##_lock_dep_map, #name, &name##_lock_key, 0); \ + for_each_possible_cpu(i) { \ + arch_spinlock_t *lock; \ + lock = &per_cpu(name##_lock, i); \ + *lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; \ + } \ + } \ + EXPORT_SYMBOL(name##_lock_init); \ + \ + void name##_local_lock(void) { \ + arch_spinlock_t *lock; \ + preempt_disable(); \ + rwlock_acquire_read(&name##_lock_dep_map, 0, 0, _THIS_IP_); \ + lock = &__get_cpu_var(name##_lock); \ + arch_spin_lock(lock); \ + } \ + EXPORT_SYMBOL(name##_local_lock); \ + \ + void name##_local_unlock(void) { \ + arch_spinlock_t *lock; \ + rwlock_release(&name##_lock_dep_map, 1, _THIS_IP_); \ + lock = &__get_cpu_var(name##_lock); \ + arch_spin_unlock(lock); \ + preempt_enable(); \ + } \ + EXPORT_SYMBOL(name##_local_unlock); \ + \ + void name##_local_lock_cpu(int cpu) { \ + arch_spinlock_t *lock; \ + preempt_disable(); \ + rwlock_acquire_read(&name##_lock_dep_map, 0, 0, _THIS_IP_); \ + lock = &per_cpu(name##_lock, cpu); \ + arch_spin_lock(lock); \ + } \ + EXPORT_SYMBOL(name##_local_lock_cpu); \ + \ + void name##_local_unlock_cpu(int cpu) { \ + arch_spinlock_t *lock; \ + rwlock_release(&name##_lock_dep_map, 1, _THIS_IP_); \ + lock = &per_cpu(name##_lock, cpu); \ + arch_spin_unlock(lock); \ + preempt_enable(); \ + } \ + EXPORT_SYMBOL(name##_local_unlock_cpu); \ + \ + void name##_global_lock_online(void) { \ + int i; \ + preempt_disable(); \ + rwlock_acquire(&name##_lock_dep_map, 0, 0, _RET_IP_); \ + for_each_online_cpu(i) { \ + arch_spinlock_t *lock; \ + lock = &per_cpu(name##_lock, i); \ + arch_spin_lock(lock); \ + } \ + } \ + EXPORT_SYMBOL(name##_global_lock_online); \ + \ + void name##_global_unlock_online(void) { \ + int i; \ + rwlock_release(&name##_lock_dep_map, 1, _RET_IP_); \ + for_each_online_cpu(i) { \ + arch_spinlock_t *lock; \ + lock = &per_cpu(name##_lock, i); \ + arch_spin_unlock(lock); \ + } \ + preempt_enable(); \ + } \ + EXPORT_SYMBOL(name##_global_unlock_online); \ + \ + void name##_global_lock(void) { \ + int i; \ + preempt_disable(); \ + rwlock_acquire(&name##_lock_dep_map, 0, 0, _RET_IP_); \ + for_each_online_cpu(i) { \ + arch_spinlock_t *lock; \ + lock = &per_cpu(name##_lock, i); \ + arch_spin_lock(lock); \ + } \ + } \ + EXPORT_SYMBOL(name##_global_lock); \ + \ + void name##_global_unlock(void) { \ + int i; \ + rwlock_release(&name##_lock_dep_map, 1, _RET_IP_); \ + for_each_online_cpu(i) { \ + arch_spinlock_t *lock; \ + lock = &per_cpu(name##_lock, i); \ + arch_spin_unlock(lock); \ + } \ + preempt_enable(); \ + } \ + EXPORT_SYMBOL(name##_global_unlock); +#endif
PATCH 7/52 fs: brlock vfsmount_lock
In reply to [email protected]Use a brlock for the vfsmount lock. It must be taken for write whenever modifying the mount hash or associated fields, and may be taken for read when performing mount hash lookups.
The number of atomics should remain the same for fastpath rlock cases, though code will be slightly slower due to per-cpu access. Scalability will probably not be much improved in common cases yet, due to other locks getting in the way. However independent path lookups over mountpoints should be one case where scalability is improved.
The slowpath will be made significantly slower due to use of brlock. On a 64 core, 64 socket, 32 node Altix system (so a decent amount of latency to remote nodes), a simple umount microbenchmark (mount --bind mnt mnt2 ; umount mnt2 loop 1000 times), before this patch it took 6.8s, afterwards took 7.1s, for about 5% increase in elapsed time.
--- fs/dcache.c | 11 +-- fs/internal.h | 5 + fs/namei.c | 7 +- fs/namespace.c | 177 +++++++++++++++++++++++++++++++++++---------------------- fs/pnode.c | 11 ++- 5 files changed, 134 insertions(+), 77 deletions(-)
fs/dcache.c +6 -5
@@ -1928,7 +1928,7 @@ char *__d_path(const struct path *path,char *end = buffer + buflen;char *retval; -spin_lock (&vfsmount_lock); +br_read_lock (vfsmount_lock);prepend (&end, &buflen,"\0" ,1 );if (d_unlinked (dentry) && (prepend (&end, &buflen," (deleted)" ,10 ) !=0 ))
@@ -1964,7 +1964,7 @@ char *__d_path(const struct path *path, } out: -spin_unlock (&vfsmount_lock); +br_read_unlock (vfsmount_lock);return retval; global_root:
@@ -2195,11 +2195,12 @@ int path_is_under(struct path *path1, ststruct vfsmount *mnt = path1->mnt;struct dentry *dentry = path1->dentry;int res; -spin_lock (&vfsmount_lock); + +br_read_lock (vfsmount_lock);if (mnt != path2->mnt) {for (;;) {if (mnt->mnt_parent == mnt) { -spin_unlock (&vfsmount_lock); +br_read_unlock (vfsmount_lock);return 0 ; }if (mnt->mnt_parent == path2->mnt)
@@ -2209,7 +2210,7 @@ int path_is_under(struct path *path1, st dentry = mnt->mnt_mountpoint; } res =is_subdir (dentry, path2->dentry); -spin_unlock (&vfsmount_lock); +br_read_unlock (vfsmount_lock);return res; }EXPORT_SYMBOL (path_is_under);
fs/namei.c +4 -3
@@ -601,15 +601,16 @@ int follow_up(struct path *path) {struct vfsmount *parent;struct dentry *mountpoint; -spin_lock (&vfsmount_lock); + +br_read_lock (vfsmount_lock); parent = path->mnt->mnt_parent;if (parent == path->mnt) { -spin_unlock (&vfsmount_lock); +br_read_unlock (vfsmount_lock);return 0 ; }mntget (parent); mountpoint =dget (path->mnt->mnt_mountpoint); -spin_unlock (&vfsmount_lock); +br_read_unlock (vfsmount_lock);dput (path->dentry); path->dentry = mountpoint;mntput (path->mnt);
fs/namespace.c +111 -66
487 lines not on this page · raw message
fs/pnode.c +9 -2
@@ -126,6 +126,9 @@ static int do_make_slave(struct vfsmountreturn 0 ; } +/* +* vfsmount lock must be held for write +*/ void change_mnt_propagation (struct vfsmount *mnt,int type) {if (type ==MS_SHARED ) {
@@ -270,12 +273,12 @@ int propagate_mnt(struct vfsmount *dest_ prev_src_mnt = child; } out: -spin_lock (&vfsmount_lock); +br_write_lock (vfsmount_lock);while (!list_empty (&tmp_list)) { child = list_first_entry(&tmp_list, struct vfsmount, mnt_hash);umount_tree (child,0 , &umount_list); } -spin_unlock (&vfsmount_lock); +br_write_unlock (vfsmount_lock);release_mounts (&umount_list);return ret; }
@@ -296,6 +299,8 @@ static inline int do_refcount_check(stru* other mounts its parent propagates to. * Check if any of these mounts that **do not have submounts** * have more references than 'refcnt'. If so return busy. +* +* vfsmount lock must be held for read or write */ int propagate_mount_busy (struct vfsmount *mnt,int refcnt) {
@@ -353,6 +358,8 @@ static void __propagate_umount(struct vf* collect all mounts that receive propagation from the mount in @list, * and return these additional mounts in the same list. * @list: the list of mounts to be unmounted. +* +* vfsmount lock must be held for write */ int propagate_umount (struct list_head *list) {
fs/internal.h +4 -1
@@ -9,6 +9,8 @@* 2 of the License, or (at your option) any later version. */ +#include <linux/lglock.h> +struct super_block ;struct linux_binprm ;struct path ;
@@ -70,7 +72,8 @@ extern struct vfsmount *copy_tree(structextern void __init mnt_init (void ); -extern spinlock_t vfsmount_lock; +DECLARE_BRLOCK (vfsmount_lock); +/* * fs_struct.c
PATCH 8/52 fs: scale mntget/mntput
In reply to [email protected]Improve scalability of mntget/mntput by using per-cpu counters protected by the reader side of the brlock vfsmount_lock. If the mnt_hash field of the vfsmount structure is attached to a list, then it is mounted which contributes to its refcount, so the per-cpu counters need not be summed.
MNT_PSEUDO keeps track of whether the vfsmount is actually a pseudo filesystem that will never be attached (such as sockfs).
No extra atomics in the common case because atomic mnt refcount is now replaced with per-CPU spinlock. Code will be bigger and more complex however. With the previous per-cpu locking patch, mount lookups and common case refcounting are now per-cpu and should be ideally scalable. path lookups (and hence path_get/path_put) within the same vfsmount should now be more scalable, however this will often be hidden by dcache_lock on final dput, and d_lock on common path elements (eg. cwd or root dentry).
[Note: this is not for merging. Un-attached operation (lazy umount) may not be
uncommon and will be slowed down and actually have worse scalablilty after this patch. I need to think about how to do fast refcounting with unattached mounts.]
--- drivers/mtd/mtdchar.c | 1 fs/internal.h | 1 fs/libfs.c | 1 fs/namespace.c | 155 +++++++++++++++++++++++++++++++++++++++++++------- fs/pnode.c | 4 - include/linux/mount.h | 26 +------- 6 files changed, 144 insertions(+), 44 deletions(-)
fs/namespace.c +134 -21
@@ -138,6 +138,64 @@ void mnt_release_group_id(struct vfsmoun mnt->mnt_group_id =0 ; } +/* +* vfsmount lock must be held for read +*/ +static inline void add_mnt_count (struct vfsmount *mnt,int n) +{ +#ifdef CONFIG_SMP + (*per_cpu_ptr (mnt->mnt_count,smp_processor_id ())) += n; +#else + mnt->mnt_count += n; +#endif +} + +static inline void set_mnt_count (struct vfsmount *mnt,int n) +{ +#ifdef CONFIG_SMP +preempt_disable (); + (*per_cpu_ptr (mnt->mnt_count,smp_processor_id ())) = n; +preempt_enable (); +#else + mnt->mnt_count = n; +#endif +} + +/* +* vfsmount lock must be held for read +*/ +static inline void inc_mnt_count (struct vfsmount *mnt) +{ +add_mnt_count (mnt,1 ); +} + +/* +* vfsmount lock must be held for read +*/ +static inline void dec_mnt_count (struct vfsmount *mnt) +{ +add_mnt_count (mnt,-1 ); +} + +/* +* vfsmount lock must be held for write +*/ +unsigned int count_mnt_count (struct vfsmount *mnt) +{ +#ifdef CONFIG_SMP +unsigned int count =0 ; +int cpu; + +for_each_possible_cpu (cpu) { + count += *per_cpu_ptr (mnt->mnt_count, cpu); + } + +return count; +#else +return mnt->mnt_count; +#endif +} +struct vfsmount *alloc_vfsmnt (const char *name) {struct vfsmount *mnt =kmem_cache_zalloc (mnt_cache,GFP_KERNEL );
@@ -154,7 +212,15 @@ struct vfsmount *alloc_vfsmnt(const char goto out_free_id; } -atomic_set (&mnt->mnt_count,1 ); +#ifdef CONFIG_SMP + mnt->mnt_count =alloc_percpu (int); +if (!mnt->mnt_count) + goto out_free_devname; +#else + mnt->mnt_count =0 ; +#endif +set_mnt_count (mnt,1 ); +INIT_LIST_HEAD (&mnt->mnt_hash);INIT_LIST_HEAD (&mnt->mnt_child);INIT_LIST_HEAD (&mnt->mnt_mounts);
@@ -166,7 +232,7 @@ struct vfsmount *alloc_vfsmnt(const char#ifdef CONFIG_SMP mnt->mnt_writers =alloc_percpu (int);if (!mnt->mnt_writers) - goto out_free_devname; + goto out_free_mntcount;#else mnt->mnt_writers =0 ;#endif
@@ -174,6 +240,8 @@ struct vfsmount *alloc_vfsmnt(const charreturn mnt;#ifdef CONFIG_SMP +out_free_mntcount: +free_percpu (mnt->mnt_count); out_free_devname:kfree (mnt->mnt_devname);#endif
@@ -591,7 +659,7 @@ static struct vfsmount *clone_mnt(struct goto out_free; } - mnt->mnt_flags = old->mnt_flags; +WARN_ON (mnt->mnt_flags &MNT_WRITE_HOLD );atomic_inc (&sb->s_active); mnt->mnt_sb = sb; mnt->mnt_root =dget (root);
@@ -638,6 +706,11 @@ static inline void __mntput(struct vfsmo/* * atomic_dec_and_lock() used to deal with ->mnt_count decrements * provides barriers, so count_mnt_writers() below is safe. AV +* XXX: We no longer have an atomic_dec_and_lock, so load of +* mnt_writers may be moved up into the vfsmount lock critical section? +* Do we need an smp_mb()? I don't see how it is possible because an +* elevated write count should also have elevated ref count so we'd +* never get here. */ WARN_ON (count_mnt_writers (mnt));dput (mnt->mnt_root);
@@ -648,45 +721,76 @@ static inline void __mntput(struct vfsmovoid mntput_no_expire (struct vfsmount *mnt) { repeat: -if (atomic_add_unless (&mnt->mnt_count,-1 ,1 )) +if (likely (!list_empty (&mnt->mnt_hash) || + mnt->mnt_flags &MNT_PSEUDO )) { +br_read_lock (vfsmount_lock); +if (unlikely (list_empty (&mnt->mnt_hash) && + (!(mnt->mnt_flags &MNT_PSEUDO )))) { +br_read_unlock (vfsmount_lock); + goto repeat; + } +dec_mnt_count (mnt); +br_read_unlock (vfsmount_lock);return ; + } +br_write_lock (vfsmount_lock); -if (!atomic_dec_and_test (&mnt->mnt_count)) { +dec_mnt_count (mnt); +if (count_mnt_count (mnt)) {br_write_unlock (vfsmount_lock);return ; } -if (likely (!mnt->mnt_pinned)) { +if (unlikely (mnt->mnt_pinned)) { +add_mnt_count (mnt, mnt->mnt_pinned +1 ); + mnt->mnt_pinned =0 ;br_write_unlock (vfsmount_lock); -__mntput (mnt); -return ; +acct_auto_close_mnt (mnt); + goto repeat; } -atomic_add (mnt->mnt_pinned +1 , &mnt->mnt_count); - mnt->mnt_pinned =0 ;br_write_unlock (vfsmount_lock); -acct_auto_close_mnt (mnt); - goto repeat; +__mntput (mnt); }EXPORT_SYMBOL (mntput_no_expire); +void mntput (struct vfsmount *mnt) +{ +if (mnt) { +/* avoid cacheline pingpong, hope gcc doesn't get "smart" */ +if (unlikely (mnt->mnt_expiry_mark)) + mnt->mnt_expiry_mark =0 ; +mntput_no_expire (mnt); + } +} +EXPORT_SYMBOL (mntput); + +struct vfsmount *mntget (struct vfsmount *mnt) +{ +if (mnt) { +preempt_disable (); +inc_mnt_count (mnt); +preempt_enable (); + } +return mnt; +} +EXPORT_SYMBOL (mntget); +void mnt_pin (struct vfsmount *mnt) {br_write_lock (vfsmount_lock); mnt->mnt_pinned++;br_write_unlock (vfsmount_lock); } -EXPORT_SYMBOL (mnt_pin);void mnt_unpin (struct vfsmount *mnt) {br_write_lock (vfsmount_lock);if (mnt->mnt_pinned) { -atomic_inc (&mnt->mnt_count); +inc_mnt_count (mnt); mnt->mnt_pinned--; }br_write_unlock (vfsmount_lock); } -EXPORT_SYMBOL (mnt_unpin);static inline void mangle (struct seq_file *m,const char *s)
@@ -982,12 +1086,13 @@ int may_umount_tree(struct vfsmount *mntint minimum_refs =0 ;struct vfsmount *p; -br_read_lock (vfsmount_lock); +/* write lock needed for count_mnt_count */ +br_write_lock (vfsmount_lock);for (p = mnt; p; p =next_mnt (p, mnt)) { - actual_refs +=atomic_read (&p->mnt_count); + actual_refs +=count_mnt_count (p); minimum_refs +=2 ; } -br_read_unlock (vfsmount_lock); +br_write_unlock (vfsmount_lock);if (actual_refs > minimum_refs)return 0 ;
@@ -1014,10 +1119,10 @@ int may_umount(struct vfsmount *mnt) {int ret =1 ;down_read (&namespace_sem); -br_read_lock (vfsmount_lock); +br_write_lock (vfsmount_lock);if (propagate_mount_busy (mnt,2 )) ret =0 ; -br_read_unlock (vfsmount_lock); +br_write_unlock (vfsmount_lock);up_read (&namespace_sem);return ret; }
@@ -1099,8 +1204,16 @@ static int do_umount(struct vfsmount *mn flags & (MNT_FORCE | MNT_DETACH))return -EINVAL ; -if (atomic_read (&mnt->mnt_count) !=2 ) +/* +* probably don't strictly need the lock here if we examined +* all race cases, but it's a slowpath. +*/ +br_write_lock (vfsmount_lock); +if (count_mnt_count (mnt) !=2 ) { +br_write_lock (vfsmount_lock);return -EBUSY ; + } +br_write_unlock (vfsmount_lock);if (!xchg (&mnt->mnt_expiry_mark,1 ))return -EAGAIN ;
include/linux/mount.h +5 -21
@@ -31,6 +31,7 @@ struct mnt_namespace;#define MNT_SHRINKABLE 0x100#define MNT_WRITE_HOLD 0x200 +#define MNT_PSEUDO 0x400#define MNT_SHARED 0x1000/* if the vfsmount is a shared mount */ #define MNT_UNBINDABLE 0x2000/* if the vfsmount is a unbindable mount */
@@ -67,19 +68,15 @@ struct vfsmount {struct mnt_namespace *mnt_ns;/* containing namespace */ int mnt_id;/* mount identifier */ int mnt_group_id;/* peer group identifier */ -/* -* We put mnt_count & mnt_expiry_mark at the end of struct vfsmount -* to let these frequently modified fields in a separate cache line -* (so that reads of mnt_flags wont ping-pong on SMP machines) -*/ -atomic_t mnt_count;int mnt_expiry_mark;/* true if marked for expiry */ int mnt_pinned;int mnt_ghosts;#ifdef CONFIG_SMP int __percpu *mnt_writers; +int __percpu *mnt_count;#else int mnt_writers; +int mnt_count;#endif };
@@ -92,13 +89,6 @@ static inline int *get_mnt_writers_ptr(s#endif } -static inline struct vfsmount *mntget (struct vfsmount *mnt) -{ -if (mnt) -atomic_inc (&mnt->mnt_count); -return mnt; -} -struct file ;/* forward dec */ extern int mnt_want_write (struct vfsmount *mnt);
@@ -106,18 +96,12 @@ extern int mnt_want_write_file(struct fiextern int mnt_clone_write (struct vfsmount *mnt);extern void mnt_drop_write (struct vfsmount *mnt);extern void mntput_no_expire (struct vfsmount *mnt); +extern void mntput (struct vfsmount *mnt); +extern struct vfsmount *mntget (struct vfsmount *mnt);extern void mnt_pin (struct vfsmount *mnt);extern void mnt_unpin (struct vfsmount *mnt);extern int __mnt_is_readonly (struct vfsmount *mnt); -static inline void mntput (struct vfsmount *mnt) -{ -if (mnt) { - mnt->mnt_expiry_mark =0 ; -mntput_no_expire (mnt); - } -} -extern struct vfsmount *do_kern_mount (const char *fstype,int flags,const char *name,void *data);
fs/pnode.c +2 -2
@@ -288,7 +288,7 @@ out:*/ static inline int do_refcount_check (struct vfsmount *mnt,int count) { -int mycount =atomic_read (&mnt->mnt_count) - mnt->mnt_ghosts; +int mycount =count_mnt_count (mnt) - mnt->mnt_ghosts;return (mycount > count); }
@@ -300,7 +300,7 @@ static inline int do_refcount_check(stru* Check if any of these mounts that **do not have submounts** * have more references than 'refcnt'. If so return busy. * -* vfsmount lock must be held for read or write +* vfsmount lock must be held for write */ int propagate_mount_busy (struct vfsmount *mnt,int refcnt) {
fs/internal.h +1 -0
@@ -63,6 +63,7 @@ extern int copy_mount_string(const voidextern void free_vfsmnt (struct vfsmount *);extern struct vfsmount *alloc_vfsmnt (const char *); +extern unsigned int count_mnt_count (struct vfsmount *mnt);extern struct vfsmount *__lookup_mnt (struct vfsmount *,struct dentry *,int );extern void mnt_set_mountpoint (struct vfsmount *,struct dentry *,struct vfsmount *);
fs/libfs.c +1 -0
@@ -241,6 +241,7 @@ int get_sb_pseudo(struct file_system_typd_instantiate (dentry, root); s->s_root = dentry; s->s_flags |=MS_ACTIVE ; + mnt->mnt_flags |=MNT_PSEUDO ;simple_set_mnt (mnt, s);return 0 ;
drivers/mtd/mtdchar.c +1 -0
@@ -1048,6 +1048,7 @@ err_unregister_chdev: static void __exit cleanup_mtdchar(void) {unregister_mtd_user (&mtdchar_notifier); + mtd_inode_mnt &= ~MNT_PSEUDO ;mntput (mtd_inode_mnt);unregister_filesystem (&mtd_inodefs_type);__unregister_chrdev (MTD_CHAR_MAJOR ,0 ,1 <<MINORBITS ,"mtd" );
PATCH 13/52 fs: dcache scale d_unhashed
In reply to [email protected]Protect d_unhashed(dentry) condition with d_lock.
--- arch/powerpc/platforms/cell/spufs/inode.c | 3 + fs/configfs/configfs_internal.h | 2 + fs/dcache.c | 58 ++++++++++++++++++++++++------ fs/libfs.c | 29 ++++++++++----- fs/ocfs2/dcache.c | 5 ++ fs/seq_file.c | 3 + security/tomoyo/realpath.c | 2 + 7 files changed, 81 insertions(+), 21 deletions(-)
fs/libfs.c +20 -9
@@ -16,6 +16,11 @@#include <asm/uaccess.h> +static inline int simple_positive (struct dentry *dentry) +{ +return dentry->d_inode && !d_unhashed (dentry); +} +int simple_getattr (struct vfsmount *mnt,struct dentry *dentry,struct kstat *stat) {
@@ -100,8 +105,10 @@ loff_t dcache_dir_lseek(struct file *filwhile (n && p != &file->f_path.dentry->d_subdirs) {struct dentry *next; next = list_entry(p, struct dentry, d_u.d_child); -if (!d_unhashed (next) && next->d_inode) +spin_lock (&next->d_lock); +if (simple_positive (next)) n--; +spin_unlock (&next->d_lock); p = p->next; }list_add_tail (&cursor->d_u.d_child, p);
@@ -155,9 +162,13 @@ int dcache_readdir(struct file * filp, vfor (p=q->next; p != &dentry->d_subdirs; p=p->next) {struct dentry *next; next = list_entry(p, struct dentry, d_u.d_child); -if (d_unhashed (next) || !next->d_inode) +spin_lock_nested (&next->d_lock,DENTRY_D_LOCK_NESTED ); +if (!simple_positive (next)) { +spin_unlock (&next->d_lock);continue ; + } +spin_unlock (&next->d_lock);spin_unlock (&dcache_lock); if (filldir(dirent, next->d_name.name, next->d_name.len, filp->f_pos,
@@ -262,20 +273,20 @@ int simple_link(struct dentry *old_dentrreturn 0 ; } -static inline int simple_positive (struct dentry *dentry) -{ -return dentry->d_inode && !d_unhashed (dentry); -} -int simple_empty (struct dentry *dentry) {struct dentry *child;int ret =0 ;spin_lock (&dcache_lock); -list_for_each_entry (child, &dentry->d_subdirs, d_u.d_child) -if (simple_positive (child)) +list_for_each_entry (child, &dentry->d_subdirs, d_u.d_child) { +spin_lock_nested (&child->d_lock,DENTRY_D_LOCK_NESTED ); +if (simple_positive (child)) { +spin_unlock (&child->d_lock); goto out; + } +spin_unlock (&child->d_lock); + } ret =1 ; out:spin_unlock (&dcache_lock);
fs/seq_file.c +5 -0
@@ -6,10 +6,13 @@*/ #include <linux/fs.h> +#include <linux/mount.h> #include <linux/module.h> #include <linux/seq_file.h> #include <linux/slab.h> +#include "internal.h" +#include <asm/uaccess.h> #include <asm/page.h>
@@ -463,7 +466,9 @@ int seq_path_root(struct seq_file *m, stchar *p;spin_lock (&dcache_lock); +br_read_lock (vfsmount_lock); p =__d_path (path, root, buf, size); +br_read_unlock (vfsmount_lock);spin_unlock (&dcache_lock); res =PTR_ERR (p);if (!IS_ERR (p)) {
fs/dcache.c +59 -12
234 lines not on this page · raw message
arch/powerpc/platforms/cell/spufs/inode.c +3 -0
@@ -165,6 +165,9 @@ static void spufs_prune_dir(struct dentr__d_drop (dentry);spin_unlock (&dentry->d_lock);simple_unlink (dir->d_inode, dentry); +/* XXX: what is dcache_lock protecting here? Other +* filesystems (IB, configfs) release dcache_lock +* before unlink */ spin_unlock (&dcache_lock);dput (dentry); }else {
fs/configfs/configfs_internal.h +2 -0
@@ -121,6 +121,7 @@ static inline struct config_item *configstruct config_item * item =NULL ;spin_lock (&dcache_lock); +spin_lock (&dentry->d_lock);if (!d_unhashed (dentry)) {struct configfs_dirent * sd = dentry->d_fsdata;if (sd->s_type &CONFIGFS_ITEM_LINK ) {
@@ -129,6 +130,7 @@ static inline struct config_item *config }else item =config_item_get (sd->s_element); } +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);return item;
fs/ocfs2/dcache.c +4 -1
@@ -156,13 +156,16 @@ struct dentry *ocfs2_find_local_alias(stlist_for_each (p, &inode->i_dentry) { dentry = list_entry(p, struct dentry, d_alias); +spin_lock (&dentry->d_lock);if (ocfs2_match_dentry (dentry, parent_blkno, skip_unhashed)) {mlog (0 ,"dentry found: %.*s\n" , dentry->d_name.len, dentry->d_name.name); -dget_locked (dentry); +dget_locked_dlock (dentry); +spin_unlock (&dentry->d_lock);break ; } +spin_unlock (&dentry->d_lock); dentry =NULL ; }
security/tomoyo/realpath.c +3 -0
@@ -17,6 +17,7 @@#include <linux/magic.h> #include <linux/slab.h> #include "common.h" +#include "../../fs/internal.h" /** * tomoyo_encode: Convert binary string to ascii string.
@@ -92,8 +93,10 @@ int tomoyo_realpath_from_path2(struct pastruct path ns_root = {.mnt =NULL , .dentry =NULL };spin_lock (&dcache_lock); +br_read_lock (vfsmount_lock);/* go to whatever namespace root we are under */ sp =__d_path (path, &ns_root, newname, newname_len); +br_read_unlock (vfsmount_lock);spin_unlock (&dcache_lock);/* Prepend "/proc" prefix if using internal proc vfs mount. */ if (!IS_ERR(sp) && (path->mnt->mnt_flags & MNT_INTERNAL) &&
drivers/usb/core/inode.c +3 -0
@@ -351,10 +351,13 @@ static int usbfs_empty (struct dentry *dlist_for_each (list, &dentry->d_subdirs) { struct dentry *de = list_entry(list, struct dentry, d_u.d_child); +spin_lock (&de->d_lock);if (usbfs_positive (de)) { +spin_unlock (&de->d_lock);spin_unlock (&dcache_lock);return 0 ; } +spin_unlock (&de->d_lock); }spin_unlock (&dcache_lock);
fs/ceph/dir.c +3 -2
@@ -135,6 +135,7 @@ more: fi->at_end =1 ; goto out_unlock; } +spin_lock (&dentry->d_lock); if (!d_unhashed(dentry) && dentry->d_inode && ceph_snap(dentry->d_inode) != CEPH_SNAPDIR && ceph_ino(dentry->d_inode) != CEPH_INO_CEPH &&
@@ -144,13 +145,13 @@ more: dentry->d_name.len, dentry->d_name.name, di->offset, filp->f_pos,d_unhashed (dentry) ?" unhashed" :"" , !dentry->d_inode ? " null" : ""); +spin_unlock (&dentry->d_lock); p = p->prev; dentry = list_entry(p, struct dentry, d_u.d_child); di =ceph_dentry (dentry); } -spin_lock (&dentry->d_lock); - dentry->d_count++; +dget_dlock (dentry);spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);spin_unlock (&inode->i_lock);
PATCH 14/52 fs: dcache scale subdirs
In reply to [email protected]Protect d_subdirs and d_child with d_lock, except in filesystems that aren't using dcache_lock for these anyway (eg. using i_mutex).
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 say d_child list is protected by d_parent->d_lock. d_parent could remain protected with d_lock.
XXX: leave dcache_lock in there until remove dcache_lock patch
--- drivers/usb/core/inode.c | 8 +- fs/autofs4/expire.c | 87 +++++++++++++++------- fs/autofs4/root.c | 6 + fs/ceph/dir.c | 6 + fs/ceph/inode.c | 8 +- fs/coda/cache.c | 2 fs/dcache.c | 164 ++++++++++++++++++++++++++++++++++--------- fs/libfs.c | 40 ++++++---- fs/ncpfs/dir.c | 3 fs/ncpfs/ncplib_kernel.h | 4 + fs/notify/fsnotify.c | 4 - fs/notify/inotify/inotify.c | 4 - fs/smbfs/cache.c | 4 + include/linux/dcache.h | 1 kernel/cgroup.c | 19 ++++ security/selinux/selinuxfs.c | 12 ++- 16 files changed, 283 insertions(+), 89 deletions(-)
fs/dcache.c +130 -34
@@ -47,6 +47,8 @@* - d_lru * - d_count * - d_unhashed() +* - d_parent and d_subdirs +* - childrens' d_child and d_parent * * Ordering: * dcache_lock
@@ -219,7 +221,8 @@ static void dentry_lru_del_init(struct d* * If this is the root of the dentry tree, return NULL. * -* dcache_lock and d_lock must be held by caller, are dropped by d_kill. +* dcache_lock and d_lock and d_parent->d_lock must be held by caller, and +* are dropped by d_kill. */ static struct dentry *d_kill (struct dentry *dentry) __releases(dentry->d_lock)
@@ -228,12 +231,14 @@ static struct dentry *d_kill(struct dentstruct dentry *parent;list_del (&dentry->d_u.d_child); -/*drops the locks, at that point nobody can reach this dentry */ -dentry_iput (dentry); +if (dentry->d_parent && dentry != dentry->d_parent) +spin_unlock (&dentry->d_parent->d_lock);if (IS_ROOT (dentry)) parent =NULL ;else parent = dentry->d_parent; +/*drops the locks, at that point nobody can reach this dentry */ +dentry_iput (dentry);d_free (dentry);return parent; }
@@ -269,6 +274,7 @@ static struct dentry *d_kill(struct dentvoid dput (struct dentry *dentry) { +struct dentry *parent =NULL ;if (!dentry)return ;
@@ -287,10 +293,20 @@ repeat:spin_unlock (&dentry->d_lock); goto repeat; } + 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; + } + } } dentry->d_count--;if (dentry->d_count) {spin_unlock (&dentry->d_lock); +if (parent && parent != dentry) +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock);return ; }
@@ -310,6 +326,8 @@ repeat:dentry_lru_add (dentry); }spin_unlock (&dentry->d_lock); +if (parent && parent != dentry) +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock);return ;
@@ -545,10 +563,22 @@ static void prune_one_dentry(struct dent* because dcache_lock needs to be taken anyway. */ while (dentry) { +struct dentry *parent =NULL ; +spin_lock (&dcache_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); + goto again; + } + parent = dentry->d_parent; + } dentry->d_count--;if (dentry->d_count) { +if (parent) +spin_unlock (&parent->d_lock);spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);return ;
@@ -626,20 +656,27 @@ again: dentry = list_entry(tmp.prev, struct dentry, d_lru);if (!spin_trylock (&dentry->d_lock)) { +again1:spin_unlock (&dcache_lru_lock); goto again; } -__dentry_lru_del_init (dentry);/* * We found an inuse dentry which was not removed from * the LRU because of laziness during lookup. Do not free * it - just keep it off the LRU list. */ if (dentry->d_count) { +__dentry_lru_del_init (dentry);spin_unlock (&dentry->d_lock);continue ; } - +if (dentry->d_parent && dentry->d_parent != dentry) { +if (!spin_trylock (&dentry->d_parent->d_lock)) { +spin_unlock (&dentry->d_lock); + goto again1; + } + } +__dentry_lru_del_init (dentry);spin_unlock (&dcache_lru_lock);prune_one_dentry (dentry);/* dcache_lock and dentry->d_lock dropped */
@@ -776,14 +813,15 @@ static void shrink_dcache_for_umount_sub/* this is a branch with children - detach all of them * from the system in one go */ spin_lock (&dcache_lock); +spin_lock (&dentry->d_lock);list_for_each_entry (loop, &dentry->d_subdirs, d_u.d_child) { -spin_lock (&loop->d_lock); +spin_lock_nested (&loop->d_lock,DENTRY_D_LOCK_NESTED );dentry_lru_del_init (loop);__d_drop (loop);spin_unlock (&loop->d_lock); -cond_resched_lock (&dcache_lock); } +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);/* move to the first child */
@@ -811,16 +849,17 @@ static void shrink_dcache_for_umount_subBUG (); } -if (IS_ROOT (dentry)) +if (IS_ROOT (dentry)) { parent =NULL ; -else { +list_del (&dentry->d_u.d_child); + }else { parent = dentry->d_parent;spin_lock (&parent->d_lock); parent->d_count--; +list_del (&dentry->d_u.d_child);spin_unlock (&parent->d_lock); } -list_del (&dentry->d_u.d_child); detached++; inode = dentry->d_inode;
@@ -905,6 +944,7 @@ int have_submounts(struct dentry *parentspin_lock (&dcache_lock);if (d_mountpoint (parent)) goto positive; +spin_lock (&this_parent->d_lock); repeat: next = this_parent->d_subdirs.next; resume:
@@ -912,22 +952,34 @@ resume:struct list_head *tmp = next; struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child); next = tmp->next; + +spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED );/* Have we found a mount point ? */ -if (d_mountpoint (dentry)) +if (d_mountpoint (dentry)) { +spin_unlock (&dentry->d_lock); +spin_unlock (&this_parent->d_lock); goto positive; + }if (!list_empty (&dentry->d_subdirs)) { +spin_unlock (&this_parent->d_lock); +spin_release (&dentry->d_lock.dep_map,1 , _RET_IP_); this_parent = dentry; +spin_acquire (&this_parent->d_lock.dep_map,0 ,1 , _RET_IP_); goto repeat; } +spin_unlock (&dentry->d_lock); }/* * All done at this level ... ascend and resume the search. */ if (this_parent != parent) { next = this_parent->d_u.d_child.next; +spin_unlock (&this_parent->d_lock); this_parent = this_parent->d_parent; +spin_lock (&this_parent->d_lock); goto resume; } +spin_unlock (&this_parent->d_lock);spin_unlock (&dcache_lock);return 0 ;/* No mount points found in tree */ positive:
@@ -957,6 +1009,7 @@ static int select_parent(struct dentry *int found =0 ;spin_lock (&dcache_lock); +spin_lock (&this_parent->d_lock); repeat: next = this_parent->d_subdirs.next; resume:
@@ -964,8 +1017,9 @@ 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 (&dentry->d_lock); +spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED );dentry_lru_del_init (dentry);/* * move only zero ref count dentries to the end
@@ -975,33 +1029,45 @@ resume:dentry_lru_add_tail (dentry); found++; } -spin_unlock (&dentry->d_lock);/* * We can return to the caller if we have found some (this * ensures forward progress). We'll be coming back to find * the rest. */ -if (found &&need_resched ()) +if (found &&need_resched ()) { +spin_unlock (&dentry->d_lock); goto out; + }/* * Descend a level if the d_subdirs list is non-empty. */ if (!list_empty (&dentry->d_subdirs)) { +spin_unlock (&this_parent->d_lock); +spin_release (&dentry->d_lock.dep_map,1 , _RET_IP_); this_parent = dentry; +spin_acquire (&this_parent->d_lock.dep_map,0 ,1 , _RET_IP_); goto repeat; } + +spin_unlock (&dentry->d_lock); }/* * All done at this level ... ascend and resume the search. */ if (this_parent != parent) { +struct dentry *tmp; next = this_parent->d_u.d_child.next; - this_parent = this_parent->d_parent; + tmp = this_parent->d_parent; +spin_unlock (&this_parent->d_lock); +BUG_ON (tmp == this_parent); + this_parent = tmp; +spin_lock (&this_parent->d_lock); goto resume; } out: +spin_unlock (&this_parent->d_lock);spin_unlock (&dcache_lock);return found; }
@@ -1098,19 +1164,20 @@ struct dentry *d_alloc(struct dentry * pINIT_LIST_HEAD (&dentry->d_lru);INIT_LIST_HEAD (&dentry->d_subdirs);INIT_LIST_HEAD (&dentry->d_alias); - -if (parent) { - dentry->d_parent =dget (parent); - dentry->d_sb = parent->d_sb; - }else { -INIT_LIST_HEAD (&dentry->d_u.d_child); - } +INIT_LIST_HEAD (&dentry->d_u.d_child);if (parent) {spin_lock (&dcache_lock); +spin_lock (&parent->d_lock); +spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED ); + dentry->d_parent =dget_dlock (parent); + dentry->d_sb = parent->d_sb;list_add (&dentry->d_u.d_child, &parent->d_subdirs); +spin_unlock (&dentry->d_lock); +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock); } +atomic_inc (&dentry_stat.nr_dentry);return dentry;
@@ -1802,15 +1869,26 @@ static void d_move_locked(struct dentry/* * XXXX: do we really need to take target->d_lock? */ -if (d_ancestor (dentry, target)) { -spin_lock (&dentry->d_lock); -spin_lock_nested (&target->d_lock,DENTRY_D_LOCK_NESTED ); - }else if (d_ancestor (target, dentry) || target < dentry) { -spin_lock (&target->d_lock); -spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED ); - }else { -spin_lock (&dentry->d_lock); -spin_lock_nested (&target->d_lock,DENTRY_D_LOCK_NESTED ); +BUG_ON (d_ancestor (dentry, target)); +BUG_ON (d_ancestor (target, dentry)); + +if (dentry->d_parent == target->d_parent) +spin_lock (&dentry->d_parent->d_lock); +else { +if (d_ancestor (dentry->d_parent, target->d_parent)) { +spin_lock (&dentry->d_parent->d_lock); +spin_lock_nested (&target->d_parent->d_lock,DENTRY_D_LOCK_NESTED ); + }else { +spin_lock (&target->d_parent->d_lock); +spin_lock_nested (&dentry->d_parent->d_lock,DENTRY_D_LOCK_NESTED ); + } + } +if (target < dentry) { +spin_lock_nested (&target->d_lock,2 ); +spin_lock_nested (&dentry->d_lock,3 ); + }else { +spin_lock_nested (&dentry->d_lock,2 ); +spin_lock_nested (&target->d_lock,3 ); }/* Move the dentry to the target hash queue, if on different bucket */
@@ -1843,6 +1921,10 @@ static void d_move_locked(struct dentry }list_add (&dentry->d_u.d_child, &dentry->d_parent->d_subdirs); +if (target->d_parent != dentry->d_parent) +spin_unlock (&dentry->d_parent->d_lock); +if (target->d_parent != target) +spin_unlock (&target->d_parent->d_lock);spin_unlock (&target->d_lock);fsnotify_d_move (dentry);spin_unlock (&dentry->d_lock);
@@ -1943,6 +2025,13 @@ static void __d_materialise_dentry(struc dparent = dentry->d_parent; aparent = anon->d_parent; +/* XXX: hack */ +/* returns with anon->d_lock held! */ +spin_lock (&aparent->d_lock); +spin_lock (&dparent->d_lock); +spin_lock (&dentry->d_lock); +spin_lock (&anon->d_lock); + dentry->d_parent = (aparent == anon) ? dentry : aparent;list_del (&dentry->d_u.d_child);if (!IS_ROOT (dentry))
@@ -1957,6 +2046,10 @@ static void __d_materialise_dentry(strucelse INIT_LIST_HEAD (&anon->d_u.d_child); +spin_unlock (&dentry->d_lock); +spin_unlock (&dparent->d_lock); +spin_unlock (&aparent->d_lock); + anon->d_flags &= ~DCACHE_DISCONNECTED ; }
@@ -1992,7 +2085,6 @@ struct dentry *d_materialise_unique(stru/* Is this an anonymous mountpoint that we could splice * into our tree? */ if (IS_ROOT (alias)) { -spin_lock (&alias->d_lock);__d_materialise_dentry (dentry, alias);__d_drop (alias); goto found;
@@ -2396,6 +2488,7 @@ void d_genocide(struct dentry *root)struct list_head *next;spin_lock (&dcache_lock); +spin_lock (&this_parent->d_lock); repeat: next = this_parent->d_subdirs.next; resume:
@@ -2409,8 +2502,10 @@ resume:continue ; }if (!list_empty (&dentry->d_subdirs)) { -spin_unlock (&dentry->d_lock); +spin_unlock (&this_parent->d_lock); +spin_release (&dentry->d_lock.dep_map,1 , _RET_IP_); this_parent = dentry; +spin_acquire (&this_parent->d_lock.dep_map,0 ,1 , _RET_IP_); goto repeat; } dentry->d_count--;
@@ -2418,12 +2513,13 @@ resume: }if (this_parent != root) { next = this_parent->d_u.d_child.next; -spin_lock (&this_parent->d_lock); this_parent->d_count--;spin_unlock (&this_parent->d_lock); this_parent = this_parent->d_parent; +spin_lock (&this_parent->d_lock); goto resume; } +spin_unlock (&this_parent->d_lock);spin_unlock (&dcache_lock); }
fs/libfs.c +25 -15
@@ -81,7 +81,8 @@ int dcache_dir_close(struct inode *inodeloff_t dcache_dir_lseek (struct file *file,loff_t offset,int origin) { -mutex_lock (&file->f_path.dentry->d_inode->i_mutex); +struct dentry *dentry = file->f_path.dentry; +mutex_lock (&dentry->d_inode->i_mutex);switch (origin) {case 1 : offset += file->f_pos;
@@ -89,7 +90,7 @@ loff_t dcache_dir_lseek(struct file *filif (offset >=0 )break ;default : -mutex_unlock (&file->f_path.dentry->d_inode->i_mutex); +mutex_unlock (&dentry->d_inode->i_mutex);return -EINVAL ; }if (offset != file->f_pos) {
@@ -99,23 +100,27 @@ loff_t dcache_dir_lseek(struct file *filstruct dentry *cursor = file->private_data;loff_t n = file->f_pos -2 ; -spin_lock (&dcache_lock); +spin_lock (&dentry->d_lock); +spin_lock_nested (&cursor->d_lock,DENTRY_D_LOCK_NESTED );list_del (&cursor->d_u.d_child); - p = file->f_path.dentry->d_subdirs.next; -while (n && p != &file->f_path.dentry->d_subdirs) { +spin_unlock (&cursor->d_lock); + p = dentry->d_subdirs.next; +while (n && p != &dentry->d_subdirs) {struct dentry *next; next = list_entry(p, struct dentry, d_u.d_child); -spin_lock (&next->d_lock); +spin_lock_nested (&next->d_lock,DENTRY_D_LOCK_NESTED );if (simple_positive (next)) n--;spin_unlock (&next->d_lock); p = p->next; } +spin_lock_nested (&cursor->d_lock,DENTRY_D_LOCK_NESTED );list_add_tail (&cursor->d_u.d_child, p); -spin_unlock (&dcache_lock); +spin_unlock (&cursor->d_lock); +spin_unlock (&dentry->d_lock); } } -mutex_unlock (&file->f_path.dentry->d_inode->i_mutex); +mutex_unlock (&dentry->d_inode->i_mutex);return offset; }
@@ -155,9 +160,12 @@ int dcache_readdir(struct file * filp, v i++;/* fallthrough */ default : -spin_lock (&dcache_lock); -if (filp->f_pos ==2 ) +spin_lock (&dentry->d_lock); +if (filp->f_pos ==2 ) { +spin_lock_nested (&cursor->d_lock,DENTRY_D_LOCK_NESTED );list_move (q, &dentry->d_subdirs); +spin_unlock (&cursor->d_lock); + }for (p=q->next; p != &dentry->d_subdirs; p=p->next) {struct dentry *next;
@@ -169,19 +177,21 @@ int dcache_readdir(struct file * filp, v }spin_unlock (&next->d_lock); -spin_unlock (&dcache_lock); +spin_unlock (&dentry->d_lock);if (filldir (dirent, next->d_name.name, next->d_name.len, filp->f_pos, next->d_inode->i_ino,dt_type (next->d_inode)) <0 )return 0 ; -spin_lock (&dcache_lock); +spin_lock (&dentry->d_lock); +spin_lock_nested (&next->d_lock,DENTRY_D_LOCK_NESTED );/* next is still alive */ list_move (q, p); +spin_unlock (&next->d_lock); p = q; filp->f_pos++; } -spin_unlock (&dcache_lock); +spin_unlock (&dentry->d_lock); }return 0 ; }
@@ -278,7 +288,7 @@ int simple_empty(struct dentry *dentry)struct dentry *child;int ret =0 ; -spin_lock (&dcache_lock); +spin_lock (&dentry->d_lock);list_for_each_entry (child, &dentry->d_subdirs, d_u.d_child) {spin_lock_nested (&child->d_lock,DENTRY_D_LOCK_NESTED );if (simple_positive (child)) {
@@ -289,7 +299,7 @@ int simple_empty(struct dentry *dentry) } ret =1 ; out: -spin_unlock (&dcache_lock); +spin_unlock (&dentry->d_lock);return ret; }
fs/notify/inotify/inotify.c +3 -1
@@ -185,17 +185,19 @@ static void set_dentry_child_flags(struclist_for_each_entry (alias, &inode->i_dentry, d_alias) {struct dentry *child; +spin_lock (&alias->d_lock);list_for_each_entry (child, &alias->d_subdirs, d_u.d_child) {if (!child->d_inode)continue ; -spin_lock (&child->d_lock); +spin_lock_nested (&child->d_lock,DENTRY_D_LOCK_NESTED );if (watched) child->d_flags |=DCACHE_INOTIFY_PARENT_WATCHED ;else child->d_flags &=~DCACHE_INOTIFY_PARENT_WATCHED ;spin_unlock (&child->d_lock); } +spin_unlock (&alias->d_lock); }spin_unlock (&dcache_lock); }
include/linux/dcache.h +1 -0
@@ -342,6 +342,7 @@ static inline struct dentry *dget_dlock( }return dentry; } +static inline struct dentry *dget (struct dentry *dentry) {if (dentry) {
drivers/usb/core/inode.c +5 -3
@@ -348,18 +348,20 @@ static int usbfs_empty (struct dentry *dstruct list_head *list;spin_lock (&dcache_lock); - +spin_lock (&dentry->d_lock);list_for_each (list, &dentry->d_subdirs) { struct dentry *de = list_entry(list, struct dentry, d_u.d_child); -spin_lock (&de->d_lock); + +spin_lock_nested (&de->d_lock,DENTRY_D_LOCK_NESTED );if (usbfs_positive (de)) {spin_unlock (&de->d_lock); +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);return 0 ; }spin_unlock (&de->d_lock); } - +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);return 1 ; }
fs/autofs4/expire.c +59 -28
169 lines not on this page · raw message
fs/autofs4/root.c +6 -0
@@ -135,10 +135,13 @@ static int autofs4_dir_open(struct inode* it. */ spin_lock (&dcache_lock); +spin_lock (&dentry->d_lock);if (!d_mountpoint (dentry) &&list_empty (&dentry->d_subdirs)) { +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);return -ENOENT ; } +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock); out:
@@ -246,7 +249,9 @@ static void *autofs4_follow_link(struct lookup_type =autofs4_need_mount (nd->flags);spin_lock (&sbi->fs_lock);spin_lock (&dcache_lock); +spin_lock (&dentry->d_lock);if (!(lookup_type || ino->flags &AUTOFS_INF_PENDING )) { +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);spin_unlock (&sbi->fs_lock); goto follow;
@@ -268,6 +273,7 @@ static void *autofs4_follow_link(struct goto follow; } +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);spin_unlock (&sbi->fs_lock); follow:
fs/coda/cache.c +2 -0
@@ -87,6 +87,7 @@ static void coda_flag_children(struct destruct dentry *de;spin_lock (&dcache_lock); +spin_lock (&parent->d_lock);list_for_each (child, &parent->d_subdirs) { de = list_entry(child, struct dentry, d_u.d_child);
@@ -95,6 +96,7 @@ static void coda_flag_children(struct decontinue ;coda_flag_inode (de->d_inode, flag); } +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock);return ; }
fs/ncpfs/dir.c +3 -0
@@ -365,6 +365,7 @@ ncp_dget_fpos(struct dentry *dentry, str/* If a pointer is invalid, we search the dentry. */ spin_lock (&dcache_lock); +spin_lock (&parent->d_lock); next = parent->d_subdirs.next;while (next != &parent->d_subdirs) { dent = list_entry(next, struct dentry, d_u.d_child);
@@ -373,11 +374,13 @@ ncp_dget_fpos(struct dentry *dentry, strdget_locked (dent); else dent =NULL ; +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock); goto out; } next = next->next; } +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock);return NULL ;
fs/ncpfs/ncplib_kernel.h +4 -0
@@ -193,6 +193,7 @@ ncp_renew_dentries(struct dentry *parentstruct dentry *dentry;spin_lock (&dcache_lock); +spin_lock (&parent->d_lock); next = parent->d_subdirs.next;while (next != &parent->d_subdirs) { dentry = list_entry(next, struct dentry, d_u.d_child);
@@ -204,6 +205,7 @@ ncp_renew_dentries(struct dentry *parent next = next->next; } +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock); }
@@ -215,6 +217,7 @@ ncp_invalidate_dircache_entries(struct dstruct dentry *dentry;spin_lock (&dcache_lock); +spin_lock (&parent->d_lock); next = parent->d_subdirs.next;while (next != &parent->d_subdirs) { dentry = list_entry(next, struct dentry, d_u.d_child);
@@ -222,6 +225,7 @@ ncp_invalidate_dircache_entries(struct dncp_age_dentry (server, dentry); next = next->next; } +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock); }
fs/smbfs/cache.c +4 -0
@@ -63,6 +63,7 @@ smb_invalidate_dircache_entries(struct dstruct dentry *dentry;spin_lock (&dcache_lock); +spin_lock (&parent->d_lock); next = parent->d_subdirs.next;while (next != &parent->d_subdirs) { dentry = list_entry(next, struct dentry, d_u.d_child);
@@ -70,6 +71,7 @@ smb_invalidate_dircache_entries(struct dsmb_age_dentry (server, dentry); next = next->next; } +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock); }
@@ -97,6 +99,7 @@ smb_dget_fpos(struct dentry *dentry, str/* If a pointer is invalid, we search the dentry. */ spin_lock (&dcache_lock); +spin_lock (&parent->d_lock); next = parent->d_subdirs.next;while (next != &parent->d_subdirs) { dent = list_entry(next, struct dentry, d_u.d_child);
@@ -111,6 +114,7 @@ smb_dget_fpos(struct dentry *dentry, str } dent =NULL ; out_unlock: +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock);return dent; }
kernel/cgroup.c +17 -2
@@ -870,23 +870,31 @@ static void cgroup_clear_directory(strucBUG_ON (!mutex_is_locked (&dentry->d_inode->i_mutex));spin_lock (&dcache_lock); +spin_lock (&dentry->d_lock); node = dentry->d_subdirs.next;while (node != &dentry->d_subdirs) { struct dentry *d = list_entry(node, struct dentry, d_u.d_child); + +spin_lock_nested (&d->d_lock,DENTRY_D_LOCK_NESTED );list_del_init (node);if (d->d_inode) {/* This should never be called on a cgroup * directory with child cgroups */ BUG_ON (d->d_inode->i_mode &S_IFDIR ); - d =dget_locked (d); +dget_locked_dlock (d); +spin_unlock (&d->d_lock); +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);d_delete (d);simple_unlink (dentry->d_inode, d);dput (d);spin_lock (&dcache_lock); - } +spin_lock (&dentry->d_lock); + }else +spin_unlock (&d->d_lock); node = dentry->d_subdirs.next; } +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock); }
@@ -895,10 +903,17 @@ static void cgroup_clear_directory(struc*/ static void cgroup_d_remove_dir (struct dentry *dentry) { +struct dentry *parent; +cgroup_clear_directory (dentry);spin_lock (&dcache_lock); + parent = dentry->d_parent; +spin_lock (&parent->d_lock); +spin_lock (&dentry->d_lock);list_del_init (&dentry->d_u.d_child); +spin_unlock (&dentry->d_lock); +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock);remove_dir (dentry); }
security/selinux/selinuxfs.c +10 -2
@@ -942,22 +942,30 @@ static void sel_remove_entries(struct destruct list_head *node;spin_lock (&dcache_lock); +spin_lock (&de->d_lock); node = de->d_subdirs.next;while (node != &de->d_subdirs) { struct dentry *d = list_entry(node, struct dentry, d_u.d_child); + +spin_lock_nested (&d->d_lock,DENTRY_D_LOCK_NESTED );list_del_init (node);if (d->d_inode) { - d =dget_locked (d); +dget_locked_dlock (d); +spin_unlock (&de->d_lock); +spin_unlock (&d->d_lock);spin_unlock (&dcache_lock);d_delete (d);simple_unlink (de->d_inode, d);dput (d);spin_lock (&dcache_lock); - } +spin_lock (&de->d_lock); + }else +spin_unlock (&d->d_lock); node = de->d_subdirs.next; } +spin_unlock (&de->d_lock);spin_unlock (&dcache_lock); }
fs/notify/fsnotify.c +3 -1
@@ -62,17 +62,19 @@ void __fsnotify_update_child_dentry_flag/* run all of the children of the original inode and fix their * d_flags to indicate parental interest (their parent is the * original inode) */ +spin_lock (&alias->d_lock);list_for_each_entry (child, &alias->d_subdirs, d_u.d_child) {if (!child->d_inode)continue ; -spin_lock (&child->d_lock); +spin_lock_nested (&child->d_lock,DENTRY_D_LOCK_NESTED );if (watched) child->d_flags |=DCACHE_FSNOTIFY_PARENT_WATCHED ;else child->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED ;spin_unlock (&child->d_lock); } +spin_unlock (&alias->d_lock); }spin_unlock (&dcache_lock); }
fs/ceph/dir.c +5 -1
@@ -112,6 +112,7 @@ static int __dcache_readdir(struct file last);spin_lock (&dcache_lock); +spin_lock (&parent->d_lock);/* start at beginning? */ if (filp->f_pos == 2 || (last &&
@@ -135,7 +136,7 @@ more: fi->at_end =1 ; goto out_unlock; } -spin_lock (&dentry->d_lock); +spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED ); if (!d_unhashed(dentry) && dentry->d_inode && ceph_snap(dentry->d_inode) != CEPH_SNAPDIR && ceph_ino(dentry->d_inode) != CEPH_INO_CEPH &&
@@ -153,6 +154,7 @@ more:dget_dlock (dentry);spin_unlock (&dentry->d_lock); +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock);spin_unlock (&inode->i_lock);
@@ -177,6 +179,7 @@ more:spin_lock (&inode->i_lock);spin_lock (&dcache_lock); +spin_lock (&parent->d_lock); last = dentry;
@@ -193,6 +196,7 @@ more: err = -EAGAIN ; out_unlock: +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock);if (last) {
fs/ceph/inode.c +6 -2
@@ -826,11 +826,13 @@ static void ceph_set_dentry_offset(strucspin_unlock (&inode->i_lock);spin_lock (&dcache_lock); -spin_lock (&dn->d_lock); +spin_lock (&dir->d_lock); +spin_lock_nested (&dn->d_lock,DENTRY_D_LOCK_NESTED );list_move (&dn->d_u.d_child, &dir->d_subdirs);dout ("set_dentry_offset %p %lld (%p %p)\n" , dn, di->offset, dn->d_u.d_child.prev, dn->d_u.d_child.next);spin_unlock (&dn->d_lock); +spin_unlock (&dir->d_lock);spin_unlock (&dcache_lock); }
@@ -1212,9 +1214,11 @@ retry_lookup: }else {/* reorder parent's d_subdirs */ spin_lock (&dcache_lock); -spin_lock (&dn->d_lock); +spin_lock (&parent->d_lock); +spin_lock_nested (&dn->d_lock,DENTRY_D_LOCK_NESTED );list_move (&dn->d_u.d_child, &parent->d_subdirs);spin_unlock (&dn->d_lock); +spin_unlock (&parent->d_lock);spin_unlock (&dcache_lock); }
PATCH 16/52 fs: dcache RCU for multi-step operaitons
In reply to [email protected]The remaining usages for dcache_lock is to allow atomic, multi-step read-side operations over the directory tree by excluding modifications to the tree. Also, to walk in the leaf->root direction in the tree where we don't have a natural d_lock ordering.
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.
XXX: hmm, we could of course just take the rename lock if there is any worry about livelock. Most of these are slow paths.
--- drivers/staging/pohmelfs/path_entry.c | 15 ++- fs/autofs4/waitq.c | 16 +++ fs/dcache.c | 151 +++++++++++++++++++++++++++------- fs/nfs/namespace.c | 14 ++- fs/seq_file.c | 1 5 files changed, 163 insertions(+), 34 deletions(-)
fs/dcache.c +131 -30
@@ -80,6 +80,7 @@ static __cacheline_aligned_in_smp DEFINE__cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_lock );__cacheline_aligned_in_smp DEFINE_SEQLOCK (rename_lock ); +EXPORT_SYMBOL (rename_lock);EXPORT_SYMBOL (dcache_inode_lock);EXPORT_SYMBOL (dcache_hash_lock);EXPORT_SYMBOL (dcache_lock);
@@ -961,11 +962,15 @@ void shrink_dcache_for_umount(struct sup* Return true if the parent or its subdirectories contain * a mount point */ -int have_submounts (struct dentry *parent) { -struct dentry *this_parent = parent; +struct dentry *this_parent;struct list_head *next; +unsigned seq; + +rename_retry: + this_parent = parent; + seq =read_seqbegin (&rename_lock);spin_lock (&dcache_lock);if (d_mountpoint (parent))
@@ -999,17 +1004,38 @@ resume:* All done at this level ... ascend and resume the search. */ if (this_parent != parent) { - next = this_parent->d_u.d_child.next; +struct dentry *tmp; +struct dentry *child; + + tmp = this_parent->d_parent; +rcu_read_lock ();spin_unlock (&this_parent->d_lock); - this_parent = this_parent->d_parent; + child = this_parent; + this_parent = tmp;spin_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; goto resume; }spin_unlock (&this_parent->d_lock);spin_unlock (&dcache_lock); +if (read_seqretry (&rename_lock, seq)) + goto rename_retry;return 0 ;/* No mount points found in tree */ positive:spin_unlock (&dcache_lock); +if (read_seqretry (&rename_lock, seq)) + goto rename_retry;return 1 ; }EXPORT_SYMBOL (have_submounts);
@@ -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) {struct 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;spin_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; goto resume; } out:spin_unlock (&this_parent->d_lock);spin_unlock (&dcache_lock); +if (read_seqretry (&rename_lock, seq)) + goto rename_retry;return found; }
@@ -1606,7 +1653,7 @@ EXPORT_SYMBOL(d_add_ci);struct dentry *d_lookup (struct dentry * parent,struct qstr * name) {struct dentry * dentry =NULL ; -unsigned long seq; +unsigned seq; do { seq = read_seqbegin(&rename_lock);
@@ -2211,12 +2258,20 @@ static int prepend_name(char **buffer, ichar *__d_path (const struct path *path,struct path *root,char *buffer,int buflen) { -struct dentry *dentry = path->dentry; -struct vfsmount *vfsmnt = path->mnt; -char *end = buffer + buflen; +struct dentry *dentry; +struct vfsmount *vfsmnt; +char *end;char *retval; +unsigned seq; +rename_retry: + dentry = path->dentry; + vfsmnt = path->mnt; + end = buffer + buflen;prepend (&end, &buflen,"\0" ,1 ); + + seq =read_seqbegin (&rename_lock); +rcu_read_lock ();spin_lock (&dentry->d_lock); unlinked: if (d_unlinked(dentry) &&
@@ -2253,12 +2308,16 @@ unlinked: retval = end;spin_unlock (&dentry->d_lock); dentry = parent; +spin_lock (&dentry->d_lock);if (d_unlinked (dentry)) goto unlinked; } out:spin_unlock (&dentry->d_lock); +rcu_read_unlock (); +if (read_seqretry (&rename_lock, seq)) + goto rename_retry;return retval; global_root:
@@ -2267,6 +2326,7 @@ global_root: goto Elong; root->mnt = vfsmnt; root->dentry = dentry; +/* XXX: this could wrongly modify root if we rename retry */ goto out; Elong:
@@ -2349,12 +2409,19 @@ char *dynamic_dname(struct dentry *dentr*/ char *dentry_path (struct dentry *dentry,char *buf,int buflen) { -char *end = buf + buflen; +char *end;char *retval; +unsigned seq; + +rename_retry: + end = buf + buflen; +prepend (&end, &buflen,"\0" ,1 ); + seq =read_seqbegin (&rename_lock);spin_lock (&dcache_lock); +br_read_lock (vfsmount_lock); +rcu_read_lock ();/* protect parent */ spin_lock (&dentry->d_lock); -prepend (&end, &buflen,"\0" ,1 ); unlinked:if (d_unlinked (dentry) && (prepend (&end, &buflen,"//deleted" ,9 ) !=0 ))
@@ -2380,13 +2447,17 @@ unlinked:if (d_unlinked (dentry)) goto unlinked; } +out:spin_unlock (&dentry->d_lock); +rcu_read_unlock (); +br_read_unlock (vfsmount_lock);spin_unlock (&dcache_lock); +if (read_seqretry (&rename_lock, seq)) + goto rename_retry;return retval; Elong: -spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); -return ERR_PTR (-ENAMETOOLONG ); + retval =ERR_PTR (-ENAMETOOLONG ); + goto out; }/*
@@ -2481,25 +2552,25 @@ out:int is_subdir (struct dentry *new_dentry,struct dentry *old_dentry) {int result; -unsigned long seq; +unsigned seq;if (new_dentry == old_dentry)return 1 ; -/* -* Need rcu_readlock to protect against the d_parent trashing -* due to d_move -*/ -rcu_read_lock ();do {/* for restarting inner loop in case of seq retry */ seq =read_seqbegin (&rename_lock); +/* +* Need rcu_readlock to protect against the d_parent trashing +* due to d_move +*/ +rcu_read_lock ();if (d_ancestor (old_dentry, new_dentry)) result =1 ;else result =0 ; +rcu_read_unlock (); }while (read_seqretry (&rename_lock, seq)); -rcu_read_unlock ();return result; }
@@ -2531,9 +2602,13 @@ EXPORT_SYMBOL(path_is_under);void d_genocide (struct dentry *root) { -struct dentry *this_parent = root; +struct dentry *this_parent;struct list_head *next; +unsigned seq; +rename_retry: + this_parent = root; + seq =read_seqbegin (&rename_lock);spin_lock (&dcache_lock);spin_lock (&this_parent->d_lock); repeat:
@@ -2543,6 +2618,7 @@ resume:struct list_head *tmp = next; struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child); next = tmp->next; +spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED );if (d_unhashed (dentry) || !dentry->d_inode) {spin_unlock (&dentry->d_lock);
@@ -2555,19 +2631,44 @@ resume:spin_acquire (&this_parent->d_lock.dep_map,0 ,1 , _RET_IP_); goto repeat; } - dentry->d_count--; +if (!(dentry->d_flags &DCACHE_GENOCIDE )) { + dentry->d_flags |=DCACHE_GENOCIDE ; + dentry->d_count--; + }spin_unlock (&dentry->d_lock); }if (this_parent != root) { - next = this_parent->d_u.d_child.next; - this_parent->d_count--; +struct dentry *tmp; +struct dentry *child; + + tmp = this_parent->d_parent; +if (!(this_parent->d_flags &DCACHE_GENOCIDE )) { + this_parent->d_flags |=DCACHE_GENOCIDE ; + this_parent->d_count--; + } +rcu_read_lock ();spin_unlock (&this_parent->d_lock); - this_parent = this_parent->d_parent; + child = this_parent; + this_parent = tmp;spin_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; goto resume; }spin_unlock (&this_parent->d_lock);spin_unlock (&dcache_lock); +if (read_seqretry (&rename_lock, seq)) + goto rename_retry; }/**
fs/seq_file.c +1 -0
@@ -470,6 +470,7 @@ int seq_path_root(struct seq_file *m, st p =__d_path (path, root, buf, size);br_read_unlock (vfsmount_lock);spin_unlock (&dcache_lock); + res =PTR_ERR (p);if (!IS_ERR (p)) {char *end =mangle_path (buf, p, esc);
drivers/staging/pohmelfs/path_entry.c +12 -3
@@ -83,10 +83,11 @@ out:int pohmelfs_path_length (struct pohmelfs_inode *pi) {struct dentry *d, *root, *first; -int len =1 ;/* Root slash */ +int len; +unsigned seq; - first = d =d_find_alias (&pi->vfs_inode); -if (!d) { + first =d_find_alias (&pi->vfs_inode); +if (!first) {dprintk ("%s: ino: %llu, mode: %o.\n" , __func__, pi->ino, pi->vfs_inode.i_mode);return -ENOENT ; }
@@ -95,6 +96,11 @@ int pohmelfs_path_length(struct pohmelfs root =dget (current->fs->root.dentry);spin_unlock (¤t->fs->lock); +rename_retry: + len =1 ;/* Root slash */ + d = first; + seq =read_seqbegin (&rename_lock); +rcu_read_lock ();spin_lock (&dcache_lock);if (!IS_ROOT (d) &&d_unhashed (d))
@@ -105,6 +111,9 @@ int pohmelfs_path_length(struct pohmelfs d = d->d_parent; }spin_unlock (&dcache_lock); +rcu_read_unlock (); +if (read_seqretry (&rename_lock, seq)) + goto rename_retry;dput (root);dput (first);
fs/autofs4/waitq.c +14 -2
@@ -186,16 +186,25 @@ static int autofs4_getpath(struct autofs {struct dentry *root = sbi->sb->s_root;struct dentry *tmp; -char *buf = *name; +char *buf;char *p; -int len =0 ; +int len; +unsigned seq; +rename_retry: + buf = *name; + len =0 ; + seq =read_seqbegin (&rename_lock); +rcu_read_lock ();spin_lock (&dcache_lock);for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent) len += tmp->d_name.len +1 ;if (!len || --len >NAME_MAX ) {spin_unlock (&dcache_lock); +rcu_read_unlock (); +if (read_seqretry (&rename_lock, seq)) + goto rename_retry;return 0 ; }
@@ -209,6 +218,9 @@ static int autofs4_getpath(struct autofsstrncpy (p, tmp->d_name.name, tmp->d_name.len); }spin_unlock (&dcache_lock); +rcu_read_unlock (); +if (read_seqretry (&rename_lock, seq)) + goto rename_retry;return len; }
fs/nfs/namespace.c +13 -1
@@ -49,11 +49,17 @@ char *nfs_path(const char *base,const struct dentry *dentry, char *buffer, ssize_t buflen) { - char *end = buffer+buflen; + char *end;int namelen; +unsigned seq; +rename_retry: + end = buffer+buflen; *--end ='\0' ; buflen--; + + seq =read_seqbegin (&rename_lock); +rcu_read_lock ();spin_lock (&dcache_lock);while (!IS_ROOT (dentry) && dentry != droot) { namelen = dentry->d_name.len;
@@ -66,6 +72,9 @@ char *nfs_path(const char *base, dentry = dentry->d_parent; }spin_unlock (&dcache_lock); +rcu_read_unlock (); +if (read_seqretry (&rename_lock, seq)) + goto rename_retry;if (*end !='/' ) {if (--buflen <0 ) goto Elong;
@@ -83,6 +92,9 @@ char *nfs_path(const char *base,return end; Elong_unlock:spin_unlock (&dcache_lock); +rcu_read_unlock (); +if (read_seqretry (&rename_lock, seq)) + goto rename_retry; Elong:return ERR_PTR (-ENAMETOOLONG ); }
include/linux/dcache.h +1 -0
@@ -187,6 +187,7 @@ d_iput: no no no yes#define DCACHE_FSNOTIFY_PARENT_WATCHED 0x0080/* Parent inode is watched by some fsnotify listener */ #define DCACHE_CANT_MOUNT 0x0100 +#define DCACHE_GENOCIDE 0x0200extern spinlock_t dcache_inode_lock;extern spinlock_t dcache_hash_lock;
PATCH 17/52 fs: dcache remove dcache_lock
In reply to [email protected]dcache_lock no longer protects anything. remove it.
--- Documentation/filesystems/Locking | 2 arch/powerpc/platforms/cell/spufs/inode.c | 5 - drivers/infiniband/hw/ipath/ipath_fs.c | 6 - drivers/infiniband/hw/qib/qib_fs.c | 3 drivers/staging/pohmelfs/path_entry.c | 2 drivers/usb/core/inode.c | 3 fs/affs/amigaffs.c | 2 fs/autofs4/autofs_i.h | 3 fs/autofs4/expire.c | 24 ++--- fs/autofs4/root.c | 14 +-- fs/autofs4/waitq.c | 7 - fs/ceph/dir.c | 6 - fs/ceph/inode.c | 4 fs/coda/cache.c | 2 fs/configfs/configfs_internal.h | 2 fs/configfs/inode.c | 6 - fs/dcache.c | 135 ++++-------------------------- fs/exportfs/expfs.c | 4 fs/namei.c | 9 -- fs/ncpfs/dir.c | 3 fs/ncpfs/ncplib_kernel.h | 4 fs/nfs/dir.c | 3 fs/nfs/getroot.c | 2 fs/nfs/namespace.c | 3 fs/notify/fsnotify.c | 2 fs/notify/inotify/inotify.c | 4 fs/ocfs2/dcache.c | 2 fs/seq_file.c | 2 fs/smbfs/cache.c | 4 include/linux/dcache.h | 17 +-- include/linux/fs.h | 4 include/linux/fsnotify_backend.h | 5 - kernel/cgroup.c | 6 - security/selinux/selinuxfs.c | 4 security/tomoyo/realpath.c | 2 35 files changed, 67 insertions(+), 239 deletions(-)
fs/dcache.c +20 -115
@@ -54,11 +54,10 @@* - d_alias, d_inode * * Ordering: -* dcache_lock -* dcache_inode_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
@@ -77,13 +76,11 @@ EXPORT_SYMBOL_GPL(sysctl_vfs_cache_press__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 (rename_lock);EXPORT_SYMBOL (dcache_inode_lock);EXPORT_SYMBOL (dcache_hash_lock); -EXPORT_SYMBOL (dcache_lock);static struct kmem_cache *dentry_cache__read_mostly ;
@@ -125,7 +122,7 @@ static void d_callback(struct rcu_head * }/* -* no dcache_lock, please. +* no locks, please. */ static void d_free (struct dentry *dentry) {
@@ -147,7 +144,6 @@ static void d_free(struct dentry *dentrystatic void dentry_iput (struct dentry * dentry) __releases(dentry->d_lock)__releases (dcache_inode_lock) -__releases (dcache_lock) {struct inode *inode = dentry->d_inode;if (inode) {
@@ -155,7 +151,6 @@ static void dentry_iput(struct dentry *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);if (dentry->d_op && dentry->d_op->d_iput)
@@ -165,7 +160,6 @@ static void dentry_iput(struct dentry * }else {spin_unlock (&dentry->d_lock);spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock); } }
@@ -231,13 +225,12 @@ static void dentry_lru_del_init(struct d* * If this is the root of the dentry tree, return NULL. * -* dcache_lock and d_lock and d_parent->d_lock must be held by caller, and +* d_lock and d_parent->d_lock must be held by caller, and * are dropped by d_kill. */ static struct dentry *d_kill (struct dentry *dentry) __releases(dentry->d_lock)__releases (dcache_inode_lock) -__releases (dcache_lock) {struct dentry *parent;
@@ -294,21 +287,10 @@ repeat:might_sleep ();spin_lock (&dentry->d_lock);if (dentry->d_count ==1 ) { -if (!spin_trylock (&dcache_lock)) { -/* -* Something of a livelock possibility we could avoid -* by taking dcache_lock and trying again, but we -* 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; +spin_unlock (&dentry->d_lock); + goto repeat; } parent = dentry->d_parent;if (parent && parent != dentry) {
@@ -323,7 +305,6 @@ drop2:spin_unlock (&dentry->d_lock);if (parent && parent != dentry)spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock);return ; }
@@ -345,7 +326,6 @@ drop2:if (parent && parent != dentry)spin_unlock (&parent->d_lock);spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock);return ; unhash_it:
@@ -376,11 +356,9 @@ int d_invalidate(struct dentry * dentry)/* * If it's already been dropped, return OK. */ -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);if (d_unhashed (dentry)) {spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);return 0 ; }/*
@@ -389,9 +367,7 @@ int d_invalidate(struct dentry * dentry)*/ if (!list_empty (&dentry->d_subdirs)) {spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);shrink_dcache_parent (dentry); -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock); }
@@ -408,19 +384,17 @@ int d_invalidate(struct dentry * dentry)if (dentry->d_count >1 ) {if (dentry->d_inode &&S_ISDIR (dentry->d_inode->i_mode)) {spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);return -EBUSY ; } }__d_drop (dentry);spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);return 0 ; }EXPORT_SYMBOL (d_invalidate); -/* This must be called with dcache_lock and d_lock held */ +/* This must be called with d_lock held */ static inline struct dentry *__dget_locked_dlock (struct dentry *dentry) { dentry->d_count++;
@@ -428,7 +402,7 @@ static inline struct dentry * __dget_locreturn dentry; } -/* This should be called _only_ with dcache_lock held */ +/* This must be called with d_lock held */ static inline struct dentry *__dget_locked (struct dentry *dentry) {spin_lock (&dentry->d_lock);
@@ -526,11 +500,9 @@ struct dentry * d_find_alias(struct inodstruct dentry *de =NULL ;if (!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; }
@@ -544,7 +516,6 @@ void d_prune_aliases(struct inode *inode {struct 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);
@@ -553,14 +524,12 @@ restart:__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);
@@ -574,20 +543,16 @@ EXPORT_SYMBOL(d_prune_aliases);*/ static void prune_one_dentry (struct dentry * dentry) __releases(dentry->d_lock) -__releases (dcache_lock) -__acquires (dcache_lock) {__d_drop (dentry); dentry =d_kill (dentry);/* -* Prune ancestors. Locking is simpler than in dput(), -* because dcache_lock needs to be taken anyway. +* Prune ancestors. */ while (dentry) {struct dentry *parent =NULL ; -spin_lock (&dcache_lock);spin_lock (&dcache_inode_lock); again:spin_lock (&dentry->d_lock);
@@ -604,7 +569,6 @@ again:spin_unlock (&parent->d_lock);spin_unlock (&dentry->d_lock);spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock);return ; }
@@ -673,7 +637,6 @@ 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 */
@@ -703,14 +666,13 @@ again1: }__dentry_lru_del_init (dentry);spin_unlock (&dcache_lru_lock); +prune_one_dentry (dentry); -/* dcache_lock and dentry->d_lock dropped */ -spin_lock (&dcache_lock); +/* dentry->d_lock dropped */ 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)) goto restart;
@@ -740,7 +702,6 @@ static void prune_dcache(int count)if (unused ==0 || count ==0 )return ; -spin_lock (&dcache_lock);if (count >= unused) prune_ratio =1 ;else
@@ -777,11 +738,9 @@ static void prune_dcache(int count)if (down_read_trylock (&sb->s_umount)) {if ((sb->s_root !=NULL ) && (!list_empty (&sb->s_dentry_lru))) { -spin_unlock (&dcache_lock);__shrink_dcache_sb (sb, &w_count,DCACHE_REFERENCED ); pruned -= w_count; -spin_lock (&dcache_lock); }up_read (&sb->s_umount); }
@@ -795,7 +754,6 @@ static void prune_dcache(int count)break ; }spin_unlock (&sb_lock); -spin_unlock (&dcache_lock); }/**
@@ -825,12 +783,10 @@ static void shrink_dcache_for_umount_subBUG_ON (!IS_ROOT (dentry));/* detach this root from the system */ -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);dentry_lru_del_init (dentry);__d_drop (dentry);spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);for (;;) {/* descend to the first leaf in the current subtree */
@@ -839,7 +795,6 @@ static void shrink_dcache_for_umount_sub/* this is a branch with children - detach all of them * from the system in one go */ -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);list_for_each_entry (loop, &dentry->d_subdirs, d_u.d_child) {
@@ -849,7 +804,6 @@ static void shrink_dcache_for_umount_subspin_unlock (&loop->d_lock); }spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);/* move to the first child */ dentry = list_entry(dentry->d_subdirs.next,
@@ -920,8 +874,7 @@ out:/* * destroy the dentries attached to a superblock on unmounting -* - we don't need to use dentry->d_lock, and only need dcache_lock when -* removing the dentry from the system lists and hashes because: +* - we don't need to use dentry->d_lock because: * - the superblock is detached from all mountings and open files, so the * dentry trees will not be rearranged by the VFS * - s_umount is write-locked, so the memory pressure shrinker will ignore
@@ -972,7 +925,6 @@ rename_retry: this_parent = parent; seq =read_seqbegin (&rename_lock); -spin_lock (&dcache_lock);if (d_mountpoint (parent)) goto positive;spin_lock (&this_parent->d_lock);
@@ -1019,7 +971,6 @@ resume:// 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; }
@@ -1028,12 +979,10 @@ resume: goto resume; }spin_unlock (&this_parent->d_lock); -spin_unlock (&dcache_lock);if (read_seqretry (&rename_lock, seq)) goto rename_retry;return 0 ;/* No mount points found in tree */ positive: -spin_unlock (&dcache_lock);if (read_seqretry (&rename_lock, seq)) goto rename_retry;return 1 ;
@@ -1066,7 +1015,6 @@ rename_retry: this_parent = parent; seq =read_seqbegin (&rename_lock); -spin_lock (&dcache_lock);spin_lock (&this_parent->d_lock); repeat: next = this_parent->d_subdirs.next;
@@ -1129,7 +1077,6 @@ resume:// 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; }
@@ -1139,7 +1086,6 @@ resume: } out:spin_unlock (&this_parent->d_lock); -spin_unlock (&dcache_lock);if (read_seqretry (&rename_lock, seq)) goto rename_retry;return found;
@@ -1240,7 +1186,6 @@ struct dentry *d_alloc(struct dentry * pINIT_LIST_HEAD (&dentry->d_u.d_child);if (parent) { -spin_lock (&dcache_lock);spin_lock (&parent->d_lock);spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED ); dentry->d_parent =dget_dlock (parent);
@@ -1248,7 +1193,6 @@ struct dentry *d_alloc(struct dentry * plist_add (&dentry->d_u.d_child, &parent->d_subdirs);spin_unlock (&dentry->d_lock);spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock); }atomic_inc (&dentry_stat.nr_dentry);
@@ -1268,7 +1212,6 @@ struct dentry *d_alloc_name(struct dentr }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);
@@ -1297,11 +1240,9 @@ static void __d_instantiate(struct dentrvoid d_instantiate (struct dentry *entry,struct inode * inode) {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); }EXPORT_SYMBOL (d_instantiate);
@@ -1360,11 +1301,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) {security_d_instantiate (entry, inode);
@@ -1453,12 +1392,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; }
@@ -1474,7 +1411,6 @@ struct dentry *d_obtain_alias(struct inospin_unlock (&tmp->d_lock);spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock);return tmp; out_iput:
@@ -1504,21 +1440,18 @@ struct dentry *d_splice_alias(struct inostruct dentry *new =NULL ;if (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);iput (inode); }else { -/* already taking dcache_lock, so d_add() by hand */ +/* already got dcache_inode_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); }
@@ -1591,12 +1524,10 @@ struct dentry *d_add_ci(struct dentry *d* Negative dentry: instantiate it unless the inode is a directory and * 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; }
@@ -1608,7 +1539,6 @@ 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);iput (inode);
@@ -1631,7 +1561,7 @@ EXPORT_SYMBOL(d_add_ci);* is returned. The caller must use dput to free the entry when it has * finished using it. %NULL is returned on failure. * -* __d_lookup is dcache_lock free. The hash list is protected using RCU. +* __d_lookup is global lock free. The hash list is protected using RCU. * Memory barriers are used while updating and doing lockless traversal. * To avoid races with d_move while rename is happening, d_lock is used. *
@@ -1643,7 +1573,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 dcache_lock +* select_parent and __dget_locked. This laziness saves lookup from LRU lock * acquisition. * * d_lookup() is protected against the concurrent renames in some unrelated
@@ -1774,25 +1704,22 @@ int d_validate(struct dentry *dentry, stif (dentry->d_parent != dparent) goto out; -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);spin_lock (&dcache_hash_lock); base =d_hash (dparent, dentry->d_name.hash);hlist_for_each (lhp,base) {/* hlist_for_each_entry_rcu() not required for d_hash list -* as it is parsed under dcache_lock +* as it is parsed under dcache_hash_lock */ if (dentry == hlist_entry(lhp, struct dentry, d_hash)) {spin_unlock (&dcache_hash_lock);__dget_locked_dlock (dentry);spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);return 1 ; } }spin_unlock (&dcache_hash_lock);spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); out:return 0 ; }
@@ -1825,7 +1752,6 @@ 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);
@@ -1841,7 +1767,6 @@ void d_delete(struct dentry * dentry)spin_unlock (&dentry->d_lock);spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock);fsnotify_nameremove (dentry, isdir); }
@@ -1868,13 +1793,11 @@ static void _d_rehash(struct dentry * envoid d_rehash (struct dentry * entry) { -spin_lock (&dcache_lock);spin_lock (&entry->d_lock);spin_lock (&dcache_hash_lock);_d_rehash (entry);spin_unlock (&dcache_hash_lock);spin_unlock (&entry->d_lock); -spin_unlock (&dcache_lock); }EXPORT_SYMBOL (d_rehash);
@@ -2032,9 +1955,7 @@ static void d_move_locked(struct dentryvoid d_move (struct dentry * dentry,struct dentry * target) { -spin_lock (&dcache_lock);d_move_locked (dentry, target); -spin_unlock (&dcache_lock); }EXPORT_SYMBOL (d_move);
@@ -2061,13 +1982,12 @@ struct dentry *d_ancestor(struct dentry* This helper attempts to cope with remotely renamed directories * * It assumes that the caller is already holding -* dentry->d_parent->d_inode->i_mutex and the dcache_lock +* dentry->d_parent->d_inode->i_mutex * * Note: If ever the locking in lock_rename() changes, then please * remember to update this too... */ static struct dentry *__d_unalias (struct dentry *dentry,struct dentry *alias) -__releases (dcache_lock) {struct mutex *m1 =NULL , *m2 =NULL ;struct dentry *ret;
@@ -2094,7 +2014,6 @@ out_unalias: ret = alias; out_err:spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock);if (m2)mutex_unlock (m2);if (m1)
@@ -2158,7 +2077,6 @@ struct dentry *d_materialise_unique(struBUG_ON (!d_unhashed (dentry)); -spin_lock (&dcache_lock);spin_lock (&dcache_inode_lock);if (!inode) {
@@ -2204,7 +2122,6 @@ found:spin_unlock (&dcache_hash_lock);spin_unlock (&actual->d_lock);spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock); out_nolock:if (actual == dentry) {security_d_instantiate (dentry, inode);
@@ -2216,7 +2133,6 @@ out_nolock: shouldnt_be_hashed:spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock);BUG (); }EXPORT_SYMBOL_GPL (d_materialise_unique);
@@ -2249,8 +2165,7 @@ static int prepend_name(char **buffer, i* Returns a pointer into the buffer or an error code if the * path was too long. * -* "buflen" should be positive. Caller holds the dcache_lock and -* path->dentry->d_lock. +* "buflen" should be positive. Caller holds the path->dentry->d_lock. * * If path is not reachable from the supplied root, then the value of * root is changed (without modifying refcounts).
@@ -2371,12 +2286,10 @@ char *d_path(const struct path *path, chpath_get (&root);spin_unlock (¤t->fs->lock); -spin_lock (&dcache_lock);br_read_lock (vfsmount_lock); tmp = root; res =__d_path (path, &tmp, buf, buflen);br_read_unlock (vfsmount_lock); -spin_unlock (&dcache_lock);path_put (&root);return res;
@@ -2418,7 +2331,6 @@ rename_retry:prepend (&end, &buflen,"\0" ,1 ); seq =read_seqbegin (&rename_lock); -spin_lock (&dcache_lock);br_read_lock (vfsmount_lock);rcu_read_lock ();/* protect parent */ spin_lock (&dentry->d_lock);
@@ -2451,7 +2363,6 @@ out:spin_unlock (&dentry->d_lock);rcu_read_unlock ();br_read_unlock (vfsmount_lock); -spin_unlock (&dcache_lock);if (read_seqretry (&rename_lock, seq)) goto rename_retry;return retval;
@@ -2495,7 +2406,6 @@ SYSCALL_DEFINE2(getcwd, char __user *, bspin_unlock (¤t->fs->lock); error = -ENOENT ; -spin_lock (&dcache_lock);br_read_lock (vfsmount_lock);spin_lock (&pwd.dentry->d_lock);if (!d_unlinked (pwd.dentry)) {
@@ -2507,7 +2417,6 @@ SYSCALL_DEFINE2(getcwd, char __user *, b/* XXX: race here, have to close (eg. return unlinked from __d_path) */ cwd =__d_path (&pwd, &tmp, page,PAGE_SIZE );br_read_unlock (vfsmount_lock); -spin_unlock (&dcache_lock); error =PTR_ERR (cwd);if (IS_ERR (cwd))
@@ -2523,7 +2432,6 @@ SYSCALL_DEFINE2(getcwd, char __user *, b }else {spin_unlock (&pwd.dentry->d_lock);br_read_unlock (vfsmount_lock); -spin_unlock (&dcache_lock); } out:
@@ -2609,7 +2517,6 @@ void d_genocide(struct dentry *root) rename_retry: this_parent = root; seq =read_seqbegin (&rename_lock); -spin_lock (&dcache_lock);spin_lock (&this_parent->d_lock); repeat: next = this_parent->d_subdirs.next;
@@ -2657,7 +2564,6 @@ resume:// 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; }
@@ -2666,7 +2572,6 @@ resume: goto resume; }spin_unlock (&this_parent->d_lock); -spin_unlock (&dcache_lock);if (read_seqretry (&rename_lock, seq)) goto rename_retry; }
fs/namei.c +2 -7
@@ -618,8 +618,8 @@ int follow_up(struct path *path)return 1 ; } -/* no need for dcache_lock, as serialization is taken care in -* namespace.c +/* +* serialization is taken care of in namespace.c */ static int __follow_mount (struct path *path) {
@@ -651,9 +651,6 @@ static void follow_mount(struct path *pa } } -/* no need for dcache_lock, as serialization is taken care in -* namespace.c -*/ int follow_down (struct path *path) {struct vfsmount *mounted;
@@ -2152,12 +2149,10 @@ void dentry_unhash(struct dentry *dentry {dget (dentry);shrink_dcache_parent (dentry); -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);if (dentry->d_count ==2 )__d_drop (dentry);spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); }int vfs_rmdir (struct inode *dir,struct dentry *dentry)
fs/seq_file.c +0 -2
@@ -465,11 +465,9 @@ int seq_path_root(struct seq_file *m, stif (size) {char *p; -spin_lock (&dcache_lock);br_read_lock (vfsmount_lock); p =__d_path (path, root, buf, size);br_read_unlock (vfsmount_lock); -spin_unlock (&dcache_lock); res =PTR_ERR (p);if (!IS_ERR (p)) {
include/linux/dcache.h +7 -10
@@ -150,13 +150,13 @@ struct dentry_operations {/* locking rules: -big lock dcache_lock d_lock may block -d_revalidate: no no no yes -d_hash no no no yes -d_compare: no yes yes no -d_delete: no yes no no -d_release: no no no yes -d_iput: no no no yes +big lock d_lock may block +d_revalidate: no no yes +d_hash no no yes +d_compare: no yes no +d_delete: no no no +d_release: no no yes +d_iput: no no yes */ /* d_flags entries */
@@ -191,7 +191,6 @@ d_iput: no no no yesextern spinlock_t dcache_inode_lock;extern spinlock_t dcache_hash_lock; -extern spinlock_t dcache_lock;extern seqlock_t rename_lock;/**
@@ -222,11 +221,9 @@ static inline void __d_drop(struct dentrstatic inline void d_drop (struct dentry *dentry) { -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);__d_drop (dentry);spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); }static inline int dname_external (struct dentry *dentry)
fs/notify/inotify/inotify.c +2 -2
@@ -181,7 +181,6 @@ static void set_dentry_child_flags(struc {struct dentry *alias; -spin_lock (&dcache_lock);spin_lock (&dcache_inode_lock);list_for_each_entry (alias, &inode->i_dentry, d_alias) {struct dentry *child;
@@ -201,7 +200,6 @@ static void set_dentry_child_flags(strucspin_unlock (&alias->d_lock); }spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock); }/*
@@ -269,6 +267,7 @@ void inotify_d_instantiate(struct dentryif (!inode)return ; +/* XXX: need parent lock in place of dcache_lock? */ spin_lock (&entry->d_lock); parent = entry->d_parent;if (parent->d_inode &&inotify_inode_watched (parent->d_inode))
@@ -283,6 +282,7 @@ void inotify_d_move(struct dentry *entry {struct dentry *parent; +/* XXX: need parent lock in place of dcache_lock? */ parent = entry->d_parent;if (inotify_inode_watched (parent->d_inode)) entry->d_flags |=DCACHE_INOTIFY_PARENT_WATCHED ;
fs/exportfs/expfs.c +0 -4
@@ -47,24 +47,20 @@ find_acceptable_alias(struct dentry *resif (acceptable (context, result))return 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);if (dentry != result &&acceptable (context, dentry)) {dput (result);return dentry; } -spin_lock (&dcache_lock);spin_lock (&dcache_inode_lock); toput = dentry; }spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock);if (toput)dput (toput);
Documentation/filesystems/Locking +1 -1
@@ -17,7 +17,7 @@ prototypes: void (*d_iput)(struct dentry *, struct inode *); char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen); -locking rules: +locking rules: XXX: update these!! none have BKL dcache_lock rename_lock ->d_lock may block d_revalidate: no no no yes
arch/powerpc/platforms/cell/spufs/inode.c +1 -4
@@ -158,21 +158,18 @@ static void spufs_prune_dir(struct dentrmutex_lock (&dir->d_inode->i_mutex);list_for_each_entry_safe (dentry, tmp, &dir->d_subdirs, d_u.d_child) { -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);if (!(d_unhashed (dentry)) && dentry->d_inode) {dget_locked_dlock (dentry);__d_drop (dentry);spin_unlock (&dentry->d_lock);simple_unlink (dir->d_inode, dentry); -/* XXX: what is dcache_lock protecting here? Other +/* XXX: what was dcache_lock protecting here? Other * filesystems (IB, configfs) release dcache_lock * before unlink */ -spin_unlock (&dcache_lock);dput (dentry); }else {spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); } }shrink_dcache_parent (dir);
drivers/infiniband/hw/ipath/ipath_fs.c +1 -5
@@ -273,18 +273,14 @@ static int remove_file(struct dentry *pa goto bail; } -spin_lock (&dcache_lock);spin_lock (&tmp->d_lock);if (!(d_unhashed (tmp) && tmp->d_inode)) {dget_locked_dlock (tmp);__d_drop (tmp);spin_unlock (&tmp->d_lock); -spin_unlock (&dcache_lock);simple_unlink (parent->d_inode, tmp); - }else { + }else spin_unlock (&tmp->d_lock); -spin_unlock (&dcache_lock); - } ret =0 ; bail:
drivers/usb/core/inode.c +0 -3
@@ -347,7 +347,6 @@ static int usbfs_empty (struct dentry *d {struct list_head *list; -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);list_for_each (list, &dentry->d_subdirs) { struct dentry *de = list_entry(list, struct dentry, d_u.d_child);
@@ -356,13 +355,11 @@ static int usbfs_empty (struct dentry *dif (usbfs_positive (de)) {spin_unlock (&de->d_lock);spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);return 0 ; }spin_unlock (&de->d_lock); }spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);return 1 ; }
fs/affs/amigaffs.c +0 -2
@@ -128,7 +128,6 @@ affs_fix_dcache(struct dentry *dentry, uvoid *data = dentry->d_fsdata;struct list_head *head, *next; -spin_lock (&dcache_lock);spin_lock (&dcache_inode_lock); head = &inode->i_dentry; next = head->next;
@@ -141,7 +140,6 @@ affs_fix_dcache(struct dentry *dentry, u next = next->next; }spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock); }
fs/coda/cache.c +0 -2
@@ -86,7 +86,6 @@ static void coda_flag_children(struct destruct list_head *child;struct dentry *de; -spin_lock (&dcache_lock);spin_lock (&parent->d_lock);list_for_each (child, &parent->d_subdirs) {
@@ -97,7 +96,6 @@ static void coda_flag_children(struct decoda_flag_inode (de->d_inode, flag); }spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock);return ; }
fs/configfs/configfs_internal.h +0 -2
@@ -120,7 +120,6 @@ static inline struct config_item *config {struct config_item * item =NULL ; -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);if (!d_unhashed (dentry)) {struct configfs_dirent * sd = dentry->d_fsdata;
@@ -131,7 +130,6 @@ static inline struct config_item *config item =config_item_get (sd->s_element); }spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);return item; }
fs/configfs/inode.c +1 -5
@@ -249,18 +249,14 @@ void configfs_drop_dentry(struct configfstruct dentry * dentry = sd->s_dentry;if (dentry) { -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);if (!(d_unhashed (dentry) && dentry->d_inode)) {dget_locked_dlock (dentry);__d_drop (dentry);spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);simple_unlink (parent->d_inode, dentry); - }else { + }else spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); - } } }
fs/ncpfs/dir.c +0 -3
@@ -364,7 +364,6 @@ ncp_dget_fpos(struct dentry *dentry, str }/* If a pointer is invalid, we search the dentry. */ -spin_lock (&dcache_lock);spin_lock (&parent->d_lock); next = parent->d_subdirs.next;while (next != &parent->d_subdirs) {
@@ -375,13 +374,11 @@ ncp_dget_fpos(struct dentry *dentry, strelse dent =NULL ;spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock); goto out; } next = next->next; }spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock);return NULL ; out:
fs/ncpfs/ncplib_kernel.h +0 -4
@@ -192,7 +192,6 @@ ncp_renew_dentries(struct dentry *parentstruct list_head *next;struct dentry *dentry; -spin_lock (&dcache_lock);spin_lock (&parent->d_lock); next = parent->d_subdirs.next;while (next != &parent->d_subdirs) {
@@ -206,7 +205,6 @@ ncp_renew_dentries(struct dentry *parent next = next->next; }spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock); } static inline void
@@ -216,7 +214,6 @@ ncp_invalidate_dircache_entries(struct dstruct list_head *next;struct dentry *dentry; -spin_lock (&dcache_lock);spin_lock (&parent->d_lock); next = parent->d_subdirs.next;while (next != &parent->d_subdirs) {
@@ -226,7 +223,6 @@ ncp_invalidate_dircache_entries(struct d next = next->next; }spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock); }struct ncp_cache_head {
fs/nfs/dir.c +0 -3
@@ -1464,11 +1464,9 @@ static int nfs_unlink(struct inode *dir,dfprintk (VFS ,"NFS: unlink(%s/%ld, %s)\n" , dir->i_sb->s_id, dir->i_ino, dentry->d_name.name); -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);if (dentry->d_count >1 ) {spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);/* Start asynchronous writeout of the inode */ write_inode_now (dentry->d_inode,0 ); error =nfs_sillyrename (dir, dentry);
@@ -1479,7 +1477,6 @@ static int nfs_unlink(struct inode *dir, need_rehash =1 ; }spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); error =nfs_safe_remove (dentry);if (!error || error == -ENOENT ) {nfs_set_verifier (dentry,nfs_save_change_attribute (dir));
fs/ocfs2/dcache.c +0 -2
@@ -151,7 +151,6 @@ struct dentry *ocfs2_find_local_alias(ststruct list_head *p;struct 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);
@@ -171,7 +170,6 @@ struct dentry *ocfs2_find_local_alias(st }spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock);return dentry; }
fs/smbfs/cache.c +0 -4
@@ -62,7 +62,6 @@ smb_invalidate_dircache_entries(struct dstruct list_head *next;struct dentry *dentry; -spin_lock (&dcache_lock);spin_lock (&parent->d_lock); next = parent->d_subdirs.next;while (next != &parent->d_subdirs) {
@@ -72,7 +71,6 @@ smb_invalidate_dircache_entries(struct d next = next->next; }spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock); }/*
@@ -98,7 +96,6 @@ smb_dget_fpos(struct dentry *dentry, str }/* If a pointer is invalid, we search the dentry. */ -spin_lock (&dcache_lock);spin_lock (&parent->d_lock); next = parent->d_subdirs.next;while (next != &parent->d_subdirs) {
@@ -115,7 +112,6 @@ smb_dget_fpos(struct dentry *dentry, str dent =NULL ; out_unlock:spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock);return dent; }
kernel/cgroup.c +0 -6
@@ -869,7 +869,6 @@ static void cgroup_clear_directory(strucstruct list_head *node;BUG_ON (!mutex_is_locked (&dentry->d_inode->i_mutex)); -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock); node = dentry->d_subdirs.next;while (node != &dentry->d_subdirs) {
@@ -884,18 +883,15 @@ static void cgroup_clear_directory(strucdget_locked_dlock (d);spin_unlock (&d->d_lock);spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock);d_delete (d);simple_unlink (dentry->d_inode, d);dput (d); -spin_lock (&dcache_lock);spin_lock (&dentry->d_lock); }else spin_unlock (&d->d_lock); node = dentry->d_subdirs.next; }spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); }/*
@@ -907,14 +903,12 @@ static void cgroup_d_remove_dir(struct dcgroup_clear_directory (dentry); -spin_lock (&dcache_lock); parent = dentry->d_parent;spin_lock (&parent->d_lock);spin_lock (&dentry->d_lock);list_del_init (&dentry->d_u.d_child);spin_unlock (&dentry->d_lock);spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock);remove_dir (dentry); }
security/selinux/selinuxfs.c +0 -4
@@ -941,7 +941,6 @@ static void sel_remove_entries(struct de {struct list_head *node; -spin_lock (&dcache_lock);spin_lock (&de->d_lock); node = de->d_subdirs.next;while (node != &de->d_subdirs) {
@@ -954,11 +953,9 @@ static void sel_remove_entries(struct dedget_locked_dlock (d);spin_unlock (&de->d_lock);spin_unlock (&d->d_lock); -spin_unlock (&dcache_lock);d_delete (d);simple_unlink (de->d_inode, d);dput (d); -spin_lock (&dcache_lock);spin_lock (&de->d_lock); }else spin_unlock (&d->d_lock);
@@ -966,7 +963,6 @@ static void sel_remove_entries(struct de }spin_unlock (&de->d_lock); -spin_unlock (&dcache_lock); }#define BOOL_DIR_NAME "booleans"
security/tomoyo/realpath.c +0 -2
@@ -92,12 +92,10 @@ int tomoyo_realpath_from_path2(struct pa }else {struct path ns_root = {.mnt =NULL , .dentry =NULL }; -spin_lock (&dcache_lock);br_read_lock (vfsmount_lock);/* go to whatever namespace root we are under */ sp =__d_path (path, &ns_root, newname, newname_len);br_read_unlock (vfsmount_lock); -spin_unlock (&dcache_lock);/* Prepend "/proc" prefix if using internal proc vfs mount. */ if (!IS_ERR (sp) && (path->mnt->mnt_flags &MNT_INTERNAL ) && (path->mnt->mnt_sb->s_magic ==PROC_SUPER_MAGIC )) {
fs/nfs/getroot.c +0 -2
@@ -64,13 +64,11 @@ static int nfs_superblock_set_dummy_root* This again causes shrink_dcache_for_umount_subtree() to * 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 ; }
drivers/staging/pohmelfs/path_entry.c +0 -2
@@ -101,7 +101,6 @@ rename_retry: d = first; seq =read_seqbegin (&rename_lock);rcu_read_lock (); -spin_lock (&dcache_lock);if (!IS_ROOT (d) &&d_unhashed (d)) len +=UNHASHED_OBSCURE_STRING_SIZE ;/* Obscure " (deleted)" string */
@@ -110,7 +109,6 @@ rename_retry: len += d->d_name.len +1 ;/* Plus slash */ d = d->d_parent; } -spin_unlock (&dcache_lock);rcu_read_unlock ();if (read_seqretry (&rename_lock, seq)) goto rename_retry;
fs/nfs/namespace.c +0 -3
@@ -60,7 +60,6 @@ rename_retry: seq =read_seqbegin (&rename_lock);rcu_read_lock (); -spin_lock (&dcache_lock);while (!IS_ROOT (dentry) && dentry != droot) { namelen = dentry->d_name.len; buflen -= namelen +1 ;
@@ -71,7 +70,6 @@ rename_retry: *--end ='/' ; dentry = dentry->d_parent; } -spin_unlock (&dcache_lock);rcu_read_unlock ();if (read_seqretry (&rename_lock, seq)) goto rename_retry;
@@ -91,7 +89,6 @@ rename_retry:memcpy (end, base, namelen);return end; Elong_unlock: -spin_unlock (&dcache_lock);rcu_read_unlock ();if (read_seqretry (&rename_lock, seq)) goto rename_retry;
include/linux/fsnotify_backend.h +1 -4
@@ -276,10 +276,10 @@ static inline void __fsnotify_update_dca {struct dentry *parent; -assert_spin_locked (&dcache_lock);assert_spin_locked (&dentry->d_lock); parent = dentry->d_parent; +/* XXX: after dcache_lock removal, there is a race with parent->d_inode and fsnotify_inode_watches_children. must fix */ if (parent->d_inode &&fsnotify_inode_watches_children (parent->d_inode)) dentry->d_flags |=DCACHE_FSNOTIFY_PARENT_WATCHED ;else
@@ -288,15 +288,12 @@ static inline void __fsnotify_update_dca/* * fsnotify_d_instantiate - instantiate a dentry for inode -* Called with dcache_lock held. */ static inline void __fsnotify_d_instantiate (struct dentry *dentry,struct inode *inode) {if (!inode)return ; -assert_spin_locked (&dcache_lock); -spin_lock (&dentry->d_lock);__fsnotify_update_dcache_flags (dentry);spin_unlock (&dentry->d_lock);
fs/notify/fsnotify.c +0 -2
@@ -53,7 +53,6 @@ void __fsnotify_update_child_dentry_flag/* determine if the children should tell inode about their events */ 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 */
@@ -78,7 +77,6 @@ void __fsnotify_update_child_dentry_flagspin_unlock (&alias->d_lock); }spin_unlock (&dcache_inode_lock); -spin_unlock (&dcache_lock); }/* Notify this dentry's parent about a child's events. */
include/linux/fs.h +4 -0
@@ -2425,6 +2425,10 @@ static inline ino_t parent_ino(struct de {ino_t res; +/* +* Don't strictly need d_lock here? If the parent ino could change +* then surely we'd have a deeper race in the caller? +*/ spin_lock (&dentry->d_lock); res = dentry->d_parent->d_inode->i_ino;spin_unlock (&dentry->d_lock);
fs/autofs4/autofs_i.h +3 -0
@@ -16,6 +16,7 @@#include <linux/auto_fs4.h> #include <linux/auto_dev-ioctl.h> #include <linux/mutex.h> +#include <linux/spinlock.h> #include <linux/list.h> /* This is the range of ioctl() numbers we claim as ours */
@@ -60,6 +61,8 @@ do { \ current->pid, __func__, ##args); \ } while (0) +extern spinlock_t autofs4_lock; +/* Unified info structure. This is pointed to by both the dentry and inode structures. Each file in the filesystem has an instance of this structure. It holds a reference to the dentry, so dentries are never
fs/autofs4/expire.c +12 -12
@@ -94,9 +94,9 @@ done:* Calculate next entry in top down tree traversal. * From next_mnt in namespace.c - elegant. * -* How is this supposed to work if we drop dcache_lock between calls anyway? +* How is this supposed to work if we drop autofs4_lock between calls anyway? * How does it cope with renames? -* And also callers dput the returned dentry before taking dcache_lock again +* And also callers dput the returned dentry before taking autofs4_lock again * so what prevents it from being freed?? */ static struct dentry *get_next_positive_dentry(struct dentry *p,
@@ -105,7 +105,7 @@ static struct dentry *get_next_positive_struct list_head *next;struct dentry *ret; -spin_lock (&dcache_lock); +spin_lock (&autofs4_lock); again:spin_lock (&p->d_lock); next = p->d_subdirs.next;
@@ -115,7 +115,7 @@ again:if (p == root) {spin_unlock (&p->d_lock); -spin_unlock (&dcache_lock); +spin_unlock (&autofs4_lock);return NULL ; }
@@ -143,7 +143,7 @@ again:dget_dlock (ret);spin_unlock (&ret->d_lock);spin_unlock (&p->d_lock); -spin_unlock (&dcache_lock); +spin_unlock (&autofs4_lock);return ret; }
@@ -313,7 +313,7 @@ struct dentry *autofs4_expire_direct(str* A tree is eligible if :- * - it is unused by any user process * - it has been unused for exp_timeout time -* This seems to be racy dropping dcache_lock and asking for next->next after +* This seems to be racy dropping autofs4_lock and asking for next->next after * the lock has been dropped. */ struct dentry *autofs4_expire_indirect(struct super_block *sb,
@@ -336,7 +336,7 @@ struct dentry *autofs4_expire_indirect(s now = jiffies; timeout = sbi->exp_timeout; -spin_lock (&dcache_lock); +spin_lock (&autofs4_lock);spin_lock (&root->d_lock); next = root->d_subdirs.next;
@@ -355,7 +355,7 @@ struct dentry *autofs4_expire_indirect(s dentry =dget_dlock (dentry);spin_unlock (&dentry->d_lock);spin_unlock (&root->d_lock); -spin_unlock (&dcache_lock); +spin_unlock (&autofs4_lock);spin_lock (&sbi->fs_lock); ino =autofs4_dentry_ino (dentry);
@@ -420,12 +420,12 @@ struct dentry *autofs4_expire_indirect(s next:spin_unlock (&sbi->fs_lock);dput (dentry); -spin_lock (&dcache_lock); +spin_lock (&autofs4_lock);spin_lock (&root->d_lock); next = next->next; }spin_unlock (&root->d_lock); -spin_unlock (&dcache_lock); +spin_unlock (&autofs4_lock);return NULL ; found:
@@ -435,13 +435,13 @@ found: ino->flags |=AUTOFS_INF_EXPIRING ;init_completion (&ino->expire_complete);spin_unlock (&sbi->fs_lock); -spin_lock (&dcache_lock); +spin_lock (&autofs4_lock);spin_lock (&expired->d_parent->d_lock);spin_lock_nested (&expired->d_lock,DENTRY_D_LOCK_NESTED );list_move (&expired->d_parent->d_subdirs, &expired->d_u.d_child);spin_unlock (&expired->d_lock);spin_unlock (&expired->d_parent->d_lock); -spin_unlock (&dcache_lock); +spin_unlock (&autofs4_lock);return expired; }
fs/autofs4/root.c +7 -7
@@ -134,15 +134,15 @@ static int autofs4_dir_open(struct inode* autofs file system so just let the libfs routines handle * it. */ -spin_lock (&dcache_lock); +spin_lock (&autofs4_lock);spin_lock (&dentry->d_lock);if (!d_mountpoint (dentry) &&list_empty (&dentry->d_subdirs)) {spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); +spin_unlock (&autofs4_lock);return -ENOENT ; }spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); +spin_unlock (&autofs4_lock); out:return dcache_dir_open (inode, file);
@@ -248,11 +248,11 @@ static void *autofs4_follow_link(struct/* We trigger a mount for almost all flags */ lookup_type =autofs4_need_mount (nd->flags);spin_lock (&sbi->fs_lock); -spin_lock (&dcache_lock); +spin_lock (&autofs4_lock);spin_lock (&dentry->d_lock);if (!(lookup_type || ino->flags &AUTOFS_INF_PENDING )) {spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); +spin_unlock (&autofs4_lock);spin_unlock (&sbi->fs_lock); goto follow; }
@@ -274,7 +274,7 @@ static void *autofs4_follow_link(struct goto follow; }spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_lock); +spin_unlock (&autofs4_lock);spin_unlock (&sbi->fs_lock); follow:/*
@@ -476,7 +476,7 @@ static struct dentry *autofs4_lookup_expconst unsigned char *str = name->name;struct list_head *p, *head; -spin_lock (&dcache_lock); +spin_lock (&autofs4_lock);spin_lock (&sbi->lookup_lock); head = &sbi->expiring_list;list_for_each (p, head) {
fs/autofs4/waitq.c +4 -3
@@ -194,14 +194,15 @@ static int autofs4_getpath(struct autofs rename_retry: buf = *name; len =0 ; + seq =read_seqbegin (&rename_lock);rcu_read_lock (); -spin_lock (&dcache_lock); +spin_lock (&autofs4_lock);for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent) len += tmp->d_name.len +1 ;if (!len || --len >NAME_MAX ) { -spin_unlock (&dcache_lock); +spin_unlock (&autofs4_lock);rcu_read_unlock ();if (read_seqretry (&rename_lock, seq)) goto rename_retry;
@@ -217,7 +218,7 @@ rename_retry: p -= tmp->d_name.len;strncpy (p, tmp->d_name.name, tmp->d_name.len); } -spin_unlock (&dcache_lock); +spin_unlock (&autofs4_lock);rcu_read_unlock ();if (read_seqretry (&rename_lock, seq)) goto rename_retry;
drivers/infiniband/hw/qib/qib_fs.c +0 -3
@@ -451,17 +451,14 @@ static int remove_file(struct dentry *pa goto bail; } -spin_lock (&dcache_lock);spin_lock (&tmp->d_lock);if (!(d_unhashed (tmp) && tmp->d_inode)) {dget_locked_dlock (tmp);__d_drop (tmp);spin_unlock (&tmp->d_lock); -spin_unlock (&dcache_lock);simple_unlink (parent->d_inode, tmp); }else {spin_unlock (&tmp->d_lock); -spin_unlock (&dcache_lock); } ret =0 ;
fs/ceph/dir.c +1 -5
@@ -111,7 +111,6 @@ static int __dcache_readdir(struct filedout ("__dcache_readdir %p at %llu (last %p)\n" , dir, filp->f_pos, last); -spin_lock (&dcache_lock);spin_lock (&parent->d_lock);/* start at beginning? */
@@ -155,7 +154,6 @@ more:dget_dlock (dentry);spin_unlock (&dentry->d_lock);spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock);spin_unlock (&inode->i_lock); dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, filp->f_pos,
@@ -178,7 +176,6 @@ more: }spin_lock (&inode->i_lock); -spin_lock (&dcache_lock);spin_lock (&parent->d_lock); last = dentry;
@@ -189,7 +186,7 @@ more: p = p->prev; filp->f_pos++; -/* make sure a dentry wasn't dropped while we didn't have dcache_lock */ +/* make sure a dentry wasn't dropped while we didn't have parent->d_lock */ if ((ceph_inode (dir)->i_ceph_flags &CEPH_I_COMPLETE )) goto more;dout (" lost I_COMPLETE on %p; falling back to mds\n" , dir);
@@ -197,7 +194,6 @@ more: out_unlock:spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock);if (last) {spin_unlock (&inode->i_lock);
fs/ceph/inode.c +0 -4
@@ -825,7 +825,6 @@ static void ceph_set_dentry_offset(struc di->offset =ceph_inode (inode)->i_max_offset++;spin_unlock (&inode->i_lock); -spin_lock (&dcache_lock);spin_lock (&dir->d_lock);spin_lock_nested (&dn->d_lock,DENTRY_D_LOCK_NESTED );list_move (&dn->d_u.d_child, &dir->d_subdirs);
@@ -833,7 +832,6 @@ static void ceph_set_dentry_offset(struc dn->d_u.d_child.prev, dn->d_u.d_child.next);spin_unlock (&dn->d_lock);spin_unlock (&dir->d_lock); -spin_unlock (&dcache_lock); }/*
@@ -1213,13 +1211,11 @@ retry_lookup: goto retry_lookup; }else {/* reorder parent's d_subdirs */ -spin_lock (&dcache_lock);spin_lock (&parent->d_lock);spin_lock_nested (&dn->d_lock,DENTRY_D_LOCK_NESTED );list_move (&dn->d_u.d_child, &parent->d_subdirs);spin_unlock (&dn->d_lock);spin_unlock (&parent->d_lock); -spin_unlock (&dcache_lock); } di = dn->d_fsdata;
PATCH 18/52 fs: dcache reduce dput locking
In reply to [email protected]It is possible to run dput without taking locks up-front. In many cases where we don't kill the dentry anyway, these locks are not required.
(I think... need to think about it more). Further changes ->d_delete locking which is not all audited. d_delete must be idempotent, for one.
--- fs/dcache.c | 60 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 28 deletions(-)
fs/dcache.c +32 -28
@@ -278,7 +278,8 @@ static struct dentry *d_kill(struct dentvoid dput (struct dentry *dentry) { -struct dentry *parent =NULL ; +struct dentry *parent; +if (!dentry)return ;
@@ -286,25 +287,10 @@ repeat:if (dentry->d_count ==1 )might_sleep ();spin_lock (&dentry->d_lock); -if (dentry->d_count ==1 ) { -if (!spin_trylock (&dcache_inode_lock)) { -drop2: -spin_unlock (&dentry->d_lock); - goto repeat; - } - parent = dentry->d_parent; -if (parent && parent != dentry) { -if (!spin_trylock (&parent->d_lock)) { -spin_unlock (&dcache_inode_lock); - goto drop2; - } - } - } - dentry->d_count--; -if (dentry->d_count) { +BUG_ON (!dentry->d_count); +if (dentry->d_count >1 ) { + dentry->d_count--;spin_unlock (&dentry->d_lock); -if (parent && parent != dentry) -spin_unlock (&parent->d_lock);return ; }
@@ -312,8 +298,10 @@ drop2:* AV: ->d_delete() is _NOT_ allowed to block now. */ if (dentry->d_op && dentry->d_op->d_delete) { -if (dentry->d_op->d_delete (dentry)) - goto unhash_it; +if (dentry->d_op->d_delete (dentry)) { +__d_drop (dentry); + goto kill_it; + } }/* Unreachable? Get rid of it */ if (d_unhashed (dentry))
@@ -322,15 +310,31 @@ drop2: dentry->d_flags |=DCACHE_REFERENCED ;dentry_lru_add (dentry); } -spin_unlock (&dentry->d_lock); -if (parent && parent != dentry) -spin_unlock (&parent->d_lock); -spin_unlock (&dcache_inode_lock); -return ; + dentry->d_count--; +spin_unlock (&dentry->d_lock); +return ; -unhash_it: -__d_drop (dentry); kill_it: +spin_unlock (&dentry->d_lock); +spin_lock (&dcache_inode_lock); +relock: +spin_lock (&dentry->d_lock); + parent = dentry->d_parent; +if (parent && parent != dentry) { +if (!spin_trylock (&parent->d_lock)) { +spin_unlock (&dentry->d_lock); + goto relock; + } + } + dentry->d_count--; +if (dentry->d_count) { +/* This case should be fine */ +spin_unlock (&dentry->d_lock); +if (parent && parent != dentry) +spin_unlock (&parent->d_lock); +spin_unlock (&dcache_inode_lock); +return ; + }/* if dentry was on the d_lru list delete it from there */ dentry_lru_del (dentry); dentry =d_kill (dentry);
PATCH 19/52 fs: dcache per-bucket dcache hash locking
In reply to [email protected]We can turn the dcache hash locking from a global dcache_hash_lock into per-bucket locking.
--- fs/dcache.c | 234 +++++++++++++++++++++++++++---------------------- fs/super.c | 3 include/linux/dcache.h | 23 ---- include/linux/fs.h | 3 4 files changed, 141 insertions(+), 122 deletions(-)
fs/dcache.c +134 -101
@@ -33,13 +33,15 @@#include <linux/bootmem.h> #include <linux/fs_struct.h> #include <linux/hardirq.h> +#include <linux/bit_spinlock.h> +#include <linux/rculist_bl.h> #include "internal.h" /* * Usage: * dcache_inode_lock protects: * - i_dentry, d_alias, d_inode -* dcache_hash_lock protects: +* dcache_hash_bucket lock protects: * - the dcache hash table * dcache_lru_lock protects: * - the dcache lru lists and counters
@@ -57,7 +59,7 @@* dcache_inode_lock * dentry->d_lock * dcache_lru_lock -* dcache_hash_lock +* dcache_hash_bucket lock * * If there is an ancestor relationship: * dentry->d_parent->...->d_parent->d_lock
@@ -74,13 +76,11 @@ int sysctl_vfs_cache_pressure __read_mosEXPORT_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_SEQLOCK (rename_lock );EXPORT_SYMBOL (rename_lock);EXPORT_SYMBOL (dcache_inode_lock); -EXPORT_SYMBOL (dcache_hash_lock);static struct kmem_cache *dentry_cache__read_mostly ;
@@ -99,7 +99,11 @@ static struct kmem_cache *dentry_cache _static unsigned int d_hash_mask__read_mostly ;static unsigned int d_hash_shift__read_mostly ; -static struct hlist_head *dentry_hashtable__read_mostly ; + +struct dcache_hash_bucket { +struct hlist_bl_head head; +}; +static struct dcache_hash_bucket *dentry_hashtable__read_mostly ;/* Statistics gathering. */ struct dentry_stat_t dentry_stat = {
@@ -107,6 +111,24 @@ struct dentry_stat_t dentry_stat = { .age_limit = 45, }; +static inline struct dcache_hash_bucket *d_hash (struct dentry *parent, +unsigned long hash) +{ + hash += ((unsigned long ) parent ^GOLDEN_RATIO_PRIME ) /L1_CACHE_BYTES ; + hash = hash ^ ((hash ^GOLDEN_RATIO_PRIME ) >>D_HASHBITS ); +return dentry_hashtable + (hash &D_HASHMASK ); +} + +static inline void spin_lock_bucket (struct dcache_hash_bucket *b) +{ +bit_spin_lock (0 , (unsigned long *)b); +} + +static inline void spin_unlock_bucket (struct dcache_hash_bucket *b) +{ +__bit_spin_unlock (0 , (unsigned long *)b); +} +static void __d_free (struct dentry *dentry) {WARN_ON (!list_empty (&dentry->d_alias));
@@ -131,7 +153,7 @@ static void d_free(struct dentry *dentryif (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 */ -if (hlist_unhashed (&dentry->d_hash)) +if (hlist_bl_unhashed (&dentry->d_hash))__d_free (dentry);else call_rcu (&dentry->d_u.d_rcu, d_callback);
@@ -247,6 +269,81 @@ static struct dentry *d_kill(struct dentreturn parent; } +void __d_drop (struct dentry *dentry) +{ +if (!(dentry->d_flags &DCACHE_UNHASHED )) { +struct dcache_hash_bucket *b; + b =d_hash (dentry->d_parent, dentry->d_name.hash); +/* XXX: put unhashed inside hash lock? (don't need to actually) */ + dentry->d_flags |=DCACHE_UNHASHED ; +spin_lock_bucket (b); +hlist_bl_del_rcu (&dentry->d_hash); +spin_unlock_bucket (b); + } +} +EXPORT_SYMBOL (__d_drop); + +void d_drop (struct dentry *dentry) +{ +spin_lock (&dentry->d_lock); +__d_drop (dentry); +spin_unlock (&dentry->d_lock); +} +EXPORT_SYMBOL (d_drop); + +/* This must be called with d_lock held */ +static inline struct dentry *__dget_locked_dlock (struct dentry *dentry) +{ + dentry->d_count++; +dentry_lru_del_init (dentry); +return dentry; +} + +static inline struct dentry *__dget_locked (struct dentry *dentry) +{ +spin_lock (&dentry->d_lock); +__dget_locked_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); +} +EXPORT_SYMBOL (dget_locked); + +struct dentry *dget_parent (struct dentry *dentry) +{ +struct dentry *ret; + +repeat: +spin_lock (&dentry->d_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); + goto repeat; + } +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); +/* * This is dput *
@@ -398,60 +495,6 @@ int d_invalidate(struct dentry * dentry) }EXPORT_SYMBOL (d_invalidate); -/* This must be called with d_lock held */ -static inline struct dentry *__dget_locked_dlock (struct dentry *dentry) -{ - dentry->d_count++; -dentry_lru_del_init (dentry); -return dentry; -} - -/* This must be called with d_lock held */ -static inline struct dentry *__dget_locked (struct dentry *dentry) -{ -spin_lock (&dentry->d_lock); -__dget_locked_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); -} -EXPORT_SYMBOL (dget_locked); - -struct dentry *dget_parent (struct dentry *dentry) -{ -struct dentry *ret; - -repeat: -spin_lock (&dentry->d_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); - goto repeat; - } -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); -/** * d_find_alias - grab a hashed alias of inode * @inode: inode in question
@@ -900,8 +943,8 @@ void shrink_dcache_for_umount(struct supspin_unlock (&dentry->d_lock);shrink_dcache_for_umount_subtree (dentry); -while (!hlist_empty (&sb->s_anon)) { - dentry = hlist_entry(sb->s_anon.first, struct dentry, d_hash); +while (!hlist_bl_empty (&sb->s_anon)) { + dentry = hlist_bl_entry(hlist_bl_first(&sb->s_anon), struct dentry, d_hash);shrink_dcache_for_umount_subtree (dentry); } }
@@ -1183,7 +1226,7 @@ struct dentry *d_alloc(struct dentry * p dentry->d_op =NULL ; dentry->d_fsdata =NULL ; dentry->d_mounted =0 ; -INIT_HLIST_NODE (&dentry->d_hash); +INIT_HLIST_BL_NODE (&dentry->d_hash);INIT_LIST_HEAD (&dentry->d_lru);INIT_LIST_HEAD (&dentry->d_subdirs);INIT_LIST_HEAD (&dentry->d_alias);
@@ -1348,14 +1391,6 @@ struct dentry * d_alloc_root(struct inod }EXPORT_SYMBOL (d_alloc_root); -static inline struct hlist_head *d_hash (struct dentry *parent, -unsigned long hash) -{ - hash += ((unsigned long ) parent ^GOLDEN_RATIO_PRIME ) /L1_CACHE_BYTES ; - hash = hash ^ ((hash ^GOLDEN_RATIO_PRIME ) >>D_HASHBITS ); -return dentry_hashtable + (hash &D_HASHMASK ); -} -/** * d_obtain_alias - find or allocate a dentry for a given inode * @inode: inode to allocate the dentry for
@@ -1411,7 +1446,7 @@ struct dentry *d_obtain_alias(struct ino tmp->d_flags |=DCACHE_DISCONNECTED ; tmp->d_flags &= ~DCACHE_UNHASHED ;list_add (&tmp->d_alias, &inode->i_dentry); -hlist_add_head (&tmp->d_hash, &inode->i_sb->s_anon); +hlist_bl_add_head (&tmp->d_hash, &inode->i_sb->s_anon);/* XXX: make s_anon a bl list */ spin_unlock (&tmp->d_lock);spin_unlock (&dcache_inode_lock);
@@ -1604,14 +1639,14 @@ struct dentry * __d_lookup(struct dentryunsigned int len = name->len;unsigned int hash = name->hash;const unsigned char *str = name->name; -struct hlist_head *head =d_hash (parent,hash); +struct dcache_hash_bucket *b =d_hash (parent, hash); +struct hlist_bl_node *node;struct dentry *found =NULL ; -struct hlist_node *node;struct dentry *dentry;rcu_read_lock (); -hlist_for_each_entry_rcu (dentry, node, head, d_hash) { +hlist_bl_for_each_entry_rcu (dentry, node, &b->head, d_hash) {struct qstr *qstr;if (dentry->d_name.hash != hash)
@@ -1698,8 +1733,9 @@ out:int d_validate (struct dentry *dentry,struct dentry *dparent) { -struct hlist_head *base; -struct hlist_node *lhp; +struct dcache_hash_bucket *b; +struct dentry *lhp; +struct hlist_bl_node *node;/* Check whether the ptr might be valid at all.. */ if (!kmem_ptr_validate (dentry_cache, dentry))
@@ -1709,20 +1745,17 @@ int d_validate(struct dentry *dentry, st goto out;spin_lock (&dentry->d_lock); -spin_lock (&dcache_hash_lock); - base =d_hash (dparent, dentry->d_name.hash); -hlist_for_each (lhp,base) { -/* hlist_for_each_entry_rcu() not required for d_hash list -* as it is parsed under dcache_hash_lock -*/ - if (dentry == hlist_entry(lhp, struct dentry, d_hash)) { -spin_unlock (&dcache_hash_lock); + b =d_hash (dparent, dentry->d_name.hash); +rcu_read_lock (); +hlist_bl_for_each_entry_rcu (lhp, node, &b->head, d_hash) { +if (dentry == lhp) { +rcu_read_unlock ();__dget_locked_dlock (dentry);spin_unlock (&dentry->d_lock);return 1 ; } } -spin_unlock (&dcache_hash_lock); +rcu_read_unlock ();spin_unlock (&dentry->d_lock); out:return 0 ;
@@ -1776,11 +1809,12 @@ void d_delete(struct dentry * dentry) }EXPORT_SYMBOL (d_delete); -static void __d_rehash (struct dentry * entry,struct hlist_head *list) +static void __d_rehash (struct dentry * entry,struct dcache_hash_bucket *b) { - entry->d_flags &= ~DCACHE_UNHASHED ; -hlist_add_head_rcu (&entry->d_hash, list); +spin_lock_bucket (b); +hlist_bl_add_head_rcu (&entry->d_hash, &b->head); +spin_unlock_bucket (b); }static void _d_rehash (struct dentry * entry)
@@ -1798,9 +1832,7 @@ static void _d_rehash(struct dentry * envoid d_rehash (struct dentry * entry) {spin_lock (&entry->d_lock); -spin_lock (&dcache_hash_lock);_d_rehash (entry); -spin_unlock (&dcache_hash_lock);spin_unlock (&entry->d_lock); }EXPORT_SYMBOL (d_rehash);
@@ -1879,6 +1911,7 @@ static void switch_names(struct dentry **/ static void d_move_locked (struct dentry * dentry,struct dentry * target) { +struct dcache_hash_bucket *b;if (!dentry->d_inode)printk (KERN_WARNING "VFS: moving negative dcache entry\n" );
@@ -1909,11 +1942,13 @@ static void d_move_locked(struct dentry }/* Move the dentry to the target hash queue, if on different bucket */ -spin_lock (&dcache_hash_lock); -if (!d_unhashed (dentry)) -hlist_del_rcu (&dentry->d_hash); +if (!d_unhashed (dentry)) { + b =d_hash (dentry->d_parent, dentry->d_name.hash); +spin_lock_bucket (b); +hlist_bl_del_rcu (&dentry->d_hash); +spin_unlock_bucket (b); + }__d_rehash (dentry,d_hash (target->d_parent, target->d_name.hash)); -spin_unlock (&dcache_hash_lock);/* Unhash the target: dput() will then get rid of it */ __d_drop (target);
@@ -2121,9 +2156,7 @@ struct dentry *d_materialise_unique(stru found_lock:spin_lock (&actual->d_lock); found: -spin_lock (&dcache_hash_lock);_d_rehash (actual); -spin_unlock (&dcache_hash_lock);spin_unlock (&actual->d_lock);spin_unlock (&dcache_inode_lock); out_nolock:
@@ -2631,7 +2664,7 @@ static void __init dcache_init_early(voi dentry_hashtable = alloc_large_system_hash("Dentry cache", - sizeof(struct hlist_head), + sizeof(struct dcache_hash_bucket), dhash_entries, 13, HASH_EARLY,
@@ -2640,7 +2673,7 @@ static void __init dcache_init_early(voi 0);for (loop =0 ; loop < (1 << d_hash_shift); loop++) -INIT_HLIST_HEAD (&dentry_hashtable[loop]); +INIT_HLIST_BL_HEAD (&dentry_hashtable[loop].head); }static void __init dcache_init (void )
@@ -2663,7 +2696,7 @@ static void __init dcache_init(void) dentry_hashtable = alloc_large_system_hash("Dentry cache", - sizeof(struct hlist_head), + sizeof(struct dcache_hash_bucket), dhash_entries, 13, 0,
@@ -2672,7 +2705,7 @@ static void __init dcache_init(void) 0);for (loop =0 ; loop < (1 << d_hash_shift); loop++) -INIT_HLIST_HEAD (&dentry_hashtable[loop]); +INIT_HLIST_BL_HEAD (&dentry_hashtable[loop].head); }/* SLAB cache for __getname() consumers */
include/linux/dcache.h +4 -19
@@ -4,6 +4,7 @@#include <asm/atomic.h> #include <linux/list.h> #include <linux/rculist.h> +#include <linux/rculist_bl.h> #include <linux/spinlock.h> #include <linux/cache.h> #include <linux/rcupdate.h>
@@ -97,7 +98,7 @@ struct dentry {* The next three fields are touched by __d_lookup. Place them here * so they all fit in a cache line. */ -struct hlist_node d_hash;/* lookup hash list */ +struct hlist_bl_node d_hash;/* lookup hash list */ struct dentry *d_parent;/* parent directory */ struct qstr d_name;
@@ -190,7 +191,6 @@ d_iput: no no yes#define DCACHE_GENOCIDE 0x0200extern spinlock_t dcache_inode_lock; -extern spinlock_t dcache_hash_lock;extern seqlock_t rename_lock;/**
@@ -208,23 +208,8 @@ extern seqlock_t rename_lock;* * __d_drop requires dentry->d_lock. */ - -static inline void __d_drop (struct dentry *dentry) -{ -if (!(dentry->d_flags &DCACHE_UNHASHED )) { - dentry->d_flags |=DCACHE_UNHASHED ; -spin_lock (&dcache_hash_lock); -hlist_del_rcu (&dentry->d_hash); -spin_unlock (&dcache_hash_lock); - } -} - -static inline void d_drop (struct dentry *dentry) -{ -spin_lock (&dentry->d_lock); -__d_drop (dentry); -spin_unlock (&dentry->d_lock); -} +void d_drop (struct dentry *dentry); +void __d_drop (struct dentry *dentry);static inline int dname_external (struct dentry *dentry) {
fs/super.c +2 -1
@@ -30,6 +30,7 @@#include <linux/idr.h> #include <linux/mutex.h> #include <linux/backing-dev.h> +#include <linux/rculist_bl.h> #include "internal.h"
@@ -71,7 +72,7 @@ static struct super_block *alloc_super(sINIT_LIST_HEAD (&s->s_files);#endif INIT_LIST_HEAD (&s->s_instances); -INIT_HLIST_HEAD (&s->s_anon); +INIT_HLIST_BL_HEAD (&s->s_anon);INIT_LIST_HEAD (&s->s_inodes);INIT_LIST_HEAD (&s->s_dentry_lru);init_rwsem (&s->s_umount);
include/linux/fs.h +2 -1
@@ -382,6 +382,7 @@ struct inodes_stat_t {#include <linux/capability.h> #include <linux/semaphore.h> #include <linux/fiemap.h> +#include <linux/rculist_bl.h> #include <asm/atomic.h> #include <asm/byteorder.h>
@@ -1341,7 +1342,7 @@ struct super_block {const struct xattr_handler **s_xattr;struct list_head s_inodes;/* all inodes */ -struct hlist_head s_anon;/* anonymous dentries for (nfs) exporting */ +struct hlist_bl_head s_anon;/* anonymous dentries for (nfs) exporting */ #ifdef CONFIG_SMP struct list_head __percpu *s_files;#else
PATCH 20/52 fs: dcache reduce dcache_inode_lock
In reply to [email protected]dcache_inode_lock can be avoided in d_delete() and d_materialise_unique() in cases where it is not required.
--- fs/dcache.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
fs/dcache.c +12 -12
@@ -1789,10 +1789,15 @@ void d_delete(struct dentry * dentry)/* * Are we the only user? */ -spin_lock (&dcache_inode_lock); +again:spin_lock (&dentry->d_lock); isdir =S_ISDIR (dentry->d_inode->i_mode);if (dentry->d_count ==1 ) { +if (!spin_trylock (&dcache_inode_lock)) { +spin_unlock (&dentry->d_lock); +cpu_relax (); + goto again; + } dentry->d_flags &= ~DCACHE_CANT_MOUNT ;dentry_iput (dentry);fsnotify_nameremove (dentry, isdir);
@@ -1803,7 +1808,6 @@ void d_delete(struct dentry * dentry)__d_drop (dentry);spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_inode_lock);fsnotify_nameremove (dentry, isdir); }
@@ -2116,14 +2120,15 @@ struct dentry *d_materialise_unique(struBUG_ON (!d_unhashed (dentry)); -spin_lock (&dcache_inode_lock); -if (!inode) { actual = dentry;__d_instantiate (dentry,NULL ); - goto found_lock; +d_rehash (actual); + goto out_nolock; } +spin_lock (&dcache_inode_lock); +if (S_ISDIR (inode->i_mode)) {struct dentry *alias;
@@ -2150,10 +2155,9 @@ struct dentry *d_materialise_unique(stru actual =__d_instantiate_unique (dentry, inode);if (!actual) actual = dentry; -else if (unlikely (!d_unhashed (actual))) - goto shouldnt_be_hashed; +else +BUG_ON (!d_unhashed (actual)); -found_lock:spin_lock (&actual->d_lock); found:_d_rehash (actual);
@@ -2167,10 +2171,6 @@ out_nolock:iput (inode);return actual; - -shouldnt_be_hashed: -spin_unlock (&dcache_inode_lock); -BUG (); }EXPORT_SYMBOL_GPL (d_materialise_unique);
PATCH 21/52 fs: dcache per-inode inode alias locking
In reply to [email protected]dcache_inode_lock can be replaced with per-inode locking. Use existing inode->i_lock for this. This is slightly non-trivial because we sometimes need to find the inode from the dentry, which requires d_inode to be stabilised (either with refcount or d_lock).
--- fs/affs/amigaffs.c | 4 - fs/dcache.c | 117 +++++++++++++++++++++++++------------------- fs/exportfs/expfs.c | 12 ++-- fs/nfs/getroot.c | 4 - fs/notify/fsnotify.c | 4 - fs/notify/inotify/inotify.c | 4 - fs/ocfs2/dcache.c | 4 - fs/sysfs/dir.c | 6 +- include/linux/dcache.h | 1 9 files changed, 89 insertions(+), 67 deletions(-)
fs/dcache.c +68 -47
@@ -39,8 +39,8 @@/* * Usage: -* dcache_inode_lock protects: -* - i_dentry, d_alias, d_inode +* dcache->d_inode->i_lock protects: +* - i_dentry, d_alias, d_inode of aliases * dcache_hash_bucket lock protects: * - the dcache hash table * dcache_lru_lock protects:
@@ -56,7 +56,7 @@* - d_alias, d_inode * * Ordering: -* dcache_inode_lock +* dentry->d_inode->i_lock * dentry->d_lock * dcache_lru_lock * dcache_hash_bucket lock
@@ -75,12 +75,10 @@int sysctl_vfs_cache_pressure__read_mostly =100 ;EXPORT_SYMBOL_GPL (sysctl_vfs_cache_pressure); -__cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_inode_lock );static __cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_lru_lock );__cacheline_aligned_in_smp DEFINE_SEQLOCK (rename_lock );EXPORT_SYMBOL (rename_lock); -EXPORT_SYMBOL (dcache_inode_lock);static struct kmem_cache *dentry_cache__read_mostly ;
@@ -165,14 +163,13 @@ static void d_free(struct dentry *dentry*/ static void dentry_iput (struct dentry * dentry) __releases(dentry->d_lock) -__releases (dcache_inode_lock) {struct inode *inode = dentry->d_inode;if (inode) { dentry->d_inode =NULL ;list_del_init (&dentry->d_alias);spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock);if (!inode->i_nlink)fsnotify_inoderemove (inode);if (dentry->d_op && dentry->d_op->d_iput)
@@ -181,7 +178,6 @@ static void dentry_iput(struct dentry *iput (inode); }else {spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_inode_lock); } }
@@ -252,7 +248,6 @@ static void dentry_lru_del_init(struct d*/ static struct dentry *d_kill (struct dentry *dentry) __releases(dentry->d_lock) -__releases (dcache_inode_lock) {struct dentry *parent;
@@ -376,6 +371,7 @@ EXPORT_SYMBOL(dget_parent);void dput (struct dentry *dentry) {struct dentry *parent; +struct inode *inode;if (!dentry)return ;
@@ -412,14 +408,21 @@ repeat:return ; kill_it: -spin_unlock (&dentry->d_lock); -spin_lock (&dcache_inode_lock); + inode = dentry->d_inode; +if (inode) { +if (!spin_trylock (&inode->i_lock)) { relock: -spin_lock (&dentry->d_lock); +spin_unlock (&dentry->d_lock); +cpu_relax (); +spin_lock (&dentry->d_lock); + goto kill_it; + } + } parent = dentry->d_parent;if (parent && parent != dentry) {if (!spin_trylock (&parent->d_lock)) { -spin_unlock (&dentry->d_lock); +if (inode) +spin_unlock (&inode->i_lock); goto relock; } }
@@ -429,7 +432,8 @@ relock:spin_unlock (&dentry->d_lock);if (parent && parent != dentry)spin_unlock (&parent->d_lock); -spin_unlock (&dcache_inode_lock); +if (inode) +spin_unlock (&inode->i_lock);return ; }/* if dentry was on the d_lru list delete it from there */
@@ -547,9 +551,9 @@ struct dentry * d_find_alias(struct inodstruct dentry *de =NULL ;if (!list_empty (&inode->i_dentry)) { -spin_lock (&dcache_inode_lock); +spin_lock (&inode->i_lock); de =__d_find_alias (inode,0 ); -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock); }return de; }
@@ -563,20 +567,20 @@ void d_prune_aliases(struct inode *inode {struct dentry *dentry; restart: -spin_lock (&dcache_inode_lock); +spin_lock (&inode->i_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 (&inode->i_lock);dput (dentry); goto restart; }spin_unlock (&dentry->d_lock); } -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock); }EXPORT_SYMBOL (d_prune_aliases);
@@ -599,8 +603,10 @@ static void prune_one_dentry(struct dent*/ while (dentry) {struct dentry *parent =NULL ; +struct inode *inode = dentry->d_inode; -spin_lock (&dcache_inode_lock); +if (inode) +spin_lock (&inode->i_lock); again:spin_lock (&dentry->d_lock);if (dentry->d_parent && dentry != dentry->d_parent) {
@@ -615,7 +621,8 @@ again:if (parent)spin_unlock (&parent->d_lock);spin_unlock (&dentry->d_lock); -spin_unlock (&dcache_inode_lock); +if (inode) +spin_unlock (&inode->i_lock);return ; }
@@ -684,10 +691,11 @@ restart: }spin_unlock (&dcache_lru_lock); -spin_lock (&dcache_inode_lock); again:spin_lock (&dcache_lru_lock);/* lru_lock also protects tmp list */ while (!list_empty (&tmp)) { +struct inode *inode; + dentry = list_entry(tmp.prev, struct dentry, d_lru);if (!spin_trylock (&dentry->d_lock)) {
@@ -705,10 +713,17 @@ again1:spin_unlock (&dentry->d_lock);continue ; } + inode = dentry->d_inode; +if (inode && !spin_trylock (&inode->i_lock)) { +again2: +spin_unlock (&dentry->d_lock); + goto again1; + }if (dentry->d_parent && dentry->d_parent != dentry) {if (!spin_trylock (&dentry->d_parent->d_lock)) { -spin_unlock (&dentry->d_lock); - goto again1; +if (inode) +spin_unlock (&inode->i_lock); + goto again2; } }__dentry_lru_del_init (dentry);
@@ -716,10 +731,8 @@ again1:prune_one_dentry (dentry);/* dentry->d_lock dropped */ -spin_lock (&dcache_inode_lock);spin_lock (&dcache_lru_lock); } -spin_unlock (&dcache_inode_lock);if (count ==NULL && !list_empty (&sb->s_dentry_lru)) goto restart;
@@ -1287,9 +1300,11 @@ static void __d_instantiate(struct dentrvoid d_instantiate (struct dentry *entry,struct inode * inode) {BUG_ON (!list_empty (&entry->d_alias)); -spin_lock (&dcache_inode_lock); +if (inode) +spin_lock (&inode->i_lock);__d_instantiate (entry, inode); -spin_unlock (&dcache_inode_lock); +if (inode) +spin_unlock (&inode->i_lock);security_d_instantiate (entry, inode); }EXPORT_SYMBOL (d_instantiate);
@@ -1348,9 +1363,11 @@ struct dentry *d_instantiate_unique(struBUG_ON (!list_empty (&entry->d_alias)); -spin_lock (&dcache_inode_lock); +if (inode) +spin_lock (&inode->i_lock); result =__d_instantiate_unique (entry, inode); -spin_unlock (&dcache_inode_lock); +if (inode) +spin_unlock (&inode->i_lock);if (!result) {security_d_instantiate (entry, inode);
@@ -1431,10 +1448,10 @@ struct dentry *d_obtain_alias(struct ino } tmp->d_parent = tmp;/* make sure dput doesn't croak */ -spin_lock (&dcache_inode_lock); +spin_lock (&inode->i_lock); res =__d_find_alias (inode,0 );if (res) { -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock);dput (tmp); goto out_iput; }
@@ -1448,7 +1465,7 @@ struct dentry *d_obtain_alias(struct inolist_add (&tmp->d_alias, &inode->i_dentry);hlist_bl_add_head (&tmp->d_hash, &inode->i_sb->s_anon);/* XXX: make s_anon a bl list */ spin_unlock (&tmp->d_lock); -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock);return tmp;
@@ -1479,18 +1496,18 @@ struct dentry *d_splice_alias(struct inostruct dentry *new =NULL ;if (inode &&S_ISDIR (inode->i_mode)) { -spin_lock (&dcache_inode_lock); +spin_lock (&inode->i_lock); new =__d_find_alias (inode,1 );if (new) {BUG_ON (!(new->d_flags &DCACHE_DISCONNECTED )); -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock);security_d_instantiate (new, inode);d_move (new, dentry);iput (inode); }else { -/* already got dcache_inode_lock, so d_add() by hand */ +/* already got inode->i_lock, so d_add() by hand */ __d_instantiate (dentry, inode); -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock);security_d_instantiate (dentry, inode);d_rehash (dentry); }
@@ -1563,10 +1580,10 @@ struct dentry *d_add_ci(struct dentry *d* Negative dentry: instantiate it unless the inode is a directory and * already has a dentry. */ -spin_lock (&dcache_inode_lock); +spin_lock (&inode->i_lock);if (!S_ISDIR (inode->i_mode) ||list_empty (&inode->i_dentry)) {__d_instantiate (found, inode); -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock);security_d_instantiate (found, inode);return found; }
@@ -1577,7 +1594,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 (&inode->i_lock);security_d_instantiate (found, inode);d_move (new, found);iput (inode);
@@ -1785,15 +1802,17 @@ EXPORT_SYMBOL(d_validate);void d_delete (struct dentry * dentry) { +struct inode *inode;int isdir =0 ;/* * Are we the only user? */ again:spin_lock (&dentry->d_lock); - isdir =S_ISDIR (dentry->d_inode->i_mode); + inode = dentry->d_inode; + isdir =S_ISDIR (inode->i_mode);if (dentry->d_count ==1 ) { -if (!spin_trylock (&dcache_inode_lock)) { +if (inode && !spin_trylock (&inode->i_lock)) {spin_unlock (&dentry->d_lock);cpu_relax (); goto again;
@@ -2034,6 +2053,7 @@ static struct dentry *__d_unalias(struct {struct mutex *m1 =NULL , *m2 =NULL ;struct dentry *ret; +struct inode *inode;/* If alias and dentry share a parent, then no extra locks required */ if (alias->d_parent == dentry->d_parent)
@@ -2049,14 +2069,15 @@ static struct dentry *__d_unalias(structif (!mutex_trylock (&dentry->d_sb->s_vfs_rename_mutex)) goto out_err; m1 = &dentry->d_sb->s_vfs_rename_mutex; -if (!mutex_trylock (&alias->d_parent->d_inode->i_mutex)) + inode = alias->d_parent->d_inode; +if (!mutex_trylock (&inode->i_mutex)) goto out_err; - m2 = &alias->d_parent->d_inode->i_mutex; + m2 = &inode->i_mutex; out_unalias:d_move_locked (alias, dentry); ret = alias; out_err: -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock);if (m2)mutex_unlock (m2);if (m1)
@@ -2127,7 +2148,7 @@ struct dentry *d_materialise_unique(stru goto out_nolock; } -spin_lock (&dcache_inode_lock); +spin_lock (&inode->i_lock);if (S_ISDIR (inode->i_mode)) {struct dentry *alias;
@@ -2162,7 +2183,7 @@ struct dentry *d_materialise_unique(stru found:_d_rehash (actual);spin_unlock (&actual->d_lock); -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock); out_nolock:if (actual == dentry) {security_d_instantiate (dentry, inode);
include/linux/dcache.h +0 -1
@@ -190,7 +190,6 @@ d_iput: no no yes#define DCACHE_CANT_MOUNT 0x0100#define DCACHE_GENOCIDE 0x0200 -extern spinlock_t dcache_inode_lock;extern seqlock_t rename_lock;/**
fs/notify/inotify/inotify.c +2 -2
@@ -181,7 +181,7 @@ static void set_dentry_child_flags(struc {struct dentry *alias; -spin_lock (&dcache_inode_lock); +spin_lock (&inode->i_lock);list_for_each_entry (alias, &inode->i_dentry, d_alias) {struct dentry *child;
@@ -199,7 +199,7 @@ static void set_dentry_child_flags(struc }spin_unlock (&alias->d_lock); } -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock); }/*
fs/exportfs/expfs.c +7 -5
@@ -43,24 +43,26 @@ find_acceptable_alias(struct dentry *res void *context) {struct dentry *dentry, *toput =NULL ; +struct inode *inode;if (acceptable (context, result))return result; -spin_lock (&dcache_inode_lock); -list_for_each_entry (dentry, &result->d_inode->i_dentry, d_alias) { + inode = result->d_inode; +spin_lock (&inode->i_lock); +list_for_each_entry (dentry, &inode->i_dentry, d_alias) {dget_locked (dentry); -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock);if (toput)dput (toput);if (dentry != result &&acceptable (context, dentry)) {dput (result);return dentry; } -spin_lock (&dcache_inode_lock); +spin_lock (&inode->i_lock); toput = dentry; } -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock);if (toput)dput (toput);
fs/affs/amigaffs.c +2 -2
@@ -128,7 +128,7 @@ affs_fix_dcache(struct dentry *dentry, uvoid *data = dentry->d_fsdata;struct list_head *head, *next; -spin_lock (&dcache_inode_lock); +spin_lock (&inode->i_lock); head = &inode->i_dentry; next = head->next;while (next != head) {
@@ -139,7 +139,7 @@ affs_fix_dcache(struct dentry *dentry, u } next = next->next; } -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock); }
fs/nfs/getroot.c +2 -2
@@ -64,11 +64,11 @@ static int nfs_superblock_set_dummy_root* This again causes shrink_dcache_for_umount_subtree() to * Oops, since the test for IS_ROOT() will fail. */ -spin_lock (&dcache_inode_lock); +spin_lock (&sb->s_root->d_inode->i_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 (&sb->s_root->d_inode->i_lock); }return 0 ; }
fs/ocfs2/dcache.c +2 -2
@@ -151,7 +151,7 @@ struct dentry *ocfs2_find_local_alias(ststruct list_head *p;struct dentry *dentry =NULL ; -spin_lock (&dcache_inode_lock); +spin_lock (&inode->i_lock);list_for_each (p, &inode->i_dentry) { dentry = list_entry(p, struct dentry, d_alias);
@@ -169,7 +169,7 @@ struct dentry *ocfs2_find_local_alias(st dentry =NULL ; } -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock);return dentry; }
fs/notify/fsnotify.c +2 -2
@@ -53,7 +53,7 @@ void __fsnotify_update_child_dentry_flag/* determine if the children should tell inode about their events */ watched =fsnotify_inode_watches_children (inode); -spin_lock (&dcache_inode_lock); +spin_lock (&inode->i_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,7 +76,7 @@ void __fsnotify_update_child_dentry_flag }spin_unlock (&alias->d_lock); } -spin_unlock (&dcache_inode_lock); +spin_unlock (&inode->i_lock); }/* Notify this dentry's parent about a child's events. */
PATCH 23/52 fs: dcache percpu nr_dentry
In reply to [email protected]The nr_dentry stat is a globally touched cacheline and atomic operation twice over the lifetime of a dentry. It is used for the benfit of userspace only. We could make a per-cpu counter or something for it, but it is only accessed via proc, so we could use slab stats.
XXX: must implement slab routines to return stats for a single cache, and implement the proc handler.
--- fs/dcache.c | 5 +---- include/linux/dcache.h | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-)
fs/dcache.c +1 -4
@@ -105,7 +105,7 @@ static struct dcache_hash_bucket *dentry/* Statistics gathering. */ struct dentry_stat_t dentry_stat = { - .nr_dentry =ATOMIC_INIT (0 ), + .nr_dentry =0 , .age_limit =45 , };
@@ -146,7 +146,6 @@ static void d_callback(struct rcu_head **/ static void d_free (struct dentry *dentry) { -atomic_dec (&dentry_stat.nr_dentry);BUG_ON (dentry->d_count);if (dentry->d_op && dentry->d_op->d_release) dentry->d_op->d_release (dentry);
@@ -1249,8 +1248,6 @@ struct dentry *d_alloc(struct dentry * pspin_unlock (&parent->d_lock); } -atomic_inc (&dentry_stat.nr_dentry); -return dentry; }EXPORT_SYMBOL (d_alloc);
include/linux/dcache.h +1 -1
@@ -38,7 +38,7 @@ struct qstr { };struct dentry_stat_t { -atomic_t nr_dentry; +int nr_dentry;/* unused */ int nr_unused;/* protected by dcache_lru_lock */ int age_limit;/* age in seconds */ int want_pages;/* pages requested by system */
PATCH 25/52 fs: dcache DCACHE_REFERENCED improve
In reply to [email protected]dentry referenced bit is only set when installing the dentry back onto the LRU. However with lazy LRU, the dentry can already be on the LRU list at dput time, thus missing out on setting the referenced bit. Fix this.
fs/dcache.c +3 -3
@@ -387,10 +387,10 @@ repeat:/* Unreachable? Get rid of it */ if (d_unhashed (dentry)) goto kill_it; -if (list_empty (&dentry->d_lru)) { - dentry->d_flags |=DCACHE_REFERENCED ; +/* Otherwise leave it cached and ensure it's on the LRU */ +if (list_empty (&dentry->d_lru))dentry_lru_add (dentry); - } + dentry->d_flags |=DCACHE_REFERENCED ; dentry->d_count--;spin_unlock (&dentry->d_lock);return ;
PATCH 26/52 fs: icache lock s_inodes list
In reply to [email protected]Protect sb->s_inodes with a new lock, sb_inode_list_lock.
--- fs/drop_caches.c | 4 ++++ fs/fs-writeback.c | 4 ++++ fs/inode.c | 12 ++++++++++++ fs/notify/inode_mark.c | 2 ++ fs/notify/inotify/inotify.c | 2 ++ fs/quota/dquot.c | 6 ++++++ include/linux/writeback.h | 1 + 7 files changed, 31 insertions(+)
fs/drop_caches.c +4 -0
@@ -17,18 +17,22 @@ static void drop_pagecache_sb(struct supstruct inode *inode, *toput_inode =NULL ;spin_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 )continue ;__iget (inode); +spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);invalidate_mapping_pages (inode->i_mapping,0 ,-1 );iput (toput_inode); toput_inode = inode;spin_lock (&inode_lock); +spin_lock (&sb_inode_list_lock); } +spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);iput (toput_inode); }
fs/fs-writeback.c +4 -0
@@ -1166,6 +1166,7 @@ static void wait_sb_inodes(struct super_WARN_ON (!rwsem_is_locked (&sb->s_umount));spin_lock (&inode_lock); +spin_lock (&sb_inode_list_lock);/* * Data integrity sync. Must wait for all pages under writeback,
@@ -1183,6 +1184,7 @@ static void wait_sb_inodes(struct super_if (mapping->nrpages ==0 )continue ;__iget (inode); +spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);/* * We hold a reference to 'inode' so it couldn't have
@@ -1200,7 +1202,9 @@ static void wait_sb_inodes(struct super_cond_resched ();spin_lock (&inode_lock); +spin_lock (&sb_inode_list_lock); } +spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);iput (old_inode); }
fs/inode.c +21 -0
@@ -27,6 +27,15 @@#include <linux/posix_acl.h> /* +* Usage: +* sb_inode_list_lock protects: +* s_inodes, i_sb_list +* +* Ordering: +* inode_lock +* sb_inode_list_lock +*/ +/* * This is needed for the following functions: * - inode_has_buffers * - invalidate_inode_buffers
@@ -84,6 +93,7 @@ static struct hlist_head *inode_hashtabl* the i_state of an inode while it is in use.. */ DEFINE_SPINLOCK (inode_lock); +DEFINE_SPINLOCK (sb_inode_list_lock);/* * iprune_sem provides exclusion between the kswapd or try_to_free_pages
@@ -344,7 +354,9 @@ static void dispose_list(struct list_heaspin_lock (&inode_lock);hlist_del_init (&inode->i_hash); +spin_lock (&sb_inode_list_lock);list_del_init (&inode->i_sb_list); +spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);wake_up_inode (inode);
@@ -376,6 +388,7 @@ static int invalidate_list(struct list_h* shrink_icache_memory() away. */ cond_resched_lock (&inode_lock); +cond_resched_lock (&sb_inode_list_lock); next = next->next;if (tmp == head)
@@ -413,9 +426,11 @@ int invalidate_inodes(struct super_blockdown_write (&iprune_sem);spin_lock (&inode_lock); +spin_lock (&sb_inode_list_lock);inotify_unmount_inodes (&sb->s_inodes);fsnotify_unmount_inodes (&sb->s_inodes); busy =invalidate_list (&sb->s_inodes, &throw_away); +spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);dispose_list (&throw_away);
@@ -603,7 +618,9 @@ __inode_add_to_lists(struct super_block { inodes_stat.nr_inodes++;list_add (&inode->i_list, &inode_in_use); +spin_lock (&sb_inode_list_lock);list_add (&inode->i_sb_list, &sb->s_inodes); +spin_unlock (&sb_inode_list_lock);if (head)hlist_add_head (&inode->i_hash, head); }
@@ -1197,7 +1214,9 @@ void generic_delete_inode(struct inode *const struct super_operations *op = inode->i_sb->s_op;list_del_init (&inode->i_list); +spin_lock (&sb_inode_list_lock);list_del_init (&inode->i_sb_list); +spin_unlock (&sb_inode_list_lock);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ; inodes_stat.nr_inodes--;
@@ -1255,7 +1274,9 @@ int generic_detach_inode(struct inode *ihlist_del_init (&inode->i_hash); }list_del_init (&inode->i_list); +spin_lock (&sb_inode_list_lock);list_del_init (&inode->i_sb_list); +spin_unlock (&sb_inode_list_lock);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ; inodes_stat.nr_inodes--;
fs/notify/inotify/inotify.c +2 -0
@@ -429,6 +429,7 @@ void inotify_unmount_inodes(struct list_* will be added since the umount has begun. Finally, * iprune_mutex keeps shrink_icache_memory() away. */ +spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);if (need_iput_tmp)
@@ -451,6 +452,7 @@ void inotify_unmount_inodes(struct list_iput (inode);spin_lock (&inode_lock); +spin_lock (&sb_inode_list_lock); } }EXPORT_SYMBOL_GPL (inotify_unmount_inodes);
fs/quota/dquot.c +6 -0
@@ -884,6 +884,7 @@ static void add_dquot_ref(struct super_b#endif spin_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 ;
@@ -897,6 +898,7 @@ static void add_dquot_ref(struct super_bcontinue ;__iget (inode); +spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);iput (old_inode);
@@ -908,7 +910,9 @@ static void add_dquot_ref(struct super_b* keep the reference and iput it later. */ old_inode = inode;spin_lock (&inode_lock); +spin_lock (&sb_inode_list_lock); } +spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);iput (old_inode);
@@ -988,6 +992,7 @@ static void remove_dquot_ref(struct supestruct inode *inode;spin_lock (&inode_lock); +spin_lock (&sb_inode_list_lock);list_for_each_entry (inode, &sb->s_inodes, i_sb_list) {/* * We have to scan also I_NEW inodes because they can already
@@ -998,6 +1003,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);spin_unlock (&inode_lock); }
include/linux/writeback.h +1 -0
@@ -10,6 +10,7 @@struct backing_dev_info ;extern spinlock_t inode_lock; +extern spinlock_t sb_inode_list_lock;extern struct list_head inode_in_use;extern struct list_head inode_unused;
fs/notify/inode_mark.c +2 -0
@@ -408,6 +408,7 @@ void fsnotify_unmount_inodes(struct list* will be added since the umount has begun. Finally, * iprune_mutex keeps shrink_icache_memory() away. */ +spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);if (need_iput_tmp)
@@ -421,5 +422,6 @@ void fsnotify_unmount_inodes(struct listiput (inode);spin_lock (&inode_lock); +spin_lock (&sb_inode_list_lock); } }
PATCH 29/52 fs: icache lock i_count
In reply to [email protected]Protect inode->i_count with i_lock, rather than having it atomic. Next step should also be to move things together (eg. the refcount increment into d_instantiate, which will remove a lock/unlock cycle on i_lock).
--- arch/powerpc/platforms/cell/spufs/file.c | 2 - fs/affs/inode.c | 4 ++- fs/afs/dir.c | 4 ++- fs/anon_inodes.c | 4 ++- fs/bfs/dir.c | 4 ++- fs/block_dev.c | 15 ++++++++++-- fs/btrfs/inode.c | 4 ++- fs/cifs/inode.c | 2 - fs/coda/dir.c | 4 ++- fs/exofs/inode.c | 12 +++++++--- fs/exofs/namei.c | 4 ++- fs/ext2/namei.c | 4 ++- fs/ext3/ialloc.c | 4 +-- fs/ext3/namei.c | 4 ++- fs/ext4/ialloc.c | 4 +-- fs/ext4/namei.c | 4 ++- fs/fs-writeback.c | 4 +-- fs/gfs2/ops_inode.c | 4 ++- fs/hfsplus/dir.c | 4 ++- fs/hpfs/inode.c | 2 - fs/inode.c | 37 ++++++++++++++++++++----------- fs/jffs2/dir.c | 8 +++++- fs/jfs/jfs_txnmgr.c | 4 ++- fs/jfs/namei.c | 4 ++- fs/libfs.c | 4 ++- fs/locks.c | 3 -- fs/minix/namei.c | 4 ++- fs/namei.c | 7 ++++- fs/nfs/dir.c | 4 ++- fs/nfs/getroot.c | 4 ++- fs/nfs/inode.c | 4 +-- fs/nilfs2/mdt.c | 2 - fs/nilfs2/namei.c | 4 ++- fs/notify/inode_mark.c | 22 +++++++++++------- fs/notify/inotify/inotify.c | 28 +++++++++++++---------- fs/ntfs/super.c | 4 ++- fs/ocfs2/namei.c | 4 ++- fs/reiserfs/file.c | 4 +-- fs/reiserfs/namei.c | 4 ++- fs/reiserfs/stree.c | 2 - fs/sysv/namei.c | 4 ++- fs/ubifs/dir.c | 4 ++- fs/ubifs/super.c | 2 - fs/udf/namei.c | 4 ++- fs/ufs/namei.c | 4 ++- fs/xfs/linux-2.6/xfs_iops.c | 4 ++- fs/xfs/xfs_iget.c | 2 - fs/xfs/xfs_inode.h | 6 +++-- include/linux/fs.h | 2 - ipc/mqueue.c | 7 ++++- kernel/futex.c | 4 ++- mm/shmem.c | 4 ++- 52 files changed, 201 insertions(+), 96 deletions(-)
arch/powerpc/platforms/cell/spufs/file.c +1 -1
@@ -1549,7 +1549,7 @@ static int spufs_mfc_open(struct inode *if (ctx->owner != current->mm)return -EINVAL ; -if (atomic_read (&inode->i_count) !=1 ) +if (inode->i_count !=1 )return -EBUSY ;mutex_lock (&ctx->mapping_lock);
fs/affs/inode.c +3 -1
@@ -380,7 +380,9 @@ affs_add_entry(struct inode *dir, structaffs_adjust_checksum (inode_bh, block -be32_to_cpu (chain));mark_buffer_dirty_inode (inode_bh, inode); inode->i_nlink =2 ; -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); }affs_fix_checksum (sb, bh);mark_buffer_dirty_inode (bh, inode);
fs/afs/dir.c +3 -1
@@ -1002,7 +1002,9 @@ static int afs_link(struct dentry *from,if (ret <0 ) goto link_error; -atomic_inc (&vnode->vfs_inode.i_count); +spin_lock (&vnode->vfs_inode.i_lock); + vnode->vfs_inode.i_count++; +spin_unlock (&vnode->vfs_inode.i_lock);d_instantiate (dentry, &vnode->vfs_inode);key_put (key);_leave (" = 0" );
fs/anon_inodes.c +3 -1
@@ -114,7 +114,9 @@ struct file *anon_inode_getfile(const ch* so we can avoid doing an igrab() and we can use an open-coded * atomic_inc(). */ -atomic_inc (&anon_inode_inode->i_count); +spin_lock (&anon_inode_inode->i_lock); + anon_inode_inode->i_count++; +spin_unlock (&anon_inode_inode->i_lock); path.dentry->d_op = &anon_inodefs_dentry_operations;d_instantiate (path.dentry, anon_inode_inode);
fs/block_dev.c +12 -3
@@ -549,7 +549,12 @@ EXPORT_SYMBOL(bdget);*/ struct block_device *bdgrab (struct block_device *bdev) { -atomic_inc (&bdev->bd_inode->i_count); +struct inode *inode = bdev->bd_inode; + +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); +return bdev; }
@@ -579,7 +584,9 @@ static struct block_device *bd_acquire(sspin_lock (&bdev_lock); bdev = inode->i_bdev;if (bdev) { -atomic_inc (&bdev->bd_inode->i_count); +spin_lock (&inode->i_lock); + bdev->bd_inode->i_count++; +spin_unlock (&inode->i_lock);spin_unlock (&bdev_lock);return bdev; }
@@ -595,7 +602,9 @@ static struct block_device *bd_acquire(s* So, we can access it via ->i_mapping always * without igrab(). */ -atomic_inc (&bdev->bd_inode->i_count); +spin_lock (&inode->i_lock); + bdev->bd_inode->i_count++; +spin_unlock (&inode->i_lock); inode->i_bdev = bdev; inode->i_mapping = bdev->bd_inode->i_mapping;list_add (&inode->i_devices, &bdev->bd_inodes);
fs/ext2/namei.c +3 -1
@@ -206,7 +206,9 @@ static int ext2_link (struct dentry * ol inode->i_ctime =CURRENT_TIME_SEC ;inode_inc_link_count (inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); err =ext2_add_link (dentry, inode);if (!err) {
fs/ext3/ialloc.c +2 -2
@@ -100,9 +100,9 @@ void ext3_free_inode (handle_t *handle,struct ext3_sb_info *sbi;int fatal =0 , err; -if (atomic_read (&inode->i_count) >1 ) { +if (inode->i_count >1 ) {printk ("ext3_free_inode: inode has count=%d\n" , -atomic_read (&inode->i_count)); + inode->i_count);return ; }if (inode->i_nlink) {
fs/ext3/namei.c +3 -1
@@ -2261,7 +2261,9 @@ retry: inode->i_ctime =CURRENT_TIME_SEC ;inc_nlink (inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); err =ext3_add_entry (handle, dentry, inode);if (!err) {
fs/fs-writeback.c +2 -2
@@ -427,7 +427,7 @@ writeback_single_inode(struct inode *inounsigned dirty;int ret; -if (!atomic_read (&inode->i_count)) +if (!inode->i_count)WARN_ON (!(inode->i_state & (I_WILL_FREE |I_FREEING )));else WARN_ON (inode->i_state &I_WILL_FREE );
@@ -551,7 +551,7 @@ select_queue: inode->i_state |=I_DIRTY_PAGES ;redirty_tail (inode); } - }else if (atomic_read (&inode->i_count)) { + }else if (inode->i_count) {/* * The inode is clean, inuse */
fs/inode.c +25 -13
@@ -33,14 +33,13 @@* inode_hash_lock protects: * inode hash table, i_hash * inode->i_lock protects: -* i_state +* i_state, i_count * * Ordering: * inode_lock * sb_inode_list_lock * inode->i_lock -* inode_lock -* inode_hash_lock +* inode_hash_lock */ /* * This is needed for the following functions:
@@ -151,7 +150,7 @@ int inode_init_always(struct super_block inode->i_sb = sb; inode->i_blkbits = sb->s_blocksize_bits; inode->i_flags =0 ; -atomic_set (&inode->i_count,1 ); + inode->i_count =1 ; inode->i_op = &empty_iops; inode->i_fop = &empty_fops; inode->i_nlink =1 ;
@@ -306,7 +305,8 @@ void __iget(struct inode *inode) {assert_spin_locked (&inode->i_lock); -if (atomic_inc_return (&inode->i_count) !=1 ) + inode->i_count++; +if (inode->i_count >1 )return ;if (!(inode->i_state & (I_DIRTY |I_SYNC )))
@@ -412,7 +412,7 @@ static int invalidate_list(struct list_hcontinue ; }invalidate_inode_buffers (inode); -if (!atomic_read (&inode->i_count)) { +if (!inode->i_count) {list_move (&inode->i_list, dispose);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ;
@@ -463,7 +463,7 @@ static int can_unuse(struct inode *inodereturn 0 ;if (inode_has_buffers (inode))return 0 ; -if (atomic_read (&inode->i_count)) +if (inode->i_count)return 0 ;if (inode->i_data.nrpages)return 0 ;
@@ -501,7 +501,7 @@ static void prune_icache(int nr_to_scan) inode = list_entry(inode_unused.prev, struct inode, i_list);spin_lock (&inode->i_lock); -if (inode->i_state ||atomic_read (&inode->i_count)) { +if (inode->i_state || inode->i_count) {list_move (&inode->i_list, &inode_unused);spin_unlock (&inode->i_lock);continue ;
@@ -1290,8 +1290,6 @@ void generic_delete_inode(struct inode * {const struct super_operations *op = inode->i_sb->s_op; -spin_lock (&sb_inode_list_lock); -spin_lock (&inode->i_lock);list_del_init (&inode->i_list);list_del_init (&inode->i_sb_list);spin_unlock (&sb_inode_list_lock);
@@ -1336,8 +1334,6 @@ int generic_detach_inode(struct inode *i {struct super_block *sb = inode->i_sb; -spin_lock (&sb_inode_list_lock); -spin_lock (&inode->i_lock);if (!hlist_unhashed (&inode->i_hash)) {if (!(inode->i_state & (I_DIRTY |I_SYNC )))list_move (&inode->i_list, &inode_unused);
@@ -1436,8 +1432,24 @@ void iput(struct inode *inode)if (inode) {BUG_ON (inode->i_state ==I_CLEAR ); -if (atomic_dec_and_lock (&inode->i_count, &inode_lock)) +retry: +spin_lock (&inode->i_lock); +if (inode->i_count ==1 ) { +if (!spin_trylock (&inode_lock)) { +spin_unlock (&inode->i_lock); + goto retry; + } +if (!spin_trylock (&sb_inode_list_lock)) { +spin_unlock (&inode_lock); +spin_unlock (&inode->i_lock); + goto retry; + } + inode->i_count--;iput_final (inode); + }else { + inode->i_count--; +spin_unlock (&inode->i_lock); + } } }EXPORT_SYMBOL (iput);
fs/libfs.c +3 -1
@@ -277,7 +277,9 @@ int simple_link(struct dentry *old_dentr inode->i_ctime = dir->i_ctime = dir->i_mtime =CURRENT_TIME ;inc_nlink (inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock);dget (dentry);d_instantiate (dentry, inode);return 0 ;
fs/locks.c +1 -2
@@ -1375,8 +1375,7 @@ int generic_setlease(struct file *filp,if ((arg ==F_RDLCK ) && (atomic_read (&inode->i_writecount) >0 )) goto out;if ((arg ==F_WRLCK ) - && (dentry->d_count >1 - || (atomic_read (&inode->i_count) >1 ))) + && (dentry->d_count >1 || inode->i_count >1 )) goto out; }
fs/namei.c +5 -2
@@ -2306,8 +2306,11 @@ static long do_unlinkat(int dfd, const cif (nd.last.name[nd.last.len]) goto slashes; inode = dentry->d_inode; -if (inode) -atomic_inc (&inode->i_count); +if (inode) { +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); + } error =mnt_want_write (nd.path.mnt);if (error) goto exit2;
fs/nfs/dir.c +3 -1
@@ -1570,7 +1570,9 @@ nfs_link(struct dentry *old_dentry, strud_drop (dentry); error =NFS_PROTO (dir)->link (inode, dir, &dentry->d_name);if (error ==0 ) { -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock);d_add (dentry, inode); }return error;
fs/nfs/getroot.c +3 -1
@@ -55,7 +55,9 @@ static int nfs_superblock_set_dummy_rootreturn -ENOMEM ; }/* Circumvent igrab(): we know the inode is not being freed */ -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock);/* * Ensure that this dentry is invisible to d_find_alias(). * Otherwise, it may be spliced into the tree by
fs/notify/inotify/inotify.c +16 -12
@@ -404,23 +404,28 @@ void inotify_unmount_inodes(struct list_* evict all inodes with zero i_count from icache which is * unnecessarily violent and may in fact be illegal to do. */ -if (!atomic_read (&inode->i_count)) +if (!inode->i_count)continue ; need_iput_tmp = need_iput; need_iput =NULL ;/* In case inotify_remove_watch_locked() drops a reference. */ -if (inode != need_iput_tmp) +if (inode != need_iput_tmp) { +spin_lock (&inode->i_lock);__iget (inode); -else +spin_unlock (&inode->i_lock); + }else need_iput_tmp =NULL ;/* In case the dropping of a reference would nuke next_i. */ -if ((&next_i->i_sb_list != list) && -atomic_read (&next_i->i_count) && - !(next_i->i_state & (I_CLEAR |I_FREEING | -I_WILL_FREE ))) { -__iget (next_i); - need_iput = next_i; +if (&next_i->i_sb_list != list) { +spin_lock (&next_i->i_lock); +if (next_i->i_count && + !(next_i->i_state & + (I_CLEAR |I_FREEING |I_WILL_FREE ))) { +__iget (next_i); + need_iput = next_i; + } +spin_unlock (&next_i->i_lock); }/*
@@ -439,11 +444,10 @@ void inotify_unmount_inodes(struct list_mutex_lock (&inode->inotify_mutex); watches = &inode->inotify_watches;list_for_each_entry_safe (watch, next_w, watches, i_list) { -struct inotify_handle *ih= watch->ih; +struct inotify_handle *ih = watch->ih;get_inotify_watch (watch);mutex_lock (&ih->mutex); - ih->in_ops->handle_event (watch, watch->wd,IN_UNMOUNT ,0 , -NULL ,NULL ); + ih->in_ops->handle_event (watch, watch->wd,IN_UNMOUNT ,0 ,NULL ,NULL );inotify_remove_watch_locked (ih, watch);mutex_unlock (&ih->mutex);put_inotify_watch (watch);
fs/xfs/linux-2.6/xfs_iops.c +3 -1
@@ -360,7 +360,9 @@ xfs_vn_link(if (unlikely (error))return -error; -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock);d_instantiate (dentry, inode);return 0 ; }
fs/xfs/xfs_inode.h +4 -2
@@ -483,8 +483,10 @@ void xfs_mark_inode_dirty_sync(xfs_inod#define IHOLD (ip) \ do { \ - ASSERT(atomic_read(&VFS_I(ip)->i_count) > 0) ; \ - atomic_inc(&(VFS_I(ip)->i_count)); \ + spin_lock(&VFS_I(ip)->i_lock); \ + ASSERT(VFS_I(ip)->i_count > 0) ; \ + VFS_I(ip)->i_count++; \ + spin_unlock(&VFS_I(ip)->i_lock); \ trace_xfs_ihold(ip, _THIS_IP_); \ } while (0)
include/linux/fs.h +1 -1
@@ -729,7 +729,7 @@ struct inode {struct list_head i_sb_list;struct list_head i_dentry;unsigned long i_ino; -atomic_t i_count; +unsigned int i_count;unsigned int i_nlink;uid_t i_uid;gid_t i_gid;
ipc/mqueue.c +5 -2
@@ -769,8 +769,11 @@ SYSCALL_DEFINE1(mq_unlink, const char __ } inode = dentry->d_inode; -if (inode) -atomic_inc (&inode->i_count); +if (inode) { +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); + } err =mnt_want_write (ipc_ns->mq_mnt);if (err) goto out_err;
kernel/futex.c +3 -1
@@ -168,7 +168,9 @@ static void get_futex_key_refs(union futswitch (key->both.offset & (FUT_OFF_INODE |FUT_OFF_MMSHARED )) {case FUT_OFF_INODE : -atomic_inc (&key->shared.inode->i_count); +spin_lock (&key->shared.inode->i_lock); + key->shared.inode->i_count++; +spin_unlock (&key->shared.inode->i_lock);break ;case FUT_OFF_MMSHARED :atomic_inc (&key->private.mm->mm_count);
mm/shmem.c +3 -1
@@ -1877,7 +1877,9 @@ static int shmem_link(struct dentry *old dir->i_size +=BOGO_DIRENT_SIZE ; inode->i_ctime = dir->i_ctime = dir->i_mtime =CURRENT_TIME ;inc_nlink (inode); -atomic_inc (&inode->i_count);/* New dentry reference */ +spin_lock (&inode->i_lock); + inode->i_count++;/* New dentry reference */ +spin_unlock (&inode->i_lock);dget (dentry);/* Extra pinning count for the created dentry */ d_instantiate (dentry, inode); out:
fs/bfs/dir.c +3 -1
@@ -176,7 +176,9 @@ static int bfs_link(struct dentry *old,inc_nlink (inode); inode->i_ctime =CURRENT_TIME_SEC ;mark_inode_dirty (inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock);d_instantiate (new, inode);mutex_unlock (&info->bfs_lock);return 0 ;
fs/btrfs/inode.c +3 -1
@@ -4753,7 +4753,9 @@ static int btrfs_link(struct dentry *old }btrfs_set_trans_block_group (trans, dir); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); err =btrfs_add_nondir (trans, dentry, inode,1 , index);
fs/coda/dir.c +3 -1
@@ -303,7 +303,9 @@ static int coda_link(struct dentry *sour }coda_dir_update_mtime (dir_inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock);d_instantiate (de, inode);inc_nlink (inode);
fs/exofs/inode.c +9 -3
@@ -1124,7 +1124,9 @@ static void create_done(struct exofs_io_set_obj_created (oi); -atomic_dec (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count--; +spin_unlock (&inode->i_lock);wake_up (&oi->i_wq); }
@@ -1177,14 +1179,18 @@ struct inode *exofs_new_inode(struct ino/* increment the refcount so that the inode will still be around when we * reach the callback */ -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); ios->done = create_done; ios->private = inode; ios->cred = oi->i_cred; ret =exofs_sbi_create (ios);if (ret) { -atomic_dec (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count--; +spin_unlock (&inode->i_lock);exofs_put_io_state (ios);return ERR_PTR (ret); }
fs/exofs/namei.c +3 -1
@@ -153,7 +153,9 @@ static int exofs_link(struct dentry *old inode->i_ctime =CURRENT_TIME ;inode_inc_link_count (inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock);return exofs_add_nondir (dentry, inode); }
fs/ext4/ialloc.c +2 -2
@@ -189,9 +189,9 @@ void ext4_free_inode(handle_t *handle, sstruct ext4_sb_info *sbi;int fatal =0 , err, count, cleared; -if (atomic_read (&inode->i_count) >1 ) { +if (inode->i_count >1 ) {printk (KERN_ERR "ext4_free_inode: inode has count=%d\n" , -atomic_read (&inode->i_count)); + inode->i_count);return ; }if (inode->i_nlink) {
fs/ext4/namei.c +3 -1
@@ -2340,7 +2340,9 @@ retry: inode->i_ctime =ext4_current_time (inode);ext4_inc_count (handle, inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); err =ext4_add_entry (handle, dentry, inode);if (!err) {
fs/gfs2/ops_inode.c +3 -1
@@ -253,7 +253,9 @@ out_parent:gfs2_holder_uninit (ghs);gfs2_holder_uninit (ghs +1 );if (!error) { -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock);d_instantiate (dentry, inode);mark_inode_dirty (inode); }
fs/hfsplus/dir.c +3 -1
@@ -301,7 +301,9 @@ static int hfsplus_link(struct dentry *sinc_nlink (inode);hfsplus_instantiate (dst_dentry, inode, cnid); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); inode->i_ctime =CURRENT_TIME_SEC ;mark_inode_dirty (inode);HFSPLUS_SB (sb).file_count++;
fs/hpfs/inode.c +1 -1
@@ -183,7 +183,7 @@ void hpfs_write_inode(struct inode *i)struct hpfs_inode_info *hpfs_inode =hpfs_i (i);struct inode *parent;if (i->i_ino ==hpfs_sb (i->i_sb)->sb_root)return ; -if (hpfs_inode->i_rddir_off && !atomic_read (&i->i_count)) { +if (hpfs_inode->i_rddir_off && !i->i_count) {if (*hpfs_inode->i_rddir_off)printk ("HPFS: write_inode: some position still there\n" );kfree (hpfs_inode->i_rddir_off); hpfs_inode->i_rddir_off =NULL ;
fs/jffs2/dir.c +6 -2
@@ -290,7 +290,9 @@ static int jffs2_link (struct dentry *olmutex_unlock (&f->sem);d_instantiate (dentry, old_dentry->d_inode); dir_i->i_mtime = dir_i->i_ctime =ITIME (now); -atomic_inc (&old_dentry->d_inode->i_count); +spin_lock (&old_dentry->d_inode->i_lock); + old_dentry->d_inode->i_count++; +spin_unlock (&old_dentry->d_inode->i_lock); }return ret; }
@@ -871,7 +873,9 @@ static int jffs2_rename (struct inode *oprintk (KERN_NOTICE "jffs2_rename(): Link succeeded, unlink failed (err %d). You now have a hard link\n" , ret);/* Might as well let the VFS know */ d_instantiate (new_dentry, old_dentry->d_inode); -atomic_inc (&old_dentry->d_inode->i_count); +spin_lock (&old_dentry->d_inode->i_lock); + old_dentry->d_inode->i_count++; +spin_unlock (&old_dentry->d_inode->i_lock); new_dir_i->i_mtime = new_dir_i->i_ctime =ITIME (now);return ret; }
fs/jfs/jfs_txnmgr.c +3 -1
@@ -1279,7 +1279,9 @@ int txCommit(tid_t tid, /* transaction* lazy commit thread finishes processing */ if (tblk->xflag &COMMIT_DELETE ) { -atomic_inc (&tblk->u.ip->i_count); +spin_lock (&tblk->u.ip->i_lock); + tblk->u.ip->i_count++; +spin_unlock (&tblk->u.ip->i_lock);/* * Avoid a rare deadlock *
fs/jfs/namei.c +3 -1
@@ -839,7 +839,9 @@ static int jfs_link(struct dentry *old_d ip->i_ctime =CURRENT_TIME ; dir->i_ctime = dir->i_mtime =CURRENT_TIME ;mark_inode_dirty (dir); -atomic_inc (&ip->i_count); +spin_lock (&ip->i_lock); + ip->i_count++; +spin_unlock (&ip->i_lock); iplist[0 ] = ip; iplist[1 ] = dir;
fs/minix/namei.c +3 -1
@@ -101,7 +101,9 @@ static int minix_link(struct dentry * ol inode->i_ctime =CURRENT_TIME_SEC ;inode_inc_link_count (inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock);return add_nondir (dentry, inode); }
fs/nfs/inode.c +2 -2
@@ -377,7 +377,7 @@ nfs_fhget(struct super_block *sb, structdprintk ("NFS: nfs_fhget(%s/%Ld ct=%d)\n" , inode->i_sb->s_id, (long long )NFS_FILEID (inode), -atomic_read (&inode->i_count)); + inode->i_count); out:return inode;
@@ -1123,7 +1123,7 @@ static int nfs_update_inode(struct inodedfprintk (VFS ,"NFS: %s(%s/%ld ct=%d info=0x%x)\n" , __func__, inode->i_sb->s_id, inode->i_ino, -atomic_read (&inode->i_count), fattr->valid); + inode->i_count, fattr->valid);if ((fattr->valid &NFS_ATTR_FATTR_FILEID ) && nfsi->fileid != fattr->fileid) goto out_fileid;
fs/nilfs2/mdt.c +1 -1
@@ -479,7 +479,7 @@ nilfs_mdt_new_common(struct the_nilfs *n inode->i_sb = sb;/* sb may be NULL for some meta data files */ inode->i_blkbits = nilfs->ns_blocksize_bits; inode->i_flags =0 ; -atomic_set (&inode->i_count,1 ); + inode->i_count =1 ; inode->i_nlink =1 ; inode->i_ino = ino; inode->i_mode =S_IFREG ;
fs/nilfs2/namei.c +3 -1
@@ -219,7 +219,9 @@ static int nilfs_link(struct dentry *old inode->i_ctime =CURRENT_TIME ;inode_inc_link_count (inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); err =nilfs_add_nondir (dentry, inode);if (!err)
fs/ocfs2/namei.c +3 -1
@@ -722,7 +722,9 @@ static int ocfs2_link(struct dentry *old goto out_commit; } -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); dentry->d_op = &ocfs2_dentry_ops;d_instantiate (dentry, inode);
fs/reiserfs/file.c +2 -2
@@ -39,7 +39,7 @@ static int reiserfs_file_release(structBUG_ON (!S_ISREG (inode->i_mode));/* fast out for when nothing needs to be done */ -if ((atomic_read (&inode->i_count) >1 || +if ((inode->i_count >1 || !(REISERFS_I (inode)->i_flags & i_pack_on_close_mask) || !tail_has_to_be_packed (inode)) &&REISERFS_I (inode)->i_prealloc_count <=0 ) {
@@ -94,7 +94,7 @@ static int reiserfs_file_release(structif (!err) err = jbegin_failure; -if (!err &&atomic_read (&inode->i_count) <=1 && +if (!err && inode->i_count <=1 && (REISERFS_I (inode)->i_flags & i_pack_on_close_mask) &&tail_has_to_be_packed (inode)) {/* if regular file is released by last holder and it has been
fs/reiserfs/namei.c +3 -1
@@ -1156,7 +1156,9 @@ static int reiserfs_link(struct dentry * inode->i_ctime =CURRENT_TIME_SEC ;reiserfs_update_sd (&th, inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock);d_instantiate (dentry, inode); retval =journal_end (&th, dir->i_sb, jbegin_count);reiserfs_write_unlock (dir->i_sb);
fs/reiserfs/stree.c +1 -1
@@ -1477,7 +1477,7 @@ static int maybe_indirect_to_direct(stru** reading in the last block. The user will hit problems trying to ** read the file, but for now we just skip the indirect2direct */ -if (atomic_read (&inode->i_count) >1 || +if (inode->i_count >1 || !tail_has_to_be_packed (inode) || !page || (REISERFS_I (inode)->i_flags & i_nopack_mask)) {/* leave tail in an unformatted node */
fs/sysv/namei.c +3 -1
@@ -126,7 +126,9 @@ static int sysv_link(struct dentry * old inode->i_ctime =CURRENT_TIME_SEC ;inode_inc_link_count (inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock);return add_nondir (dentry, inode); }
fs/ubifs/dir.c +3 -1
@@ -550,7 +550,9 @@ static int ubifs_link(struct dentry *oldlock_2_inodes (dir, inode);inc_nlink (inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); inode->i_ctime =ubifs_current_time (inode); dir->i_size += sz_change; dir_ui->ui_size = dir->i_size;
fs/ubifs/super.c +1 -1
@@ -342,7 +342,7 @@ static void ubifs_delete_inode(struct in goto out;dbg_gen ("inode %lu, mode %#x" , inode->i_ino, (int )inode->i_mode); -ubifs_assert (!atomic_read (&inode->i_count)); +ubifs_assert (!inode->i_count);ubifs_assert (inode->i_nlink ==0 );truncate_inode_pages (&inode->i_data,0 );
fs/udf/namei.c +3 -1
@@ -1101,7 +1101,9 @@ static int udf_link(struct dentry *old_dinc_nlink (inode); inode->i_ctime =current_fs_time (inode->i_sb);mark_inode_dirty (inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock);d_instantiate (dentry, inode);unlock_kernel ();
fs/ufs/namei.c +3 -1
@@ -180,7 +180,9 @@ static int ufs_link (struct dentry * old inode->i_ctime =CURRENT_TIME_SEC ;inode_inc_link_count (inode); -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); error =ufs_add_nondir (dentry, inode);unlock_kernel ();
fs/notify/inode_mark.c +14 -8
@@ -382,24 +382,30 @@ void fsnotify_unmount_inodes(struct list* evict all inodes with zero i_count from icache which is * unnecessarily violent and may in fact be illegal to do. */ -if (!atomic_read (&inode->i_count)) +if (!inode->i_count)continue ; need_iput_tmp = need_iput; need_iput =NULL ;/* In case fsnotify_inode_delete() drops a reference. */ -if (inode != need_iput_tmp) +if (inode != need_iput_tmp) { +spin_lock (&inode->i_lock);__iget (inode); -else +spin_unlock (&inode->i_lock); + }else need_iput_tmp =NULL ;/* In case the dropping of a reference would nuke next_i. */ -if ((&next_i->i_sb_list != list) && -atomic_read (&next_i->i_count) && - !(next_i->i_state & (I_CLEAR |I_FREEING |I_WILL_FREE ))) { -__iget (next_i); - need_iput = next_i; +if (&next_i->i_sb_list != list) { +spin_lock (&next_i->i_lock); +if (next_i->i_count && + !(next_i->i_state & + (I_CLEAR |I_FREEING |I_WILL_FREE ))) { +__iget (next_i); + need_iput = next_i; + } +spin_unlock (&next_i->i_lock); }/*
fs/ntfs/super.c +3 -1
@@ -2930,7 +2930,9 @@ static int ntfs_fill_super(struct super_ }if ((sb->s_root =d_alloc_root (vol->root_ino))) {/* We increment i_count simulating an ntfs_iget(). */ -atomic_inc (&vol->root_ino->i_count); +spin_lock (&vol->root_ino->i_lock); + vol->root_ino->i_count++; +spin_unlock (&vol->root_ino->i_lock);ntfs_debug ("Exiting, status successful." );/* Release the default upcase if it has no users. */ mutex_lock (&ntfs_lock);
fs/cifs/inode.c +1 -1
@@ -1612,7 +1612,7 @@ int cifs_revalidate_dentry(struct dentry }cFYI (1 ,"Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld " -"jiffies %ld" , full_path, inode, inode->i_count.counter, +"jiffies %ld" , full_path, inode, inode->i_count, dentry, dentry->d_time, jiffies);if (CIFS_SB (sb)->tcon->unix_ext)
fs/xfs/linux-2.6/xfs_trace.h +1 -1
@@ -576,7 +576,7 @@ DECLARE_EVENT_CLASS(xfs_inode_class,TP_fast_assign ( __entry->dev = VFS_I(ip)->i_sb->s_dev; __entry->ino = ip->i_ino; - __entry->count =atomic_read (&VFS_I (ip)->i_count); + __entry->count =VFS_I (ip)->i_count; __entry->pincount =atomic_read (&ip->i_pincount); __entry->caller_ip = caller_ip; ),
net/socket.c +3 -1
@@ -386,7 +386,9 @@ static int sock_alloc_file(struct socket &socket_file_ops);if (unlikely (!file)) {/* drop dentry, keep inode */ -atomic_inc (&path.dentry->d_inode->i_count); +spin_lock (&path.dentry->d_inode->i_lock); + path.dentry->d_inode->i_count++; +spin_unlock (&path.dentry->d_inode->i_lock);path_put (&path);put_unused_fd (fd);return -ENFILE ;
PATCH 30/52 fs: icache lock lru/writeback lists
In reply to [email protected]Add a new lock, wb_inode_list_lock, to protect i_list and various lists which the inode can be put onto.
--- fs/fs-writeback.c | 40 ++++++++++++++++++++++++++++++++++++++-- fs/inode.c | 43 +++++++++++++++++++++++++++++++++++-------- include/linux/writeback.h | 1 + mm/backing-dev.c | 4 ++++ 4 files changed, 78 insertions(+), 10 deletions(-)
fs/fs-writeback.c +49 -3
@@ -287,6 +287,7 @@ static void redirty_tail(struct inode *i {struct bdi_writeback *wb = &inode_to_bdi (inode)->wb; +assert_spin_locked (&wb_inode_list_lock);if (!list_empty (&wb->b_dirty)) {struct inode *tail;
@@ -304,6 +305,7 @@ static void requeue_io(struct inode *ino {struct bdi_writeback *wb = &inode_to_bdi (inode)->wb; +assert_spin_locked (&wb_inode_list_lock);list_move (&inode->i_list, &wb->b_more_io); }
@@ -344,6 +346,7 @@ static void move_expired_inodes(struct lstruct inode *inode;int do_sb_sort =0 ; +assert_spin_locked (&wb_inode_list_lock);while (!list_empty (delaying_queue)) { inode = list_entry(delaying_queue->prev, struct inode, i_list); if (older_than_this &&
@@ -399,11 +402,13 @@ static void inode_wait_for_writeback(str wqh =bit_waitqueue (&inode->i_state, __I_SYNC);while (inode->i_state &I_SYNC ) { +spin_unlock (&wb_inode_list_lock);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); +spin_lock (&wb_inode_list_lock); } }
@@ -457,6 +462,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 (&wb_inode_list_lock);spin_unlock (&inode->i_lock);spin_unlock (&inode_lock);
@@ -493,6 +499,7 @@ writeback_single_inode(struct inode *inospin_lock (&inode_lock);spin_lock (&inode->i_lock); +spin_lock (&wb_inode_list_lock); inode->i_state &= ~I_SYNC ;if (!(inode->i_state & (I_FREEING |I_CLEAR ))) {if ((inode->i_state &I_DIRTY_PAGES ) && wbc->for_kupdate) {
@@ -623,23 +630,31 @@ static int writeback_sb_inodes(struct sustruct bdi_writeback *wb, struct writeback_control *wbc) { +again: while (!list_empty(&wb->b_io)) { long pages_skipped;struct inode *inode =list_entry (wb->b_io.prev, struct inode, i_list); +if (!spin_trylock (&inode->i_lock)) { +spin_unlock (&wb_inode_list_lock); +spin_lock (&wb_inode_list_lock); + goto again; + }if (wbc->sb && sb != inode->i_sb) {/* super block given and doesn't match, skip this inode */ redirty_tail (inode); +spin_unlock (&inode->i_lock);continue ; } -if (sb != inode->i_sb) +if (sb != inode->i_sb) {/* finish with this superblock */ +spin_unlock (&inode->i_lock);return 0 ; -spin_lock (&inode->i_lock); + }if (inode->i_state & (I_NEW |I_WILL_FREE )) { -spin_unlock (&inode->i_lock);requeue_io (inode); +spin_unlock (&inode->i_lock);continue ; }/*
@@ -662,11 +677,13 @@ static int writeback_sb_inodes(struct su*/ redirty_tail (inode); } +spin_unlock (&wb_inode_list_lock);spin_unlock (&inode->i_lock);spin_unlock (&inode_lock);iput (inode);cond_resched ();spin_lock (&inode_lock); +spin_lock (&wb_inode_list_lock);if (wbc->nr_to_write <=0 ) { wbc->more_io =1 ;return 1 ;
@@ -685,6 +702,9 @@ static void writeback_inodes_wb(struct b wbc->wb_start = jiffies;/* livelock avoidance */ spin_lock (&inode_lock); +again: +spin_lock (&wb_inode_list_lock); +if (!wbc->for_kupdate ||list_empty (&wb->b_io))queue_io (wb, wbc->older_than_this);
@@ -697,13 +717,23 @@ static void writeback_inodes_wb(struct bif (wbc->sb && sb != wbc->sb) {/* super block given and doesn't match, skip this inode */ +if (!spin_trylock (&inode->i_lock)) { +spin_unlock (&wb_inode_list_lock); + goto again; + }redirty_tail (inode); +spin_unlock (&inode->i_lock);continue ; } state =pin_sb_for_writeback (wbc, sb);if (state ==SB_PIN_FAILED ) { +if (!spin_trylock (&inode->i_lock)) { +spin_unlock (&wb_inode_list_lock); + goto again; + }requeue_io (inode); +spin_unlock (&inode->i_lock);continue ; } ret =writeback_sb_inodes (sb, wb, wbc);
@@ -713,6 +743,7 @@ static void writeback_inodes_wb(struct bif (ret)break ; } +spin_unlock (&wb_inode_list_lock);spin_unlock (&inode_lock);/* Leave any unwritten inodes on b_io */ }
@@ -825,12 +856,21 @@ static long wb_writeback(struct bdi_writ* become available for writeback. Otherwise * we'll just busyloop. */ +retry:spin_lock (&inode_lock); +spin_lock (&wb_inode_list_lock);if (!list_empty (&wb->b_more_io)) { inode =list_entry (wb->b_more_io.prev, struct inode, i_list); +if (!spin_trylock (&inode->i_lock)) { +spin_unlock (&wb_inode_list_lock); +spin_unlock (&inode_lock); + goto retry; + }inode_wait_for_writeback (inode); +spin_unlock (&inode->i_lock); } +spin_unlock (&wb_inode_list_lock);spin_unlock (&inode_lock); }
@@ -1142,7 +1182,9 @@ void __mark_inode_dirty(struct inode *in } inode->dirtied_when = jiffies; +spin_lock (&wb_inode_list_lock);list_move (&inode->i_list, &wb->b_dirty); +spin_unlock (&wb_inode_list_lock); } } out:
@@ -1306,7 +1348,9 @@ int write_inode_now(struct inode *inode,might_sleep ();spin_lock (&inode_lock);spin_lock (&inode->i_lock); +spin_lock (&wb_inode_list_lock); ret =writeback_single_inode (inode, &wbc); +spin_unlock (&wb_inode_list_lock);spin_unlock (&inode->i_lock);spin_unlock (&inode_lock);if (sync)
@@ -1332,7 +1376,9 @@ int sync_inode(struct inode *inode, struspin_lock (&inode_lock);spin_lock (&inode->i_lock); +spin_lock (&wb_inode_list_lock); ret =writeback_single_inode (inode, wbc); +spin_unlock (&wb_inode_list_lock);spin_unlock (&inode->i_lock);spin_unlock (&inode_lock);return ret;
fs/inode.c +38 -8
153 lines not on this page · raw message
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 wb_inode_list_lock;extern spinlock_t inode_hash_lock;extern struct list_head inode_in_use;extern struct list_head inode_unused;
mm/backing-dev.c +4 -0
@@ -78,6 +78,7 @@ static int bdi_debug_stats_show(struct s*/ nr_wb = nr_dirty = nr_io = nr_more_io =0 ;spin_lock (&inode_lock); +spin_lock (&wb_inode_list_lock);list_for_each_entry (wb, &bdi->wb_list, list) { nr_wb++;list_for_each_entry (inode, &wb->b_dirty, i_list)
@@ -87,6 +88,7 @@ static int bdi_debug_stats_show(struct slist_for_each_entry (inode, &wb->b_more_io, i_list) nr_more_io++; } +spin_unlock (&wb_inode_list_lock);spin_unlock (&inode_lock);get_dirty_limits (&background_thresh, &dirty_thresh, &bdi_thresh, bdi);
@@ -712,9 +714,11 @@ void bdi_destroy(struct backing_dev_infostruct bdi_writeback *dst = &default_backing_dev_info.wb;spin_lock (&inode_lock); +spin_lock (&wb_inode_list_lock);list_splice (&bdi->wb.b_dirty, &dst->b_dirty);list_splice (&bdi->wb.b_io, &dst->b_io);list_splice (&bdi->wb.b_more_io, &dst->b_more_io); +spin_unlock (&wb_inode_list_lock);spin_unlock (&inode_lock); }
PATCH 31/52 fs: icache atomic inodes_stat
In reply to [email protected]Protect inodes_stat statistics with atomic ops rather than inode_lock.
--- fs/fs-writeback.c | 6 ++++-- fs/inode.c | 28 +++++++++++++++------------- include/linux/fs.h | 5 +++-- 3 files changed, 22 insertions(+), 17 deletions(-)
fs/fs-writeback.c +4 -2
@@ -924,7 +924,8 @@ static long wb_check_old_data_flush(stru wb->last_old_flush = jiffies; nr_pages =global_page_state (NR_FILE_DIRTY ) +global_page_state (NR_UNSTABLE_NFS ) + - (inodes_stat.nr_inodes - inodes_stat.nr_unused); + (atomic_read (&inodes_stat.nr_inodes) - +atomic_read (&inodes_stat.nr_unused));if (nr_pages) {struct wb_writeback_args args = {
@@ -1285,7 +1286,8 @@ void writeback_inodes_sb(struct super_bllong nr_to_write; nr_to_write = nr_dirty + nr_unstable + - (inodes_stat.nr_inodes - inodes_stat.nr_unused); + (atomic_read (&inodes_stat.nr_inodes) - +atomic_read (&inodes_stat.nr_unused));bdi_start_writeback (sb->s_bdi, sb, nr_to_write); }
fs/inode.c +15 -13
@@ -123,7 +123,10 @@ static DECLARE_RWSEM(iprune_sem);/* * Statistics gathering.. */ -struct inodes_stat_t inodes_stat; +struct inodes_stat_t inodes_stat = { + .nr_inodes =ATOMIC_INIT (0 ), + .nr_unused =ATOMIC_INIT (0 ), +};static struct kmem_cache *inode_cachep__read_mostly ;
@@ -318,7 +321,7 @@ void __iget(struct inode *inode)list_move (&inode->i_list, &inode_in_use);spin_unlock (&wb_inode_list_lock); } - inodes_stat.nr_unused--; +atomic_dec (&inodes_stat.nr_unused); }/**
@@ -382,9 +385,7 @@ static void dispose_list(struct list_headestroy_inode (inode); nr_disposed++; } -spin_lock (&inode_lock); - inodes_stat.nr_inodes -= nr_disposed; -spin_unlock (&inode_lock); +atomic_sub (nr_disposed, &inodes_stat.nr_inodes); }/*
@@ -433,7 +434,7 @@ static int invalidate_list(struct list_h busy =1 ; }/* only unused inodes may be cached with i_count zero */ - inodes_stat.nr_unused -= count; +atomic_sub (count, &inodes_stat.nr_unused);return busy; }
@@ -551,7 +552,7 @@ again2:spin_unlock (&inode->i_lock); nr_pruned++; } - inodes_stat.nr_unused -= nr_pruned; +atomic_sub (nr_pruned, &inodes_stat.nr_unused);if (current_is_kswapd ())__count_vm_events (KSWAPD_INODESTEAL , reap);else
@@ -584,7 +585,8 @@ static int shrink_icache_memory(int nr,return -1 ;prune_icache (nr); } -return (inodes_stat.nr_unused /100 ) * sysctl_vfs_cache_pressure; +return (atomic_read (&inodes_stat.nr_unused) /100 ) * + sysctl_vfs_cache_pressure; }static struct shrinker icache_shrinker = {
@@ -677,7 +679,7 @@ static inline void __inode_add_to_lists(struct super_block *sb, struct hlist_head *head, struct inode *inode) { - inodes_stat.nr_inodes++; + atomic_inc(&inodes_stat.nr_inodes);spin_lock (&sb_inode_list_lock);list_add (&inode->i_sb_list, &sb->s_inodes);spin_unlock (&sb_inode_list_lock);
@@ -1321,8 +1323,8 @@ void generic_delete_inode(struct inode *WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ;spin_unlock (&inode->i_lock); - inodes_stat.nr_inodes--;spin_unlock (&inode_lock); +atomic_dec (&inodes_stat.nr_inodes);if (op->delete_inode) {void (*delete)(struct inode *) = op->delete_inode;
@@ -1365,7 +1367,7 @@ int generic_detach_inode(struct inode *ilist_move (&inode->i_list, &inode_unused);spin_unlock (&wb_inode_list_lock); } - inodes_stat.nr_unused++; +atomic_inc (&inodes_stat.nr_unused);if (sb->s_flags &MS_ACTIVE ) {spin_unlock (&inode->i_lock);spin_unlock (&sb_inode_list_lock);
@@ -1383,7 +1385,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 ; - inodes_stat.nr_unused--; +atomic_dec (&inodes_stat.nr_unused);spin_lock (&inode_hash_lock);hlist_del_init (&inode->i_hash);spin_unlock (&inode_hash_lock);
@@ -1395,9 +1397,9 @@ int generic_detach_inode(struct inode *ispin_unlock (&sb_inode_list_lock);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ; - inodes_stat.nr_inodes--;spin_unlock (&inode->i_lock);spin_unlock (&inode_lock); +atomic_dec (&inodes_stat.nr_inodes);return 1 ; }EXPORT_SYMBOL_GPL (generic_detach_inode);
include/linux/fs.h +6 -7
@@ -38,13 +38,6 @@ struct files_stat_struct {int max_files;/* tunable */ }; -struct inodes_stat_t { -int nr_inodes; -int nr_unused; -int dummy[5 ];/* padding for sysctl ABI compatibility */ -}; - -#define NR_FILE 8192/* this can well be larger on a larger system */ #define MAY_EXEC 1
@@ -418,6 +411,12 @@ typedef int (get_block_t)(struct inode *typedef void (dio_iodone_t )(struct kiocb *iocb,loff_t offset,ssize_t bytes,void *private); +struct inodes_stat_t { +atomic_t nr_inodes; +atomic_t nr_unused; +int dummy[5 ];/* padding for sysctl ABI compatibility */ +}; +/* * Attribute flags. These should be or-ed together to figure out what * has been changed!
drivers/staging/pohmelfs/inode.c +5 -5
@@ -1283,11 +1283,11 @@ static void pohmelfs_put_super(struct sudprintk ("%s: ino: %llu, pi: %p, inode: %p, count: %u.\n" , __func__, pi->ino, pi, inode, count); -if (atomic_read (&inode->i_count) != count) { +if (inode->i_count != count) {printk ("%s: ino: %llu, pi: %p, inode: %p, count: %u, i_count: %d.\n" , __func__, pi->ino, pi, inode, count, -atomic_read (&inode->i_count)); - count =atomic_read (&inode->i_count); + inode->i_count); + count = inode->i_count; in_drop_list++; }
@@ -1299,7 +1299,7 @@ static void pohmelfs_put_super(struct su pi =POHMELFS_I (inode);dprintk ("%s: ino: %llu, pi: %p, inode: %p, i_count: %u.\n" , - __func__, pi->ino, pi, inode,atomic_read (&inode->i_count)); + __func__, pi->ino, pi, inode, inode->i_count);/* * These are special inodes, they were created during
@@ -1307,7 +1307,7 @@ static void pohmelfs_put_super(struct su* so they live here with reference counter being 1 and prevent * umount from succeed since it believes that they are busy. */ - count =atomic_read (&inode->i_count); + count = inode->i_count;if (count) {list_del_init (&inode->i_sb_list);while (count--)
fs/btrfs/inode.c +9 -4
@@ -1964,8 +1964,13 @@ void btrfs_add_delayed_iput(struct inodestruct btrfs_fs_info *fs_info =BTRFS_I (inode)->root->fs_info;struct delayed_iput *delayed; -if (atomic_add_unless (&inode->i_count,-1 ,1 )) +spin_lock (&inode->i_lock); +if (inode->i_count >1 ) { + inode->i_count--; +spin_unlock (&inode->i_lock);return ; + } +spin_unlock (&inode->i_lock); delayed =kmalloc (sizeof (*delayed),GFP_NOFS | __GFP_NOFAIL); delayed->inode = inode;
@@ -2718,10 +2723,10 @@ static struct btrfs_trans_handle *__unlireturn ERR_PTR (-ENOSPC );/* check if there is someone else holds reference */ -if (S_ISDIR (inode->i_mode) &&atomic_read (&inode->i_count) >1 ) +if (S_ISDIR (inode->i_mode) && inode->i_count >1 )return ERR_PTR (-ENOSPC ); -if (atomic_read (&inode->i_count) >2 ) +if (inode->i_count >2 )return ERR_PTR (-ENOSPC );if (xchg (&root->fs_info->enospc_unlink,1 ))
@@ -3934,7 +3939,7 @@ again: inode =igrab (&entry->vfs_inode);if (inode) {spin_unlock (&root->inode_lock); -if (atomic_read (&inode->i_count) >1 ) +if (inode->i_count >1 )d_prune_aliases (inode);/* * btrfs_drop_inode will remove it from
fs/ceph/mds_client.c +1 -1
@@ -1028,7 +1028,7 @@ static int trim_caps_cb(struct inode *inspin_unlock (&inode->i_lock);d_prune_aliases (inode);dout ("trim_caps_cb %p cap %p pruned, count now %d\n" , - inode, cap,atomic_read (&inode->i_count)); + inode, cap, inode->i_count);return 0 ; }
fs/logfs/dir.c +3 -1
@@ -566,7 +566,9 @@ static int logfs_link(struct dentry *oldreturn -EMLINK ; inode->i_ctime = dir->i_ctime = dir->i_mtime =CURRENT_TIME ; -atomic_inc (&inode->i_count); +spin_lock (&inode->i_lock); + inode->i_count++; +spin_unlock (&inode->i_lock); inode->i_nlink++;mark_inode_dirty_sync (inode);
fs/logfs/readwrite.c +1 -1
@@ -1002,7 +1002,7 @@ static int __logfs_is_valid_block(struct {struct logfs_inode *li =logfs_inode (inode); -if ((inode->i_nlink ==0 ) &&atomic_read (&inode->i_count) ==1 ) +if (inode->i_nlink ==0 && inode->i_count ==1 )return 0 ;if (bix <I0_BLOCKS )
PATCH 32/52 fs: icache protect inode state
In reply to [email protected]Protect i_hash, i_sb_list etc members with i_lock.
--- fs/hugetlbfs/inode.c | 1 + fs/inode.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-)
fs/inode.c +29 -4
@@ -35,7 +35,11 @@* wb_inode_list_lock protects: * inode_in_use, inode_unused, b_io, b_more_io, b_dirty, i_list * inode->i_lock protects: -* i_state, i_count +* i_state +* i_count +* i_hash +* i_list +* i_sb_list * * Ordering: * inode_lock
@@ -373,12 +377,14 @@ static void dispose_list(struct list_heaclear_inode (inode);spin_lock (&inode_lock); +spin_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); -spin_lock (&sb_inode_list_lock);list_del_init (&inode->i_sb_list);spin_unlock (&sb_inode_list_lock); +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock);wake_up_inode (inode);
@@ -680,7 +686,6 @@ __inode_add_to_lists(struct super_block struct inode *inode) {atomic_inc (&inodes_stat.nr_inodes); -spin_lock (&sb_inode_list_lock);list_add (&inode->i_sb_list, &sb->s_inodes);spin_unlock (&sb_inode_list_lock);spin_lock (&wb_inode_list_lock);
@@ -710,7 +715,10 @@ void inode_add_to_lists(struct super_blostruct hlist_head *head = inode_hashtable +hash (sb, inode->i_ino);spin_lock (&inode_lock); +spin_lock (&sb_inode_list_lock); +spin_lock (&inode->i_lock);__inode_add_to_lists (sb, head, inode); +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock); }EXPORT_SYMBOL_GPL (inode_add_to_lists);
@@ -742,9 +750,12 @@ struct inode *new_inode(struct super_blo inode =alloc_inode (sb);if (inode) {spin_lock (&inode_lock); +spin_lock (&sb_inode_list_lock); +spin_lock (&inode->i_lock); inode->i_ino = ++last_ino; inode->i_state =0 ;__inode_add_to_lists (sb,NULL , inode); +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock); }return inode;
@@ -808,11 +819,14 @@ static struct inode *get_new_inode(struc/* We released the lock, so.. */ old =find_inode (sb, head, test, data);if (!old) { +spin_lock (&sb_inode_list_lock); +spin_lock (&inode->i_lock);if (set (inode, data)) goto set_failed; inode->i_state =I_NEW ;__inode_add_to_lists (sb, head, inode); +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock);/* Return the locked inode with I_NEW set, the
@@ -837,6 +851,7 @@ static struct inode *get_new_inode(struc set_failed:spin_unlock (&inode->i_lock); +spin_unlock (&sb_inode_list_lock);spin_unlock (&inode_lock);destroy_inode (inode);return NULL ;
@@ -859,9 +874,12 @@ static struct inode *get_new_inode_fast(/* We released the lock, so.. */ old =find_inode_fast (sb, head, 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); +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock);/* Return the locked inode with I_NEW set, the
@@ -1275,10 +1293,13 @@ 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); +spin_lock (&inode_lock); +spin_lock (&inode->i_lock);spin_lock (&inode_hash_lock);hlist_add_head (&inode->i_hash, head);spin_unlock (&inode_hash_lock); +spin_unlock (&inode->i_lock);spin_unlock (&inode_lock); }EXPORT_SYMBOL (__insert_inode_hash);
@@ -1292,9 +1313,11 @@ EXPORT_SYMBOL(__insert_inode_hash);void remove_inode_hash (struct inode *inode) {spin_lock (&inode_lock); +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);spin_unlock (&inode_lock); }EXPORT_SYMBOL (remove_inode_hash);
@@ -1338,9 +1361,11 @@ void generic_delete_inode(struct inode *clear_inode (inode); }spin_lock (&inode_lock); +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);spin_unlock (&inode_lock);wake_up_inode (inode);BUG_ON (inode->i_state !=I_CLEAR );
@@ -1385,10 +1410,10 @@ int generic_detach_inode(struct inode *ispin_lock (&inode->i_lock);WARN_ON (inode->i_state &I_NEW ); inode->i_state &= ~I_WILL_FREE ; -atomic_dec (&inodes_stat.nr_unused);spin_lock (&inode_hash_lock);hlist_del_init (&inode->i_hash);spin_unlock (&inode_hash_lock); +atomic_dec (&inodes_stat.nr_unused); }spin_lock (&wb_inode_list_lock);list_del_init (&inode->i_list);
fs/hugetlbfs/inode.c +1 -0
@@ -382,6 +382,7 @@ static void hugetlbfs_forget_inode(strucif (generic_detach_inode (inode)) {truncate_hugepages (inode,0 );clear_inode (inode); +/* XXX: why no wake_up_inode? */ destroy_inode (inode); } }
PATCH 34/52 fs: icache remove inode_lock
In reply to [email protected]Remove the global inode_lock, as it doesn't protect anything.
--- fs/buffer.c | 2 - fs/drop_caches.c | 4 -- fs/fs-writeback.c | 35 ++++------------------- fs/hugetlbfs/inode.c | 2 - fs/inode.c | 65 ++------------------------------------------ fs/notify/inode_mark.c | 14 +++++---- fs/notify/inotify/inotify.c | 16 ++++++---- fs/quota/dquot.c | 6 ---- include/linux/writeback.h | 1 mm/backing-dev.c | 4 -- 10 files changed, 30 insertions(+), 119 deletions(-)
fs/buffer.c +1 -1
@@ -1144,7 +1144,7 @@ __getblk_slow(struct block_device *bdev,* inode list. * * mark_buffer_dirty() is atomic. It takes bh->b_page->mapping->private_lock, -* mapping->tree_lock and the global inode_lock. +* and mapping->tree_lock. */ void mark_buffer_dirty (struct buffer_head *bh) {
fs/drop_caches.c +0 -4
@@ -16,7 +16,6 @@ static void drop_pagecache_sb(struct sup {struct inode *inode, *toput_inode =NULL ; -spin_lock (&inode_lock);spin_lock (&sb_inode_list_lock);list_for_each_entry (inode, &sb->s_inodes, i_sb_list) {spin_lock (&inode->i_lock);
@@ -28,15 +27,12 @@ static void drop_pagecache_sb(struct sup__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 );iput (toput_inode); toput_inode = inode; -spin_lock (&inode_lock);spin_lock (&sb_inode_list_lock); }spin_unlock (&sb_inode_list_lock); -spin_unlock (&inode_lock);iput (toput_inode); }
fs/fs-writeback.c +6 -30
@@ -312,7 +312,7 @@ static void requeue_io(struct inode *inostatic void inode_sync_complete (struct inode *inode) {/* -* Prevent speculative execution through spin_unlock(&inode_lock); +* Prevent speculative execution through spin_unlock(&inode->i_lock); */ smp_mb ();wake_up_bit (&inode->i_state, __I_SYNC);
@@ -404,9 +404,7 @@ static void inode_wait_for_writeback(strwhile (inode->i_state &I_SYNC ) {spin_unlock (&wb_inode_list_lock);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);spin_lock (&wb_inode_list_lock); }
@@ -464,7 +462,6 @@ writeback_single_inode(struct inode *ino inode->i_state &= ~I_DIRTY_PAGES ;spin_unlock (&wb_inode_list_lock);spin_unlock (&inode->i_lock); -spin_unlock (&inode_lock); ret =do_writepages (mapping, wbc);
@@ -484,12 +481,10 @@ writeback_single_inode(struct inode *ino* due to delalloc, clear dirty metadata flags right before * 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 )) {int err =write_inode (inode, wbc);
@@ -497,7 +492,6 @@ writeback_single_inode(struct inode *ino ret = err; } -spin_lock (&inode_lock);spin_lock (&inode->i_lock);spin_lock (&wb_inode_list_lock); inode->i_state &= ~I_SYNC ;
@@ -679,10 +673,8 @@ again: }spin_unlock (&wb_inode_list_lock);spin_unlock (&inode->i_lock); -spin_unlock (&inode_lock);iput (inode);cond_resched (); -spin_lock (&inode_lock);spin_lock (&wb_inode_list_lock);if (wbc->nr_to_write <=0 ) { wbc->more_io =1 ;
@@ -701,7 +693,6 @@ static void writeback_inodes_wb(struct bint ret =0 ; wbc->wb_start = jiffies;/* livelock avoidance */ -spin_lock (&inode_lock); again:spin_lock (&wb_inode_list_lock);
@@ -744,7 +735,6 @@ again:break ; }spin_unlock (&wb_inode_list_lock); -spin_unlock (&inode_lock);/* Leave any unwritten inodes on b_io */ }
@@ -857,21 +847,18 @@ static long wb_writeback(struct bdi_writ* we'll just busyloop. */ retry: -spin_lock (&inode_lock);spin_lock (&wb_inode_list_lock);if (!list_empty (&wb->b_more_io)) { inode =list_entry (wb->b_more_io.prev, struct inode, i_list);if (!spin_trylock (&inode->i_lock)) {spin_unlock (&wb_inode_list_lock); -spin_unlock (&inode_lock); goto retry; }inode_wait_for_writeback (inode);spin_unlock (&inode->i_lock); }spin_unlock (&wb_inode_list_lock); -spin_unlock (&inode_lock); }return wrote;
@@ -1141,7 +1128,6 @@ void __mark_inode_dirty(struct inode *inif (unlikely (block_dump))block_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 ;
@@ -1190,7 +1176,6 @@ void __mark_inode_dirty(struct inode *in } out:spin_unlock (&inode->i_lock); -spin_unlock (&inode_lock); }EXPORT_SYMBOL (__mark_inode_dirty);
@@ -1221,7 +1206,6 @@ static void wait_sb_inodes(struct super_*/ WARN_ON (!rwsem_is_locked (&sb->s_umount)); -spin_lock (&inode_lock);spin_lock (&sb_inode_list_lock);/*
@@ -1246,14 +1230,12 @@ static void wait_sb_inodes(struct super___iget (inode);spin_unlock (&inode->i_lock);spin_unlock (&sb_inode_list_lock); -spin_unlock (&inode_lock);/* -* We hold a reference to 'inode' so it couldn't have -* been removed from s_inodes list while we dropped the -* inode_lock. We cannot iput the inode now as we can -* be holding the last reference and we cannot iput it -* under inode_lock. So we keep the reference and iput -* it later. +* We hold a reference to 'inode' so it couldn't have been +* removed from s_inodes list while we dropped the +* sb_inode_list_lock. We cannot iput the inode now as we can +* be holding the last reference and we cannot iput it under +* spinlock. So we keep the reference and iput it later. */ iput (old_inode); old_inode = inode;
@@ -1262,11 +1244,9 @@ static void wait_sb_inodes(struct super_cond_resched (); -spin_lock (&inode_lock);spin_lock (&sb_inode_list_lock); }spin_unlock (&sb_inode_list_lock); -spin_unlock (&inode_lock);iput (old_inode); }
@@ -1348,13 +1328,11 @@ int write_inode_now(struct inode *inode, wbc.nr_to_write =0 ;might_sleep (); -spin_lock (&inode_lock);spin_lock (&inode->i_lock);spin_lock (&wb_inode_list_lock); ret =writeback_single_inode (inode, &wbc);spin_unlock (&wb_inode_list_lock);spin_unlock (&inode->i_lock); -spin_unlock (&inode_lock);if (sync)inode_sync_wait (inode);return ret;
@@ -1376,13 +1354,11 @@ int sync_inode(struct inode *inode, stru {int ret; -spin_lock (&inode_lock);spin_lock (&inode->i_lock);spin_lock (&wb_inode_list_lock); ret =writeback_single_inode (inode, wbc);spin_unlock (&wb_inode_list_lock);spin_unlock (&inode->i_lock); -spin_unlock (&inode_lock);return ret; }EXPORT_SYMBOL (sync_inode);
fs/hugetlbfs/inode.c +1 -1
@@ -377,7 +377,7 @@ static void hugetlbfs_delete_inode(strucclear_inode (inode); } -static void hugetlbfs_forget_inode (struct inode *inode)__releases (inode_lock) +static void hugetlbfs_forget_inode (struct inode *inode) {if (generic_detach_inode (inode)) {truncate_hugepages (inode,0 );
fs/inode.c +4 -61
349 lines not on this page · raw message
fs/notify/inotify/inotify.c +10 -6
@@ -390,13 +390,16 @@ void inotify_unmount_inodes(struct list_struct inode *need_iput_tmp;struct list_head *watches; +spin_lock (&inode->i_lock);/* * We cannot __iget() an inode in state I_CLEAR, I_FREEING, * I_WILL_FREE, or I_NEW which is fine because by that point * the inode cannot have any associated watches. */ -if (inode->i_state & (I_CLEAR |I_FREEING |I_WILL_FREE |I_NEW )) +if (inode->i_state & (I_CLEAR |I_FREEING |I_WILL_FREE |I_NEW )) { +spin_unlock (&inode->i_lock);continue ; + }/* * If i_count is zero, the inode cannot have any watches and
@@ -404,18 +407,21 @@ void inotify_unmount_inodes(struct list_* evict all inodes with zero i_count from icache which is * unnecessarily violent and may in fact be illegal to do. */ -if (!inode->i_count) +if (!inode->i_count) { +spin_unlock (&inode->i_lock);continue ; + } need_iput_tmp = need_iput; need_iput =NULL ;/* In case inotify_remove_watch_locked() drops a reference. */ if (inode != need_iput_tmp) { -spin_lock (&inode->i_lock);__iget (inode); -spin_unlock (&inode->i_lock); }else need_iput_tmp =NULL ; + +spin_unlock (&inode->i_lock); +/* In case the dropping of a reference would nuke next_i. */ if (&next_i->i_sb_list != list) {spin_lock (&next_i->i_lock);
@@ -435,7 +441,6 @@ void inotify_unmount_inodes(struct list_* iprune_mutex keeps shrink_icache_memory() away. */ spin_unlock (&sb_inode_list_lock); -spin_unlock (&inode_lock);if (need_iput_tmp)iput (need_iput_tmp);
@@ -455,7 +460,6 @@ void inotify_unmount_inodes(struct list_mutex_unlock (&inode->inotify_mutex);iput (inode); -spin_lock (&inode_lock);spin_lock (&sb_inode_list_lock); } }
include/linux/writeback.h +0 -1
@@ -9,7 +9,6 @@struct backing_dev_info ; -extern spinlock_t inode_lock;extern spinlock_t sb_inode_list_lock;extern spinlock_t wb_inode_list_lock;extern spinlock_t inode_hash_lock;
fs/quota/dquot.c +0 -6
@@ -883,7 +883,6 @@ static void add_dquot_ref(struct super_bint reserved =0 ;#endif -spin_lock (&inode_lock);spin_lock (&sb_inode_list_lock);list_for_each_entry (inode, &sb->s_inodes, i_sb_list) {spin_lock (&inode->i_lock);
@@ -907,7 +906,6 @@ static void add_dquot_ref(struct super_b__iget (inode);spin_unlock (&inode->i_lock);spin_unlock (&sb_inode_list_lock); -spin_unlock (&inode_lock);iput (old_inode);__dquot_initialize (inode, type);
@@ -917,11 +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 (&inode_lock);spin_lock (&sb_inode_list_lock); }spin_unlock (&sb_inode_list_lock); -spin_unlock (&inode_lock);iput (old_inode);#ifdef CONFIG_QUOTA_DEBUG
@@ -999,7 +995,6 @@ static void remove_dquot_ref(struct supe {struct inode *inode; -spin_lock (&inode_lock);spin_lock (&sb_inode_list_lock);list_for_each_entry (inode, &sb->s_inodes, i_sb_list) {/*
@@ -1012,7 +1007,6 @@ static void remove_dquot_ref(struct superemove_inode_dquot_ref (inode, type, tofree_head); }spin_unlock (&sb_inode_list_lock); -spin_unlock (&inode_lock); }/* Gather all references from inodes and drop them */
fs/notify/inode_mark.c +8 -6
@@ -368,13 +368,16 @@ void fsnotify_unmount_inodes(struct listlist_for_each_entry_safe (inode, next_i, list, i_sb_list) {struct inode *need_iput_tmp; +spin_lock (&inode->i_lock);/* * We cannot __iget() an inode in state I_CLEAR, I_FREEING, * I_WILL_FREE, or I_NEW which is fine because by that point * the inode cannot have any associated watches. */ -if (inode->i_state & (I_CLEAR |I_FREEING |I_WILL_FREE |I_NEW )) +if (inode->i_state & (I_CLEAR |I_FREEING |I_WILL_FREE |I_NEW )) { +spin_unlock (&inode->i_lock);continue ; + }/* * If i_count is zero, the inode cannot have any watches and
@@ -382,19 +385,20 @@ void fsnotify_unmount_inodes(struct list* evict all inodes with zero i_count from icache which is * unnecessarily violent and may in fact be illegal to do. */ -if (!inode->i_count) +if (!inode->i_count) { +spin_unlock (&inode->i_lock);continue ; + } need_iput_tmp = need_iput; need_iput =NULL ;/* In case fsnotify_inode_delete() drops a reference. */ if (inode != need_iput_tmp) { -spin_lock (&inode->i_lock);__iget (inode); -spin_unlock (&inode->i_lock); }else need_iput_tmp =NULL ; +spin_unlock (&inode->i_lock);/* In case the dropping of a reference would nuke next_i. */ if (&next_i->i_sb_list != list) {
@@ -415,7 +419,6 @@ void fsnotify_unmount_inodes(struct list* iprune_mutex keeps shrink_icache_memory() away. */ spin_unlock (&sb_inode_list_lock); -spin_unlock (&inode_lock);if (need_iput_tmp)iput (need_iput_tmp);
@@ -427,7 +430,6 @@ void fsnotify_unmount_inodes(struct listiput (inode); -spin_lock (&inode_lock);spin_lock (&sb_inode_list_lock); } }
mm/backing-dev.c +0 -4
@@ -77,7 +77,6 @@ static int bdi_debug_stats_show(struct s* RCU on the reader side */ nr_wb = nr_dirty = nr_io = nr_more_io =0 ; -spin_lock (&inode_lock);spin_lock (&wb_inode_list_lock);list_for_each_entry (wb, &bdi->wb_list, list) { nr_wb++;
@@ -89,7 +88,6 @@ static int bdi_debug_stats_show(struct s nr_more_io++; }spin_unlock (&wb_inode_list_lock); -spin_unlock (&inode_lock);get_dirty_limits (&background_thresh, &dirty_thresh, &bdi_thresh, bdi);
@@ -713,13 +711,11 @@ void bdi_destroy(struct backing_dev_infoif (bdi_has_dirty_io (bdi)) {struct bdi_writeback *dst = &default_backing_dev_info.wb; -spin_lock (&inode_lock);spin_lock (&wb_inode_list_lock);list_splice (&bdi->wb.b_dirty, &dst->b_dirty);list_splice (&bdi->wb.b_io, &dst->b_io);list_splice (&bdi->wb.b_more_io, &dst->b_more_io);spin_unlock (&wb_inode_list_lock); -spin_unlock (&inode_lock); }bdi_unregister (bdi);
PATCH 37/52 fs: icache lazy lru
In reply to [email protected]Impelemnt lazy inode lru similarly to dcache. This will reduce lock acquisition and will help to improve lock ordering subsequently.
--- fs/fs-writeback.c | 21 +++++++-------- fs/inode.c | 61 +++++++++++++++++++--------------------------- include/linux/fs.h | 7 ++++- include/linux/writeback.h | 1 4 files changed, 42 insertions(+), 48 deletions(-)
fs/inode.c +38 -67
@@ -96,7 +96,6 @@ static unsigned int i_hash_shift __read_* allowing for low-overhead inode sync() operations. */ -LIST_HEAD (inode_in_use);LIST_HEAD (inode_unused);struct inode_hash_bucket {
@@ -298,6 +297,7 @@ void inode_init_once(struct inode *inodeINIT_HLIST_BL_NODE (&inode->i_hash);INIT_LIST_HEAD (&inode->i_dentry);INIT_LIST_HEAD (&inode->i_devices); +INIT_LIST_HEAD (&inode->i_list);INIT_RADIX_TREE (&inode->i_data.page_tree,GFP_ATOMIC );spin_lock_init (&inode->i_data.tree_lock);spin_lock_init (&inode->i_data.i_mmap_lock);
@@ -323,25 +323,6 @@ static void init_once(void *foo)inode_init_once (inode); } -/* -* inode_lock must be held -*/ -void __iget (struct inode *inode) -{ -assert_spin_locked (&inode->i_lock); - - inode->i_count++; -if (inode->i_count >1 ) -return ; - -if (!(inode->i_state & (I_DIRTY |I_SYNC ))) { -spin_lock (&wb_inode_list_lock); -list_move (&inode->i_list, &inode_in_use); -spin_unlock (&wb_inode_list_lock); - } -atomic_dec (&inodes_stat.nr_unused); -} -/** * clear_inode - clear an inode * @inode: inode to clear
@@ -384,7 +365,7 @@ static void dispose_list(struct list_heastruct inode *inode; inode = list_first_entry(head, struct inode, i_list); -list_del (&inode->i_list); +list_del_init (&inode->i_list);if (inode->i_data.nrpages)truncate_inode_pages (&inode->i_data,0 );
@@ -437,11 +418,12 @@ static int invalidate_list(struct list_hinvalidate_inode_buffers (inode);if (!inode->i_count) {spin_lock (&wb_inode_list_lock); -list_move (&inode->i_list, dispose); +list_del (&inode->i_list);spin_unlock (&wb_inode_list_lock);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ;spin_unlock (&inode->i_lock); +list_add (&inode->i_list, dispose); count++;continue ; }
@@ -480,19 +462,6 @@ int invalidate_inodes(struct super_block }EXPORT_SYMBOL (invalidate_inodes); -static int can_unuse (struct inode *inode) -{ -if (inode->i_state) -return 0 ; -if (inode_has_buffers (inode)) -return 0 ; -if (inode->i_count) -return 0 ; -if (inode->i_data.nrpages) -return 0 ; -return 1 ; -} -/* * Scan `goal' inodes on the unused list for freeable ones. They are moved to * a temporary list and then are freed outside inode_lock by dispose_list().
@@ -510,13 +479,12 @@ static void prune_icache(int nr_to_scan) {LIST_HEAD (freeable);int nr_pruned =0 ; -int nr_scanned;unsigned long reap =0 ;down_read (&iprune_sem); again:spin_lock (&wb_inode_list_lock); -for (nr_scanned =0 ; nr_scanned < nr_to_scan; nr_scanned++) { +for (; nr_to_scan; nr_to_scan--) {struct inode *inode;if (list_empty (&inode_unused))
@@ -528,33 +496,30 @@ again:spin_unlock (&wb_inode_list_lock); goto again; } -if (inode->i_state || inode->i_count) { +if (inode->i_count || (inode->i_state & ~I_REFERENCED )) { +list_del_init (&inode->i_list); +spin_unlock (&inode->i_lock); +atomic_dec (&inodes_stat.nr_unused); +continue ; + } +if (inode->i_state) {list_move (&inode->i_list, &inode_unused); + inode->i_state &= ~I_REFERENCED ;spin_unlock (&inode->i_lock);continue ; }if (inode_has_buffers (inode) || inode->i_data.nrpages) { +list_move (&inode->i_list, &inode_unused);spin_unlock (&wb_inode_list_lock);__iget (inode);spin_unlock (&inode->i_lock); +if (remove_inode_buffers (inode)) reap +=invalidate_mapping_pages (&inode->i_data,0 ,-1 );iput (inode); -again2:spin_lock (&wb_inode_list_lock); - -if (inode !=list_entry (inode_unused.next, - struct inode, i_list)) -continue ;/* wrong inode or list_empty */ -if (!spin_trylock (&inode->i_lock)) { -spin_unlock (&wb_inode_list_lock); - goto again2; - } -if (!can_unuse (inode)) { -spin_unlock (&inode->i_lock); -continue ; - } +continue ; }list_move (&inode->i_list, &freeable);WARN_ON (inode->i_state &I_NEW );
@@ -694,9 +659,6 @@ __inode_add_to_lists(struct super_blockatomic_inc (&inodes_stat.nr_inodes);list_add (&inode->i_sb_list, &sb->s_inodes);spin_unlock (&sb_inode_list_lock); -spin_lock (&wb_inode_list_lock); -list_add (&inode->i_list, &inode_in_use); -spin_unlock (&wb_inode_list_lock);if (b) {spin_lock_bucket (b);hlist_bl_add_head (&inode->i_hash, &b->head);
@@ -1343,9 +1305,13 @@ void generic_delete_inode(struct inode * {const struct super_operations *op = inode->i_sb->s_op; -spin_lock (&wb_inode_list_lock); -list_del_init (&inode->i_list); -spin_unlock (&wb_inode_list_lock); +if (!list_empty (&inode->i_list)) { +spin_lock (&wb_inode_list_lock); +list_del_init (&inode->i_list); +spin_unlock (&wb_inode_list_lock); +if (!inode->i_state) +atomic_dec (&inodes_stat.nr_unused); + }list_del_init (&inode->i_sb_list);spin_unlock (&sb_inode_list_lock);WARN_ON (inode->i_state &I_NEW );
@@ -1393,13 +1359,15 @@ int generic_detach_inode(struct inode *istruct super_block *sb = inode->i_sb;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); -spin_unlock (&wb_inode_list_lock); - } -atomic_inc (&inodes_stat.nr_unused);if (sb->s_flags &MS_ACTIVE ) { + inode->i_state |=I_REFERENCED ; +if (!(inode->i_state & (I_DIRTY |I_SYNC )) && +list_empty (&inode->i_list)) { +spin_lock (&wb_inode_list_lock); +list_add (&inode->i_list, &inode_unused); +spin_unlock (&wb_inode_list_lock); +atomic_inc (&inodes_stat.nr_unused); + }spin_unlock (&inode->i_lock);spin_unlock (&sb_inode_list_lock);return 0 ;
@@ -1414,11 +1382,14 @@ int generic_detach_inode(struct inode *iWARN_ON (inode->i_state &I_NEW ); inode->i_state &= ~I_WILL_FREE ;__remove_inode_hash (inode); -atomic_dec (&inodes_stat.nr_unused); } -spin_lock (&wb_inode_list_lock); -list_del_init (&inode->i_list); -spin_unlock (&wb_inode_list_lock); +if (!list_empty (&inode->i_list)) { +spin_lock (&wb_inode_list_lock); +list_del_init (&inode->i_list); +spin_unlock (&wb_inode_list_lock); +if (!inode->i_state) +atomic_dec (&inodes_stat.nr_unused); + }list_del_init (&inode->i_sb_list);spin_unlock (&sb_inode_list_lock);WARN_ON (inode->i_state &I_NEW );
include/linux/fs.h +13 -7
@@ -1634,16 +1634,17 @@ struct super_operations {* * Q: What is the difference between I_WILL_FREE and I_FREEING? */ -#define I_DIRTY_SYNC 1 -#define I_DIRTY_DATASYNC 2 -#define I_DIRTY_PAGES 4 +#define I_DIRTY_SYNC 0x01 +#define I_DIRTY_DATASYNC 0x02 +#define I_DIRTY_PAGES 0x04#define __I_NEW 3#define I_NEW (1 << __I_NEW) -#define I_WILL_FREE 16 -#define I_FREEING 32 -#define I_CLEAR 64 +#define I_WILL_FREE 0x10 +#define I_FREEING 0x20 +#define I_CLEAR 0x40#define __I_SYNC 7#define I_SYNC (1 << __I_SYNC) +#define I_REFERENCED 0x100#define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
@@ -2171,7 +2172,6 @@ extern int insert_inode_locked4(struct iextern int insert_inode_locked (struct inode *);extern void unlock_new_inode (struct inode *); -extern void __iget (struct inode * inode);extern void iget_failed (struct inode *);extern void clear_inode (struct inode *);extern void destroy_inode (struct inode *);
@@ -2422,6 +2422,12 @@ extern int generic_show_options(struct sextern void save_mount_options (struct super_block *sb,char *options);extern void replace_mount_options (struct super_block *sb,char *options); +static inline void __iget (struct inode *inode) +{ +assert_spin_locked (&inode->i_lock); + inode->i_count++; +} +static inline ino_t parent_ino (struct dentry *dentry) {ino_t res;
fs/fs-writeback.c +10 -18
@@ -552,15 +552,8 @@ select_queue: inode->i_state |=I_DIRTY_PAGES ;redirty_tail (inode); } - }else if (inode->i_count) { -/* -* The inode is clean, inuse -*/ -list_move (&inode->i_list, &inode_in_use); }else { -/* -* The inode is clean, unused -*/ +/* The inode is clean */ list_move (&inode->i_list, &inode_unused); } }
@@ -1206,8 +1199,6 @@ static void wait_sb_inodes(struct super_*/ WARN_ON (!rwsem_is_locked (&sb->s_umount)); -spin_lock (&sb_inode_list_lock); -/* * Data integrity sync. Must wait for all pages under writeback, * because there may have been pages dirtied before our sync
@@ -1215,7 +1206,8 @@ static void wait_sb_inodes(struct super_* In which case, the inode may not be on the dirty list, but * we still have to wait for that writeout. */ -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) {struct address_space *mapping; mapping = inode->i_mapping;
@@ -1229,13 +1221,13 @@ static void wait_sb_inodes(struct super_ }__iget (inode);spin_unlock (&inode->i_lock); -spin_unlock (&sb_inode_list_lock); +rcu_read_unlock ();/* * We hold a reference to 'inode' so it couldn't have been -* removed from s_inodes list while we dropped the -* sb_inode_list_lock. We cannot iput the inode now as we can -* be holding the last reference and we cannot iput it under -* spinlock. So we keep the reference and iput it later. +* removed from s_inodes list while we dropped the i_lock. We +* cannot iput the inode now as we can be holding the last +* reference and we cannot iput it under spinlock. So we keep +* the reference and iput it later. */ iput (old_inode); old_inode = inode;
@@ -1244,9 +1236,9 @@ static void wait_sb_inodes(struct super_cond_resched (); -spin_lock (&sb_inode_list_lock); +rcu_read_lock (); } -spin_unlock (&sb_inode_list_lock); +rcu_read_unlock ();iput (old_inode); }
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 struct list_head inode_in_use;extern struct list_head inode_unused;/*
PATCH 38/52 fs: icache RCU free inodes
In reply to [email protected]RCU free the struct inode. This will allow:
- sb_inode_list_lock to be moved inside i_lock because sb list walkers who want to take i_lock no longer need to take sb_inode_list_lock to walk the list in the first place. This will simplify and optimize locking.
- eventually, completely write-free RCU path walking. The inode must be consulted for permissions when walking, so a write-free reference (ie. RCU is helpful).
- can potentially simplify things a bit in VM land. May not need to take the page lock to get back to the page->mapping.
- can remove some nested trylock loops in dcache code
- Could remove the 'wq' allocation from socket now that the entire thing is rcu freed.
todo: convert all filesystems
--- fs/block_dev.c | 9 ++++++++- fs/ext2/super.c | 9 ++++++++- fs/ext3/super.c | 9 ++++++++- fs/fat/inode.c | 9 ++++++++- fs/hugetlbfs/inode.c | 9 ++++++++- fs/inode.c | 9 ++++++++- fs/nfs/inode.c | 9 ++++++++- fs/proc/inode.c | 9 ++++++++- include/linux/fs.h | 5 ++++- ipc/mqueue.c | 9 ++++++++- mm/shmem.c | 9 ++++++++- net/socket.c | 9 ++++++++- net/sunrpc/rpc_pipe.c | 10 +++++++++- 13 files changed, 101 insertions(+), 13 deletions(-)
fs/ext2/super.c +8 -1
@@ -161,11 +161,18 @@ static struct inode *ext2_alloc_inode(streturn &ei->vfs_inode; } -static void ext2_destroy_inode (struct inode *inode) +static void ext2_i_callback (struct rcu_head *head) { + struct inode *inode = container_of(head, struct inode, i_rcu); +INIT_LIST_HEAD (&inode->i_dentry);kmem_cache_free (ext2_inode_cachep,EXT2_I (inode)); } +static void ext2_destroy_inode (struct inode *inode) +{ +call_rcu (&inode->i_rcu, ext2_i_callback); +} +static void init_once (void *foo) {struct ext2_inode_info *ei = (struct ext2_inode_info *) foo;
fs/inode.c +71 -61
208 lines not on this page · raw message
include/linux/fs.h +4 -1
@@ -726,7 +726,10 @@ struct inode {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; +union { +struct list_head i_dentry; +struct rcu_head i_rcu; + };unsigned long i_ino;unsigned int i_count;unsigned int i_nlink;
fs/block_dev.c +8 -1
@@ -397,13 +397,20 @@ static struct inode *bdev_alloc_inode(streturn &ei->vfs_inode; } -static void bdev_destroy_inode (struct inode *inode) +static void bdev_i_callback (struct rcu_head *head) { + struct inode *inode = container_of(head, struct inode, i_rcu);struct bdev_inode *bdi =BDEV_I (inode); +INIT_LIST_HEAD (&inode->i_dentry);kmem_cache_free (bdev_cachep, bdi); } +static void bdev_destroy_inode (struct inode *inode) +{ +call_rcu (&inode->i_rcu, bdev_i_callback); +} +static void init_once (void *foo) {struct bdev_inode *ei = (struct bdev_inode *) foo;
fs/ext3/super.c +8 -1
@@ -485,6 +485,13 @@ static struct inode *ext3_alloc_inode(streturn &ei->vfs_inode; } +static void ext3_i_callback (struct rcu_head *head) +{ + struct inode *inode = container_of(head, struct inode, i_rcu); +INIT_LIST_HEAD (&inode->i_dentry); +kmem_cache_free (ext3_inode_cachep,EXT3_I (inode)); +} +static void ext3_destroy_inode (struct inode *inode) {if (!list_empty (&(EXT3_I (inode)->i_orphan))) {
@@ -495,7 +502,7 @@ static void ext3_destroy_inode(struct in false);dump_stack (); } -kmem_cache_free (ext3_inode_cachep,EXT3_I (inode)); +call_rcu (&inode->i_rcu, ext3_i_callback); }static void init_once (void *foo)
fs/hugetlbfs/inode.c +8 -1
@@ -665,11 +665,18 @@ static struct inode *hugetlbfs_alloc_inoreturn &p->vfs_inode; } +static void hugetlbfs_i_callback (struct rcu_head *head) +{ + struct inode *inode = container_of(head, struct inode, i_rcu); +INIT_LIST_HEAD (&inode->i_dentry); +kmem_cache_free (hugetlbfs_inode_cachep,HUGETLBFS_I (inode)); +} +static void hugetlbfs_destroy_inode (struct inode *inode) {hugetlbfs_inc_free_inodes (HUGETLBFS_SB (inode->i_sb));mpol_free_shared_policy (&HUGETLBFS_I (inode)->policy); -kmem_cache_free (hugetlbfs_inode_cachep,HUGETLBFS_I (inode)); +call_rcu (&inode->i_rcu, hugetlbfs_i_callback); }static const struct address_space_operations hugetlbfs_aops = {
fs/proc/inode.c +8 -1
@@ -66,11 +66,18 @@ static struct inode *proc_alloc_inode(streturn inode; } -static void proc_destroy_inode (struct inode *inode) +static void proc_i_callback (struct rcu_head *head) { + struct inode *inode = container_of(head, struct inode, i_rcu); +INIT_LIST_HEAD (&inode->i_dentry);kmem_cache_free (proc_inode_cachep,PROC_I (inode)); } +static void proc_destroy_inode (struct inode *inode) +{ +call_rcu (&inode->i_rcu, proc_i_callback); +} +static void init_once (void *foo) {struct proc_inode *ei = (struct proc_inode *) foo;
ipc/mqueue.c +8 -1
@@ -236,11 +236,18 @@ static struct inode *mqueue_alloc_inode(return &ei->vfs_inode; } -static void mqueue_destroy_inode (struct inode *inode) +static void mqueue_i_callback (struct rcu_head *head) { + struct inode *inode = container_of(head, struct inode, i_rcu); +INIT_LIST_HEAD (&inode->i_dentry);kmem_cache_free (mqueue_inode_cachep,MQUEUE_I (inode)); } +static void mqueue_destroy_inode (struct inode *inode) +{ +call_rcu (&inode->i_rcu, mqueue_i_callback); +} +static void mqueue_delete_inode (struct inode *inode) {struct mqueue_inode_info *info;
net/socket.c +8 -8
@@ -271,20 +271,20 @@ static struct inode *sock_alloc_inode(st } -static void wq_free_rcu (struct rcu_head *head) +static void sock_free_rcu (struct rcu_head *head) { - struct socket_wq *wq = container_of(head, struct socket_wq, rcu); + struct inode *inode = container_of(head, struct inode, i_rcu); + struct socket_alloc *ei = container_of(inode, struct socket_alloc, + vfs_inode); -kfree (wq); +kfree (ei->socket.wq); +INIT_LIST_HEAD (&inode->i_dentry); +kmem_cache_free (sock_inode_cachep, ei); }static void sock_destroy_inode (struct inode *inode) { -struct socket_alloc *ei; - - ei = container_of(inode, struct socket_alloc, vfs_inode); -call_rcu (&ei->socket.wq->rcu, wq_free_rcu); -kmem_cache_free (sock_inode_cachep, ei); +call_rcu (&inode->i_rcu, sock_free_rcu); }static void init_once (void *foo)
fs/fat/inode.c +8 -1
@@ -520,11 +520,18 @@ static struct inode *fat_alloc_inode(strreturn &ei->vfs_inode; } -static void fat_destroy_inode (struct inode *inode) +static void fat_i_callback (struct rcu_head *head) { + struct inode *inode = container_of(head, struct inode, i_rcu); +INIT_LIST_HEAD (&inode->i_dentry);kmem_cache_free (fat_inode_cachep,MSDOS_I (inode)); } +static void fat_destroy_inode (struct inode *inode) +{ +call_rcu (&inode->i_rcu, fat_i_callback); +} +static void init_once (void *foo) {struct msdos_inode_info *ei = (struct msdos_inode_info *)foo;
fs/nfs/inode.c +8 -1
@@ -1365,11 +1365,18 @@ struct inode *nfs_alloc_inode(struct supreturn &nfsi->vfs_inode; } -void nfs_destroy_inode (struct inode *inode) +static void nfs_i_callback (struct rcu_head *head) { + struct inode *inode = container_of(head, struct inode, i_rcu); +INIT_LIST_HEAD (&inode->i_dentry);kmem_cache_free (nfs_inode_cachep,NFS_I (inode)); } +void nfs_destroy_inode (struct inode *inode) +{ +call_rcu (&inode->i_rcu, nfs_i_callback); +} +static inline void nfs4_init_once (struct nfs_inode *nfsi) {#ifdef CONFIG_NFS_V4
mm/shmem.c +8 -1
@@ -2389,13 +2389,20 @@ static struct inode *shmem_alloc_inode(sreturn &p->vfs_inode; } +static void shmem_i_callback (struct rcu_head *head) +{ + struct inode *inode = container_of(head, struct inode, i_rcu); +INIT_LIST_HEAD (&inode->i_dentry); +kmem_cache_free (shmem_inode_cachep,SHMEM_I (inode)); +} +static void shmem_destroy_inode (struct inode *inode) {if ((inode->i_mode &S_IFMT ) ==S_IFREG ) {/* only struct inode is valid if it's an inline symlink */ mpol_free_shared_policy (&SHMEM_I (inode)->policy); } -kmem_cache_free (shmem_inode_cachep,SHMEM_I (inode)); +call_rcu (&inode->i_rcu, shmem_i_callback); }static void init_once (void *foo)
net/sunrpc/rpc_pipe.c +9 -1
@@ -163,11 +163,19 @@ rpc_alloc_inode(struct super_block *sb) }static void -rpc_destroy_inode (struct inode *inode) +rpc_i_callback (struct rcu_head *head) { + struct inode *inode = container_of(head, struct inode, i_rcu); +INIT_LIST_HEAD (&inode->i_dentry);kmem_cache_free (rpc_inode_cachep,RPC_I (inode)); } +static void +rpc_destroy_inode (struct inode *inode) +{ +call_rcu (&inode->i_rcu, rpc_i_callback); +} +static int rpc_pipe_open (struct inode *inode,struct file *filp) {
include/linux/net.h +0 -1
@@ -120,7 +120,6 @@ enum sock_shutdown_cmd {struct socket_wq {wait_queue_head_t wait;struct fasync_struct *fasync_list; -struct rcu_head rcu; }____cacheline_aligned_in_smp ;/**
PATCH 40/52 fs: dcache improve scalability of pseudo filesystems
In reply to [email protected]Regardless of how much we possibly try to scale dcache, there is likely always going to be some fundamental contention when adding or removing children under the same parent. Pseudo filesystems do not seem need to have connected dentries because by definition they are disconnected.
--- fs/anon_inodes.c | 4 +++- fs/pipe.c | 5 +++-- net/socket.c | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-)
net/socket.c +1 -1
@@ -371,7 +371,7 @@ static int sock_alloc_file(struct socketif (unlikely (fd <0 ))return fd; - path.dentry =d_alloc (sock_mnt->mnt_sb->s_root, &name); + path.dentry =d_alloc_pseudo (sock_mnt->mnt_sb, &name);if (unlikely (!path.dentry)) {put_unused_fd (fd);return -ENOMEM ;
fs/anon_inodes.c +1 -1
@@ -104,7 +104,7 @@ struct file *anon_inode_getfile(const ch this.name = name; this.len =strlen (name); this.hash =0 ; - path.dentry =d_alloc (anon_inode_mnt->mnt_sb->s_root, &this); + path.dentry =d_alloc_pseudo (anon_inode_mnt->mnt_sb, &this);if (!path.dentry) goto err_module;
fs/pipe.c +1 -1
@@ -997,7 +997,7 @@ struct file *create_write_pipe(int flags goto err; err = -ENOMEM ; - path.dentry =d_alloc (pipe_mnt->mnt_sb->s_root, &name); + path.dentry =d_alloc_pseudo (pipe_mnt->mnt_sb, &name);if (!path.dentry) goto err_inode; path.mnt =mntget (pipe_mnt);
fs/dcache.c +12 -0
@@ -1255,6 +1255,18 @@ struct dentry *d_alloc(struct dentry * p }EXPORT_SYMBOL (d_alloc); +struct dentry *d_alloc_pseudo (struct super_block *sb,const struct qstr *name) +{ +struct dentry *dentry =d_alloc (NULL , name); +if (dentry) { + dentry->d_sb = sb; + dentry->d_parent = dentry; + dentry->d_flags |=DCACHE_DISCONNECTED ; + } +return dentry; +} +EXPORT_SYMBOL (d_alloc_pseudo); +struct dentry *d_alloc_name (struct dentry *parent,const char *name) {struct qstr q;
include/linux/dcache.h +1 -0
@@ -225,6 +225,7 @@ extern void d_delete(struct dentry *);/* allocate/de-allocate */ extern struct dentry *d_alloc (struct dentry *,const struct qstr *); +extern struct dentry *d_alloc_pseudo (struct super_block *,const struct qstr *);extern struct dentry *d_splice_alias (struct inode *,struct dentry *);extern struct dentry *d_add_ci (struct dentry *,struct inode *,struct qstr *);extern struct dentry *d_obtain_alias (struct inode *);
PATCH 41/52 fs: icache reduce atomics
In reply to [email protected]Put inode counters under locks to reduce atomics.
--- fs/fs-writeback.c | 6 ++---- fs/inode.c | 30 ++++++++++++------------------ include/linux/fs.h | 4 ++-- 3 files changed, 16 insertions(+), 24 deletions(-)
fs/inode.c +15 -21
@@ -141,8 +141,8 @@ static DECLARE_RWSEM(iprune_sem);* Statistics gathering.. */ struct inodes_stat_t inodes_stat = { - .nr_inodes =ATOMIC_INIT (0 ), - .nr_unused =ATOMIC_INIT (0 ), + .nr_inodes =0 , + .nr_unused =0 , };static struct kmem_cache *inode_cachep__read_mostly ;
@@ -390,7 +390,6 @@ static void dispose_list(struct list_headestroy_inode (inode); nr_disposed++; } -atomic_sub (nr_disposed, &inodes_stat.nr_inodes); }/*
@@ -399,7 +398,7 @@ static void dispose_list(struct list_heastatic int invalidate_list (struct list_head *head,struct list_head *dispose) {struct list_head *next; -int busy =0 , count =0 ; +int busy =0 ; next = head->next;for (;;) {
@@ -419,19 +418,17 @@ static int invalidate_list(struct list_hif (!inode->i_count) {spin_lock (&wb_inode_list_lock);list_del (&inode->i_list); + inodes_stat.nr_unused--;spin_unlock (&wb_inode_list_lock);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ;spin_unlock (&inode->i_lock);list_add (&inode->i_list, dispose); - count++;continue ; }spin_unlock (&inode->i_lock); busy =1 ; } -/* only unused inodes may be cached with i_count zero */ -atomic_sub (count, &inodes_stat.nr_unused);return busy; }
@@ -483,7 +480,6 @@ EXPORT_SYMBOL(invalidate_inodes);static void prune_icache (int nr_to_scan) {LIST_HEAD (freeable); -int nr_pruned =0 ;unsigned long reap =0 ;down_read (&iprune_sem);
@@ -504,7 +500,7 @@ again:if (inode->i_count || (inode->i_state & ~I_REFERENCED )) {list_del_init (&inode->i_list);spin_unlock (&inode->i_lock); -atomic_dec (&inodes_stat.nr_unused); + inodes_stat.nr_unused--;continue ; }if (inode->i_state) {
@@ -530,9 +526,8 @@ again:WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ;spin_unlock (&inode->i_lock); - nr_pruned++; + inodes_stat.nr_unused--; } -atomic_sub (nr_pruned, &inodes_stat.nr_unused);if (current_is_kswapd ())__count_vm_events (KSWAPD_INODESTEAL , reap);else
@@ -564,8 +559,7 @@ static int shrink_icache_memory(int nr,return -1 ;prune_icache (nr); } -return (atomic_read (&inodes_stat.nr_unused) /100 ) * - sysctl_vfs_cache_pressure; +return inodes_stat.nr_unused /100 * sysctl_vfs_cache_pressure; }static struct shrinker icache_shrinker = {
@@ -661,9 +655,9 @@ static inline void __inode_add_to_lists(struct super_block *sb, struct inode_hash_bucket *b, struct inode *inode) { - atomic_inc(&inodes_stat.nr_inodes); spin_lock(&sb_inode_list_lock);list_add_rcu (&inode->i_sb_list, &sb->s_inodes); + inodes_stat.nr_inodes++;spin_unlock (&sb_inode_list_lock);if (b) {spin_lock_bucket (b);
@@ -1309,17 +1303,17 @@ void generic_delete_inode(struct inode *if (!list_empty (&inode->i_list)) {spin_lock (&wb_inode_list_lock);list_del_init (&inode->i_list); -spin_unlock (&wb_inode_list_lock);if (!inode->i_state) -atomic_dec (&inodes_stat.nr_unused); + inodes_stat.nr_unused--; +spin_unlock (&wb_inode_list_lock); }spin_lock (&sb_inode_list_lock);list_del_rcu (&inode->i_sb_list); + inodes_stat.nr_inodes--;spin_unlock (&sb_inode_list_lock);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ;spin_unlock (&inode->i_lock); -atomic_dec (&inodes_stat.nr_inodes);if (op->delete_inode) {void (*delete)(struct inode *) = op->delete_inode;
@@ -1367,8 +1361,8 @@ int generic_detach_inode(struct inode *i list_empty(&inode->i_list)) {spin_lock (&wb_inode_list_lock);list_add (&inode->i_list, &inode_unused); + inodes_stat.nr_unused++;spin_unlock (&wb_inode_list_lock); -atomic_inc (&inodes_stat.nr_unused); }spin_unlock (&inode->i_lock);return 0 ;
@@ -1385,17 +1379,17 @@ int generic_detach_inode(struct inode *iif (!list_empty (&inode->i_list)) {spin_lock (&wb_inode_list_lock);list_del_init (&inode->i_list); -spin_unlock (&wb_inode_list_lock);if (!inode->i_state) -atomic_dec (&inodes_stat.nr_unused); + inodes_stat.nr_unused--; +spin_unlock (&wb_inode_list_lock); }spin_lock (&sb_inode_list_lock);list_del_rcu (&inode->i_sb_list); + inodes_stat.nr_inodes--;spin_unlock (&sb_inode_list_lock);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ;spin_unlock (&inode->i_lock); -atomic_dec (&inodes_stat.nr_inodes);return 1 ; }EXPORT_SYMBOL_GPL (generic_detach_inode);
include/linux/fs.h +6 -6
@@ -31,6 +31,12 @@#define SEEK_END 2/* seek relative to end of file */ #define SEEK_MAX SEEK_END +struct inodes_stat_t { +int nr_inodes; +int nr_unused; +int dummy[5 ];/* padding for sysctl ABI compatibility */ +}; +/* And dynamically-tunable limits and defaults: */ struct files_stat_struct {int nr_files;/* read only */
@@ -411,12 +417,6 @@ typedef int (get_block_t)(struct inode *typedef void (dio_iodone_t )(struct kiocb *iocb,loff_t offset,ssize_t bytes,void *private); -struct inodes_stat_t { -atomic_t nr_inodes; -atomic_t nr_unused; -int dummy[5 ];/* padding for sysctl ABI compatibility */ -}; -/* * Attribute flags. These should be or-ed together to figure out what * has been changed!
fs/fs-writeback.c +2 -4
@@ -904,8 +904,7 @@ static long wb_check_old_data_flush(stru wb->last_old_flush = jiffies; nr_pages =global_page_state (NR_FILE_DIRTY ) +global_page_state (NR_UNSTABLE_NFS ) + - (atomic_read (&inodes_stat.nr_inodes) - -atomic_read (&inodes_stat.nr_unused)); + inodes_stat.nr_inodes - inodes_stat.nr_unused;if (nr_pages) {struct wb_writeback_args args = {
@@ -1258,8 +1257,7 @@ void writeback_inodes_sb(struct super_bllong nr_to_write; nr_to_write = nr_dirty + nr_unstable + - (atomic_read (&inodes_stat.nr_inodes) - -atomic_read (&inodes_stat.nr_unused)); + inodes_stat.nr_inodes - inodes_stat.nr_unused;bdi_start_writeback (sb->s_bdi, sb, nr_to_write); }
PATCH 42/52 fs: icache per-cpu last_ino allocator
In reply to [email protected]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_cpu variable, feeded by the shared last_ino, but once every 1024 allocations.
This reduce contention on the shared last_ino, and give same spreading ino numbers than before. (same wraparound after 2^32 allocations)
--- fs/inode.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-)
fs/inode.c +35 -7
@@ -664,6 +664,40 @@ __inode_add_to_lists(struct super_block } } +#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. +*/ +static DEFINE_PER_CPU(int, last_ino); +static atomic_t shared_last_ino; + +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 ; + + *p = ++res; +put_cpu_var (last_ino); +return res; +} +#else +static int last_ino_get (void ) +{ +static int last_ino; + +return ++last_ino; +} +#endif +/** * inode_add_to_lists - add a new inode to relevant lists * @sb: superblock inode belongs to
@@ -700,19 +734,13 @@ EXPORT_SYMBOL_GPL(inode_add_to_lists);*/ struct inode *new_inode (struct super_block *sb) { -/* -* 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. -*/ -static atomic_t last_ino =ATOMIC_INIT (0 );struct inode *inode; inode =alloc_inode (sb);if (inode) {/* XXX: init as locked for speedup */ spin_lock (&inode->i_lock); - inode->i_ino =atomic_inc_return (&last_ino); + inode->i_ino =last_ino_get (); inode->i_state =0 ;__inode_add_to_lists (sb,NULL , inode);spin_unlock (&inode->i_lock);
PATCH 43/52 fs: icache per-cpu nr_inodes counter
In reply to [email protected]From: Eric Dumazet <[email protected]>
Avoids cache line ping pongs between cpus and prepare next patch, because updates of nr_inodes dont need inode_lock anymore.
--- fs/fs-writeback.c | 4 ++-- fs/inode.c | 31 ++++++++++++++++++++++++++++--- include/linux/fs.h | 5 ++++- kernel/sysctl.c | 4 ++-- 4 files changed, 36 insertions(+), 8 deletions(-)
fs/fs-writeback.c +2 -2
@@ -904,7 +904,7 @@ static long wb_check_old_data_flush(stru wb->last_old_flush = jiffies; nr_pages =global_page_state (NR_FILE_DIRTY ) +global_page_state (NR_UNSTABLE_NFS ) + - inodes_stat.nr_inodes - inodes_stat.nr_unused; +get_nr_inodes () - inodes_stat.nr_unused;if (nr_pages) {struct wb_writeback_args args = {
@@ -1257,7 +1257,7 @@ void writeback_inodes_sb(struct super_bllong nr_to_write; nr_to_write = nr_dirty + nr_unstable + - inodes_stat.nr_inodes - inodes_stat.nr_unused; +get_nr_inodes () - inodes_stat.nr_unused;bdi_start_writeback (sb->s_bdi, sb, nr_to_write); }
fs/inode.c +28 -3
@@ -144,9 +144,33 @@ struct inodes_stat_t inodes_stat = { .nr_inodes = 0, .nr_unused = 0, }; +struct percpu_counter nr_inodes;static struct kmem_cache *inode_cachep__read_mostly ; +int get_nr_inodes (void ) +{ +return percpu_counter_sum_positive (&nr_inodes); +} + +/* +* Handle nr_dentry sysctl +*/ +#if defined(CONFIG_SYSCTL ) && defined(CONFIG_PROC_FS ) +int proc_nr_inodes (ctl_table *table,int write, +void __user *buffer,size_t *lenp,loff_t *ppos) +{ + inodes_stat.nr_inodes =get_nr_inodes (); +return proc_dointvec (table, write, buffer, lenp, ppos); +} +#else +int proc_nr_inodes (ctl_table *table,int write, +void __user *buffer,size_t *lenp,loff_t *ppos) +{ +return -ENOSYS ; +} +#endif +static void wake_up_inode (struct inode *inode) {/*
@@ -657,8 +681,8 @@ __inode_add_to_lists(struct super_block {spin_lock (&sb_inode_list_lock);list_add_rcu (&inode->i_sb_list, &sb->s_inodes); - inodes_stat.nr_inodes++;spin_unlock (&sb_inode_list_lock); +percpu_counter_inc (&nr_inodes);if (b) {spin_lock_bucket (b);hlist_bl_add_head_rcu (&inode->i_hash, &b->head);
@@ -1337,8 +1361,8 @@ void generic_delete_inode(struct inode * }spin_lock (&sb_inode_list_lock);list_del_rcu (&inode->i_sb_list); - inodes_stat.nr_inodes--;spin_unlock (&sb_inode_list_lock); +percpu_counter_dec (&nr_inodes);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ;spin_unlock (&inode->i_lock);
@@ -1413,8 +1437,8 @@ int generic_detach_inode(struct inode *i }spin_lock (&sb_inode_list_lock);list_del_rcu (&inode->i_sb_list); - inodes_stat.nr_inodes--;spin_unlock (&sb_inode_list_lock); +percpu_counter_dec (&nr_inodes);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ;spin_unlock (&inode->i_lock);
@@ -1723,6 +1747,7 @@ void __init inode_init(void) {int loop; +percpu_counter_init (&nr_inodes,0 );/* inode slab cache */ inode_cachep = kmem_cache_create("inode_cache", sizeof(struct inode),
include/linux/fs.h +4 -1
@@ -406,6 +406,8 @@ extern struct files_stat_struct files_stextern int get_max_files (void );extern int sysctl_nr_open;extern struct inodes_stat_t inodes_stat; +extern struct percpu_counter nr_inodes; +extern int get_nr_inodes (void );extern int leases_enable, lease_break_time;#ifdef CONFIG_DNOTIFY extern int dir_notify_enable;
@@ -2514,7 +2516,8 @@ ssize_t simple_attr_write(struct file *fstruct ctl_table ;int proc_nr_files (struct ctl_table *table,int write,void __user *buffer,size_t *lenp,loff_t *ppos); - +int proc_nr_inodes (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp,loff_t *ppos);int __init get_filesystem_list (char *buf);#define ACC_MODE (x) ("\004\002\006\006"[(x)&O_ACCMODE])
kernel/sysctl.c +2 -2
@@ -1338,14 +1338,14 @@ static struct ctl_table fs_table[] = { .data = &inodes_stat, .maxlen = 2*sizeof(int), .mode = 0444, - .proc_handler = proc_dointvec, + .proc_handler = proc_nr_inodes, }, { .procname = "inode-state", .data = &inodes_stat, .maxlen = 7*sizeof(int), .mode = 0444, - .proc_handler = proc_dointvec, + .proc_handler = proc_nr_inodes, }, { .procname = "file-nr",
PATCH 44/52 fs: icache per-CPU sb inode lists and locks
In reply to [email protected]--- fs/drop_caches.c | 37 ++++++---- fs/fs-writeback.c | 82 +++++++++++++----------- fs/inode.c | 128 +++++++++++++++++++++++++------------ fs/notify/inode_mark.c | 108 +++++++++++++++++-------------- fs/notify/inotify/inotify.c | 132 ++++++++++++++++++++------------------- fs/quota/dquot.c | 98 +++++++++++++++++----------- fs/super.c | 19 +++++ include/linux/fs.h | 10 ++ include/linux/fsnotify_backend.h | 4 - include/linux/inotify.h | 4 - 10 files changed, 373 insertions(+), 249 deletions(-)
fs/inode.c +75 -31
@@ -26,10 +26,11 @@#include <linux/async.h> #include <linux/posix_acl.h> #include <linux/bit_spinlock.h> +#include <linux/lglock.h> /* * Usage: -* sb_inode_list_lock protects: +* inode_list_lglock protects: * s_inodes, i_sb_list * inode_hash_bucket lock protects: * inode hash table, i_hash
@@ -45,7 +46,7 @@* Ordering: * inode_lock * inode->i_lock -* sb_inode_list_lock +* inode_list_lglock * wb_inode_list_lock * inode_hash_bucket lock */
@@ -120,7 +121,9 @@ static struct inode_hash_bucket *inode_h* NOTE! You also have to own the lock if you change * the i_state of an inode while it is in use.. */ -DEFINE_SPINLOCK (sb_inode_list_lock); +DECLARE_LGLOCK (inode_list_lglock); +DEFINE_LGLOCK (inode_list_lglock); +DEFINE_SPINLOCK (wb_inode_list_lock);/*
@@ -382,6 +385,8 @@ void clear_inode(struct inode *inode) }EXPORT_SYMBOL (clear_inode); +static void inode_sb_list_del (struct inode *inode); +/* * dispose_list - dispose of the contents of a local list * @head: the head of the list to free
@@ -405,9 +410,7 @@ static void dispose_list(struct list_heaspin_lock (&inode->i_lock);__remove_inode_hash (inode); -spin_lock (&sb_inode_list_lock); -list_del_rcu (&inode->i_sb_list); -spin_unlock (&sb_inode_list_lock); +inode_sb_list_del (inode);spin_unlock (&inode->i_lock);wake_up_inode (inode);
@@ -419,20 +422,12 @@ static void dispose_list(struct list_hea/* * Invalidate all inodes for a device. */ -static int invalidate_list (struct list_head *head,struct list_head *dispose) +static int invalidate_sb_inodes (struct super_block *sb,struct list_head *dispose) { -struct list_head *next; +struct inode *inode;int busy =0 ; - next = head->next; -for (;;) { -struct list_head *tmp = next; -struct inode *inode; - - next = next->next; -if (tmp == head) -break ; - inode = list_entry(tmp, struct inode, i_sb_list); +do_inode_list_for_each_entry_rcu (sb, inode) {spin_lock (&inode->i_lock);if (inode->i_state &I_NEW ) {spin_unlock (&inode->i_lock);
@@ -452,7 +447,8 @@ static int invalidate_list(struct list_h }spin_unlock (&inode->i_lock); busy =1 ; - } + }while_inode_list_for_each_entry_rcu + return busy; }
@@ -476,9 +472,9 @@ int invalidate_inodes(struct super_block*/ down_write (&iprune_sem);// spin_lock(&sb_inode_list_lock); XXX: is this safe? -inotify_unmount_inodes (&sb->s_inodes); -fsnotify_unmount_inodes (&sb->s_inodes); - busy =invalidate_list (&sb->s_inodes, &throw_away); +inotify_unmount_inodes (sb); +fsnotify_unmount_inodes (sb); + busy =invalidate_sb_inodes (sb, &throw_away);// spin_unlock(&sb_inode_list_lock); dispose_list (&throw_away);
@@ -675,13 +671,63 @@ static unsigned long hash(struct super_breturn tmp &I_HASHMASK ; } +static inline int inode_list_cpu (struct inode *inode) +{ +#ifdef CONFIG_SMP +return inode->i_sb_list_cpu; +#else +return smp_processor_id (); +#endif +} + +/* helper for file_sb_list_add to reduce ifdefs */ +static inline void __inode_sb_list_add (struct inode *inode,struct super_block *sb) +{ +struct list_head *list; +#ifdef CONFIG_SMP +int cpu; + cpu =smp_processor_id (); + inode->i_sb_list_cpu = cpu; + list =per_cpu_ptr (sb->s_inodes, cpu); +#else + list = &sb->s_inodes; +#endif +list_add_rcu (&inode->i_sb_list, list); +} + +/** +* inode_sb_list_add - add an inode to the sb's file list +* @inode: inode to add +* @sb: sb to add it to +* +* Use this function to associate an with the superblock it belongs to. +*/ +static void inode_sb_list_add (struct inode *inode,struct super_block *sb) +{ +lg_local_lock (inode_list_lglock); +__inode_sb_list_add (inode, sb); +lg_local_unlock (inode_list_lglock); +} + +/** +* inode_sb_list_del - remove an inode from the sb's inode list +* @inode: inode to remove +* @sb: sb to remove it from +* +* Use this function to remove an inode from its superblock. +*/ +static void inode_sb_list_del (struct inode *inode) +{ +lg_local_lock_cpu (inode_list_lglock,inode_list_cpu (inode)); +list_del_rcu (&inode->i_sb_list); +lg_local_unlock_cpu (inode_list_lglock,inode_list_cpu (inode)); +} +static inline void __inode_add_to_lists (struct super_block *sb,struct inode_hash_bucket *b,struct inode *inode) { -spin_lock (&sb_inode_list_lock); -list_add_rcu (&inode->i_sb_list, &sb->s_inodes); -spin_unlock (&sb_inode_list_lock); +inode_sb_list_add (inode, sb);percpu_counter_inc (&nr_inodes);if (b) {spin_lock_bucket (b);
@@ -1221,6 +1267,7 @@ repeat:continue ;if (!spin_trylock (&old->i_lock)) {spin_unlock_bucket (b); +cpu_relax (); goto repeat; } goto found_old;
@@ -1266,7 +1313,6 @@ repeat:if (!spin_trylock (&old->i_lock)) {spin_unlock_bucket (b);cpu_relax (); -cpu_relax (); goto repeat; } goto found_old;
@@ -1361,9 +1407,7 @@ void generic_delete_inode(struct inode * inodes_stat.nr_unused--;spin_unlock (&wb_inode_list_lock); } -spin_lock (&sb_inode_list_lock); -list_del_rcu (&inode->i_sb_list); -spin_unlock (&sb_inode_list_lock); +inode_sb_list_del (inode);percpu_counter_dec (&nr_inodes);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ;
@@ -1437,9 +1481,7 @@ int generic_detach_inode(struct inode *i inodes_stat.nr_unused--;spin_unlock (&wb_inode_list_lock); } -spin_lock (&sb_inode_list_lock); -list_del_rcu (&inode->i_sb_list); -spin_unlock (&sb_inode_list_lock); +inode_sb_list_del (inode);percpu_counter_dec (&nr_inodes);WARN_ON (inode->i_state &I_NEW ); inode->i_state |=I_FREEING ;
@@ -1759,6 +1801,8 @@ void __init inode_init(void) init_once);register_shrinker (&icache_shrinker); +lg_lock_init (inode_list_lglock); +/* Hash may have been set up in inode_init_early */ if (!hashdist)return ;
include/linux/fs.h +57 -1
80 lines not on this page · raw message
fs/super.c +16 -1
@@ -68,12 +68,26 @@ static struct super_block *alloc_super(sfor_each_possible_cpu (i)INIT_LIST_HEAD (per_cpu_ptr (s->s_files, i)); } + + s->s_inodes = alloc_percpu(struct list_head); +if (!s->s_inodes) { +free_percpu (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_inodes, i)); + }#else INIT_LIST_HEAD (&s->s_files); +INIT_LIST_HEAD (&s->s_inodes);#endif INIT_LIST_HEAD (&s->s_instances);INIT_HLIST_BL_HEAD (&s->s_anon); -INIT_LIST_HEAD (&s->s_inodes);INIT_LIST_HEAD (&s->s_dentry_lru);init_rwsem (&s->s_umount);mutex_init (&s->s_lock);
@@ -125,6 +139,7 @@ out:static inline void destroy_super (struct super_block *s) {#ifdef CONFIG_SMP +free_percpu (s->s_inodes);free_percpu (s->s_files);#endif security_sb_free (s);
fs/drop_caches.c +2 -2
@@ -17,7 +17,7 @@ static void drop_pagecache_sb(struct supstruct inode *inode, *toput_inode =NULL ;rcu_read_lock (); -list_for_each_entry_rcu (inode, &sb->s_inodes, i_sb_list) { +do_inode_list_for_each_entry_rcu (sb, inode) {spin_lock (&inode->i_lock);if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE |I_NEW ) || inode->i_mapping->nrpages ==0 ) {
@@ -31,7 +31,7 @@ static void drop_pagecache_sb(struct supiput (toput_inode); toput_inode = inode;rcu_read_lock (); - } + }while_inode_list_for_each_entry_rcu rcu_read_unlock ();iput (toput_inode); }
fs/fs-writeback.c +15 -14
@@ -1198,17 +1198,17 @@ static void wait_sb_inodes(struct super_*/ WARN_ON (!rwsem_is_locked (&sb->s_umount)); -/* -* Data integrity sync. Must wait for all pages under writeback, -* because there may have been pages dirtied before our sync -* call, but which had writeout started before we write it out. -* In which case, the inode may not be on the dirty list, but -* we still have to wait for that writeout. -*/ rcu_read_lock (); -list_for_each_entry_rcu (inode, &sb->s_inodes, i_sb_list) { +do_inode_list_for_each_entry_rcu (sb, inode) {struct address_space *mapping; +/* +* Data integrity sync. Must wait for all pages under writeback, +* because there may have been pages dirtied before our sync +* call, but which had writeout started before we write it out. +* In which case, the inode may not be on the dirty list, but +* we still have to wait for that writeout. +*/ mapping = inode->i_mapping;if (mapping->nrpages ==0 )continue ;
@@ -1222,11 +1222,12 @@ static void wait_sb_inodes(struct super_spin_unlock (&inode->i_lock);rcu_read_unlock ();/* -* We hold a reference to 'inode' so it couldn't have been -* removed from s_inodes list while we dropped the i_lock. We -* cannot iput the inode now as we can be holding the last -* reference and we cannot iput it under spinlock. So we keep -* the reference and iput it later. +* We hold a reference to 'inode' so it couldn't have +* been removed from s_inodes list while we dropped the +* i_lock. We cannot iput the inode now as we can be +* holding the last reference and we cannot iput it +* under spinlock. So we keep the reference and iput it +* later. */ iput (old_inode); old_inode = inode;
@@ -1236,7 +1237,7 @@ static void wait_sb_inodes(struct super_cond_resched ();rcu_read_lock (); - } + }while_inode_list_for_each_entry_rcu rcu_read_unlock ();iput (old_inode); }
fs/notify/inode_mark.c +3 -3
@@ -361,11 +361,11 @@ int fsnotify_add_mark(struct fsnotify_ma* of inodes, and with iprune_mutex held, keeping shrink_icache_memory() at bay. * We temporarily drop inode_lock, however, and CAN block. */ -void fsnotify_unmount_inodes (struct list_head *list) +void fsnotify_unmount_inodes (struct super_block *sb) {struct inode *inode, *next_i, *need_iput =NULL ; -list_for_each_entry_safe (inode, next_i, list, i_sb_list) { +do_inode_list_for_each_entry_safe (sb, inode, next_i) {struct inode *need_iput_tmp;spin_lock (&inode->i_lock);
@@ -421,5 +421,5 @@ void fsnotify_unmount_inodes(struct listfsnotify_inode_delete (inode);iput (inode); - } + } while_inode_list_for_each_entry_safe }
fs/notify/inotify/inotify.c +4 -4
@@ -381,11 +381,11 @@ EXPORT_SYMBOL_GPL(inotify_get_cookie);* of inodes, and with iprune_mutex held, keeping shrink_icache_memory() at bay. * We temporarily drop inode_lock, however, and CAN block. */ -void inotify_unmount_inodes (struct list_head *list) +void inotify_unmount_inodes (struct super_block *sb) {struct inode *inode, *next_i, *need_iput =NULL ; -list_for_each_entry_safe (inode, next_i, list, i_sb_list) { +do_inode_list_for_each_entry_safe (sb, inode, next_i) {struct inotify_watch *watch, *next_w;struct inode *need_iput_tmp;struct list_head *watches;
@@ -450,8 +450,8 @@ void inotify_unmount_inodes(struct list_put_inotify_watch (watch); }mutex_unlock (&inode->inotify_mutex); -iput (inode); - } +iput (inode); + } while_inode_list_for_each_entry_safe }EXPORT_SYMBOL_GPL (inotify_unmount_inodes);
fs/quota/dquot.c +4 -8
@@ -884,16 +884,12 @@ static void add_dquot_ref(struct super_b#endif rcu_read_lock (); -list_for_each_entry_rcu (inode, &sb->s_inodes, i_sb_list) { +do_inode_list_for_each_entry_rcu (sb, inode) {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)) {spin_unlock (&inode->i_lock);continue ;
@@ -916,7 +912,7 @@ static void add_dquot_ref(struct super_b* keep the reference and iput it later. */ old_inode = inode;rcu_read_lock (); - } + }while_inode_list_for_each_entry_rcu rcu_read_unlock ();iput (old_inode);
@@ -996,7 +992,7 @@ static void remove_dquot_ref(struct supestruct inode *inode;rcu_read_lock (); -list_for_each_entry_rcu (inode, &sb->s_inodes, i_sb_list) { +do_inode_list_for_each_entry_rcu (sb, inode) {/* * We have to scan also I_NEW inodes because they can already * have quota pointer initialized. Luckily, we need to touch
@@ -1005,7 +1001,7 @@ static void remove_dquot_ref(struct supe*/ if (!IS_NOQUOTA (inode))remove_inode_dquot_ref (inode, type, tofree_head); - } + }while_inode_list_for_each_entry_rcu rcu_read_unlock (); }
include/linux/fsnotify_backend.h +2 -2
@@ -344,7 +344,7 @@ extern void fsnotify_destroy_mark_by_entextern void fsnotify_clear_marks_by_group (struct fsnotify_group *group);extern void fsnotify_get_mark (struct fsnotify_mark_entry *entry);extern void fsnotify_put_mark (struct fsnotify_mark_entry *entry); -extern void fsnotify_unmount_inodes (struct list_head *list); +extern void fsnotify_unmount_inodes (struct super_block *sb);/* put here because inotify does some weird stuff when destroying watches */ extern struct fsnotify_event *fsnotify_create_event(struct inode *to_tell, __u32 mask,
@@ -374,7 +374,7 @@ static inline u32 fsnotify_get_cookie(vo return 0; } -static inline void fsnotify_unmount_inodes (struct list_head *list) +static inline void fsnotify_unmount_inodes (struct super_block *sb) {}#endif /* CONFIG_FSNOTIFY */
include/linux/inotify.h +2 -2
@@ -111,7 +111,7 @@ extern void inotify_inode_queue_event(st const char *, struct inode *);extern void inotify_dentry_parent_queue_event (struct dentry *,__u32 ,__u32 ,const char *); -extern void inotify_unmount_inodes (struct list_head *); +extern void inotify_unmount_inodes (struct super_block *);extern void inotify_inode_is_dead (struct inode *);extern u32 inotify_get_cookie (void );
@@ -161,7 +161,7 @@ static inline void inotify_dentry_parent { } -static inline void inotify_unmount_inodes (struct list_head *list) +static inline void inotify_unmount_inodes (struct super_block *sb) { }
include/linux/writeback.h +0 -1
@@ -9,7 +9,6 @@struct backing_dev_info ; -extern spinlock_t sb_inode_list_lock;extern spinlock_t wb_inode_list_lock;extern struct list_head inode_unused;
PATCH 45/52 fs: icache RCU hash lookups
In reply to [email protected]--- fs/inode.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-)
fs/inode.c +16 -16
@@ -603,27 +603,27 @@ static struct inode *find_inode(struct sstruct inode *inode =NULL ; repeat: -spin_lock_bucket (b); -hlist_bl_for_each_entry (inode, node, &b->head, i_hash) { +rcu_read_lock (); +hlist_bl_for_each_entry_rcu (inode, node, &b->head, i_hash) {if (inode->i_sb != sb)continue ; -if (!spin_trylock (&inode->i_lock)) { -spin_unlock_bucket (b); -cpu_relax (); - goto repeat; +spin_lock (&inode->i_lock); +if (hlist_bl_unhashed (&inode->i_hash)) { +spin_unlock (&inode->i_lock); +continue ; }if (!test (inode, data)) {spin_unlock (&inode->i_lock);continue ; }if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE )) { -spin_unlock_bucket (b); +rcu_read_unlock ();__wait_on_freeing_inode (inode); goto repeat; }break ; } -spin_unlock_bucket (b); +rcu_read_unlock ();return node ? inode :NULL ; }
@@ -639,25 +639,25 @@ static struct inode *find_inode_fast(strstruct inode *inode =NULL ; repeat: -spin_lock_bucket (b); -hlist_bl_for_each_entry (inode, node, &b->head, i_hash) { +rcu_read_lock (); +hlist_bl_for_each_entry_rcu (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_bucket (b); -cpu_relax (); - goto repeat; +spin_lock (&inode->i_lock); +if (hlist_bl_unhashed (&inode->i_hash)) { +spin_unlock (&inode->i_lock); +continue ; }if (inode->i_state & (I_FREEING |I_CLEAR |I_WILL_FREE )) { -spin_unlock_bucket (b); +rcu_read_unlock ();__wait_on_freeing_inode (inode); goto repeat; }break ; } -spin_unlock_bucket (b); +rcu_read_unlock ();return node ? inode :NULL ; }
PATCH 46/52 fs: icache reduce locking
In reply to [email protected]fs/fs-writeback.c +5 -3
@@ -484,15 +484,17 @@ writeback_single_inode(struct inode *inospin_lock (&inode->i_lock); dirty = inode->i_state &I_DIRTY ; inode->i_state &= ~(I_DIRTY_SYNC |I_DIRTY_DATASYNC ); -spin_unlock (&inode->i_lock);/* Don't write the inode if only I_DIRTY_PAGES was set */ if (dirty & (I_DIRTY_SYNC |I_DIRTY_DATASYNC )) { -int err =write_inode (inode, wbc); +int err; + +spin_unlock (&inode->i_lock); + err =write_inode (inode, wbc);if (ret ==0 ) ret = err; +spin_lock (&inode->i_lock); } -spin_lock (&inode->i_lock);spin_lock (&wb_inode_list_lock); inode->i_state &= ~I_SYNC ;if (!(inode->i_state & (I_FREEING |I_CLEAR ))) {
fs/inode.c +0 -3
@@ -810,12 +810,9 @@ struct inode *new_inode(struct super_blo inode =alloc_inode (sb);if (inode) { -/* XXX: init as locked for speedup */ -spin_lock (&inode->i_lock); inode->i_ino =last_ino_get (); inode->i_state =0 ;__inode_add_to_lists (sb,NULL , inode); -spin_unlock (&inode->i_lock); }return inode; }
PATCH 48/52 fs: icache split IO and LRU lists
In reply to [email protected]Split inode reclaim and writeback lists in preparation to scale them up (per-bdi locking for i_io and per-zone locking for i_lru)
--
fs/fs-writeback.c +17 -13
@@ -291,11 +291,11 @@ static void redirty_tail(struct inode *iif (!list_empty (&wb->b_dirty)) {struct inode *tail; - tail = list_entry(wb->b_dirty.next, struct inode, i_list); + tail = list_entry(wb->b_dirty.next, struct inode, i_io);if (time_before (inode->dirtied_when, tail->dirtied_when)) inode->dirtied_when = jiffies; } -list_move (&inode->i_list, &wb->b_dirty); +list_move (&inode->i_io, &wb->b_dirty); }/*
@@ -306,7 +306,7 @@ static void requeue_io(struct inode *inostruct bdi_writeback *wb = &inode_to_bdi (inode)->wb;assert_spin_locked (&wb_inode_list_lock); -list_move (&inode->i_list, &wb->b_more_io); +list_move (&inode->i_io, &wb->b_more_io); }static void inode_sync_complete (struct inode *inode)
@@ -348,14 +348,14 @@ static void move_expired_inodes(struct lassert_spin_locked (&wb_inode_list_lock);while (!list_empty (delaying_queue)) { - inode = list_entry(delaying_queue->prev, struct inode, i_list); + inode = list_entry(delaying_queue->prev, struct inode, i_io);if (older_than_this &&inode_dirtied_after (inode, *older_than_this))break ;if (sb && sb != inode->i_sb) do_sb_sort =1 ; sb = inode->i_sb; -list_move (&inode->i_list, &tmp); +list_move (&inode->i_io, &tmp); }/* just one sb in list, splice to dispatch_queue and we're done */
@@ -366,12 +366,12 @@ static void move_expired_inodes(struct l/* Move inodes from one superblock together */ while (!list_empty (&tmp)) { - inode = list_entry(tmp.prev, struct inode, i_list); + inode = list_entry(tmp.prev, struct inode, i_io); sb = inode->i_sb;list_for_each_prev_safe (pos, node, &tmp) { - inode = list_entry(pos, struct inode, i_list); + inode = list_entry(pos, struct inode, i_io);if (inode->i_sb == sb) -list_move (&inode->i_list, dispatch_queue); +list_move (&inode->i_io, dispatch_queue); } } }
@@ -556,7 +556,11 @@ select_queue: } }else {/* The inode is clean */ -list_move (&inode->i_list, &inode_unused); +list_del_init (&inode->i_io); +if (list_empty (&inode->i_lru)) { +list_add (&inode->i_lru, &inode_unused); + inodes_stat.nr_unused++; + } } }inode_sync_complete (inode);
@@ -623,7 +627,7 @@ again:while (!list_empty (&wb->b_io)) {long pages_skipped;struct inode *inode =list_entry (wb->b_io.prev, - struct inode, i_list); + struct inode, i_io);if (!spin_trylock (&inode->i_lock)) {spin_unlock (&wb_inode_list_lock);spin_lock (&wb_inode_list_lock);
@@ -696,7 +700,7 @@ again:while (!list_empty (&wb->b_io)) {struct inode *inode =list_entry (wb->b_io.prev, - struct inode, i_list); + struct inode, i_io);struct super_block *sb = inode->i_sb;enum sb_pin_state state;
@@ -845,7 +849,7 @@ retry:spin_lock (&wb_inode_list_lock);if (!list_empty (&wb->b_more_io)) { inode =list_entry (wb->b_more_io.prev, - struct inode, i_list); + struct inode, i_io);if (!spin_trylock (&inode->i_lock)) {spin_unlock (&wb_inode_list_lock); goto retry;
@@ -1164,7 +1168,7 @@ void __mark_inode_dirty(struct inode *in inode->dirtied_when = jiffies;spin_lock (&wb_inode_list_lock); -list_move (&inode->i_list, &wb->b_dirty); +list_move (&inode->i_io, &wb->b_dirty);spin_unlock (&wb_inode_list_lock); } }
include/linux/fs.h +2 -1
@@ -726,7 +726,8 @@ struct posix_acl;struct inode {struct hlist_bl_node i_hash; -struct list_head i_list;/* backing dev IO list */ +struct list_head i_io;/* backing dev IO list */ +struct list_head i_lru;struct list_head i_sb_list;union {struct list_head i_dentry;
mm/backing-dev.c +3 -3
@@ -80,11 +80,11 @@ static int bdi_debug_stats_show(struct sspin_lock (&wb_inode_list_lock);list_for_each_entry (wb, &bdi->wb_list, list) { nr_wb++; -list_for_each_entry (inode, &wb->b_dirty, i_list) +list_for_each_entry (inode, &wb->b_dirty, i_io) nr_dirty++; -list_for_each_entry (inode, &wb->b_io, i_list) +list_for_each_entry (inode, &wb->b_io, i_io) nr_io++; -list_for_each_entry (inode, &wb->b_more_io, i_list) +list_for_each_entry (inode, &wb->b_more_io, i_io) nr_more_io++; }spin_unlock (&wb_inode_list_lock);
fs/inode.c +34 -22
144 lines not on this page · raw message
PATCH 49/52 fs: icache scale writeback list locking
In reply to [email protected]Split wb_inode_list_lock lock into two locks, inode_lru_lock to protect inode LRU list, and a per-bdi lock to protect the inode writeback lists. Inode is given another list anchor so it can be present on both the LRU and the writeback lists, for simplicity.
--
fs/fs-writeback.c +55 -53
@@ -283,11 +283,9 @@ void bdi_start_writeback(struct backing_* the case then the inode must have been redirtied while it was being written * out and we don't reset its dirtied_when. */ -static void redirty_tail (struct inode *inode) +static void redirty_tail (struct bdi_writeback *wb,struct inode *inode) { -struct bdi_writeback *wb = &inode_to_bdi (inode)->wb; - -assert_spin_locked (&wb_inode_list_lock); +assert_spin_locked (&wb->b_lock);if (!list_empty (&wb->b_dirty)) {struct inode *tail;
@@ -301,11 +299,9 @@ static void redirty_tail(struct inode *i/* * requeue inode for re-scanning after bdi->b_io list is exhausted. */ -static void requeue_io (struct inode *inode) +static void requeue_io (struct bdi_writeback *wb,struct inode *inode) { -struct bdi_writeback *wb = &inode_to_bdi (inode)->wb; - -assert_spin_locked (&wb_inode_list_lock); +assert_spin_locked (&wb->b_lock);list_move (&inode->i_io, &wb->b_more_io); }
@@ -346,7 +342,6 @@ static void move_expired_inodes(struct lstruct inode *inode;int do_sb_sort =0 ; -assert_spin_locked (&wb_inode_list_lock);while (!list_empty (delaying_queue)) { inode = list_entry(delaying_queue->prev, struct inode, i_io); if (older_than_this &&
@@ -395,18 +390,19 @@ static int write_inode(struct inode *ino/* * Wait for writeback on an inode to complete. */ -static void inode_wait_for_writeback (struct inode *inode) +static void inode_wait_for_writeback (struct bdi_writeback *wb, +struct inode *inode) {DEFINE_WAIT_BIT (wq, &inode->i_state, __I_SYNC);wait_queue_head_t *wqh; wqh =bit_waitqueue (&inode->i_state, __I_SYNC);while (inode->i_state &I_SYNC ) { -spin_unlock (&wb_inode_list_lock); +spin_unlock (&wb->b_lock);spin_unlock (&inode->i_lock);__wait_on_bit (wqh, &wq, inode_wait,TASK_UNINTERRUPTIBLE );spin_lock (&inode->i_lock); -spin_lock (&wb_inode_list_lock); +spin_lock (&wb->b_lock); } }
@@ -424,7 +420,8 @@ static void inode_wait_for_writeback(str* Called under inode_lock. */ static int -writeback_single_inode (struct inode *inode,struct writeback_control *wbc) +writeback_single_inode (struct bdi_writeback *wb,struct inode *inode, +struct writeback_control *wbc) {struct address_space *mapping = inode->i_mapping;unsigned dirty;
@@ -445,14 +442,14 @@ writeback_single_inode(struct inode *ino* completed a full scan of b_io. */ if (wbc->sync_mode !=WB_SYNC_ALL ) { -requeue_io (inode); +requeue_io (wb, inode);return 0 ; }/* * It's a data-integrity sync. We must wait. */ -inode_wait_for_writeback (inode); +inode_wait_for_writeback (wb, inode); }BUG_ON (inode->i_state &I_SYNC );
@@ -460,7 +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 (&wb_inode_list_lock); +spin_unlock (&wb->b_lock);spin_unlock (&inode->i_lock); ret =do_writepages (mapping, wbc);
@@ -495,7 +492,7 @@ writeback_single_inode(struct inode *inospin_lock (&inode->i_lock); } -spin_lock (&wb_inode_list_lock); +spin_lock (&wb->b_lock); inode->i_state &= ~I_SYNC ;if (!(inode->i_state & (I_FREEING |I_CLEAR ))) {if ((inode->i_state &I_DIRTY_PAGES ) && wbc->for_kupdate) {
@@ -508,7 +505,7 @@ writeback_single_inode(struct inode *ino* At least XFS will redirty the inode during the * writeback (delalloc) and on io completion (isize). */ -redirty_tail (inode); +redirty_tail (wb, inode); }else if (mapping_tagged (mapping,PAGECACHE_TAG_DIRTY )) {/* * We didn't write back all the pages. nfs_writepages()
@@ -536,12 +533,12 @@ select_queue:/* * slice used up: queue for next turn */ -requeue_io (inode); +requeue_io (wb, inode); }else {/* * somehow blocked: retry later */ -redirty_tail (inode); +redirty_tail (wb, inode); } }else {/*
@@ -552,15 +549,13 @@ select_queue:* all the other files. */ inode->i_state |=I_DIRTY_PAGES ; -redirty_tail (inode); +redirty_tail (wb, inode); } }else {/* The inode is clean */ list_del_init (&inode->i_io); -if (list_empty (&inode->i_lru)) { -list_add (&inode->i_lru, &inode_unused); - inodes_stat.nr_unused++; - } +if (list_empty (&inode->i_lru)) +__inode_lru_list_add (inode); } }inode_sync_complete (inode);
@@ -629,14 +624,15 @@ again:struct inode *inode =list_entry (wb->b_io.prev, struct inode, i_io);if (!spin_trylock (&inode->i_lock)) { -spin_unlock (&wb_inode_list_lock); -spin_lock (&wb_inode_list_lock); +spin_unlock (&wb->b_lock); +cpu_relax (); +spin_lock (&wb->b_lock); goto again; }if (wbc->sb && sb != inode->i_sb) {/* super block given and doesn't match, skip this inode */ -redirty_tail (inode); +redirty_tail (wb, inode);spin_unlock (&inode->i_lock);continue ; }
@@ -646,7 +642,7 @@ again:return 0 ; }if (inode->i_state & (I_NEW |I_WILL_FREE )) { -requeue_io (inode); +requeue_io (wb, inode);spin_unlock (&inode->i_lock);continue ; }
@@ -662,19 +658,19 @@ again:BUG_ON (inode->i_state & (I_FREEING |I_CLEAR ));__iget (inode); pages_skipped = wbc->pages_skipped; -writeback_single_inode (inode, wbc); +writeback_single_inode (wb, inode, wbc);if (wbc->pages_skipped != pages_skipped) {/* * writeback is not making progress due to locked * buffers. Skip this inode for now. */ -redirty_tail (inode); +redirty_tail (wb, inode); } -spin_unlock (&wb_inode_list_lock); +spin_unlock (&wb->b_lock);spin_unlock (&inode->i_lock);iput (inode);cond_resched (); -spin_lock (&wb_inode_list_lock); +spin_lock (&wb->b_lock);if (wbc->nr_to_write <=0 ) { wbc->more_io =1 ;return 1 ;
@@ -693,7 +689,7 @@ static void writeback_inodes_wb(struct b wbc->wb_start = jiffies;/* livelock avoidance */ again: -spin_lock (&wb_inode_list_lock); +spin_lock (&wb->b_lock);if (!wbc->for_kupdate ||list_empty (&wb->b_io))queue_io (wb, wbc->older_than_this);
@@ -708,10 +704,11 @@ again:/* super block given and doesn't match, skip this inode */ if (!spin_trylock (&inode->i_lock)) { -spin_unlock (&wb_inode_list_lock); +spin_unlock (&wb->b_lock); +cpu_relax (); goto again; } -redirty_tail (inode); +redirty_tail (wb, inode);spin_unlock (&inode->i_lock);continue ; }
@@ -719,10 +716,11 @@ again:if (state ==SB_PIN_FAILED ) {if (!spin_trylock (&inode->i_lock)) { -spin_unlock (&wb_inode_list_lock); +spin_unlock (&wb->b_lock); +cpu_relax (); goto again; } -requeue_io (inode); +requeue_io (wb, inode);spin_unlock (&inode->i_lock);continue ; }
@@ -733,7 +731,7 @@ again:if (ret)break ; } -spin_unlock (&wb_inode_list_lock); +spin_unlock (&wb->b_lock);/* Leave any unwritten inodes on b_io */ }
@@ -846,18 +844,19 @@ static long wb_writeback(struct bdi_writ* we'll just busyloop. */ retry: -spin_lock (&wb_inode_list_lock); +spin_lock (&wb->b_lock);if (!list_empty (&wb->b_more_io)) { inode =list_entry (wb->b_more_io.prev, struct inode, i_io);if (!spin_trylock (&inode->i_lock)) { -spin_unlock (&wb_inode_list_lock); +spin_unlock (&wb->b_lock); +cpu_relax (); goto retry; } -inode_wait_for_writeback (inode); +inode_wait_for_writeback (wb, inode);spin_unlock (&inode->i_lock); } -spin_unlock (&wb_inode_list_lock); +spin_unlock (&wb->b_lock); }return wrote;
@@ -1156,7 +1155,7 @@ void __mark_inode_dirty(struct inode *in* reposition it (that would break b_dirty time-ordering). */ if (!was_dirty) { -struct bdi_writeback *wb = &inode_to_bdi (inode)->wb; +struct bdi_writeback *wb =inode_to_wb (inode);struct backing_dev_info *bdi = wb->bdi; if (bdi_cap_writeback_dirty(bdi) &&
@@ -1167,9 +1166,10 @@ void __mark_inode_dirty(struct inode *in } inode->dirtied_when = jiffies; -spin_lock (&wb_inode_list_lock); -list_move (&inode->i_io, &wb->b_dirty); -spin_unlock (&wb_inode_list_lock); +spin_lock (&wb->b_lock); +BUG_ON (!list_empty (&inode->i_io)); +list_add (&inode->i_io, &wb->b_dirty); +spin_unlock (&wb->b_lock); } } out:
@@ -1313,6 +1313,7 @@ EXPORT_SYMBOL(sync_inodes_sb);*/ int write_inode_now (struct inode *inode,int sync) { +struct bdi_writeback *wb =inode_to_wb (inode);int ret;struct writeback_control wbc = { .nr_to_write =LONG_MAX ,
@@ -1326,9 +1327,9 @@ int write_inode_now(struct inode *inode,might_sleep ();spin_lock (&inode->i_lock); -spin_lock (&wb_inode_list_lock); - ret =writeback_single_inode (inode, &wbc); -spin_unlock (&wb_inode_list_lock); +spin_lock (&wb->b_lock); + ret =writeback_single_inode (wb, inode, &wbc); +spin_unlock (&wb->b_lock);spin_unlock (&inode->i_lock);if (sync)inode_sync_wait (inode);
@@ -1349,12 +1350,13 @@ EXPORT_SYMBOL(write_inode_now);*/ int sync_inode (struct inode *inode,struct writeback_control *wbc) { +struct bdi_writeback *wb =inode_to_wb (inode);int ret;spin_lock (&inode->i_lock); -spin_lock (&wb_inode_list_lock); - ret =writeback_single_inode (inode, wbc); -spin_unlock (&wb_inode_list_lock); +spin_lock (&wb->b_lock); + ret =writeback_single_inode (wb, inode, wbc); +spin_unlock (&wb->b_lock);spin_unlock (&inode->i_lock);return ret; }
fs/inode.c +56 -28
200 lines not on this page · raw message
include/linux/backing-dev.h +2 -0
@@ -16,6 +16,7 @@#include <linux/sched.h> #include <linux/timer.h> #include <linux/writeback.h> +#include <linux/spinlock.h> #include <asm/atomic.h> struct page ;
@@ -53,6 +54,7 @@ struct bdi_writeback {unsigned long last_old_flush;/* last old data flush */ struct task_struct *task;/* writeback task */ +spinlock_t b_lock;/* lock for inode lists */ struct list_head b_dirty;/* dirty inodes */ struct list_head b_io;/* parked for writeback */ struct list_head b_more_io;/* parked for more writeback */
include/linux/writeback.h +0 -3
@@ -9,9 +9,6 @@struct backing_dev_info ; -extern spinlock_t wb_inode_list_lock; -extern struct list_head inode_unused; -/* * fs/fs-writeback.c */
mm/backing-dev.c +24 -7
@@ -75,19 +75,22 @@ static int bdi_debug_stats_show(struct s/* * inode lock is enough here, the bdi->wb_list is protected by * RCU on the reader side +* (so why not for_each_entry_rcu, and why no explicit rcu disable??) */ nr_wb = nr_dirty = nr_io = nr_more_io =0 ; -spin_lock (&wb_inode_list_lock); -list_for_each_entry (wb, &bdi->wb_list, list) { +rcu_read_lock (); +list_for_each_entry_rcu (wb, &bdi->wb_list, list) { nr_wb++; +spin_lock (&wb->b_lock);list_for_each_entry (inode, &wb->b_dirty, i_io) nr_dirty++;list_for_each_entry (inode, &wb->b_io, i_io) nr_io++;list_for_each_entry (inode, &wb->b_more_io, i_io) nr_more_io++; +spin_unlock (&wb->b_lock); } -spin_unlock (&wb_inode_list_lock); +rcu_read_unlock ();get_dirty_limits (&background_thresh, &dirty_thresh, &bdi_thresh, bdi);
@@ -267,6 +270,7 @@ static void bdi_wb_init(struct bdi_write wb->bdi = bdi; wb->last_old_flush = jiffies; +spin_lock_init (&wb->b_lock);INIT_LIST_HEAD (&wb->b_dirty);INIT_LIST_HEAD (&wb->b_io);INIT_LIST_HEAD (&wb->b_more_io);
@@ -700,6 +704,17 @@ err: }EXPORT_SYMBOL (bdi_init); +static void bdi_lock_two (struct backing_dev_info *bdi1,struct backing_dev_info *bdi2) +{ +if (bdi1 < bdi2) { +spin_lock (&bdi1->wb.b_lock); +spin_lock_nested (&bdi2->wb.b_lock,1 ); + }else { +spin_lock (&bdi2->wb.b_lock); +spin_lock_nested (&bdi1->wb.b_lock,1 ); + } +} +void mapping_set_bdi (struct address_space *mapping,struct backing_dev_info *bdi) {struct inode *inode = mapping->host;
@@ -708,7 +723,7 @@ void mapping_set_bdi(struct address_spacif (unlikely (old == bdi))return ; -spin_lock (&wb_inode_list_lock); +bdi_lock_two (bdi, old);if (!list_empty (&inode->i_io)) {struct inode *i;
@@ -737,7 +752,8 @@ void mapping_set_bdi(struct address_spac } found: mapping->a_bdi = bdi; -spin_unlock (&wb_inode_list_lock); +spin_unlock (&bdi->wb.b_lock); +spin_unlock (&old->wb.b_lock); }EXPORT_SYMBOL (mapping_set_bdi);
@@ -753,7 +769,7 @@ void bdi_destroy(struct backing_dev_infostruct bdi_writeback *dst = &default_backing_dev_info.wb;struct inode *i; -spin_lock (&wb_inode_list_lock); +bdi_lock_two (bdi, &default_backing_dev_info);list_for_each_entry (i, &bdi->wb.b_dirty, i_io) {list_del (&i->i_io);list_add (&i->i_io, &dst->b_dirty);
@@ -769,7 +785,8 @@ void bdi_destroy(struct backing_dev_infolist_add (&i->i_io, &dst->b_more_io); i->i_mapping->a_bdi = bdi; } -spin_unlock (&wb_inode_list_lock); +spin_unlock (&bdi->wb.b_lock); +spin_unlock (&dst->b_lock); }bdi_unregister (bdi);
fs/internal.h +2 -0
@@ -15,6 +15,8 @@ struct super_block;struct linux_binprm ;struct path ; +#define inode_to_wb (inode) (&(inode)->i_mapping->a_bdi->wb) +/* * block_dev.c */
include/linux/fs.h +2 -0
@@ -2076,6 +2076,8 @@ extern int check_disk_change(struct blocextern int __invalidate_device (struct block_device *);extern int invalidate_partition (struct gendisk *,int );#endif +extern void __inode_lru_list_add (struct inode *inode); +extern void __inode_lru_list_del (struct inode *inode);extern int invalidate_inodes (struct super_block *);unsigned long invalidate_mapping_pages (struct address_space *mapping,pgoff_t start,pgoff_t end);
PATCH 50/52 mm: implement per-zone shrinker
In reply to [email protected]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.
--- 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(-)
include/linux/mm.h +9 -7
@@ -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);/* These are for internal use */ struct list_head list; -long nr;/* objs pending delete */ }; -#define DEFAULT_SEEKS 2/* A good number if you don't know better. */ +#define DEFAULT_SEEKS (128UL*2)/* A good number if you don't know better. */ +#define SHRINK_BATCH 128/* A good number if you don't know better */ extern void register_shrinker (struct shrinker *);extern void unregister_shrinker (struct shrinker *); +extern void shrinker_add_scan (unsigned long *dst, +unsigned long scanned,unsigned long total, +unsigned long objects,unsigned int ratio); +extern unsigned long shrinker_do_scan (unsigned long *dst,unsigned long batch);int vma_wants_writenotify (struct vm_area_struct *vma);
@@ -1422,8 +1425,7 @@ int in_gate_area_no_task(unsigned long aint drop_caches_sysctl_handler (struct ctl_table *,int ,void __user *,size_t *,loff_t *); -unsigned long shrink_slab (unsigned long scanned,gfp_t gfp_mask, -unsigned long lru_pages); +void shrink_all_slab (void );#ifndef CONFIG_MMU #define randomize_va_space 0
mm/vmscan.c +82 -98
307 lines not on this page · raw message
fs/dcache.c +20 -14
@@ -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) { -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 ; }static struct shrinker dcache_shrinker = { .shrink = shrink_dcache_memory, - .seeks =DEFAULT_SEEKS , };/**
fs/inode.c +17 -13
@@ -527,7 +527,7 @@ EXPORT_SYMBOL(invalidate_inodes);* If the inode has metadata buffers attached to mapping->private_list then * try to remove them. */ -static void prune_icache (int nr_to_scan) +static void prune_icache (struct zone *zone,unsigned long nr_to_scan) {LIST_HEAD (freeable);unsigned long reap =0 ;
@@ -597,24 +597,28 @@ again:* This function is passed the number of inodes to scan, and it returns the * total number of remaining possibly-reclaimable inodes. */ -static int shrink_icache_memory (int nr,gfp_t gfp_mask) +static int shrink_icache_memory (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask) { -if (nr) { -/* -* Nasty deadlock avoidance. We may hold various FS locks, -* and we don't want to recurse into the FS that called us -* in clear_inode() and friends.. -*/ -if (!(gfp_mask & __GFP_FS)) -return -1 ; -prune_icache (nr); +static unsigned long nr_to_scan; +unsigned long nr; + +shrinker_add_scan (&nr_to_scan, scanned, global, + inodes_stat.nr_unused, +DEFAULT_SEEKS * sysctl_vfs_cache_pressure /100 ); +if (!(gfp_mask & __GFP_FS)) +return 0 ; + +while ((nr =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH ))) { +prune_icache (zone, nr); +cond_resched (); } -return inodes_stat.nr_unused /100 * sysctl_vfs_cache_pressure; + +return 0 ; }static struct shrinker icache_shrinker = { .shrink = shrink_icache_memory, - .seeks =DEFAULT_SEEKS , };static void __wait_on_freeing_inode (struct inode *inode);
fs/mbcache.c +24 -10
@@ -115,11 +115,12 @@ mb_cache_indexes(struct mb_cache *cache)* What the mbcache registers as to get shrunk dynamically. */ -static int mb_cache_shrink_fn (int nr_to_scan,gfp_t gfp_mask); +static int +mb_cache_shrink_fn (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask);static struct shrinker mb_cache_shrinker = { .shrink = mb_cache_shrink_fn, - .seeks =DEFAULT_SEEKS , }; static inline int
@@ -197,11 +198,14 @@ forget:* Returns the number of objects which are present in the cache. */ static int -mb_cache_shrink_fn (int nr_to_scan,gfp_t gfp_mask) +mb_cache_shrink_fn (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask) { +static unsigned long nr_to_scan;LIST_HEAD (free_list);struct list_head *l, *ltmp; -int count =0 ; +unsigned long count =0 ; +unsigned long nr;spin_lock (&mb_cache_spinlock);list_for_each (l, &mb_cache_list) {
@@ -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);list_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; + } +return 0 ; } -/* * mb_cache_create() create a new cache *
fs/nfs/dir.c +20 -9
@@ -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); -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 ; + +while (nr-- && !list_empty (&nfs_access_lru_list)) { +struct nfs_inode *nfsi;struct inode *inode; -if (nr_to_scan-- ==0 ) -break ; + nfsi =list_entry (nfs_access_lru_list.next, + struct nfs_inode, access_cache_inode_lru); inode = &nfsi->vfs_inode;spin_lock (&inode->i_lock);if (list_empty (&nfsi->access_cache_entry_lru))
@@ -1743,10 +1753,11 @@ remove_lru_entry:smp_mb__after_clear_bit (); }spin_unlock (&inode->i_lock); +cond_resched_lock (&nfs_access_lru_lock); }spin_unlock (&nfs_access_lru_lock);nfs_access_free_list (&head); -return (atomic_long_read (&nfs_access_nr_entries) /100 ) * sysctl_vfs_cache_pressure; +return 0 ; }static void __nfs_access_zap_cache (struct nfs_inode *nfsi,struct list_head *head)
fs/nfs/internal.h +2 -1
@@ -205,7 +205,8 @@ extern struct rpc_procinfo nfs4_procedurvoid nfs_close_context (struct nfs_open_context *ctx,int is_sync);/* dir.c */ -extern int nfs_access_cache_shrinker (int nr_to_scan,gfp_t gfp_mask); +extern int nfs_access_cache_shrinker (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask);/* inode.c */ extern struct workqueue_struct *nfsiod_workqueue;
fs/quota/dquot.c +14 -7
@@ -655,7 +655,7 @@ int dquot_quota_sync(struct super_blockEXPORT_SYMBOL (dquot_quota_sync);/* Free unused dquots from cache */ -static void prune_dqcache (int count) +static void prune_dqcache (unsigned long count) {struct list_head *head;struct dquot *dquot;
@@ -676,21 +676,28 @@ static void prune_dqcache(int count)* This is called from kswapd when we think we need some * more memory */ -static int shrink_dqcache_memory (int nr,gfp_t gfp_mask) +static int shrink_dqcache_memory (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask) { -if (nr) { +static unsigned long nr_to_scan; +unsigned long nr; + +shrinker_add_scan (&nr_to_scan, scanned, total, +percpu_counter_read_positive (&dqstats.counter[DQST_FREE_DQUOTS ]), +DEFAULT_SEEKS * sysctl_vfs_cache_pressure /100 ); + +while ((nr =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH ))) {spin_lock (&dq_list_lock);prune_dqcache (nr);spin_unlock (&dq_list_lock); +cond_resched (); } -return ((unsigned ) -percpu_counter_read_positive (&dqstats.counter[DQST_FREE_DQUOTS ]) - /100 ) * sysctl_vfs_cache_pressure; + +return 0 ; }static struct shrinker dqcache_shrinker = { .shrink = shrink_dqcache_memory, - .seeks =DEFAULT_SEEKS , };/*
fs/drop_caches.c +1 -5
@@ -38,11 +38,7 @@ static void drop_pagecache_sb(struct supstatic void drop_slab (void ) { -int nr_objects; - -do { - nr_objects =shrink_slab (1000 ,GFP_KERNEL ,1000 ); - }while (nr_objects >10 ); +shrink_all_slab (); } int drop_caches_sysctl_handler(ctl_table *table, int write,
mm/memory-failure.c +2 -8
@@ -229,14 +229,8 @@ void shake_page(struct page *p, int acce* Only all shrink_slab here (which would also * shrink other caches) if access is not potentially fatal. */ -if (access) { -int nr; -do { - nr =shrink_slab (1000 ,GFP_KERNEL ,1000 ); -if (page_count (p) ==0 ) -break ; - }while (nr >10 ); - } +if (access) +shrink_all_slab (); }EXPORT_SYMBOL_GPL (shake_page);
arch/x86/kvm/mmu.c +23 -12
@@ -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; + } +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 ; + }list_for_each_entry (kvm, &vm_list, vm_list) {int npages, idx, freed_pages;
@@ -2939,28 +2954,24 @@ static int mmu_shrink(int nr_to_scan, gfspin_lock (&kvm->mmu_lock); npages = kvm->arch.n_alloc_mmu_pages - kvm->arch.n_free_mmu_pages; - cache_count += npages; -if (!kvm_freed && nr_to_scan >0 && npages >0 ) { +if (!kvm_freed && npages >0 ) { freed_pages =kvm_mmu_remove_some_alloc_mmu_pages (kvm); - cache_count -= freed_pages; kvm_freed = kvm; } - nr_to_scan--; -spin_unlock (&kvm->mmu_lock);srcu_read_unlock (&kvm->srcu, idx); + +if (!--cache_count) +break ; }if (kvm_freed)list_move_tail (&kvm_freed->vm_list, &vm_list); - -spin_unlock (&kvm_lock); - -return cache_count; +cond_resched_lock (&kvm_lock); + goto done; }static struct shrinker mmu_shrinker = { .shrink = mmu_shrink, - .seeks =DEFAULT_SEEKS *10 , };static void mmu_destroy_caches (void )
drivers/gpu/drm/i915/i915_gem.c +31 -38
125 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_page_alloc.c +24 -16
@@ -395,30 +395,38 @@ static int ttm_pool_get_num_unused_pages/** * Callback for mm to request pool to reduce number of page held. */ -static int ttm_pool_mm_shrink (int shrink_pages,gfp_t gfp_mask) +static int ttm_pool_mm_shrink (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask) { -static atomic_t start_pool =ATOMIC_INIT (0 ); -unsigned i; -unsigned pool_offset =atomic_add_return (1 , &start_pool); -struct ttm_page_pool *pool; +static unsigned long nr_to_scan; +unsigned long shrink_pages; - pool_offset = pool_offset %NUM_POOLS ; -/* select start pool in round robin fashion */ -for (i =0 ; i <NUM_POOLS ; ++i) { -unsigned nr_free = shrink_pages; -if (shrink_pages ==0 ) -break ; - pool = &_manager.pools[(i + pool_offset)%NUM_POOLS ]; - shrink_pages =ttm_page_pool_free (pool, nr_free); +shrinker_add_scan (&nr_to_scan, scanned, global, +ttm_pool_get_num_unused_pages (), +SHRINK_FIXED ); + +while ((shrink_pages =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH ))) { +static atomic_t start_pool =ATOMIC_INIT (0 ); +unsigned pool_offset =atomic_add_return (1 , &start_pool); +struct ttm_page_pool *pool; +unsigned i; + + pool_offset = pool_offset %NUM_POOLS ; +/* select start pool in round robin fashion */ +for (i =0 ; i <NUM_POOLS ; ++i) { +unsigned nr_free = shrink_pages; +if (shrink_pages ==0 ) +break ; + pool = &_manager.pools[(i + pool_offset)%NUM_POOLS ]; + shrink_pages =ttm_page_pool_free (pool, nr_free); + } } -/* return estimated number of unused pages in pool */ -return ttm_pool_get_num_unused_pages (); +return 0 ; }static void ttm_pool_mm_shrink_init (struct ttm_pool_manager *manager) { manager->mm_shrink.shrink = &ttm_pool_mm_shrink; - manager->mm_shrink.seeks =1 ;register_shrinker (&manager->mm_shrink); }
fs/gfs2/glock.c +16 -7
@@ -1349,18 +1349,27 @@ void gfs2_glock_complete(struct gfs2_glo } -static int gfs2_shrink_glock_memory (int nr,gfp_t gfp_mask) +static int gfs2_shrink_glock_memory (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask) { +static unsigned long nr_to_scan; +unsigned long nr;struct gfs2_glock *gl;int may_demote;int nr_skipped =0 ;LIST_HEAD (skipped); -if (nr ==0 ) - goto out; +shrinker_add_scan (&nr_to_scan, scanned, global, +atomic_read (&lru_count), +DEFAULT_SEEKS * sysctl_vfs_cache_pressure /100 );if (!(gfp_mask & __GFP_FS)) -return -1 ; +return 0 ; + +done: + nr =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH ); +if (!nr) +return 0 ;spin_lock (&lru_lock);while (nr && !list_empty (&lru_list)) {
@@ -1392,13 +1401,13 @@ static int gfs2_shrink_glock_memory(intlist_splice (&skipped, &lru_list);atomic_add (nr_skipped, &lru_count);spin_unlock (&lru_lock); -out: -return (atomic_read (&lru_count) /100 ) * sysctl_vfs_cache_pressure; +if (!nr) + goto done; +return 0 ; }static struct shrinker glock_shrinker = { .shrink = gfs2_shrink_glock_memory, - .seeks =DEFAULT_SEEKS , };/**
fs/gfs2/main.c +0 -1
@@ -27,7 +27,6 @@static struct shrinker qd_shrinker = { .shrink = gfs2_shrink_qd_memory, - .seeks =DEFAULT_SEEKS , };static void gfs2_init_inode_once (void *foo)
fs/gfs2/quota.c +17 -7
@@ -43,6 +43,7 @@#include <linux/buffer_head.h> #include <linux/sort.h> #include <linux/fs.h> +#include <linux/mm.h> #include <linux/bio.h> #include <linux/gfs2_ondisk.h> #include <linux/kthread.h>
@@ -77,16 +78,25 @@ static LIST_HEAD(qd_lru_list);static atomic_t qd_lru_count =ATOMIC_INIT (0 );static DEFINE_SPINLOCK (qd_lru_lock); -int gfs2_shrink_qd_memory (int nr,gfp_t gfp_mask) +int gfs2_shrink_qd_memory (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask) { +static unsigned long nr_to_scan; +unsigned long nr;struct gfs2_quota_data *qd;struct gfs2_sbd *sdp; -if (nr ==0 ) - goto out; +shrinker_add_scan (&nr_to_scan, scanned, global, +atomic_read (&qd_lru_count), +DEFAULT_SEEKS * sysctl_vfs_cache_pressure /100 );if (!(gfp_mask & __GFP_FS)) -return -1 ; +return 0 ; + +done: + nr =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH ); +if (!nr) +return 0 ;spin_lock (&qd_lru_lock);while (nr && !list_empty (&qd_lru_list)) {
@@ -113,9 +123,9 @@ int gfs2_shrink_qd_memory(int nr, gfp_t nr--; }spin_unlock (&qd_lru_lock); - -out: -return (atomic_read (&qd_lru_count) * sysctl_vfs_cache_pressure) /100 ; +if (!nr) + goto done; +return 0 ; }static u64 qd2offset (struct gfs2_quota_data *qd)
fs/gfs2/quota.h +2 -1
@@ -51,7 +51,8 @@ static inline int gfs2_quota_lock_check( return ret; } -extern int gfs2_shrink_qd_memory (int nr,gfp_t gfp_mask); +extern int gfs2_shrink_qd_memory (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask);extern const struct quotactl_ops gfs2_quotactl_ops;#endif /* __QUOTA_DOT_H__ */
fs/nfs/super.c +0 -1
@@ -350,7 +350,6 @@ static const struct super_operations nfsstatic struct shrinker acl_shrinker = { .shrink = nfs_access_cache_shrinker, - .seeks =DEFAULT_SEEKS , };/*
fs/ubifs/shrinker.c +18 -11
@@ -277,13 +277,16 @@ static int kick_a_thread(void)return 0 ; } -int ubifs_shrinker (int nr,gfp_t gfp_mask) +int ubifs_shrinker (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask) { +static unsigned long nr_to_scan; +unsigned long nr;int freed, contention =0 ;long clean_zn_cnt =atomic_long_read (&ubifs_clean_zn_cnt); -if (nr ==0 ) -return clean_zn_cnt; +shrinker_add_scan (&nr_to_scan, scanned, global, clean_zn_cnt, +DEFAULT_SEEKS );if (!clean_zn_cnt) {/*
@@ -297,24 +300,28 @@ int ubifs_shrinker(int nr, gfp_t gfp_masreturn kick_a_thread (); } +done: + nr =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH ); +if (!nr) +return 0 ; + freed =shrink_tnc_trees (nr,OLD_ZNODE_AGE , &contention);if (freed >= nr) - goto out; + goto done;dbg_tnc ("not enough old znodes, try to free young ones" ); freed +=shrink_tnc_trees (nr - freed,YOUNG_ZNODE_AGE , &contention);if (freed >= nr) - goto out; + goto done;dbg_tnc ("not enough young znodes, free all" ); freed +=shrink_tnc_trees (nr - freed,0 , &contention); +if (freed >= nr) + goto done; -if (!freed && contention) { -dbg_tnc ("freed nothing, but contention" ); -return -1 ; - } +if (!freed && contention) + nr_to_scan += nr; -out: -dbg_tnc ("%d znodes were freed, requested %d" , freed, nr); +dbg_tnc ("%d znodes were freed, requested %lu" , freed, nr);return freed; }
fs/ubifs/super.c +0 -1
@@ -50,7 +50,6 @@ struct kmem_cache *ubifs_inode_slab;/* UBIFS TNC shrinker description */ static struct shrinker ubifs_shrinker_info = { .shrink = ubifs_shrinker, - .seeks =DEFAULT_SEEKS , };/**
fs/ubifs/ubifs.h +2 -1
@@ -1575,7 +1575,8 @@ int ubifs_tnc_start_commit(struct ubifs_int ubifs_tnc_end_commit (struct ubifs_info *c);/* shrinker.c */ -int ubifs_shrinker (int nr_to_scan,gfp_t gfp_mask); +int ubifs_shrinker (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask);/* commit.c */ int ubifs_bg_thread (void *info);
fs/xfs/linux-2.6/xfs_buf.c +8 -5
@@ -45,11 +45,11 @@static kmem_zone_t *xfs_buf_zone; STATIC int xfsbufd(void *); -STATIC int xfsbufd_wakeup(int, gfp_t); +STATIC int xfsbufd_wakeup(struct zone *, +unsigned long ,unsigned long ,unsigned long ,gfp_t ); STATIC void xfs_buf_delwri_queue(xfs_buf_t *, int);static struct shrinker xfs_buf_shake = { .shrink = xfsbufd_wakeup, - .seeks =DEFAULT_SEEKS , };static struct workqueue_struct *xfslogd_workqueue;
@@ -340,7 +340,7 @@ _xfs_buf_lookup_pages( __func__, gfp_mask);XFS_STATS_INC (xb_page_retries); -xfsbufd_wakeup (0 , gfp_mask); +xfsbufd_wakeup (NULL ,0 ,0 ,0 , gfp_mask);congestion_wait (BLK_RW_ASYNC ,HZ /50 ); goto retry; }
@@ -1762,8 +1762,11 @@ xfs_buf_runall_queues( STATIC intxfsbufd_wakeup ( -int priority, -gfp_t mask) +struct zone *zone, +unsigned long scanned, +unsigned long total, +unsigned long global, +gfp_t gfp_mask) {xfs_buftarg_t *btp;
fs/xfs/linux-2.6/xfs_sync.c +28 -19
71 lines not on this page · raw message
fs/xfs/quota/xfs_qm.c +11 -4
@@ -69,11 +69,11 @@ STATIC void xfs_qm_list_destroy(xfs_dqli STATIC int xfs_qm_init_quotainos(xfs_mount_t *); STATIC int xfs_qm_init_quotainfo(xfs_mount_t *); -STATIC int xfs_qm_shake(int, gfp_t); +STATIC int xfs_qm_shake(struct zone *, unsigned long, unsigned long, +unsigned long ,gfp_t );static struct shrinker xfs_qm_shaker = { .shrink = xfs_qm_shake, - .seeks =DEFAULT_SEEKS , };#ifdef DEBUG
@@ -2119,7 +2119,12 @@ xfs_qm_shake_freelist(*/ /* ARGSUSED */ STATIC int -xfs_qm_shake (int nr_to_scan,gfp_t gfp_mask) +xfs_qm_shake ( +struct zone *zone, +unsigned long scanned, +unsigned long total, +unsigned long global, +gfp_t gfp_mask) {int ndqused, nfree, n;
@@ -2140,7 +2145,9 @@ xfs_qm_shake(int nr_to_scan, gfp_t gfp_m ndqused *= xfs_Gqm->qm_dqfree_ratio;/* target # of free dquots */ n = nfree - ndqused - ndquot;/* # over target */ -return xfs_qm_shake_freelist (MAX (nfree, n)); +xfs_qm_shake_freelist (MAX (nfree, n)); + +return 0 ; }
net/sunrpc/auth.c +18 -10
@@ -227,8 +227,8 @@ EXPORT_SYMBOL_GPL(rpcauth_destroy_credca/* * Remove stale credentials. Avoid sleeping inside the loop. */ -static int -rpcauth_prune_expired (struct list_head *free,int nr_to_scan) +static void +rpcauth_prune_expired (struct list_head *free,unsigned long nr_to_scan) {spinlock_t *cache_lock;struct rpc_cred *cred, *next;
@@ -244,7 +244,7 @@ rpcauth_prune_expired(struct list_head **/ if (time_in_range (cred->cr_expire, expired, jiffies) &&test_bit (RPCAUTH_CRED_HASHED , &cred->cr_flags) !=0 ) -return 0 ; +break ;list_del_init (&cred->cr_lru); number_cred_unused--;
@@ -260,27 +260,36 @@ rpcauth_prune_expired(struct list_head * }spin_unlock (cache_lock); } -return (number_cred_unused /100 ) * sysctl_vfs_cache_pressure; }/* * Run memory cache shrinker. */ static int -rpcauth_cache_shrinker (int nr_to_scan,gfp_t gfp_mask) +rpcauth_cache_shrinker (struct zone *zone,unsigned long scanned, +unsigned long total,unsigned long global,gfp_t gfp_mask) { +static unsigned long nr_to_scan; +unsigned long nr;LIST_HEAD (free); -int res; +shrinker_add_scan (&nr_to_scan, scanned, global, + number_cred_unused, +DEFAULT_SEEKS * sysctl_vfs_cache_pressure /100 );if ((gfp_mask &GFP_KERNEL ) !=GFP_KERNEL ) -return (nr_to_scan ==0 ) ?0 :-1 ; +return 0 ; +again:if (list_empty (&cred_unused))return 0 ; + nr =shrinker_do_scan (&nr_to_scan,SHRINK_BATCH ); +if (!nr) +return 0 ;spin_lock (&rpc_credcache_lock); - res =rpcauth_prune_expired (&free, nr_to_scan); +rpcauth_prune_expired (&free, nr);spin_unlock (&rpc_credcache_lock);rpcauth_destroy_credlist (&free); -return res; +cond_resched (); + goto again; }/*
@@ -584,7 +593,6 @@ rpcauth_uptodatecred(struct rpc_task *tastatic struct shrinker rpc_cred_shrinker = { .shrink = rpcauth_cache_shrinker, - .seeks =DEFAULT_SEEKS , };void __init rpcauth_init_module (void )
--
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>
PATCH 51/52 fs: per-zone dentry and inode LRU
In reply to [email protected]Per-zone LRUs and shrinkers for dentry and inode caches.
include/linux/fs.h +21 -3
@@ -382,6 +382,7 @@ struct files_stat_struct {#include <linux/semaphore.h> #include <linux/fiemap.h> #include <linux/rculist_bl.h> +#include <linux/mmzone.h> #include <asm/atomic.h> #include <asm/byteorder.h>
@@ -1325,6 +1326,25 @@ extern int send_sigurg(struct fown_strucextern struct list_head super_blocks;extern spinlock_t sb_lock; +#define sb_zone_info (sb, ___z) \ + &sb->s_reclaim.node[zone_to_nid(___z)].zone[zone_idx(___z)] + +struct sb_zoneinfo { +/* protected by zone->dentry_lru_lock */ +spinlock_t s_dentry_lru_lock; +struct list_head s_dentry_lru; +long s_nr_dentry_scan; +unsigned long s_nr_dentry_unused; +}; + +struct sb_nodeinfo { +struct sb_zoneinfo zone[MAX_NR_ZONES ]; +}; + +struct sb_reclaim { +struct sb_nodeinfo node[MAX_NUMNODES ]; +}; +struct super_block {struct list_head s_list;/* Keep this first */ dev_t s_dev;/* search index; _not_ kdev_t */
@@ -1357,9 +1377,7 @@ struct super_block {struct list_head s_inodes;/* all inodes */ 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 */ +struct sb_reclaim s_reclaim;struct block_device *s_bdev;struct backing_dev_info *s_bdi;
fs/dcache.c +93 -86
332 lines not on this page · raw message
fs/inode.c +53 -52
231 lines not on this page · raw message
fs/super.c +11 -1
@@ -50,6 +50,8 @@ static struct super_block *alloc_super(sstatic const struct super_operations default_op;if (s) { +struct zone *zone; +if (security_sb_alloc (s)) {kfree (s); s =NULL ;
@@ -88,7 +90,6 @@ static struct super_block *alloc_super(s#endif INIT_LIST_HEAD (&s->s_instances);INIT_HLIST_BL_HEAD (&s->s_anon); -INIT_LIST_HEAD (&s->s_dentry_lru);init_rwsem (&s->s_umount);mutex_init (&s->s_lock);lockdep_set_class (&s->s_umount, &type->s_umount_key);
@@ -125,6 +126,15 @@ static struct super_block *alloc_super(s s->s_maxbytes =MAX_NON_LFS ; s->s_op = &default_op; s->s_time_gran =1000000000 ; + +for_each_zone (zone) { +struct sb_zoneinfo *sbz =sb_zone_info (s, zone); + +spin_lock_init (&sbz->s_dentry_lru_lock); +INIT_LIST_HEAD (&sbz->s_dentry_lru); + sbz->s_nr_dentry_scan =0 ; + sbz->s_nr_dentry_unused =0 ; + } } out:return s;
include/linux/mmzone.h +7 -0
@@ -370,6 +370,13 @@ struct zone {ZONE_PADDING (_pad2_) + + spinlock_t inode_lru_lock; +struct list_head inode_lru; +unsigned long inode_nr_lru; +unsigned long inode_nr_scan; + +ZONE_PADDING (_pad3_)/* Rarely used or read-mostly fields */ /*
include/linux/mm.h +2 -1
@@ -1004,7 +1004,8 @@ struct shrinker {/* These are for internal use */ struct list_head list; }; -#define DEFAULT_SEEKS (128UL*2)/* A good number if you don't know better. */ +#define SHRINK_FIXED (128UL)/* Fixed point for shrinker ratio */ +#define DEFAULT_SEEKS (SHRINK_FIXED*2)/* A good number if you don't know better. */ #define SHRINK_BATCH 128/* A good number if you don't know better */ extern void register_shrinker (struct shrinker *);extern void unregister_shrinker (struct shrinker *);
PATCH 1/52 kernel: add bl_list
In reply to [email protected]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.
--- include/linux/list_bl.h | 99 +++++++++++++++++++++++++++++++++++++ include/linux/rculist_bl.h | 120 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+)
include/linux/list_bl.h new file +99 -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; +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 ; +} + +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
include/linux/rculist_bl.h new file +120 -0
120 lines not on this page · raw message
PATCH 9/52 fs: dcache scale hash
In reply to [email protected]Add a new lock, dcache_hash_lock, to protect the dcache hash table from concurrent modification. d_hash is also protected by d_lock.
--- fs/dcache.c | 35 ++++++++++++++++++++++++----------- include/linux/dcache.h | 3 +++ 2 files changed, 27 insertions(+), 11 deletions(-)
fs/dcache.c +28 -11
@@ -35,12 +35,27 @@#include <linux/hardirq.h> #include "internal.h" +/* +* Usage: +* dcache_hash_lock protects dcache hash table +* +* Ordering: +* dcache_lock +* dentry->d_lock +* dcache_hash_lock +* +* if (dentry1 < dentry2) +* dentry1->d_lock +* dentry2->d_lock +*/ int sysctl_vfs_cache_pressure__read_mostly =100 ;EXPORT_SYMBOL_GPL (sysctl_vfs_cache_pressure); -__cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_lock ); +__cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_hash_lock ); +__cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_lock );__cacheline_aligned_in_smp DEFINE_SEQLOCK (rename_lock ); +EXPORT_SYMBOL (dcache_hash_lock);EXPORT_SYMBOL (dcache_lock);static struct kmem_cache *dentry_cache__read_mostly ;
@@ -1480,17 +1495,20 @@ int d_validate(struct dentry *dentry, st goto out;spin_lock (&dcache_lock); +spin_lock (&dcache_hash_lock); base =d_hash (dparent, dentry->d_name.hash);hlist_for_each (lhp,base) {/* hlist_for_each_entry_rcu() not required for d_hash list * as it is parsed under dcache_lock */ if (dentry == hlist_entry(lhp, struct dentry, d_hash)) { +spin_unlock (&dcache_hash_lock);__dget_locked (dentry);spin_unlock (&dcache_lock);return 1 ; } } +spin_unlock (&dcache_hash_lock);spin_unlock (&dcache_lock); out:return 0 ;
@@ -1567,7 +1585,9 @@ void d_rehash(struct dentry * entry) {spin_lock (&dcache_lock);spin_lock (&entry->d_lock); +spin_lock (&dcache_hash_lock);_d_rehash (entry); +spin_unlock (&dcache_hash_lock);spin_unlock (&entry->d_lock);spin_unlock (&dcache_lock); }
@@ -1647,8 +1667,6 @@ static void switch_names(struct dentry **/ static void d_move_locked (struct dentry * dentry,struct dentry * target) { -struct hlist_head *list; -if (!dentry->d_inode)printk (KERN_WARNING "VFS: moving negative dcache entry\n" );
@@ -1665,14 +1683,11 @@ static void d_move_locked(struct dentry }/* Move the dentry to the target hash queue, if on different bucket */ -if (d_unhashed (dentry)) - goto already_unhashed; - -hlist_del_rcu (&dentry->d_hash); - -already_unhashed: - list =d_hash (target->d_parent, target->d_name.hash); -__d_rehash (dentry, list); +spin_lock (&dcache_hash_lock); +if (!d_unhashed (dentry)) +hlist_del_rcu (&dentry->d_hash); +__d_rehash (dentry,d_hash (target->d_parent, target->d_name.hash)); +spin_unlock (&dcache_hash_lock);/* Unhash the target: dput() will then get rid of it */ __d_drop (target);
@@ -1869,7 +1884,9 @@ struct dentry *d_materialise_unique(stru found_lock:spin_lock (&actual->d_lock); found: +spin_lock (&dcache_hash_lock);_d_rehash (actual); +spin_unlock (&dcache_hash_lock);spin_unlock (&actual->d_lock);spin_unlock (&dcache_lock); out_nolock:
include/linux/dcache.h +3 -0
@@ -188,6 +188,7 @@ d_iput: no no no yes#define DCACHE_CANT_MOUNT 0x0100 +extern spinlock_t dcache_hash_lock;extern spinlock_t dcache_lock;extern seqlock_t rename_lock;
@@ -211,7 +212,9 @@ static inline void __d_drop(struct dentr {if (!(dentry->d_flags &DCACHE_UNHASHED )) { dentry->d_flags |=DCACHE_UNHASHED ; +spin_lock (&dcache_hash_lock);hlist_del_rcu (&dentry->d_hash); +spin_unlock (&dcache_hash_lock); } }
PATCH 10/52 fs: dcache scale lru
In reply to [email protected]Add a new lock, dcache_lru_lock, to protect the dcache hash table from concurrent modification. d_lru is also protected by d_lock.
Move lru scanning out from underneath dcache_lock. XXX Maybe do that in another patch
--- fs/dcache.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 20 deletions(-)
fs/dcache.c +85 -20
@@ -37,11 +37,19 @@/* * Usage: -* dcache_hash_lock protects dcache hash table +* dcache_hash_lock protects: +* - the dcache hash table +* dcache_lru_lock protects: +* - the dcache lru lists and counters +* d_lock protects: +* - d_flags +* - d_name +* - d_lru * * Ordering: * dcache_lock * dentry->d_lock +* dcache_lru_lock * dcache_hash_lock * * if (dentry1 < dentry2)
@@ -52,6 +60,7 @@ int sysctl_vfs_cache_pressure __read_mosEXPORT_SYMBOL_GPL (sysctl_vfs_cache_pressure);__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 );
@@ -138,37 +147,56 @@ static void dentry_iput(struct dentry * }/* -* dentry_lru_(add|add_tail|del|del_init) must be called with dcache_lock held. +* dentry_lru_(add|add_tail|del|del_init) must be called with d_lock held +* to protect list_empty(d_lru) condition. */ static void dentry_lru_add (struct dentry *dentry) { +spin_lock (&dcache_lru_lock);list_add (&dentry->d_lru, &dentry->d_sb->s_dentry_lru); dentry->d_sb->s_nr_dentry_unused++; dentry_stat.nr_unused++; +spin_unlock (&dcache_lru_lock); }static void dentry_lru_add_tail (struct dentry *dentry) { +spin_lock (&dcache_lru_lock);list_add_tail (&dentry->d_lru, &dentry->d_sb->s_dentry_lru); dentry->d_sb->s_nr_dentry_unused++; dentry_stat.nr_unused++; +spin_unlock (&dcache_lru_lock); +} + +static void __dentry_lru_del (struct dentry *dentry) +{ +list_del (&dentry->d_lru); + dentry->d_sb->s_nr_dentry_unused--; + dentry_stat.nr_unused--; +} + +static void __dentry_lru_del_init (struct dentry *dentry) +{ +list_del_init (&dentry->d_lru); + dentry->d_sb->s_nr_dentry_unused--; + dentry_stat.nr_unused--; }static void dentry_lru_del (struct dentry *dentry) {if (!list_empty (&dentry->d_lru)) { -list_del (&dentry->d_lru); - dentry->d_sb->s_nr_dentry_unused--; - dentry_stat.nr_unused--; +spin_lock (&dcache_lru_lock); +__dentry_lru_del (dentry); +spin_unlock (&dcache_lru_lock); } }static void dentry_lru_del_init (struct dentry *dentry) {if (likely (!list_empty (&dentry->d_lru))) { -list_del_init (&dentry->d_lru); - dentry->d_sb->s_nr_dentry_unused--; - dentry_stat.nr_unused--; +spin_lock (&dcache_lru_lock); +__dentry_lru_del_init (dentry); +spin_unlock (&dcache_lru_lock); } }
@@ -179,6 +207,8 @@ static void dentry_lru_del_init(struct d* The dentry must already be unhashed and removed from the LRU. * * If this is the root of the dentry tree, return NULL. +* +* dcache_lock and d_lock must be held by caller, are dropped by d_kill. */ static struct dentry *d_kill (struct dentry *dentry) __releases(dentry->d_lock)
@@ -333,11 +363,19 @@ int d_invalidate(struct dentry * dentry)EXPORT_SYMBOL (d_invalidate);/* This should be called _only_ with dcache_lock held */ +static inline struct dentry *__dget_locked_dlock (struct dentry *dentry) +{ +atomic_inc (&dentry->d_count); +dentry_lru_del_init (dentry); +return dentry; +}static inline struct dentry *__dget_locked (struct dentry *dentry) {atomic_inc (&dentry->d_count); +spin_lock (&dentry->d_lock);dentry_lru_del_init (dentry); +spin_unlock (&dentry->d_lock);return dentry; }
@@ -416,7 +454,7 @@ restart:list_for_each_entry (dentry, &inode->i_dentry, d_alias) {spin_lock (&dentry->d_lock);if (!atomic_read (&dentry->d_count)) { -__dget_locked (dentry); +__dget_locked_dlock (dentry);__d_drop (dentry);spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);
@@ -449,17 +487,18 @@ static void prune_one_dentry(struct dent* Prune ancestors. Locking is simpler than in dput(), * because dcache_lock needs to be taken anyway. */ -spin_lock (&dcache_lock);while (dentry) { -if (!atomic_dec_and_lock (&dentry->d_count, &dentry->d_lock)) +spin_lock (&dcache_lock); +if (!atomic_dec_and_lock (&dentry->d_count, &dentry->d_lock)) { +spin_unlock (&dcache_lock);return ; + }if (dentry->d_op && dentry->d_op->d_delete) dentry->d_op->d_delete (dentry);dentry_lru_del_init (dentry);__d_drop (dentry); dentry =d_kill (dentry); -spin_lock (&dcache_lock); } }
@@ -480,10 +519,11 @@ static void __shrink_dcache_sb(struct suBUG_ON (!sb);BUG_ON ((flags &DCACHE_REFERENCED ) && count ==NULL ); -spin_lock (&dcache_lock);if (count !=NULL )/* called from prune_dcache() and shrink_dcache_parent() */ cnt = *count; +relock: +spin_lock (&dcache_lru_lock); restart:if (count ==NULL )list_splice_init (&sb->s_dentry_lru, &tmp);
@@ -493,7 +533,10 @@ restart: struct dentry, d_lru);BUG_ON (dentry->d_sb != sb); -spin_lock (&dentry->d_lock); +if (!spin_trylock (&dentry->d_lock)) { +spin_unlock (&dcache_lru_lock); + goto relock; + }/* * If we are honouring the DCACHE_REFERENCED flag and * the dentry has this flag set, don't free it. Clear
@@ -511,13 +554,22 @@ restart:if (!cnt)break ; } -cond_resched_lock (&dcache_lock); +cond_resched_lock (&dcache_lru_lock); } } +spin_unlock (&dcache_lru_lock); + +spin_lock (&dcache_lock); +again: +spin_lock (&dcache_lru_lock);/* lru_lock also protects tmp list */ while (!list_empty (&tmp)) { dentry = list_entry(tmp.prev, struct dentry, d_lru); -dentry_lru_del_init (dentry); -spin_lock (&dentry->d_lock); + +if (!spin_trylock (&dentry->d_lock)) { +spin_unlock (&dcache_lru_lock); + goto again; + } +__dentry_lru_del_init (dentry);/* * We found an inuse dentry which was not removed from * the LRU because of laziness during lookup. Do not free
@@ -527,17 +579,22 @@ restart:spin_unlock (&dentry->d_lock);continue ; } + +spin_unlock (&dcache_lru_lock);prune_one_dentry (dentry); -/* dentry->d_lock was dropped in prune_one_dentry() */ -cond_resched_lock (&dcache_lock); +/* dcache_lock and dentry->d_lock dropped */ +spin_lock (&dcache_lock); +spin_lock (&dcache_lru_lock); } +spin_unlock (&dcache_lock); +if (count ==NULL && !list_empty (&sb->s_dentry_lru)) goto restart;if (count !=NULL ) *count = cnt;if (!list_empty (&referenced))list_splice (&referenced, &sb->s_dentry_lru); -spin_unlock (&dcache_lock); +spin_unlock (&dcache_lru_lock); }/**
@@ -645,7 +702,9 @@ static void shrink_dcache_for_umount_sub/* detach this root from the system */ spin_lock (&dcache_lock); +spin_lock (&dentry->d_lock);dentry_lru_del_init (dentry); +spin_unlock (&dentry->d_lock);__d_drop (dentry);spin_unlock (&dcache_lock);
@@ -659,7 +718,9 @@ static void shrink_dcache_for_umount_subspin_lock (&dcache_lock);list_for_each_entry (loop, &dentry->d_subdirs, d_u.d_child) { +spin_lock (&loop->d_lock);dentry_lru_del_init (loop); +spin_unlock (&loop->d_lock);__d_drop (loop);cond_resched_lock (&dcache_lock); }
@@ -843,13 +904,17 @@ resume: struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child); next = tmp->next; +spin_lock (&dentry->d_lock);dentry_lru_del_init (dentry); +spin_unlock (&dentry->d_lock);/* * move only zero ref count dentries to the end * of the unused list for prune_dcache */ if (!atomic_read (&dentry->d_count)) { +spin_lock (&dentry->d_lock);dentry_lru_add_tail (dentry); +spin_unlock (&dentry->d_lock); found++; }
PATCH 12/52 fs: dcache scale dentry refcount
In reply to [email protected]Make d_count non-atomic and protect it with d_lock. This allows us to ensure a 0 refcount dentry remains 0 without dcache_lock. It is also fairly natural when we start protecting many other dentry members with d_lock.
--- arch/powerpc/platforms/cell/spufs/inode.c | 2 drivers/infiniband/hw/ipath/ipath_fs.c | 2 fs/autofs4/expire.c | 8 +- fs/autofs4/root.c | 6 - fs/coda/dir.c | 2 fs/configfs/dir.c | 3 fs/configfs/inode.c | 2 fs/dcache.c | 107 ++++++++++++++++++++++-------- fs/ecryptfs/inode.c | 2 fs/exportfs/expfs.c | 9 ++ fs/hpfs/namei.c | 2 fs/locks.c | 2 fs/namei.c | 2 fs/nfs/dir.c | 12 +-- fs/nfsd/vfs.c | 5 - fs/notify/fsnotify.c | 11 ++- fs/notify/inotify/inotify.c | 14 +++ fs/smbfs/dir.c | 8 +- fs/smbfs/proc.c | 8 +- include/linux/dcache.h | 29 ++++---- kernel/cgroup.c | 2 21 files changed, 162 insertions(+), 76 deletions(-)
fs/dcache.c +82 -27
@@ -45,6 +45,7 @@* - d_flags * - d_name * - d_lru +* - d_count * * Ordering: * dcache_lock
@@ -112,6 +113,7 @@ static void d_callback(struct rcu_head *static void d_free (struct dentry *dentry) {atomic_dec (&dentry_stat.nr_dentry); +BUG_ON (dentry->d_count);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 */
@@ -263,13 +265,23 @@ void dput(struct dentry *dentry)return ; repeat: -if (atomic_read (&dentry->d_count) ==1 ) +if (dentry->d_count ==1 )might_sleep (); -if (!atomic_dec_and_lock (&dentry->d_count, &dcache_lock)) -return ; -spin_lock (&dentry->d_lock); -if (atomic_read (&dentry->d_count)) { +if (dentry->d_count ==1 ) { +if (!spin_trylock (&dcache_lock)) { +/* +* Something of a livelock possibility we could avoid +* by taking dcache_lock and trying again, but we +* want to reduce dcache_lock anyway so this will +* get improved. +*/ +spin_unlock (&dentry->d_lock); + goto repeat; + } + } + dentry->d_count--; +if (dentry->d_count) {spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);return ;
@@ -347,7 +359,7 @@ int d_invalidate(struct dentry * dentry)* working directory or similar). */ spin_lock (&dentry->d_lock); -if (atomic_read (&dentry->d_count) >1 ) { +if (dentry->d_count >1 ) {if (dentry->d_inode &&S_ISDIR (dentry->d_inode->i_mode)) {spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);
@@ -362,29 +374,60 @@ int d_invalidate(struct dentry * dentry) }EXPORT_SYMBOL (d_invalidate); -/* This should be called _only_ with dcache_lock held */ +/* This must be called with dcache_lock and d_lock held */ static inline struct dentry *__dget_locked_dlock (struct dentry *dentry) { -atomic_inc (&dentry->d_count); + dentry->d_count++;dentry_lru_del_init (dentry);return dentry; } +/* This should be called _only_ with dcache_lock held */ static inline struct dentry *__dget_locked (struct dentry *dentry) { -atomic_inc (&dentry->d_count);spin_lock (&dentry->d_lock); -dentry_lru_del_init (dentry); +__dget_locked_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); }EXPORT_SYMBOL (dget_locked); +struct dentry *dget_parent (struct dentry *dentry) +{ +struct dentry *ret; + +repeat: +spin_lock (&dentry->d_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); + goto repeat; + } +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); +/** * d_find_alias - grab a hashed alias of inode * @inode: inode in question
@@ -453,7 +496,7 @@ restart:spin_lock (&dcache_lock);list_for_each_entry (dentry, &inode->i_dentry, d_alias) {spin_lock (&dentry->d_lock); -if (!atomic_read (&dentry->d_count)) { +if (!dentry->d_count) {__dget_locked_dlock (dentry);__d_drop (dentry);spin_unlock (&dentry->d_lock);
@@ -489,7 +532,10 @@ static void prune_one_dentry(struct dent*/ while (dentry) {spin_lock (&dcache_lock); -if (!atomic_dec_and_lock (&dentry->d_count, &dentry->d_lock)) { +spin_lock (&dentry->d_lock); + dentry->d_count--; +if (dentry->d_count) { +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);return ; }
@@ -575,7 +621,7 @@ again:* the LRU because of laziness during lookup. Do not free * it - just keep it off the LRU list. */ -if (atomic_read (&dentry->d_count)) { +if (dentry->d_count) {spin_unlock (&dentry->d_lock);continue ; }
@@ -736,7 +782,7 @@ static void shrink_dcache_for_umount_sub do { struct inode *inode; - if (atomic_read(&dentry->d_count) != 0) { + if (dentry->d_count != 0) { printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%s}" " still in use (%d)"
@@ -745,7 +791,7 @@ static void shrink_dcache_for_umount_sub dentry->d_inode ? dentry->d_inode->i_ino :0UL , dentry->d_name.name, -atomic_read (&dentry->d_count), + dentry->d_count, dentry->d_sb->s_type->name, dentry->d_sb->s_id);BUG ();
@@ -755,7 +801,9 @@ static void shrink_dcache_for_umount_sub parent =NULL ; else { parent = dentry->d_parent; -atomic_dec (&parent->d_count); +spin_lock (&parent->d_lock); + parent->d_count--; +spin_unlock (&parent->d_lock); }list_del (&dentry->d_u.d_child);
@@ -810,7 +858,9 @@ void shrink_dcache_for_umount(struct sup dentry = sb->s_root; sb->s_root =NULL ; -atomic_dec (&dentry->d_count); +spin_lock (&dentry->d_lock); + dentry->d_count--; +spin_unlock (&dentry->d_lock);shrink_dcache_for_umount_subtree (dentry);while (!hlist_empty (&sb->s_anon)) {
@@ -903,17 +953,15 @@ resume:spin_lock (&dentry->d_lock);dentry_lru_del_init (dentry); -spin_unlock (&dentry->d_lock);/* * move only zero ref count dentries to the end * of the unused list for prune_dcache */ -if (!atomic_read (&dentry->d_count)) { -spin_lock (&dentry->d_lock); +if (!dentry->d_count) {dentry_lru_add_tail (dentry); -spin_unlock (&dentry->d_lock); found++; } +spin_unlock (&dentry->d_lock);/* * We can return to the caller if we have found some (this
@@ -1023,7 +1071,7 @@ struct dentry *d_alloc(struct dentry * pmemcpy (dname, name->name, name->len); dname[name->len] =0 ; -atomic_set (&dentry->d_count,1 ); + dentry->d_count =1 ; dentry->d_flags =DCACHE_UNHASHED ;spin_lock_init (&dentry->d_lock); dentry->d_inode =NULL ;
@@ -1497,7 +1545,7 @@ struct dentry * __d_lookup(struct dentry goto next; } -atomic_inc (&dentry->d_count); + dentry->d_count++; found = dentry;spin_unlock (&dentry->d_lock);break ;
@@ -1558,6 +1606,7 @@ int d_validate(struct dentry *dentry, st goto out;spin_lock (&dcache_lock); +spin_lock (&dentry->d_lock);spin_lock (&dcache_hash_lock); base =d_hash (dparent, dentry->d_name.hash);hlist_for_each (lhp,base) {
@@ -1566,12 +1615,14 @@ int d_validate(struct dentry *dentry, st*/ if (dentry == hlist_entry(lhp, struct dentry, d_hash)) {spin_unlock (&dcache_hash_lock); -__dget_locked (dentry); +__dget_locked_dlock (dentry); +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);return 1 ; } }spin_unlock (&dcache_hash_lock); +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock); out:return 0 ;
@@ -1608,7 +1659,7 @@ void d_delete(struct dentry * dentry)spin_lock (&dcache_lock);spin_lock (&dentry->d_lock); isdir =S_ISDIR (dentry->d_inode->i_mode); -if (atomic_read (&dentry->d_count) ==1 ) { +if (dentry->d_count ==1 ) { dentry->d_flags &= ~DCACHE_CANT_MOUNT ;dentry_iput (dentry);fsnotify_nameremove (dentry, isdir);
@@ -2314,11 +2365,15 @@ resume: this_parent = dentry; goto repeat; } -atomic_dec (&dentry->d_count); +spin_lock (&dentry->d_lock); + dentry->d_count--; +spin_unlock (&dentry->d_lock); }if (this_parent != root) { next = this_parent->d_u.d_child.next; -atomic_dec (&this_parent->d_count); +spin_lock (&this_parent->d_lock); + this_parent->d_count--; +spin_unlock (&this_parent->d_lock); this_parent = this_parent->d_parent; goto resume; }
include/linux/dcache.h +15 -14
@@ -87,7 +87,7 @@ full_name_hash(const unsigned char *name#endif struct dentry { -atomic_t d_count; +unsigned int d_count;/* protected by d_lock */ unsigned int d_flags;/* protected by d_lock */ spinlock_t d_lock;/* per dentry lock */ int d_mounted;
@@ -334,17 +334,28 @@ extern char *dentry_path(struct dentry ** needs and they take necessary precautions) you should hold dcache_lock * and call dget_locked() instead of dget(). */ - +static inline struct dentry *dget_dlock (struct dentry *dentry) +{ +if (dentry) { +BUG_ON (!dentry->d_count); + dentry->d_count++; + } +return dentry; +}static inline struct dentry *dget (struct dentry *dentry) {if (dentry) { -BUG_ON (!atomic_read (&dentry->d_count)); -atomic_inc (&dentry->d_count); +spin_lock (&dentry->d_lock); +dget_dlock (dentry); +spin_unlock (&dentry->d_lock); }return dentry; }extern struct dentry *dget_locked (struct dentry *); +extern struct dentry *dget_locked_dlock (struct dentry *); + +extern struct dentry *dget_parent (struct dentry *dentry);/** * d_unhashed - is dentry hashed
@@ -375,16 +386,6 @@ static inline void dont_mount(struct denspin_unlock (&dentry->d_lock); } -static inline struct dentry *dget_parent (struct dentry *dentry) -{ -struct dentry *ret; - -spin_lock (&dentry->d_lock); - ret =dget (dentry->d_parent); -spin_unlock (&dentry->d_lock); -return ret; -} -extern void dput (struct dentry *);static inline int d_mountpoint (struct dentry *dentry)
fs/configfs/dir.c +1 -2
@@ -399,8 +399,7 @@ static void remove_dir(struct dentry * dif (d->d_inode)simple_rmdir (parent->d_inode,d); -pr_debug (" o %s removing done (%d)\n" ,d->d_name.name, -atomic_read (&d->d_count)); +pr_debug (" o %s removing done (%d)\n" ,d->d_name.name, d->d_count);dput (parent); }
fs/locks.c +1 -1
@@ -1375,7 +1375,7 @@ int generic_setlease(struct file *filp,if ((arg ==F_RDLCK ) && (atomic_read (&inode->i_writecount) >0 )) goto out;if ((arg ==F_WRLCK ) - && ((atomic_read (&dentry->d_count) >1 ) + && (dentry->d_count >1 || (atomic_read (&inode->i_count) >1 ))) goto out; }
fs/namei.c +1 -1
@@ -2154,7 +2154,7 @@ void dentry_unhash(struct dentry *dentryshrink_dcache_parent (dentry);spin_lock (&dcache_lock);spin_lock (&dentry->d_lock); -if (atomic_read (&dentry->d_count) ==2 ) +if (dentry->d_count ==2 )__d_drop (dentry);spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);
fs/autofs4/expire.c +4 -4
@@ -198,7 +198,7 @@ static int autofs4_tree_busy(struct vfsmelse ino_count++; -if (atomic_read (&p->d_count) > ino_count) { +if (p->d_count > ino_count) { top_ino->last_used = jiffies;dput (p);return 1 ;
@@ -347,7 +347,7 @@ struct dentry *autofs4_expire_indirect(s/* Path walk currently on this dentry? */ ino_count =atomic_read (&ino->count) +2 ; -if (atomic_read (&dentry->d_count) > ino_count) +if (dentry->d_count > ino_count) goto next;/* Can we umount this guy */
@@ -369,7 +369,7 @@ struct dentry *autofs4_expire_indirect(sif (!exp_leaves) {/* Path walk currently on this dentry? */ ino_count =atomic_read (&ino->count) +1 ; -if (atomic_read (&dentry->d_count) > ino_count) +if (dentry->d_count > ino_count) goto next;if (!autofs4_tree_busy (mnt, dentry, timeout, do_now)) {
@@ -383,7 +383,7 @@ struct dentry *autofs4_expire_indirect(s }else {/* Path walk currently on this dentry? */ ino_count =atomic_read (&ino->count) +1 ; -if (atomic_read (&dentry->d_count) > ino_count) +if (dentry->d_count > ino_count) goto next; expired =autofs4_check_leaves (mnt, dentry, timeout, do_now);
fs/coda/dir.c +1 -1
@@ -612,7 +612,7 @@ static int coda_dentry_revalidate(structif (cii->c_flags &C_FLUSH )coda_flag_inode_children (inode,C_FLUSH ); -if (atomic_read (&de->d_count) >1 ) +if (de->d_count >1 )/* pretend it's valid, but don't change the flags */ goto out;
fs/ecryptfs/inode.c +1 -1
@@ -255,7 +255,7 @@ int ecryptfs_lookup_and_interpose_lower( ecryptfs_dentry->d_parent)); lower_inode = lower_dentry->d_inode;fsstack_copy_attr_atime (ecryptfs_dir_inode, lower_dir_dentry->d_inode); -BUG_ON (!atomic_read (&lower_dentry->d_count)); +BUG_ON (!lower_dentry->d_count);ecryptfs_set_dentry_private (ecryptfs_dentry,kmem_cache_alloc (ecryptfs_dentry_info_cache,GFP_KERNEL ));
fs/nfs/dir.c +5 -5
@@ -1357,7 +1357,7 @@ static int nfs_sillyrename(struct inodedfprintk (VFS ,"NFS: silly-rename(%s/%s, ct=%d)\n" , dentry->d_parent->d_name.name, dentry->d_name.name, -atomic_read (&dentry->d_count)); + dentry->d_count);nfs_inc_stats (dir,NFSIOS_SILLYRENAME );/*
@@ -1466,7 +1466,7 @@ static int nfs_unlink(struct inode *dir,spin_lock (&dcache_lock);spin_lock (&dentry->d_lock); -if (atomic_read (&dentry->d_count) >1 ) { +if (dentry->d_count >1 ) {spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);/* Start asynchronous writeout of the inode */
@@ -1614,7 +1614,7 @@ static int nfs_rename(struct inode *old_dfprintk (VFS ,"NFS: rename(%s/%s -> %s/%s, ct=%d)\n" , old_dentry->d_parent->d_name.name, old_dentry->d_name.name, new_dentry->d_parent->d_name.name, new_dentry->d_name.name, -atomic_read (&new_dentry->d_count)); + new_dentry->d_count);/* * For non-directories, check whether the target is busy and if so,
@@ -1632,7 +1632,7 @@ static int nfs_rename(struct inode *old_ rehash = new_dentry; } -if (atomic_read (&new_dentry->d_count) >2 ) { +if (new_dentry->d_count >2 ) {int err;/* copy the target dentry's name */
@@ -1655,7 +1655,7 @@ static int nfs_rename(struct inode *old_/* * ... prune child dentries and writebacks if needed. */ -if (atomic_read (&old_dentry->d_count) >1 ) { +if (old_dentry->d_count >1 ) {if (S_ISREG (old_inode->i_mode))nfs_wb_all (old_inode);shrink_dcache_parent (old_dentry);
fs/nfsd/vfs.c +2 -3
@@ -1752,8 +1752,7 @@ nfsd_rename(struct svc_rqst *rqstp, stru goto out_dput_new;if (svc_msnfs (ffhp) && - ((atomic_read (&odentry->d_count) >1 ) - || (atomic_read (&ndentry->d_count) >1 ))) { + ((odentry->d_count >1 ) || (ndentry->d_count >1 ))) { host_err = -EPERM ; goto out_dput_new; }
@@ -1839,7 +1838,7 @@ nfsd_unlink(struct svc_rqst *rqstp, struif (type !=S_IFDIR ) {/* It's UNLINK */ #ifdef MSNFS if ((fhp->fh_export->ex_flags &NFSEXP_MSNFS ) && - (atomic_read (&rdentry->d_count) >1 )) { + (rdentry->d_count >1 )) { host_err = -EPERM ; } else#endif
fs/exportfs/expfs.c +8 -1
@@ -74,12 +74,19 @@ static struct dentry * find_disconnected_root(struct dentry *dentry) {dget (dentry); +again:spin_lock (&dentry->d_lock);while (!IS_ROOT (dentry) && (dentry->d_parent->d_flags &DCACHE_DISCONNECTED )) {struct dentry *parent = dentry->d_parent; -dget (parent); + +if (!spin_trylock (&parent->d_lock)) { +spin_unlock (&dentry->d_lock); + goto again; + } +dget_dlock (parent);spin_unlock (&dentry->d_lock); +spin_unlock (&parent->d_lock);dput (dentry); dentry = parent;spin_lock (&dentry->d_lock);
fs/notify/inotify/inotify.c +12 -2
@@ -335,18 +335,28 @@ void inotify_dentry_parent_queue_event(sif (!(dentry->d_flags &DCACHE_INOTIFY_PARENT_WATCHED ))return ; +again:spin_lock (&dentry->d_lock); parent = dentry->d_parent; +if (parent != dentry && !spin_trylock (&parent->d_lock)) { +spin_unlock (&dentry->d_lock); + goto again; + } inode = parent->d_inode;if (inotify_inode_watched (inode)) { -dget (parent); +dget_dlock (parent);spin_unlock (&dentry->d_lock); +if (parent != dentry) +spin_unlock (&parent->d_lock);inotify_inode_queue_event (inode, mask, cookie, name, dentry->d_inode);dput (parent); - }else + }else {spin_unlock (&dentry->d_lock); +if (parent != dentry) +spin_unlock (&parent->d_lock); + } }EXPORT_SYMBOL_GPL (inotify_dentry_parent_queue_event);
fs/smbfs/dir.c +7 -1
@@ -406,6 +406,7 @@ void smb_renew_times(struct dentry * dentry) {dget (dentry); +again:spin_lock (&dentry->d_lock);for (;;) {struct dentry *parent;
@@ -414,8 +415,13 @@ smb_renew_times(struct dentry * dentry)if (IS_ROOT (dentry))break ; parent = dentry->d_parent; -dget (parent); +if (!spin_trylock (&parent->d_lock)) { +spin_unlock (&dentry->d_lock); + goto again; + } +dget_dlock (parent);spin_unlock (&dentry->d_lock); +spin_unlock (&parent->d_lock);dput (dentry); dentry = parent;spin_lock (&dentry->d_lock);
fs/smbfs/proc.c +7 -1
@@ -332,6 +332,7 @@ static int smb_build_path(struct smb_sb_* and store it in reversed order [see reverse_string()] */ dget (entry); +again:spin_lock (&entry->d_lock);while (!IS_ROOT (entry)) {struct dentry *parent;
@@ -350,6 +351,7 @@ static int smb_build_path(struct smb_sb_dput (entry);return len; } +reverse_string (path, len); path += len;if (unicode) {
@@ -361,7 +363,11 @@ static int smb_build_path(struct smb_sb_ maxlen -= len+1 ; parent = entry->d_parent; -dget (parent); +if (!spin_trylock (&parent->d_lock)) { +spin_unlock (&entry->d_lock); + goto again; + } +dget_dlock (parent);spin_unlock (&entry->d_lock);dput (entry); entry = parent;
kernel/cgroup.c +0 -2
@@ -3545,9 +3545,7 @@ again:list_del (&cgrp->sibling);cgroup_unlock_hierarchy (cgrp->root); -spin_lock (&cgrp->dentry->d_lock); d =dget (cgrp->dentry); -spin_unlock (&d->d_lock);cgroup_d_remove_dir (d);dput (d);
arch/powerpc/platforms/cell/spufs/inode.c +1 -1
@@ -161,7 +161,7 @@ static void spufs_prune_dir(struct dentrspin_lock (&dcache_lock);spin_lock (&dentry->d_lock);if (!(d_unhashed (dentry)) && dentry->d_inode) { -dget_locked (dentry); +dget_locked_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
@@ -276,7 +276,7 @@ static int remove_file(struct dentry *paspin_lock (&dcache_lock);spin_lock (&tmp->d_lock);if (!(d_unhashed (tmp) && tmp->d_inode)) { -dget_locked (tmp); +dget_locked_dlock (tmp);__d_drop (tmp);spin_unlock (&tmp->d_lock);spin_unlock (&dcache_lock);
fs/configfs/inode.c +1 -1
@@ -252,7 +252,7 @@ void configfs_drop_dentry(struct configfspin_lock (&dcache_lock);spin_lock (&dentry->d_lock);if (!(d_unhashed (dentry) && dentry->d_inode)) { -dget_locked (dentry); +dget_locked_dlock (dentry);__d_drop (dentry);spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);
fs/notify/fsnotify.c +9 -2
@@ -88,13 +88,18 @@ void __fsnotify_parent(struct dentry *deif (!(dentry->d_flags &DCACHE_FSNOTIFY_PARENT_WATCHED ))return ; +again:spin_lock (&dentry->d_lock); parent = dentry->d_parent; +if (parent != dentry && !spin_trylock (&parent->d_lock)) { +spin_unlock (&dentry->d_lock); + goto again; + } p_inode = parent->d_inode;if (fsnotify_inode_watches_children (p_inode)) {if (p_inode->i_fsnotify_mask & mask) { -dget (parent); +dget_dlock (parent); send = true; } }else {
@@ -104,11 +109,13 @@ void __fsnotify_parent(struct dentry *de* children and update their d_flags to let them know p_inode * doesn't care about them any more. */ -dget (parent); +dget_dlock (parent); should_update_children = true; }spin_unlock (&dentry->d_lock); +if (parent != dentry) +spin_unlock (&parent->d_lock);if (send) {/* we are notifying a parent so come up with the new mask which
fs/ceph/dir.c +3 -1
@@ -149,7 +149,9 @@ more: di =ceph_dentry (dentry); } -atomic_inc (&dentry->d_count); +spin_lock (&dentry->d_lock); + dentry->d_count++; +spin_unlock (&dentry->d_lock);spin_unlock (&dcache_lock);spin_unlock (&inode->i_lock);
fs/ceph/inode.c +2 -2
@@ -863,8 +863,8 @@ static struct dentry *splice_dentry(stru }else if (realdn) {dout ("dn %p (%d) spliced with %p (%d) " "inode %p ino %llx.%llx\n" , - dn,atomic_read (&dn->d_count), - realdn,atomic_read (&realdn->d_count), + dn, dn->d_count, + realdn, realdn->d_count, realdn->d_inode,ceph_vinop (realdn->d_inode));dput (dn); dn = realdn;
fs/ceph/mds_client.c +1 -1
@@ -1371,7 +1371,7 @@ retry: *base =ceph_ino (temp->d_inode); *plen = len;dout ("build_path on %p %d built %llx '%.*s'\n" , - dentry,atomic_read (&dentry->d_count), *base, len, path); + dentry, dentry->d_count, *base, len, path);return path; }
drivers/infiniband/hw/qib/qib_fs.c +1 -1
@@ -454,7 +454,7 @@ static int remove_file(struct dentry *paspin_lock (&dcache_lock);spin_lock (&tmp->d_lock);if (!(d_unhashed (tmp) && tmp->d_inode)) { -dget_locked (tmp); +dget_locked_dlock (tmp);__d_drop (tmp);spin_unlock (&tmp->d_lock);spin_unlock (&dcache_lock);