Skip to content

Commit b5c84bf

Browse files
author
Nick Piggin
committed
fs: dcache remove dcache_lock
dcache_lock no longer protects anything. remove it. Signed-off-by: Nick Piggin <npiggin@kernel.dk>
1 parent 949854d commit b5c84bf

40 files changed

Lines changed: 109 additions & 307 deletions

File tree

‎Documentation/filesystems/Locking‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ prototypes:
2121
char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen);
2222

2323
locking rules:
24-
dcache_lock rename_lock ->d_lock may block
25-
d_revalidate: no no no yes
26-
d_hash no no no no
27-
d_compare: no yes no no
28-
d_delete: yes no yes no
29-
d_release: no no no yes
30-
d_iput: no no no yes
31-
d_dname: no no no no
24+
rename_lock ->d_lock may block
25+
d_revalidate: no no yes
26+
d_hash no no no
27+
d_compare: yes no no
28+
d_delete: no yes no
29+
d_release: no no yes
30+
d_iput: no no yes
31+
d_dname: no no no
3232

3333
--------------------------- inode_operations ---------------------------
3434
prototypes:

‎Documentation/filesystems/dentry-locking.txt‎

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ significant change is the way d_lookup traverses the hash chain, it
3131
doesn't acquire the dcache_lock for this and rely on RCU to ensure
3232
that the dentry has not been *freed*.
3333

34+
dcache_lock no longer exists, dentry locking is explained in fs/dcache.c
3435

3536
Dcache locking details
3637
======================
@@ -50,14 +51,12 @@ Safe lock-free look-up of dcache hash table
5051

5152
Dcache is a complex data structure with the hash table entries also
5253
linked 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

5756
1. 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

6261
2. 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

8381
4. 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

9492
6. There are several ways to do reference counting of RCU protected
9593
objects. One such example is in ipv4 route cache where deferred

‎Documentation/filesystems/porting‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ had ->revalidate()) add calls in ->follow_link()/->readlink().
216216
->d_parent changes are not protected by BKL anymore. Read access is safe
217217
if at least one of the following is true:
218218
* filesystem has no cross-directory rename()
219-
* dcache_lock is held
220219
* we know that parent had been locked (e.g. we are looking at
221220
->d_parent of ->lookup() argument).
222221
* we are called from ->rename().
@@ -340,3 +339,10 @@ look at examples of other filesystems) for guidance.
340339
.d_hash() calling convention and locking rules are significantly
341340
changed. Read updated documentation in Documentation/filesystems/vfs.txt (and
342341
look at examples of other filesystems) for guidance.
342+
343+
---
344+
[mandatory]
345+
dcache_lock is gone, replaced by fine grained locks. See fs/dcache.c
346+
for details of what locks to replace dcache_lock with in order to protect
347+
particular things. Most of the time, a filesystem only needs ->d_lock, which
348+
protects *all* the dcache state of a given dentry.

‎arch/powerpc/platforms/cell/spufs/inode.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,18 @@ static void spufs_prune_dir(struct dentry *dir)
159159

160160
mutex_lock(&dir->d_inode->i_mutex);
161161
list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
162-
spin_lock(&dcache_lock);
163162
spin_lock(&dentry->d_lock);
164163
if (!(d_unhashed(dentry)) && dentry->d_inode) {
165164
dget_locked_dlock(dentry);
166165
__d_drop(dentry);
167166
spin_unlock(&dentry->d_lock);
168167
simple_unlink(dir->d_inode, dentry);
169-
/* XXX: what is dcache_lock protecting here? Other
168+
/* XXX: what was dcache_lock protecting here? Other
170169
* filesystems (IB, configfs) release dcache_lock
171170
* before unlink */
172-
spin_unlock(&dcache_lock);
173171
dput(dentry);
174172
} else {
175173
spin_unlock(&dentry->d_lock);
176-
spin_unlock(&dcache_lock);
177174
}
178175
}
179176
shrink_dcache_parent(dir);

‎drivers/infiniband/hw/ipath/ipath_fs.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,18 +277,14 @@ static int remove_file(struct dentry *parent, char *name)
277277
goto bail;
278278
}
279279

280-
spin_lock(&dcache_lock);
281280
spin_lock(&tmp->d_lock);
282281
if (!(d_unhashed(tmp) && tmp->d_inode)) {
283282
dget_locked_dlock(tmp);
284283
__d_drop(tmp);
285284
spin_unlock(&tmp->d_lock);
286-
spin_unlock(&dcache_lock);
287285
simple_unlink(parent->d_inode, tmp);
288-
} else {
286+
} else
289287
spin_unlock(&tmp->d_lock);
290-
spin_unlock(&dcache_lock);
291-
}
292288

293289
ret = 0;
294290
bail:

‎drivers/infiniband/hw/qib/qib_fs.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,17 +453,14 @@ static int remove_file(struct dentry *parent, char *name)
453453
goto bail;
454454
}
455455

456-
spin_lock(&dcache_lock);
457456
spin_lock(&tmp->d_lock);
458457
if (!(d_unhashed(tmp) && tmp->d_inode)) {
459458
dget_locked_dlock(tmp);
460459
__d_drop(tmp);
461460
spin_unlock(&tmp->d_lock);
462-
spin_unlock(&dcache_lock);
463461
simple_unlink(parent->d_inode, tmp);
464462
} else {
465463
spin_unlock(&tmp->d_lock);
466-
spin_unlock(&dcache_lock);
467464
}
468465

469466
ret = 0;

‎drivers/staging/pohmelfs/path_entry.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ int pohmelfs_path_length(struct pohmelfs_inode *pi)
101101
d = first;
102102
seq = read_seqbegin(&rename_lock);
103103
rcu_read_lock();
104-
spin_lock(&dcache_lock);
105104

106105
if (!IS_ROOT(d) && d_unhashed(d))
107106
len += UNHASHED_OBSCURE_STRING_SIZE; /* Obscure " (deleted)" string */
@@ -110,7 +109,6 @@ int pohmelfs_path_length(struct pohmelfs_inode *pi)
110109
len += d->d_name.len + 1; /* Plus slash */
111110
d = d->d_parent;
112111
}
113-
spin_unlock(&dcache_lock);
114112
rcu_read_unlock();
115113
if (read_seqretry(&rename_lock, seq))
116114
goto rename_retry;

‎drivers/staging/smbfs/cache.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ smb_invalidate_dircache_entries(struct dentry *parent)
6262
struct list_head *next;
6363
struct dentry *dentry;
6464

65-
spin_lock(&dcache_lock);
6665
spin_lock(&parent->d_lock);
6766
next = parent->d_subdirs.next;
6867
while (next != &parent->d_subdirs) {
@@ -72,7 +71,6 @@ smb_invalidate_dircache_entries(struct dentry *parent)
7271
next = next->next;
7372
}
7473
spin_unlock(&parent->d_lock);
75-
spin_unlock(&dcache_lock);
7674
}
7775

7876
/*
@@ -98,7 +96,6 @@ smb_dget_fpos(struct dentry *dentry, struct dentry *parent, unsigned long fpos)
9896
}
9997

10098
/* If a pointer is invalid, we search the dentry. */
101-
spin_lock(&dcache_lock);
10299
spin_lock(&parent->d_lock);
103100
next = parent->d_subdirs.next;
104101
while (next != &parent->d_subdirs) {
@@ -115,7 +112,6 @@ smb_dget_fpos(struct dentry *dentry, struct dentry *parent, unsigned long fpos)
115112
dent = NULL;
116113
out_unlock:
117114
spin_unlock(&parent->d_lock);
118-
spin_unlock(&dcache_lock);
119115
return dent;
120116
}
121117

‎drivers/usb/core/inode.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ static int usbfs_empty (struct dentry *dentry)
343343
{
344344
struct list_head *list;
345345

346-
spin_lock(&dcache_lock);
347346
spin_lock(&dentry->d_lock);
348347
list_for_each(list, &dentry->d_subdirs) {
349348
struct dentry *de = list_entry(list, struct dentry, d_u.d_child);
@@ -352,13 +351,11 @@ static int usbfs_empty (struct dentry *dentry)
352351
if (usbfs_positive(de)) {
353352
spin_unlock(&de->d_lock);
354353
spin_unlock(&dentry->d_lock);
355-
spin_unlock(&dcache_lock);
356354
return 0;
357355
}
358356
spin_unlock(&de->d_lock);
359357
}
360358
spin_unlock(&dentry->d_lock);
361-
spin_unlock(&dcache_lock);
362359
return 1;
363360
}
364361

‎fs/9p/vfs_inode.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,11 @@ static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode)
270270
{
271271
struct dentry *dentry;
272272

273-
spin_lock(&dcache_lock);
274273
spin_lock(&dcache_inode_lock);
275274
/* Directory should have only one entry. */
276275
BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry));
277276
dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
278277
spin_unlock(&dcache_inode_lock);
279-
spin_unlock(&dcache_lock);
280278
return dentry;
281279
}
282280

0 commit comments

Comments
 (0)