Re: d_splice_alias() problem.

From: Greg Banks
Date: Tue May 04 2004 - 02:03:02 EST


Neil Brown wrote:
>
> > * Dentry_stat.nr_unused can be be spuriously decremented when dput()
> > races with __dget_unlocked(). Eventual result is nr_unused<0
> > and kswapd loops. This is the problem I mentioned earlier. Note
> > that this is not an NFS-specific problem. Fix is:
> >
> > --- linux.orig/fs/dcache.c Mon May 3 21:46:30 2004
> > +++ linux/fs/dcache.c Mon May 3 21:49:07 2004
> > @@ -255,8 +255,8 @@
> >
> > static inline struct dentry * __dget_locked(struct dentry *dentry)
> > {
> > - atomic_inc(&dentry->d_count);
> > - if (atomic_read(&dentry->d_count) == 1) {
> > + if (atomic_inc(&dentry->d_count) == 1) {
>
> One problem with this is that (in include/asm-i386/atomic.h at least):
> static __inline__ void atomic_inc(atomic_t *v)

Ok, how about this...it's portable, and not racy, but may perturb the
logic slightly by also taking dentries off the unused list in the case
where they already had d_count>=1. I'm not sure how significant that is.
In any case this also passes my tests.


--- linux.orig/fs/dcache.c Mon May 3 21:46:30 2004
+++ linux/fs/dcache.c Tue May 4 14:34:44 2004
@@ -256,7 +256,7 @@
static inline struct dentry * __dget_locked(struct dentry *dentry)
{
atomic_inc(&dentry->d_count);
- if (atomic_read(&dentry->d_count) == 1) {
+ if (!list_empty(&dentry->d_lru)) {
dentry_stat.nr_unused--;
list_del_init(&dentry->d_lru);
}
@@ -663,6 +663,7 @@
if (gfp_mask & __GFP_FS)
prune_dcache(nr);
}
+ BUG_ON(dentry_stat.nr_unused < 0);
return dentry_stat.nr_unused;
}



Greg.
--
Greg Banks, R&D Software Engineer, SGI Australian Software Group.
I don't speak for SGI.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/