Skip to content

Commit 50417d2

Browse files
Sebastian Andrzej SiewiorAl Viro
authored andcommitted
fs/dcache: Move wakeup out of i_seq_dir write held region.
__d_add() and __d_move() wake up waiters on dentry::d_wait from within the i_seq_dir write held region. This violates the PREEMPT_RT constraints as the wake up acquires wait_queue_head::lock which is a "sleeping" spinlock on RT. There is no requirement to do so. __d_lookup_unhash() has cleared DCACHE_PAR_LOOKUP and dentry::d_wait and returned the now unreachable wait queue head pointer to the caller, so the actual wake up can be postponed until the i_dir_seq write side critical section is left. The only requirement is that dentry::lock is held across the whole sequence including the wake up. The previous commit includes an analysis why this is considered safe. Move the wake up past end_dir_add() which leaves the i_dir_seq write side critical section and enables preemption. For non RT kernels there is no difference because preemption is still disabled due to dentry::lock being held, but it shortens the time between wake up and unlocking dentry::lock, which reduces the contention for the woken up waiter. Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 45f78b0 commit 50417d2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

fs/dcache.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,11 +2581,13 @@ static inline unsigned start_dir_add(struct inode *dir)
25812581
}
25822582
}
25832583

2584-
static inline void end_dir_add(struct inode *dir, unsigned n)
2584+
static inline void end_dir_add(struct inode *dir, unsigned int n,
2585+
wait_queue_head_t *d_wait)
25852586
{
25862587
smp_store_release(&dir->i_dir_seq, n + 2);
25872588
if (IS_ENABLED(CONFIG_PREEMPT_RT))
25882589
preempt_enable();
2590+
wake_up_all(d_wait);
25892591
}
25902592

25912593
static void d_wait_lookup(struct dentry *dentry)
@@ -2756,7 +2758,6 @@ static inline void __d_add(struct dentry *dentry, struct inode *inode)
27562758
dir = dentry->d_parent->d_inode;
27572759
n = start_dir_add(dir);
27582760
d_wait = __d_lookup_unhash(dentry);
2759-
wake_up_all(d_wait);
27602761
}
27612762
if (inode) {
27622763
unsigned add_flags = d_flags_for_inode(inode);
@@ -2768,7 +2769,7 @@ static inline void __d_add(struct dentry *dentry, struct inode *inode)
27682769
}
27692770
__d_rehash(dentry);
27702771
if (dir)
2771-
end_dir_add(dir, n);
2772+
end_dir_add(dir, n, d_wait);
27722773
spin_unlock(&dentry->d_lock);
27732774
if (inode)
27742775
spin_unlock(&inode->i_lock);
@@ -2947,7 +2948,6 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
29472948
dir = target->d_parent->d_inode;
29482949
n = start_dir_add(dir);
29492950
d_wait = __d_lookup_unhash(target);
2950-
wake_up_all(d_wait);
29512951
}
29522952

29532953
write_seqcount_begin(&dentry->d_seq);
@@ -2983,7 +2983,7 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
29832983
write_seqcount_end(&dentry->d_seq);
29842984

29852985
if (dir)
2986-
end_dir_add(dir, n);
2986+
end_dir_add(dir, n, d_wait);
29872987

29882988
if (dentry->d_parent != old_parent)
29892989
spin_unlock(&dentry->d_parent->d_lock);

0 commit comments

Comments
 (0)