@@ -31,6 +31,7 @@ significant change is the way d_lookup traverses the hash chain, it
3131doesn't acquire the dcache_lock for this and rely on RCU to ensure
3232that the dentry has not been *freed*.
3333
34+ dcache_lock no longer exists, dentry locking is explained in fs/dcache.c
3435
3536Dcache locking details
3637======================
@@ -50,14 +51,12 @@ Safe lock-free look-up of dcache hash table
5051
5152Dcache is a complex data structure with the hash table entries also
5253linked together in other lists. In 2.4 kernel, dcache_lock protected
53- all the lists. We applied RCU only on hash chain walking. The rest of
54- the lists are still protected by dcache_lock. Some of the important
55- changes are :
54+ all the lists. RCU dentry hash walking works like this:
5655
57561. The deletion from hash chain is done using hlist_del_rcu() macro
5857 which doesn't initialize next pointer of the deleted dentry and
5958 this allows us to walk safely lock-free while a deletion is
60- happening.
59+ happening. This is a standard hlist_rcu iteration.
6160
62612. Insertion of a dentry into the hash table is done using
6362 hlist_add_head_rcu() which take care of ordering the writes - the
@@ -66,30 +65,29 @@ changes are :
6665 which has since been replaced by hlist_for_each_entry_rcu(), while
6766 walking the hash chain. The only requirement is that all
6867 initialization to the dentry must be done before
69- hlist_add_head_rcu() since we don't have dcache_lock protection
70- while traversing the hash chain. This isn't different from the
71- existing code.
72-
73- 3. The dentry looked up without holding dcache_lock by cannot be
74- returned for walking if it is unhashed. It then may have a NULL
75- d_inode or other bogosity since RCU doesn't protect the other
76- fields in the dentry. We therefore use a flag DCACHE_UNHASHED to
77- indicate unhashed dentries and use this in conjunction with a
78- per-dentry lock (d_lock). Once looked up without the dcache_lock,
79- we acquire the per-dentry lock (d_lock) and check if the dentry is
80- unhashed. If so, the look-up is failed. If not, the reference count
81- of the dentry is increased and the dentry is returned.
68+ hlist_add_head_rcu() since we don't have lock protection
69+ while traversing the hash chain.
70+
71+ 3. The dentry looked up without holding locks cannot be returned for
72+ walking if it is unhashed. It then may have a NULL d_inode or other
73+ bogosity since RCU doesn't protect the other fields in the dentry. We
74+ therefore use a flag DCACHE_UNHASHED to indicate unhashed dentries
75+ and use this in conjunction with a per-dentry lock (d_lock). Once
76+ looked up without locks, we acquire the per-dentry lock (d_lock) and
77+ check if the dentry is unhashed. If so, the look-up is failed. If not,
78+ the reference count of the dentry is increased and the dentry is
79+ returned.
8280
83814. Once a dentry is looked up, it must be ensured during the path walk
8482 for that component it doesn't go away. In pre-2.5.10 code, this was
8583 done holding a reference to the dentry. dcache_rcu does the same.
8684 In some sense, dcache_rcu path walking looks like the pre-2.5.10
8785 version.
8886
89- 5. All dentry hash chain updates must take the dcache_lock as well as
90- the per-dentry lock in that order. dput() does this to ensure that
91- a dentry that has just been looked up in another CPU doesn't get
92- deleted before dget() can be done on it .
87+ 5. All dentry hash chain updates must take the per-dentry lock (see
88+ fs/dcache.c). This excludes dput() to ensure that a dentry that has
89+ been looked up concurrently does not get deleted before dget() can
90+ take a ref .
9391
94926. There are several ways to do reference counting of RCU protected
9593 objects. One such example is in ipv4 route cache where deferred
0 commit comments