Skip to contentSkip to conversation

Q. locking order of dcache_lru_lock

DISCUSSION J. R. Okajima 3 participants 7 messages Apr 8, 2011 – Apr 11, 2011

lore
Share & tools
lore
#0 lore raw

Hello Al Viro, Christoph Hellwig and Nick Piggin,

I have a question about the locking order of dcache_lru_lock.

The comment in fs/dcache.c says
* Ordering:
* dentry->d_inode->i_lock
* dentry->d_lock
* dcache_lru_lock

	:::

d_lock should be before dcache_lru_lock.
Actually dentry_lru_(add|del|move_tail) functions (and their callers) do it expectedly.
But __shrink_dcache_sb() looks different.

__shrink_dcache_sb()

{
	:::
relock:
	spin_lock(&dcache_lru_lock);
	while (!list_empty(&sb->s_dentry_lru)) {
		::
		if (!spin_trylock(&dentry->d_lock)) {
			spin_unlock(&dcache_lru_lock);
			cpu_relax();
			goto relock;
		}
	:::
}

When spin_trylock(&dentry->d_lock) successfully acquired d_lock, does the violation of locking order happen (or a deadlock, in worse case)?

By the way, the code is introduced by the commit

	2304450 2011-01-07 fs: dcache scale lru

by Nick Piggin.
Is he allright? Does anyone know anything?
We have not received from him for a long time.

J. R. Okajima

#1 lore raw
Quoted 3 lines · J. R. Okajima

When spin_trylock(&dentry->d_lock) successfully acquired d_lock, does the violation of locking order happen (or a deadlock, in worse case)?

No, since a trylock never actually blocks a deadlock cannot occur.

#2 lore raw

Peter Zijlstra:

Quoted 6 lines · J. R. Okajima
Quoted 3 lines

=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?

J. R. Okajima

#3 lore raw
Quoted 7 lines · J. R. Okajima

Peter Zijlstra:

Quoted 5 lines · J. R. Okajima
Quoted 3 lines

=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

Quoted 7 lines
Quoted 1 line

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?

From fs/dcache.c:

* Ordering:
* dentry->d_inode->i_lock
* dentry->d_lock

 *     dcache_lru_lock
 *     dcache_hash_bucket lock
 *     s_anon lock

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#4 lore raw
In reply to J. R. Okajima
Quoted 11 lines · J. R. Okajima

Peter Zijlstra:

Quoted 6 lines · J. R. Okajima
Quoted 3 lines

=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.

#5 lore raw

Peter Zijlstra:

Quoted 3 lines

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.

I see.
Then lockdep always ignore all tyrlocks?

Thank you for answering.

J. R. Okajima

#6 lore raw
Quoted 7 lines · J. R. Okajima

Peter Zijlstra:

Quoted 3 lines

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.

I see.
Then lockdep always ignore all tyrlocks?

For tracking dependencies, yes. It does register we hold the lock when the trylock is successful.