Commit dc0474be3e27463d4d4a2793f82366eed906f223

Authored by Nick Piggin
1 parent 357f8e658b

fs: dcache rationalise dget variants

dget_locked was a shortcut to avoid the lazy lru manipulation when we already
held dcache_lock (lru manipulation was relatively cheap at that point).
However, how that the lru lock is an innermost one, we never hold it at any
caller, so the lock cost can now be avoided. We already have well working lazy
dcache LRU, so it should be fine to defer LRU manipulations to scan time.

Signed-off-by: Nick Piggin <npiggin@kernel.dk>

Showing 12 changed files with 24 additions and 47 deletions Side-by-side Diff

arch/powerpc/platforms/cell/spufs/inode.c
... ... @@ -161,7 +161,7 @@
161 161 list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
162 162 spin_lock(&dentry->d_lock);
163 163 if (!(d_unhashed(dentry)) && dentry->d_inode) {
164   - dget_locked_dlock(dentry);
  164 + dget_dlock(dentry);
165 165 __d_drop(dentry);
166 166 spin_unlock(&dentry->d_lock);
167 167 simple_unlink(dir->d_inode, dentry);
drivers/infiniband/hw/ipath/ipath_fs.c
... ... @@ -279,7 +279,7 @@
279 279  
280 280 spin_lock(&tmp->d_lock);
281 281 if (!(d_unhashed(tmp) && tmp->d_inode)) {
282   - dget_locked_dlock(tmp);
  282 + dget_dlock(tmp);
283 283 __d_drop(tmp);
284 284 spin_unlock(&tmp->d_lock);
285 285 simple_unlink(parent->d_inode, tmp);
drivers/infiniband/hw/qib/qib_fs.c
... ... @@ -455,7 +455,7 @@
455 455  
456 456 spin_lock(&tmp->d_lock);
457 457 if (!(d_unhashed(tmp) && tmp->d_inode)) {
458   - dget_locked_dlock(tmp);
  458 + dget_dlock(tmp);
459 459 __d_drop(tmp);
460 460 spin_unlock(&tmp->d_lock);
461 461 simple_unlink(parent->d_inode, tmp);
drivers/staging/smbfs/cache.c
... ... @@ -102,7 +102,7 @@
102 102 dent = list_entry(next, struct dentry, d_u.d_child);
103 103 if ((unsigned long)dent->d_fsdata == fpos) {
104 104 if (dent->d_inode)
105   - dget_locked(dent);
  105 + dget(dent);
106 106 else
107 107 dent = NULL;
108 108 goto out_unlock;
... ... @@ -252,7 +252,7 @@
252 252 if (dentry) {
253 253 spin_lock(&dentry->d_lock);
254 254 if (!(d_unhashed(dentry) && dentry->d_inode)) {
255   - dget_locked_dlock(dentry);
  255 + dget_dlock(dentry);
256 256 __d_drop(dentry);
257 257 spin_unlock(&dentry->d_lock);
258 258 simple_unlink(parent->d_inode, dentry);
... ... @@ -429,33 +429,18 @@
429 429 EXPORT_SYMBOL(d_invalidate);
430 430  
431 431 /* This must be called with d_lock held */
432   -static inline struct dentry * __dget_locked_dlock(struct dentry *dentry)
  432 +static inline void __dget_dlock(struct dentry *dentry)
433 433 {
434 434 dentry->d_count++;
435   - dentry_lru_del(dentry);
436   - return dentry;
437 435 }
438 436  
439   -/* This must be called with d_lock held */
440   -static inline struct dentry * __dget_locked(struct dentry *dentry)
  437 +static inline void __dget(struct dentry *dentry)
441 438 {
442 439 spin_lock(&dentry->d_lock);
443   - __dget_locked_dlock(dentry);
  440 + __dget_dlock(dentry);
444 441 spin_unlock(&dentry->d_lock);
445   - return dentry;
446 442 }
447 443  
448   -struct dentry * dget_locked_dlock(struct dentry *dentry)
449   -{
450   - return __dget_locked_dlock(dentry);
451   -}
452   -
453   -struct dentry * dget_locked(struct dentry *dentry)
454   -{
455   - return __dget_locked(dentry);
456   -}
457   -EXPORT_SYMBOL(dget_locked);
458   -
459 444 struct dentry *dget_parent(struct dentry *dentry)
460 445 {
461 446 struct dentry *ret;
... ... @@ -512,7 +497,7 @@
512 497 (alias->d_flags & DCACHE_DISCONNECTED)) {
513 498 discon_alias = alias;
514 499 } else if (!want_discon) {
515   - __dget_locked_dlock(alias);
  500 + __dget_dlock(alias);
516 501 spin_unlock(&alias->d_lock);
517 502 return alias;
518 503 }
... ... @@ -525,7 +510,7 @@
525 510 if (S_ISDIR(inode->i_mode) || !d_unhashed(alias)) {
526 511 if (IS_ROOT(alias) &&
527 512 (alias->d_flags & DCACHE_DISCONNECTED)) {
528   - __dget_locked_dlock(alias);
  513 + __dget_dlock(alias);
529 514 spin_unlock(&alias->d_lock);
530 515 return alias;
531 516 }
... ... @@ -561,7 +546,7 @@
561 546 list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
562 547 spin_lock(&dentry->d_lock);
563 548 if (!dentry->d_count) {
564   - __dget_locked_dlock(dentry);
  549 + __dget_dlock(dentry);
565 550 __d_drop(dentry);
566 551 spin_unlock(&dentry->d_lock);
567 552 spin_unlock(&dcache_inode_lock);
... ... @@ -1257,7 +1242,8 @@
1257 1242 * don't need child lock because it is not subject
1258 1243 * to concurrency here
1259 1244 */
1260   - dentry->d_parent = dget_dlock(parent);
  1245 + __dget_dlock(parent);
  1246 + dentry->d_parent = parent;
1261 1247 dentry->d_sb = parent->d_sb;
1262 1248 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
1263 1249 spin_unlock(&parent->d_lock);
... ... @@ -1360,7 +1346,7 @@
1360 1346 continue;
1361 1347 if (memcmp(qstr->name, name, len))
1362 1348 continue;
1363   - dget_locked(alias);
  1349 + __dget(alias);
1364 1350 return alias;
1365 1351 }
1366 1352  
... ... @@ -1613,7 +1599,7 @@
1613 1599 * reference to it, move it in place and use it.
1614 1600 */
1615 1601 new = list_entry(inode->i_dentry.next, struct dentry, d_alias);
1616   - dget_locked(new);
  1602 + __dget(new);
1617 1603 spin_unlock(&dcache_inode_lock);
1618 1604 security_d_instantiate(found, inode);
1619 1605 d_move(new, found);
... ... @@ -1789,7 +1775,7 @@
1789 1775 list_for_each_entry(child, &dparent->d_subdirs, d_u.d_child) {
1790 1776 if (dentry == child) {
1791 1777 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
1792   - __dget_locked_dlock(dentry);
  1778 + __dget_dlock(dentry);
1793 1779 spin_unlock(&dentry->d_lock);
1794 1780 spin_unlock(&dparent->d_lock);
1795 1781 return 1;
... ... @@ -49,7 +49,7 @@
49 49  
50 50 spin_lock(&dcache_inode_lock);
51 51 list_for_each_entry(dentry, &result->d_inode->i_dentry, d_alias) {
52   - dget_locked(dentry);
  52 + dget(dentry);
53 53 spin_unlock(&dcache_inode_lock);
54 54 if (toput)
55 55 dput(toput);
... ... @@ -397,7 +397,7 @@
397 397 dent = list_entry(next, struct dentry, d_u.d_child);
398 398 if ((unsigned long)dent->d_fsdata == fpos) {
399 399 if (dent->d_inode)
400   - dget_locked(dent);
  400 + dget(dent);
401 401 else
402 402 dent = NULL;
403 403 spin_unlock(&parent->d_lock);
... ... @@ -178,7 +178,7 @@
178 178 mlog(0, "dentry found: %.*s\n",
179 179 dentry->d_name.len, dentry->d_name.name);
180 180  
181   - dget_locked_dlock(dentry);
  181 + dget_dlock(dentry);
182 182 spin_unlock(&dentry->d_lock);
183 183 break;
184 184 }
include/linux/dcache.h
... ... @@ -287,23 +287,17 @@
287 287 /* Allocation counts.. */
288 288  
289 289 /**
290   - * dget, dget_locked - get a reference to a dentry
  290 + * dget, dget_dlock - get a reference to a dentry
291 291 * @dentry: dentry to get a reference to
292 292 *
293 293 * Given a dentry or %NULL pointer increment the reference count
294 294 * if appropriate and return the dentry. A dentry will not be
295   - * destroyed when it has references. dget() should never be
296   - * called for dentries with zero reference counter. For these cases
297   - * (preferably none, functions in dcache.c are sufficient for normal
298   - * needs and they take necessary precautions) you should hold d_lock
299   - * and call dget_dlock() instead of dget().
  295 + * destroyed when it has references.
300 296 */
301 297 static inline struct dentry *dget_dlock(struct dentry *dentry)
302 298 {
303   - if (dentry) {
304   - BUG_ON(!dentry->d_count);
  299 + if (dentry)
305 300 dentry->d_count++;
306   - }
307 301 return dentry;
308 302 }
309 303  
... ... @@ -316,9 +310,6 @@
316 310 }
317 311 return dentry;
318 312 }
319   -
320   -extern struct dentry * dget_locked(struct dentry *);
321   -extern struct dentry * dget_locked_dlock(struct dentry *);
322 313  
323 314 extern struct dentry *dget_parent(struct dentry *dentry);
324 315  
... ... @@ -887,7 +887,7 @@
887 887 /* This should never be called on a cgroup
888 888 * directory with child cgroups */
889 889 BUG_ON(d->d_inode->i_mode & S_IFDIR);
890   - dget_locked_dlock(d);
  890 + dget_dlock(d);
891 891 spin_unlock(&d->d_lock);
892 892 spin_unlock(&dentry->d_lock);
893 893 d_delete(d);
security/selinux/selinuxfs.c
... ... @@ -1154,7 +1154,7 @@
1154 1154 list_del_init(node);
1155 1155  
1156 1156 if (d->d_inode) {
1157   - dget_locked_dlock(d);
  1157 + dget_dlock(d);
1158 1158 spin_unlock(&de->d_lock);
1159 1159 spin_unlock(&d->d_lock);
1160 1160 d_delete(d);