Re: Q. locking order of dcache_lru_lock

Peter Zijlstra
2011-04-11T08:31:04Z

On Mon, 2011-04-11 at 14:09 +0900, J. R. Okajima wrote:
> Peter Zijlstra:
> > On Fri, 2011-04-08 at 22:20 +0900, J. R. Okajima wrote:
> > >=20
> > > When spin_trylock(&dentry->d_lock) successfully acquired d_lock, does
> > > the violation of locking order happen (or a deadlock, in worse case)?=20
> >
> > No, since a trylock never actually blocks a deadlock cannot occur.
>
> Ah, exactly. I had to be sleeping when I wrote about deadlock.
> How about the locking order? Do you think d_lock after dcache_lru_lock
> is a problem?

Not really a problem, locking order is simply a tool/scheme to avoid
deadlocks. Since there is no deadlock potential its fine to 'violate'
locking order.

This is a common pattern with trylocks. In situations where you would
need somewhat expensive lock operations to grab the locks in the right
order, you can trylock to see if you can get them in the wrong order. If
the trylock succeeds, yay! you got it cheap. If not, bummer, and you
have to try the expensive way.