Re: [PATCH] shrink_dcache_parent() races against shrink_dcache_memory()

From: Jan Blunck
Date: Mon Jan 23 2006 - 10:11:47 EST


On Sun, Jan 22, Andrew Morton wrote:

> > -void dput(struct dentry *dentry)
> > +static void dput_locked(struct dentry *dentry, struct list_head *list)
> > {
> > if (!dentry)
> > return;
> >
> > -repeat:
> > - if (atomic_read(&dentry->d_count) == 1)
> > - might_sleep();
> > - if (!atomic_dec_and_lock(&dentry->d_count, &dcache_lock))
> > + if (!atomic_dec_and_test(&dentry->d_count))
> > return;
> >
> > +
> >
> > ...
> >
> > +void dput(struct dentry *dentry)
> > +{
> > + LIST_HEAD(free_list);
> > +
> > + if (!dentry)
> > + return;
> > +
> > + if (atomic_add_unless(&dentry->d_count, -1, 1))
> > + return;
> > +
> > + spin_lock(&dcache_lock);
> > + dput_locked(dentry, &free_list);
> > + spin_unlock(&dcache_lock);
>
> This seems to be an open-coded copy of atomic_dec_and_lock()?
>

Yes, it is. Otherwise the reference counting would be like

if(!atomic_dec_and_lock())
return;
atomic_inc();
dput_locked();

or something similar stupid/racy.

Regards,
Jan

--
Jan Blunck jblunck@xxxxxxx
SuSE LINUX AG - A Novell company
Maxfeldstr. 5 +49-911-74053-608
D-90409 Nürnberg http://www.suse.de
-
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/