Skip to content

Commit

Permalink
fs/dcache: disable preemption on i_dir_seq's write side.
Browse files Browse the repository at this point in the history
This is an update of the original patch.
It reverts the __i_dir_seq rename and inlines preempt_enable_rt().

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  • Loading branch information
Sebastian Andrzej Siewior committed Nov 2, 2021
1 parent 514342e commit 18e08ba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
22 changes: 14 additions & 8 deletions fs/dcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2537,20 +2537,26 @@ EXPORT_SYMBOL(d_rehash);

static inline unsigned start_dir_add(struct inode *dir)
{

preempt_disable_rt();
/*
* The caller has a spinlock_t (dentry::d_lock) acquired which disables
* preemption on !PREEMPT_RT. On PREEMPT_RT the lock does not disable
* preemption and it has be done explicitly.
*/
if (IS_ENABLED(CONFIG_PREEMPT_RT))
preempt_disable();
for (;;) {
unsigned n = dir->__i_dir_seq;
if (!(n & 1) && cmpxchg(&dir->__i_dir_seq, n, n + 1) == n)
unsigned n = dir->i_dir_seq;
if (!(n & 1) && cmpxchg(&dir->i_dir_seq, n, n + 1) == n)
return n;
cpu_relax();
}
}

static inline void end_dir_add(struct inode *dir, unsigned n)
{
smp_store_release(&dir->__i_dir_seq, n + 2);
preempt_enable_rt();
smp_store_release(&dir->i_dir_seq, n + 2);
if (IS_ENABLED(CONFIG_PREEMPT_RT))
preempt_enable();
}

static void d_wait_lookup(struct dentry *dentry)
Expand Down Expand Up @@ -2586,7 +2592,7 @@ struct dentry *d_alloc_parallel(struct dentry *parent,

retry:
rcu_read_lock();
seq = smp_load_acquire(&parent->d_inode->__i_dir_seq);
seq = smp_load_acquire(&parent->d_inode->i_dir_seq);
r_seq = read_seqbegin(&rename_lock);
dentry = __d_lookup_rcu(parent, name, &d_seq);
if (unlikely(dentry)) {
Expand Down Expand Up @@ -2614,7 +2620,7 @@ struct dentry *d_alloc_parallel(struct dentry *parent,
}

hlist_bl_lock(b);
if (unlikely(READ_ONCE(parent->d_inode->__i_dir_seq) != seq)) {
if (unlikely(READ_ONCE(parent->d_inode->i_dir_seq) != seq)) {
hlist_bl_unlock(b);
rcu_read_unlock();
goto retry;
Expand Down
2 changes: 1 addition & 1 deletion fs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
inode->i_pipe = NULL;
inode->i_cdev = NULL;
inode->i_link = NULL;
inode->__i_dir_seq = 0;
inode->i_dir_seq = 0;
inode->i_rdev = 0;
inode->dirtied_when = 0;

Expand Down
2 changes: 1 addition & 1 deletion include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ struct inode {
struct pipe_inode_info *i_pipe;
struct cdev *i_cdev;
char *i_link;
unsigned __i_dir_seq;
unsigned i_dir_seq;
};

__u32 i_generation;
Expand Down

0 comments on commit 18e08ba

Please sign in to comment.