dcache: make dcache more scalable on large system
Subsystems (8)
v2 cover dcache: make dcache more scalable on large system
Change log:
v1->v2
- Include performance improvement in the AIM7 benchmark results because of this patch.
- Modify dget_parent() to avoid taking the lock, if possible, to further improve AIM7 benchmark results.
During some perf-record sessions of the kernel running the high_systime workload of the AIM7 benchmark, it was found that quite a large portion of the spinlock contention was due to the perf_event_mmap_event() function itself. This perf kernel function calls d_path() which, in turn, call path_get() and dput() indirectly. These 3 functions were the hottest functions shown in the perf-report output of the _raw_spin_lock() function in an 8-socket system with 80 cores (hyperthreading off) with a 3.7.10 kernel with a mutex patch applied:
- 11.97% reaim [kernel.kallsyms] [k] _raw_spin_lock
- _raw_spin_lock
+ 46.17% d_path
+ 20.31% path_get
+ 19.75% dput
In fact, the output of the "perf record -s -a" (without call-graph) showed:
11.73% reaim [kernel.kallsyms] [k] _raw_spin_lock 8.85% ls [kernel.kallsyms] [k] _raw_spin_lock 3.97% true [kernel.kallsyms] [k] _raw_spin_lock
Without using the perf monitoring tool, the actual execution profile will be quite different. In fact, with this patch set applied, the output of the same "perf record -s -a" command became:
2.05% reaim [kernel.kallsyms] [k] _raw_spin_lock 0.30% ls [kernel.kallsyms] [k] _raw_spin_lock 0.25% true [kernel.kallsyms] [k] _raw_spin_lock
So the time spent on _raw_spin_lock() function went down from 24.55% to 2.60%. It can be seen that the performance data collected by the perf-record command can be heavily skewed in some cases on a system with a large number of CPUs. This set of patches enables the perf command to give a more accurate and reliable picture of what is really happening in the system. At the same time, they can also improve the general performance of systems especially those with a large number of CPUs.
The d_path() function takes the following two locks:
1. dentry->d_lock [spinlock] from dget()/dget_parent()/dput()
2. rename_lock [seqlock] from d_path()
This set of patches were designed to minimize the locking overhead of these code paths.
The current kernel takes the dentry->d_lock lock whenever it wants to increment or decrement the d_count reference count. However, nothing big will really happen until the reference count goes all the way to 1 or 0. Actually, we don't need to take the lock when reference count is bigger than 1. Instead, atomic cmpxchg() function can be used to increment or decrement the count in these situations. For safety, other reference count update operations have to be changed to use atomic instruction as well.
The rename_lock is a sequence lock. The d_path() function takes the writer lock because it needs to traverse different dentries through pointers to get the full path name. Hence it can't tolerate changes in those pointers. But taking the writer lock also prevent multiple d_path() calls to proceed concurrently.
A solution is to introduce a new lock type where there will be a second type of reader which can block the writers - the sequence read/write lock (seqrwlock). The d_path() and related functions will then be changed to take the reader lock instead of the writer lock. This will allow multiple d_path() operations to proceed concurrently.
Additional performance testing was conducted using the AIM7 benchmark. It is mainly the first patch that has impact on the AIM7 benchmark. Please see the patch description of the first patch on more information about the benchmark results.
Incidentally, these patches also have a favorable impact on Oracle database performance when measured by the Oracle SLOB benchmark.
The following tests with multiple threads were also run on kernels with and without the patch on an 8-socket 80-core system and a PC with 4-core i5 processor:
1. find $HOME -size 0b
2. cat /proc/*/maps /proc/*/numa_maps
3. git diff
For both the find-size and cat-maps tests, the performance difference with hot cache was within a few percentage points and hence within the margin of error. Single-thread performance was slightly worse, but multithread performance was generally a bit better. Apparently, reference count update isn't a significant factor in those tests. Their perf traces indicates that there was less spinlock content in functions like dput(), but the function itself ran a little bit longer on average.
The git-diff test showed no difference in performance. There is a slight increase in system time compensated by a slight decrease in user time.
Of the 4 patches, patch 3 is dependent on patch 2. The other 2 patches are independent can be applied individually.
Waiman Long (4):
dcache: Don't take unnecessary lock in d_count update
dcache: introduce a new sequence read/write lock type
dcache: change rename_lock to a sequence read/write lock
dcache: don't need to take d_lock in prepend_path()
fs/autofs4/waitq.c | 6 +- fs/ceph/mds_client.c | 4 +- fs/cifs/dir.c | 4 +- fs/dcache.c | 125 ++++++++++++++++++++--------------------- fs/namei.c | 2 +- fs/nfs/namespace.c | 6 +- include/linux/dcache.h | 105 +++++++++++++++++++++++++++++++++-- include/linux/seqrwlock.h | 137 +++++++++++++++++++++++++++++++++++++++++++++ kernel/auditsc.c | 4 +- 9 files changed, 311 insertions(+), 82 deletions(-) create mode 100644 include/linux/seqrwlock.h
PATCH v2 1/4 dcache: Don't take unnecessary lock in d_count update
The current code takes the dentry's d_lock lock whenever the d_count reference count is being updated. In reality, nothing big really happens until d_count goes to 0 in dput(). So it is not necessary to take the lock if the reference count won't go to 0.
Without using a lock, multiple threads may update d_count simultaneously. Therefore, atomic instructions must be used to ensure consistency except in shrink_dcache_for_umount*() where the whole superblock is being dismounted and locking is not needed.
The worst case scenarios are:
1. d_lock taken in dput with d_count = 2 in one thread and another thread comes in to atomically decrement d_count without taking the lock. This may result in a d_count of 0 with no deleting action taken.
2. d_lock taken in dput with d_count = 1 in one thread and another thread comes in to atomically increment d_count without taking the lock. This may result in the dentry in the deleted state while having a d_count of 1.
Without taking a lock, we need to make sure the decrementing or incrementing action should not be taken while other threads are updating d_count simultaneously. This can be done by using the atomic cmpxchg instruction which will fail if the underlying value is changed. If the lock is taken, it should be safe to use a simpler atomic increment or decrement instruction.
To make sure that the above worst case scenarios will not happen, the dget() function must take the lock if d_count <= 1. Similarly, the dput() function must take the lock if d_count <= 2. The cmpxchg() call to update d_count will be tried twice before falling back to using the lock as there is a fairly good chance that the cmpxchg() may fail in a busy situation.
Finally, the CPU must have an instructional level cmpxchg instruction or the emulated cmpxchg() function may be too expensive to use. Therefore, the above mentioned changes will only be applied if the __HAVE_ARCH_CMPXCHG flag is set. Most of the major architectures supported by Linux have this flag set with the notation exception of ARM.
As for the performance of the updated reference counting code, it all depends on whether the cmpxchg instruction is used or not. The original code has 2 atomic instructions to lock and unlock the spinlock. The new code path has either 1 atomic cmpxchg instruction or 3 atomic instructions if the lock has to be taken. Depending on how frequent the cmpxchg instruction is used (d_count > 1 or 2), the new code can be faster or slower than the original one.
This patch has a particular big impact on the short workload of the AIM7 benchmark with ramdisk filesystem. The table below show the performance improvement due to this patch on an 8-socket 80-core x86-64 system with a 3.8.5 kernel in a 1/2/4/8 node configuration by using numactl to restrict the execution of the workload on certain nodes.
+-----------------+------------------+------------------+----------+ | Configuration | Mean Transaction | Mean Transaction | % Change | | | Rate w/o patch | Rate with patch | | +-----------------+------------------------------------------------+ | | User Range 10 - 100 | +-----------------+------------------------------------------------+ | 8 nodes, HT off | 1929234 | 2966230 | +53.8% | | 4 nodes, HT off | 1700737 | 3177040 | +86.8% | | 2 nodes, HT off | 1964055 | 3088446 | +57.3% | | 1 node , HT off | 2187851 | 2127176 | -2.8% | +-----------------+------------------------------------------------+ | | User Range 200 - 1000 | +-----------------+------------------------------------------------+ | 8 nodes, HT off | 1096000 | 2474223 | +125.8% | | 4 nodes, HT off | 1369181 | 2731234 | +99.5% | | 2 nodes, HT off | 967425 | 2867641 | +196.4% | | 1 node , HT off | 2052671 | 2042276 | -0.5% | +-----------------+------------------------------------------------+ | | User Range 1100 - 2000 | +-----------------+------------------------------------------------+ | 8 nodes, HT off | 1088118 | 2235631 | +105.5% | | 4 nodes, HT off | 1380696 | 2518980 | +82.4% | | 2 nodes, HT off | 839542 | 2743082 | +226.7% | | 1 node , HT off | 1970821 | 1980873 | +0.5% | +-----------------+------------------+------------------+----------+
It can be seen that with 20 CPUs (2 nodes) or more, this patch can significantly improve the short workload performance. With only 1 node, the performance is similar with or without the patch.
A perf call-graph report of the short workload at 800 users without the patch on 8 nodes indicates that about 88% of the workload's total time were spent in the _raw_spin_lock() function. Almost all of which can be attributed to the following 2 kernel functions:
1. dget_parent (50.14%)
2. dput (49.48%)
With this patch on, the time spent on _raw_spin_lock() is only 1.31% which is a huge improvement.
This impact of this patch on other AIM7 workloads were much more modest. The table below show the mean %change due to this patch on the same 8-socket system with a 3.7.10 kernel.
+--------------+---------------+----------------+-----------------+ | Workload | mean % change | mean % change | mean % change | | | 10-100 users | 200-1000 users | 1100-2000 users | +--------------+---------------+----------------+-----------------+ | alltests | +0.6% | +9.7% | +2.9% | | five_sec | +0.4% | 0.0% | +0.3% | | fserver | +0.7% | +2.4% | +2.0% | | high_systime | -1.5% | -15.2% | -38.0% | | new_fserver | -2.2% | +6.5% | +0.4% | | shared | +3.9% | +1.1% | +6.1% | +--------------+---------------+----------------+-----------------+
The regression in the high_systime workload was probably caused by the decrease in spinlock contention led to a larger increase in mutex contention. In fact, after applying a mutex patch to reduce mutex contention, the performance difference due to the addition of this dcache patch changed to:
+--------------+---------------+----------------+-----------------+ | Workload | mean % change | mean % change | mean % change | | | 10-100 users | 200-1000 users | 1100-2000 users | +--------------+---------------+----------------+-----------------+ | high_systime | -0.1% | -0.2% | +1.2% | +--------------+---------------+----------------+-----------------+
--- fs/dcache.c | 39 ++++++++---------- fs/namei.c | 2 +- include/linux/dcache.h | 101 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 117 insertions(+), 25 deletions(-)
fs/dcache.c +18 -21
@@ -484,7 +484,7 @@ relock: }if (ref) - dentry->d_count--; +dcount_dec (dentry);/* * if dentry was on the d_lru list delete it from there. * inform the fs via d_prune that this dentry is about to be
@@ -530,10 +530,13 @@ void dput(struct dentry *dentry) repeat:if (dentry->d_count ==1 )might_sleep (); +if (dcount_dec_cmpxchg (dentry)) +return ; +spin_lock (&dentry->d_lock);BUG_ON (!dentry->d_count);if (dentry->d_count >1 ) { - dentry->d_count--; +dcount_dec (dentry);spin_unlock (&dentry->d_lock);return ; }
@@ -550,7 +553,7 @@ repeat: dentry->d_flags |=DCACHE_REFERENCED ;dentry_lru_add (dentry); - dentry->d_count--; +dcount_dec (dentry);spin_unlock (&dentry->d_lock);return ;
@@ -621,11 +624,13 @@ EXPORT_SYMBOL(d_invalidate);/* This must be called with d_lock held */ static inline void __dget_dlock (struct dentry *dentry) { - dentry->d_count++; +dcount_inc (dentry); }static inline void __dget (struct dentry *dentry) { +if (dcount_inc_cmpxchg (dentry)) +return ;spin_lock (&dentry->d_lock);__dget_dlock (dentry);spin_unlock (&dentry->d_lock);
@@ -635,22 +640,14 @@ struct dentry *dget_parent(struct dentry *dentry) {struct dentry *ret; -repeat: -/* -* Don't need rcu_dereference because we re-check it was correct under -* the lock. -*/ rcu_read_lock (); - ret = dentry->d_parent; -spin_lock (&ret->d_lock); -if (unlikely (ret != dentry->d_parent)) { -spin_unlock (&ret->d_lock); -rcu_read_unlock (); - goto repeat; - } + ret =rcu_dereference (dentry->d_parent);rcu_read_unlock (); +if (dcount_inc_cmpxchg (ret)) +return ret; +spin_lock (&ret->d_lock);BUG_ON (!ret->d_count); - ret->d_count++; +dcount_inc (ret);spin_unlock (&ret->d_lock);return ret; }
@@ -780,7 +777,7 @@ static void try_prune_one_dentry(struct dentry *dentry)while (dentry) {spin_lock (&dentry->d_lock);if (dentry->d_count >1 ) { - dentry->d_count--; +dcount_dec (dentry);spin_unlock (&dentry->d_lock);return ; }
@@ -1981,7 +1978,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name) goto next; } - dentry->d_count++; +dcount_inc (dentry); found = dentry;spin_unlock (&dentry->d_lock);break ;
@@ -2943,7 +2940,7 @@ resume: }if (!(dentry->d_flags &DCACHE_GENOCIDE )) { dentry->d_flags |=DCACHE_GENOCIDE ; - dentry->d_count--; +dcount_dec (dentry); }spin_unlock (&dentry->d_lock); }
@@ -2951,7 +2948,7 @@ resume:struct dentry *child = this_parent;if (!(this_parent->d_flags &DCACHE_GENOCIDE )) { this_parent->d_flags |=DCACHE_GENOCIDE ; - this_parent->d_count--; +dcount_dec (this_parent); } this_parent =try_to_ascend (this_parent, locked, seq);if (!this_parent)
fs/namei.c +1 -1
@@ -537,7 +537,7 @@ static int unlazy_walk(struct nameidata *nd, struct dentry *dentry)*/ BUG_ON (!IS_ROOT (dentry) && dentry->d_parent != parent);BUG_ON (!parent->d_count); - parent->d_count++; +dcount_inc (parent);spin_unlock (&dentry->d_lock); }spin_unlock (&parent->d_lock);
include/linux/dcache.h +98 -3
131 lines not on this page · raw message
Signature · 1 line
1.7.1
Al Viro
maintainerRe: [PATCH v2 1/4] dcache: Don't take unnecessary lock in d_count update
Quoted 12 lines
fs/dcache.c +0
-7@@ -635,22 +640,14 @@ struct dentry *dget_parent(struct dentry *dentry) {struct dentry *ret; -repeat: -/* -* Don't need rcu_dereference because we re-check it was correct under -* the lock. -*/ rcu_read_lock (); - ret = dentry->d_parent; -spin_lock (&ret->d_lock);
fs/dcache.c struct dentry *dget_parent(struct dentry *dentry) · line 648
Quoted 10 lines
fs/dcache.c +4
-5-if (unlikely (ret != dentry->d_parent)) { -spin_unlock (&ret->d_lock); -rcu_read_unlock (); - goto repeat; - } + ret =rcu_dereference (dentry->d_parent);rcu_read_unlock (); +if (dcount_inc_cmpxchg (ret)) +return ret; +spin_lock (&ret->d_lock);
And WTF is going to protect your "ret" from being freed just as you'd done rcu_read_unlock()?
Re: [PATCH v2 1/4] dcache: Don't take unnecessary lock in d_count update
Quoted 16 lines · Al Viro
Quoted 16 lines
fs/dcache.c +0
-11@@ -635,22 +640,14 @@ struct dentry *dget_parent(struct dentry *dentry) {struct dentry *ret; -repeat: -/* -* Don't need rcu_dereference because we re-check it was correct under -* the lock. -*/ rcu_read_lock (); - ret = dentry->d_parent; -spin_lock (&ret->d_lock); -if (unlikely (ret != dentry->d_parent)) { -spin_unlock (&ret->d_lock); -rcu_read_unlock (); - goto repeat;
Quoted 8 lines
fs/dcache.c struct dentry *dget_parent(struct dentry *dentry) · line 648
Quoted 6 lines
fs/dcache.c +4
-1- } + ret =rcu_dereference (dentry->d_parent);rcu_read_unlock (); +if (dcount_inc_cmpxchg (ret)) +return ret; +spin_lock (&ret->d_lock);And WTF is going to protect your "ret" from being freed just as you'd done
rcu_read_unlock()?
I think I had made a mistake here. I should move the rcu_read_unlock() down to before the return statement as well as after the spin_lock(). Thank for pointing this out. I will fix that in the next version. Anything else that needs to be fixed?
Regards,
Longman
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/4 dcache: Don't take unnecessary lock in d_count update
In reply to Waiman LongThe current code takes the dentry's d_lock lock whenever the d_count reference count is being updated. In reality, nothing big really happens until d_count goes to 0 in dput(). So it is not necessary to take the lock if the reference count won't go to 0.
Without using a lock, multiple threads may update d_count simultaneously. Therefore, atomic instructions must be used to ensure consistency except in shrink_dcache_for_umount*() where the whole superblock is being dismounted and locking is not needed.
The worst case scenarios are:
1. d_lock taken in dput with d_count = 2 in one thread and another thread comes in to atomically decrement d_count without taking the lock. This may result in a d_count of 0 with no deleting action taken.
2. d_lock taken in dput with d_count = 1 in one thread and another thread comes in to atomically increment d_count without taking the lock. This may result in the dentry in the deleted state while having a d_count of 1.
Without taking a lock, we need to make sure the decrementing or incrementing action should not be taken while other threads are updating d_count simultaneously. This can be done by using the atomic cmpxchg instruction which will fail if the underlying value is changed. If the lock is taken, it should be safe to use a simpler atomic increment or decrement instruction.
To make sure that the above worst case scenarios will not happen, the dget() function must take the lock if d_count <= 1. Similarly, the dput() function must take the lock if d_count <= 2. The cmpxchg() call to update d_count will be tried twice before falling back to using the lock as there is a fairly good chance that the cmpxchg() may fail in a busy situation.
Finally, the CPU must have an instructional level cmpxchg instruction or the emulated cmpxchg() function may be too expensive to use. Therefore, the above mentioned changes will only be applied if the __HAVE_ARCH_CMPXCHG flag is set. Most of the major architectures supported by Linux have this flag set with the notation exception of ARM.
As for the performance of the updated reference counting code, it all depends on whether the cmpxchg instruction is used or not. The original code has 2 atomic instructions to lock and unlock the spinlock. The new code path has either 1 atomic cmpxchg instruction or 3 atomic instructions if the lock has to be taken. Depending on how frequent the cmpxchg instruction is used (d_count > 1 or 2), the new code can be faster or slower than the original one.
This patch has a particular big impact on the short workload of the AIM7 benchmark with ramdisk filesystem. The table below show the performance improvement due to this patch on an 8-socket 80-core x86-64 system with a 3.8.5 kernel in a 1/2/4/8 node configuration by using numactl to restrict the execution of the workload on certain nodes.
+-----------------+------------------+------------------+----------+ | Configuration | Mean Transaction | Mean Transaction | % Change | | | Rate w/o patch | Rate with patch | | +-----------------+------------------------------------------------+ | | User Range 10 - 100 | +-----------------+------------------------------------------------+ | 8 nodes, HT off | 1929234 | 2966230 | +53.8% | | 4 nodes, HT off | 1700737 | 3177040 | +86.8% | | 2 nodes, HT off | 1964055 | 3088446 | +57.3% | | 1 node , HT off | 2187851 | 2127176 | -2.8% | +-----------------+------------------------------------------------+ | | User Range 200 - 1000 | +-----------------+------------------------------------------------+ | 8 nodes, HT off | 1096000 | 2474223 | +125.8% | | 4 nodes, HT off | 1369181 | 2731234 | +99.5% | | 2 nodes, HT off | 967425 | 2867641 | +196.4% | | 1 node , HT off | 2052671 | 2042276 | -0.5% | +-----------------+------------------------------------------------+ | | User Range 1100 - 2000 | +-----------------+------------------------------------------------+ | 8 nodes, HT off | 1088118 | 2235631 | +105.5% | | 4 nodes, HT off | 1380696 | 2518980 | +82.4% | | 2 nodes, HT off | 839542 | 2743082 | +226.7% | | 1 node , HT off | 1970821 | 1980873 | +0.5% | +-----------------+------------------+------------------+----------+
It can be seen that with 20 CPUs (2 nodes) or more, this patch can significantly improve the short workload performance. With only 1 node, the performance is similar with or without the patch.
A perf call-graph report of the short workload at 800 users without the patch on 8 nodes indicates that about 88% of the workload's total time were spent in the _raw_spin_lock() function. Almost all of which can be attributed to the following 2 kernel functions:
1. dget_parent (50.14%)
2. dput (49.48%)
With this patch on, the time spent on _raw_spin_lock() is only 1.31% which is a huge improvement.
This impact of this patch on other AIM7 workloads were much more modest. The table below show the mean %change due to this patch on the same 8-socket system with a 3.7.10 kernel.
+--------------+---------------+----------------+-----------------+ | Workload | mean % change | mean % change | mean % change | | | 10-100 users | 200-1000 users | 1100-2000 users | +--------------+---------------+----------------+-----------------+ | alltests | +0.6% | +9.7% | +2.9% | | five_sec | +0.4% | 0.0% | +0.3% | | fserver | +0.7% | +2.4% | +2.0% | | high_systime | -1.5% | -15.2% | -38.0% | | new_fserver | -2.2% | +6.5% | +0.4% | | shared | +3.9% | +1.1% | +6.1% | +--------------+---------------+----------------+-----------------+
The regression in the high_systime workload was probably caused by the decrease in spinlock contention led to a larger increase in mutex contention. In fact, after applying a mutex patch to reduce mutex contention, the performance difference due to the addition of this dcache patch changed to:
+--------------+---------------+----------------+-----------------+ | Workload | mean % change | mean % change | mean % change | | | 10-100 users | 200-1000 users | 1100-2000 users | +--------------+---------------+----------------+-----------------+ | high_systime | -0.1% | -0.2% | +1.2% | +--------------+---------------+----------------+-----------------+
--- fs/dcache.c | 39 ++++++++---------- fs/namei.c | 2 +- include/linux/dcache.h | 101 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 117 insertions(+), 25 deletions(-)
fs/dcache.c +18 -21
@@ -484,7 +484,7 @@ relock: }if (ref) - dentry->d_count--; +dcount_dec (dentry);/* * if dentry was on the d_lru list delete it from there. * inform the fs via d_prune that this dentry is about to be
@@ -530,10 +530,13 @@ void dput(struct dentry *dentry) repeat:if (dentry->d_count ==1 )might_sleep (); +if (dcount_dec_cmpxchg (dentry)) +return ; +spin_lock (&dentry->d_lock);BUG_ON (!dentry->d_count);if (dentry->d_count >1 ) { - dentry->d_count--; +dcount_dec (dentry);spin_unlock (&dentry->d_lock);return ; }
@@ -550,7 +553,7 @@ repeat: dentry->d_flags |=DCACHE_REFERENCED ;dentry_lru_add (dentry); - dentry->d_count--; +dcount_dec (dentry);spin_unlock (&dentry->d_lock);return ;
@@ -621,11 +624,13 @@ EXPORT_SYMBOL(d_invalidate);/* This must be called with d_lock held */ static inline void __dget_dlock (struct dentry *dentry) { - dentry->d_count++; +dcount_inc (dentry); }static inline void __dget (struct dentry *dentry) { +if (dcount_inc_cmpxchg (dentry)) +return ;spin_lock (&dentry->d_lock);__dget_dlock (dentry);spin_unlock (&dentry->d_lock);
@@ -635,22 +640,14 @@ struct dentry *dget_parent(struct dentry *dentry) {struct dentry *ret; -repeat: -/* -* Don't need rcu_dereference because we re-check it was correct under -* the lock. -*/ rcu_read_lock (); - ret = dentry->d_parent; -spin_lock (&ret->d_lock); -if (unlikely (ret != dentry->d_parent)) { -spin_unlock (&ret->d_lock); -rcu_read_unlock (); - goto repeat; - } + ret =rcu_dereference (dentry->d_parent);rcu_read_unlock (); +if (dcount_inc_cmpxchg (ret)) +return ret; +spin_lock (&ret->d_lock);BUG_ON (!ret->d_count); - ret->d_count++; +dcount_inc (ret);spin_unlock (&ret->d_lock);return ret; }
@@ -780,7 +777,7 @@ static void try_prune_one_dentry(struct dentry *dentry)while (dentry) {spin_lock (&dentry->d_lock);if (dentry->d_count >1 ) { - dentry->d_count--; +dcount_dec (dentry);spin_unlock (&dentry->d_lock);return ; }
@@ -1981,7 +1978,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name) goto next; } - dentry->d_count++; +dcount_inc (dentry); found = dentry;spin_unlock (&dentry->d_lock);break ;
@@ -2943,7 +2940,7 @@ resume: }if (!(dentry->d_flags &DCACHE_GENOCIDE )) { dentry->d_flags |=DCACHE_GENOCIDE ; - dentry->d_count--; +dcount_dec (dentry); }spin_unlock (&dentry->d_lock); }
@@ -2951,7 +2948,7 @@ resume:struct dentry *child = this_parent;if (!(this_parent->d_flags &DCACHE_GENOCIDE )) { this_parent->d_flags |=DCACHE_GENOCIDE ; - this_parent->d_count--; +dcount_dec (this_parent); } this_parent =try_to_ascend (this_parent, locked, seq);if (!this_parent)
fs/namei.c +1 -1
@@ -537,7 +537,7 @@ static int unlazy_walk(struct nameidata *nd, struct dentry *dentry)*/ BUG_ON (!IS_ROOT (dentry) && dentry->d_parent != parent);BUG_ON (!parent->d_count); - parent->d_count++; +dcount_inc (parent);spin_unlock (&dentry->d_lock); }spin_unlock (&parent->d_lock);
include/linux/dcache.h +98 -3
131 lines not on this page · raw message
Signature · 1 line
1.7.1
RFC PATCH v2 2/4 dcache: introduce a new sequence read/write lock type
In reply to Waiman LongThe current sequence lock supports 2 types of lock users:
1. A reader who wants a consistent set of information and is willing to retry if the information changes. The information that the reader needs cannot contain pointers, because any writer could invalidate a pointer that a reader was following. This reader will never block but they may have to retry if a writer is in progress.
2. A writer who may need to modify content of a data structure. Writer blocks only if another writer is in progress.
This type of lock is suitable for cases where there are a large number of readers and much less writers. However, it has a limitation that reader who may want to follow pointer or cannot tolerate unexpected changes in the protected data structure must take the writer lock even if it doesn't need to make any changes.
To more efficiently support this type of readers, a new lock type is introduced by this patch: sequence read/write lock. Two types of readers are supported by this new lock:
1. Reader who has the same behavior as a sequence lock reader.
2. Reader who may need to follow pointers. This reader will block if a writer is in progress. In turn, it blocks a writer if it is in progress. Multiple readers of this type can proceed concurrently. Taking this reader lock won't update the sequence number.
This new lock type is a combination of the sequence lock and read/write lock. Hence it will have the same limitation of a read/write lock that writers may be starved if there is a lot of contention.
--- include/linux/seqrwlock.h | 137 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 137 insertions(+), 0 deletions(-) create mode 100644 include/linux/seqrwlock.h
include/linux/seqrwlock.h new file +137 -0
@@ -0,0 +1,137 @@ +#ifndef __LINUX_SEQRWLOCK_H +#define __LINUX_SEQRWLOCK_H +/* +* Sequence Read/Write Lock +* ------------------------ +* This new lock type is a combination of the sequence lock and read/write +* lock. Three types of lock users are supported: +* 1. Reader who wants a consistent set of information and is willing to +* retry if the information changes. The information that the reader +* need cannot contain pointers, because any writer could invalidate +* a pointer that a reader was following. This reader never block but +* they may have to retry if a writer is in progress. +* 2. Reader who may need to follow pointers. This reader will block if +* a writer is in progress. +* 3. Writer who may need to modify content of a data structure. Writer +* blocks if another writer or the 2nd type of reader is in progress. +* +* The current implementation layered on top of the regular read/write +* lock. There is a chance that the writers may be starved by the readers. +* So be careful when you decided to use this lock. +* +* Expected 1st type reader usage: +* do { +* seq = read_seqrwbegin(&foo); +* ... +* } while (read_seqrwretry(&foo, seq)); +* +* Expected 2nd type reader usage: +* read_seqrwlock(&foo) +* ... +* read_seqrwunlock(&foo) +* +* Expected writer usage: +* write_seqrwlock(&foo) +* ... +* write_seqrwunlock(&foo) +* +* Based on the seqlock.h file +* by Waiman Long +*/ + +#include <linux/rwlock.h> +#include <linux/preempt.h> +#include <asm/processor.h> + +typedef struct { +unsigned sequence; +rwlock_t lock; +}seqrwlock_t ; + +#define __SEQRWLOCK_UNLOCKED (lockname) \ + { 0, __RW_LOCK_UNLOCKED(lockname) } + +#define seqrwlock_init (x) \ + do { \ + (x)->sequence = 0; \ + rwlock_init(&(x)->lock); \ + } while (0) + +#define DEFINE_SEQRWLOCK (x) \ + seqrwlock_t x = __SEQRWLOCK_UNLOCKED(x) + +/* For writer: +* Lock out other writers and 2nd type of readers and update the sequence +* number. Don't need preempt_disable() because that is in the read_lock and +* write_lock already. +*/ +static inline void write_seqrwlock (seqrwlock_t *sl) +{ +write_lock (&sl->lock); + ++sl->sequence; +smp_wmb (); +} + +static inline void write_seqrwunlock (seqrwlock_t *sl) +{ +smp_wmb (); + sl->sequence++; +write_unlock (&sl->lock); +} + +static inline int write_tryseqrwlock (seqrwlock_t *sl) +{ +int ret =write_trylock (&sl->lock); + +if (ret) { + ++sl->sequence; +smp_wmb (); + } +return ret; +} + +/* For 2nd type of reader: +* Lock out other writers, but don't update the sequence number +*/ +static inline void read_seqrwlock (seqrwlock_t *sl) +{ +read_lock (&sl->lock); +} + +static inline void read_seqrwunlock (seqrwlock_t *sl) +{ +read_unlock (&sl->lock); +} + +static inline int read_tryseqrwlock (seqrwlock_t *sl) +{ +return read_trylock (&sl->lock); +} + +/* Start of read calculation -- fetch last complete writer token */ +static __always_inline unsigned read_seqrwbegin (const seqrwlock_t *sl) +{ +unsigned ret; + +repeat: + ret =ACCESS_ONCE (sl->sequence); +if (unlikely (ret &1 )) { +cpu_relax (); + goto repeat; + } +smp_rmb (); +return ret; +} + +/* +* Test if reader processed invalid data. +* +* If sequence value changed then writer changed data while in section. +*/ +static __always_inline int read_seqrwretry(const seqrwlock_t *sl, unsigned start) +{ +smp_rmb (); +return unlikely (sl->sequence != start); +} + +#endif /* __LINUX_SEQLOCK_H */
Signature · 1 line
1.7.1
RFC PATCH v2 2/4 dcache: introduce a new sequence read/write lock type
In reply to Waiman LongThe current sequence lock supports 2 types of lock users:
1. A reader who wants a consistent set of information and is willing to retry if the information changes. The information that the reader needs cannot contain pointers, because any writer could invalidate a pointer that a reader was following. This reader will never block but they may have to retry if a writer is in progress.
2. A writer who may need to modify content of a data structure. Writer blocks only if another writer is in progress.
This type of lock is suitable for cases where there are a large number of readers and much less writers. However, it has a limitation that reader who may want to follow pointer or cannot tolerate unexpected changes in the protected data structure must take the writer lock even if it doesn't need to make any changes.
To more efficiently support this type of readers, a new lock type is introduced by this patch: sequence read/write lock. Two types of readers are supported by this new lock:
1. Reader who has the same behavior as a sequence lock reader.
2. Reader who may need to follow pointers. This reader will block if a writer is in progress. In turn, it blocks a writer if it is in progress. Multiple readers of this type can proceed concurrently. Taking this reader lock won't update the sequence number.
This new lock type is a combination of the sequence lock and read/write lock. Hence it will have the same limitation of a read/write lock that writers may be starved if there is a lot of contention.
--- include/linux/seqrwlock.h | 137 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 137 insertions(+), 0 deletions(-) create mode 100644 include/linux/seqrwlock.h
include/linux/seqrwlock.h new file +137 -0
@@ -0,0 +1,137 @@ +#ifndef __LINUX_SEQRWLOCK_H +#define __LINUX_SEQRWLOCK_H +/* +* Sequence Read/Write Lock +* ------------------------ +* This new lock type is a combination of the sequence lock and read/write +* lock. Three types of lock users are supported: +* 1. Reader who wants a consistent set of information and is willing to +* retry if the information changes. The information that the reader +* need cannot contain pointers, because any writer could invalidate +* a pointer that a reader was following. This reader never block but +* they may have to retry if a writer is in progress. +* 2. Reader who may need to follow pointers. This reader will block if +* a writer is in progress. +* 3. Writer who may need to modify content of a data structure. Writer +* blocks if another writer or the 2nd type of reader is in progress. +* +* The current implementation layered on top of the regular read/write +* lock. There is a chance that the writers may be starved by the readers. +* So be careful when you decided to use this lock. +* +* Expected 1st type reader usage: +* do { +* seq = read_seqrwbegin(&foo); +* ... +* } while (read_seqrwretry(&foo, seq)); +* +* Expected 2nd type reader usage: +* read_seqrwlock(&foo) +* ... +* read_seqrwunlock(&foo) +* +* Expected writer usage: +* write_seqrwlock(&foo) +* ... +* write_seqrwunlock(&foo) +* +* Based on the seqlock.h file +* by Waiman Long +*/ + +#include <linux/rwlock.h> +#include <linux/preempt.h> +#include <asm/processor.h> + +typedef struct { +unsigned sequence; +rwlock_t lock; +}seqrwlock_t ; + +#define __SEQRWLOCK_UNLOCKED (lockname) \ + { 0, __RW_LOCK_UNLOCKED(lockname) } + +#define seqrwlock_init (x) \ + do { \ + (x)->sequence = 0; \ + rwlock_init(&(x)->lock); \ + } while (0) + +#define DEFINE_SEQRWLOCK (x) \ + seqrwlock_t x = __SEQRWLOCK_UNLOCKED(x) + +/* For writer: +* Lock out other writers and 2nd type of readers and update the sequence +* number. Don't need preempt_disable() because that is in the read_lock and +* write_lock already. +*/ +static inline void write_seqrwlock (seqrwlock_t *sl) +{ +write_lock (&sl->lock); + ++sl->sequence; +smp_wmb (); +} + +static inline void write_seqrwunlock (seqrwlock_t *sl) +{ +smp_wmb (); + sl->sequence++; +write_unlock (&sl->lock); +} + +static inline int write_tryseqrwlock (seqrwlock_t *sl) +{ +int ret =write_trylock (&sl->lock); + +if (ret) { + ++sl->sequence; +smp_wmb (); + } +return ret; +} + +/* For 2nd type of reader: +* Lock out other writers, but don't update the sequence number +*/ +static inline void read_seqrwlock (seqrwlock_t *sl) +{ +read_lock (&sl->lock); +} + +static inline void read_seqrwunlock (seqrwlock_t *sl) +{ +read_unlock (&sl->lock); +} + +static inline int read_tryseqrwlock (seqrwlock_t *sl) +{ +return read_trylock (&sl->lock); +} + +/* Start of read calculation -- fetch last complete writer token */ +static __always_inline unsigned read_seqrwbegin (const seqrwlock_t *sl) +{ +unsigned ret; + +repeat: + ret =ACCESS_ONCE (sl->sequence); +if (unlikely (ret &1 )) { +cpu_relax (); + goto repeat; + } +smp_rmb (); +return ret; +} + +/* +* Test if reader processed invalid data. +* +* If sequence value changed then writer changed data while in section. +*/ +static __always_inline int read_seqrwretry(const seqrwlock_t *sl, unsigned start) +{ +smp_rmb (); +return unlikely (sl->sequence != start); +} + +#endif /* __LINUX_SEQLOCK_H */
Signature · 1 line
1.7.1
RFC PATCH v2 3/4 dcache: change rename_lock to a sequence read/write lock
In reply to Waiman LongThe d_path() and related kernel functions currently take a writer lock on rename_lock because they need to follow pointers. By changing rename_lock to be the new sequence read/write lock, a reader lock can be taken and multiple d_path() threads can proceed concurrently without blocking each other.
It is unlikely that the frequency of filesystem changes and d_path() name lookup will be high enough to cause writer starvation, the current limitation of the read/write lock should be acceptable in that case.
All the sites where rename_lock is referenced were modified to use the sequence read/write lock declaration and access functions.
When apply this patch to 3.8 or earlier releases, the unused function d_path_with_unreachable() in fs/dcache.c should be removed to avoid compilation warning.
--- fs/autofs4/waitq.c | 6 ++-- fs/ceph/mds_client.c | 4 +- fs/cifs/dir.c | 4 +- fs/dcache.c | 83 ++++++++++++++++++++++++----------------------- fs/nfs/namespace.c | 6 ++-- include/linux/dcache.h | 4 +- kernel/auditsc.c | 4 +- 7 files changed, 56 insertions(+), 55 deletions(-)
fs/autofs4/waitq.c +3 -3
@@ -197,7 +197,7 @@ rename_retry: buf = *name; len =0 ; - seq =read_seqbegin (&rename_lock); + seq =read_seqrwbegin (&rename_lock);rcu_read_lock ();spin_lock (&sbi->fs_lock);for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
@@ -206,7 +206,7 @@ rename_retry:if (!len || --len >NAME_MAX ) {spin_unlock (&sbi->fs_lock);rcu_read_unlock (); -if (read_seqretry (&rename_lock, seq)) +if (read_seqrwretry (&rename_lock, seq)) goto rename_retry;return 0 ; }
@@ -222,7 +222,7 @@ rename_retry: }spin_unlock (&sbi->fs_lock);rcu_read_unlock (); -if (read_seqretry (&rename_lock, seq)) +if (read_seqrwretry (&rename_lock, seq)) goto rename_retry;return len;
fs/ceph/mds_client.c +2 -2
@@ -1486,7 +1486,7 @@ char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base, retry: len =0 ; - seq =read_seqbegin (&rename_lock); + seq =read_seqrwbegin (&rename_lock);rcu_read_lock ();for (temp = dentry; !IS_ROOT (temp);) {struct inode *inode = temp->d_inode;
@@ -1536,7 +1536,7 @@ retry: temp = temp->d_parent; }rcu_read_unlock (); -if (pos !=0 ||read_seqretry (&rename_lock, seq)) { +if (pos !=0 ||read_seqrwretry (&rename_lock, seq)) {pr_err ("build_path did not end path lookup where " "expected, namelen is %d, pos is %d\n" , len, pos);/* presumably this is only possible if racing with a
fs/cifs/dir.c +2 -2
@@ -96,7 +96,7 @@ build_path_from_dentry(struct dentry *direntry) dfsplen =0 ; cifs_bp_rename_retry: namelen = dfsplen; - seq =read_seqbegin (&rename_lock); + seq =read_seqrwbegin (&rename_lock);rcu_read_lock ();for (temp = direntry; !IS_ROOT (temp);) { namelen += (1 + temp->d_name.len);
@@ -136,7 +136,7 @@ cifs_bp_rename_retry: } }rcu_read_unlock (); -if (namelen != dfsplen ||read_seqretry (&rename_lock, seq)) { +if (namelen != dfsplen ||read_seqrwretry (&rename_lock, seq)) {cFYI (1 ,"did not end path lookup where expected. namelen=%d " "dfsplen=%d" , namelen, dfsplen);/* presumably this is only possible if racing with a rename
fs/dcache.c +42 -41
289 lines not on this page · raw message
fs/nfs/namespace.c +3 -3
@@ -60,7 +60,7 @@ rename_retry: *--end ='\0' ; buflen--; - seq =read_seqbegin (&rename_lock); + seq =read_seqrwbegin (&rename_lock);rcu_read_lock ();while (1 ) {spin_lock (&dentry->d_lock);
@@ -76,7 +76,7 @@ rename_retry:spin_unlock (&dentry->d_lock); dentry = dentry->d_parent; } -if (read_seqretry (&rename_lock, seq)) { +if (read_seqrwretry (&rename_lock, seq)) {spin_unlock (&dentry->d_lock);rcu_read_unlock (); goto rename_retry;
@@ -117,7 +117,7 @@ rename_retry: Elong_unlock:spin_unlock (&dentry->d_lock);rcu_read_unlock (); -if (read_seqretry (&rename_lock, seq)) +if (read_seqrwretry (&rename_lock, seq)) goto rename_retry; Elong:return ERR_PTR (-ENAMETOOLONG );
include/linux/dcache.h +2 -2
@@ -6,7 +6,7 @@#include <linux/rculist.h> #include <linux/rculist_bl.h> #include <linux/spinlock.h> -#include <linux/seqlock.h> +#include <linux/seqrwlock.h> #include <linux/cache.h> #include <linux/rcupdate.h>
@@ -210,7 +210,7 @@ struct dentry_operations {#define DCACHE_DENTRY_KILLED 0x100000 -extern seqlock_t rename_lock; +extern seqrwlock_t rename_lock;static inline int dname_external (struct dentry *dentry) {
kernel/auditsc.c +2 -2
@@ -1892,7 +1892,7 @@ retry: drop =NULL ; d = dentry;rcu_read_lock (); - seq =read_seqbegin (&rename_lock); + seq =read_seqrwbegin (&rename_lock);for (;;) {struct inode *inode = d->d_inode;if (inode &&unlikely (!hlist_empty (&inode->i_fsnotify_marks))) {
@@ -1910,7 +1910,7 @@ retry:break ; d = parent; } -if (unlikely (read_seqretry (&rename_lock, seq) || drop)) {/* in this order */ +if (unlikely (read_seqrwretry (&rename_lock, seq) || drop)) {/* in this order */ rcu_read_unlock ();if (!drop) {/* just a race with rename */
Signature · 1 line
1.7.1
RFC PATCH v2 3/4 dcache: change rename_lock to a sequence read/write lock
In reply to Waiman LongThe d_path() and related kernel functions currently take a writer lock on rename_lock because they need to follow pointers. By changing rename_lock to be the new sequence read/write lock, a reader lock can be taken and multiple d_path() threads can proceed concurrently without blocking each other.
It is unlikely that the frequency of filesystem changes and d_path() name lookup will be high enough to cause writer starvation, the current limitation of the read/write lock should be acceptable in that case.
All the sites where rename_lock is referenced were modified to use the sequence read/write lock declaration and access functions.
When apply this patch to 3.8 or earlier releases, the unused function d_path_with_unreachable() in fs/dcache.c should be removed to avoid compilation warning.
--- fs/autofs4/waitq.c | 6 ++-- fs/ceph/mds_client.c | 4 +- fs/cifs/dir.c | 4 +- fs/dcache.c | 83 ++++++++++++++++++++++++----------------------- fs/nfs/namespace.c | 6 ++-- include/linux/dcache.h | 4 +- kernel/auditsc.c | 4 +- 7 files changed, 56 insertions(+), 55 deletions(-)
fs/autofs4/waitq.c +3 -3
@@ -197,7 +197,7 @@ rename_retry: buf = *name; len =0 ; - seq =read_seqbegin (&rename_lock); + seq =read_seqrwbegin (&rename_lock);rcu_read_lock ();spin_lock (&sbi->fs_lock);for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
@@ -206,7 +206,7 @@ rename_retry:if (!len || --len >NAME_MAX ) {spin_unlock (&sbi->fs_lock);rcu_read_unlock (); -if (read_seqretry (&rename_lock, seq)) +if (read_seqrwretry (&rename_lock, seq)) goto rename_retry;return 0 ; }
@@ -222,7 +222,7 @@ rename_retry: }spin_unlock (&sbi->fs_lock);rcu_read_unlock (); -if (read_seqretry (&rename_lock, seq)) +if (read_seqrwretry (&rename_lock, seq)) goto rename_retry;return len;
fs/ceph/mds_client.c +2 -2
@@ -1486,7 +1486,7 @@ char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base, retry: len =0 ; - seq =read_seqbegin (&rename_lock); + seq =read_seqrwbegin (&rename_lock);rcu_read_lock ();for (temp = dentry; !IS_ROOT (temp);) {struct inode *inode = temp->d_inode;
@@ -1536,7 +1536,7 @@ retry: temp = temp->d_parent; }rcu_read_unlock (); -if (pos !=0 ||read_seqretry (&rename_lock, seq)) { +if (pos !=0 ||read_seqrwretry (&rename_lock, seq)) {pr_err ("build_path did not end path lookup where " "expected, namelen is %d, pos is %d\n" , len, pos);/* presumably this is only possible if racing with a
fs/cifs/dir.c +2 -2
@@ -96,7 +96,7 @@ build_path_from_dentry(struct dentry *direntry) dfsplen =0 ; cifs_bp_rename_retry: namelen = dfsplen; - seq =read_seqbegin (&rename_lock); + seq =read_seqrwbegin (&rename_lock);rcu_read_lock ();for (temp = direntry; !IS_ROOT (temp);) { namelen += (1 + temp->d_name.len);
@@ -136,7 +136,7 @@ cifs_bp_rename_retry: } }rcu_read_unlock (); -if (namelen != dfsplen ||read_seqretry (&rename_lock, seq)) { +if (namelen != dfsplen ||read_seqrwretry (&rename_lock, seq)) {cFYI (1 ,"did not end path lookup where expected. namelen=%d " "dfsplen=%d" , namelen, dfsplen);/* presumably this is only possible if racing with a rename
fs/dcache.c +42 -41
289 lines not on this page · raw message
fs/nfs/namespace.c +3 -3
@@ -60,7 +60,7 @@ rename_retry: *--end ='\0' ; buflen--; - seq =read_seqbegin (&rename_lock); + seq =read_seqrwbegin (&rename_lock);rcu_read_lock ();while (1 ) {spin_lock (&dentry->d_lock);
@@ -76,7 +76,7 @@ rename_retry:spin_unlock (&dentry->d_lock); dentry = dentry->d_parent; } -if (read_seqretry (&rename_lock, seq)) { +if (read_seqrwretry (&rename_lock, seq)) {spin_unlock (&dentry->d_lock);rcu_read_unlock (); goto rename_retry;
@@ -117,7 +117,7 @@ rename_retry: Elong_unlock:spin_unlock (&dentry->d_lock);rcu_read_unlock (); -if (read_seqretry (&rename_lock, seq)) +if (read_seqrwretry (&rename_lock, seq)) goto rename_retry; Elong:return ERR_PTR (-ENAMETOOLONG );
include/linux/dcache.h +2 -2
@@ -6,7 +6,7 @@#include <linux/rculist.h> #include <linux/rculist_bl.h> #include <linux/spinlock.h> -#include <linux/seqlock.h> +#include <linux/seqrwlock.h> #include <linux/cache.h> #include <linux/rcupdate.h>
@@ -210,7 +210,7 @@ struct dentry_operations {#define DCACHE_DENTRY_KILLED 0x100000 -extern seqlock_t rename_lock; +extern seqrwlock_t rename_lock;static inline int dname_external (struct dentry *dentry) {
kernel/auditsc.c +2 -2
@@ -1892,7 +1892,7 @@ retry: drop =NULL ; d = dentry;rcu_read_lock (); - seq =read_seqbegin (&rename_lock); + seq =read_seqrwbegin (&rename_lock);for (;;) {struct inode *inode = d->d_inode;if (inode &&unlikely (!hlist_empty (&inode->i_fsnotify_marks))) {
@@ -1910,7 +1910,7 @@ retry:break ; d = parent; } -if (unlikely (read_seqretry (&rename_lock, seq) || drop)) {/* in this order */ +if (unlikely (read_seqrwretry (&rename_lock, seq) || drop)) {/* in this order */ rcu_read_unlock ();if (!drop) {/* just a race with rename */
Signature · 1 line
1.7.1
PATCH v2 4/4 dcache: don't need to take d_lock in prepend_path()
In reply to Waiman LongThe d_lock was used in prepend_path() to protect dentry->d_name from being changed under the hood. As the caller of prepend_path() has to take the rename_lock before calling into it, there is no chance that d_name will be changed. The d_lock lock is only needed when the rename_lock is not taken.
--- fs/dcache.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
fs/dcache.c +1 -2
@@ -2529,6 +2529,7 @@ static int prepend_name(char **buffer, int *buflen, struct qstr *name)* @buflen: pointer to buffer length * * Caller holds the rename_lock. +* There is no need to lock the dentry as its name cannot be changed. */ static int prepend_path(const struct path *path, const struct path *root,
@@ -2555,9 +2556,7 @@ static int prepend_path(const struct path *path, } parent = dentry->d_parent;prefetch (parent); -spin_lock (&dentry->d_lock); error =prepend_name (buffer, buflen, &dentry->d_name); -spin_unlock (&dentry->d_lock);if (!error) error =prepend (buffer, buflen,"/" ,1 );if (error)
Signature · 6 lines
1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 4/4 dcache: don't need to take d_lock in prepend_path()
In reply to Waiman LongThe d_lock was used in prepend_path() to protect dentry->d_name from being changed under the hood. As the caller of prepend_path() has to take the rename_lock before calling into it, there is no chance that d_name will be changed. The d_lock lock is only needed when the rename_lock is not taken.
--- fs/dcache.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
fs/dcache.c +1 -2
@@ -2529,6 +2529,7 @@ static int prepend_name(char **buffer, int *buflen, struct qstr *name)* @buflen: pointer to buffer length * * Caller holds the rename_lock. +* There is no need to lock the dentry as its name cannot be changed. */ static int prepend_path(const struct path *path, const struct path *root,
@@ -2555,9 +2556,7 @@ static int prepend_path(const struct path *path, } parent = dentry->d_parent;prefetch (parent); -spin_lock (&dentry->d_lock); error =prepend_name (buffer, buflen, &dentry->d_name); -spin_unlock (&dentry->d_lock);if (!error) error =prepend (buffer, buflen,"/" ,1 );if (error)
Signature · 1 line
1.7.1