Commit f283c86afe6aa70b733d1ecebad5d9464943b774

Authored by Dave Chinner
Committed by Al Viro
1 parent 02afc410f3

fs: remove inode_lock from iput_final and prune_icache

Now that inode state changes are protected by the inode->i_lock and
the inode LRU manipulations by the inode_lru_lock, we can remove the
inode_lock from prune_icache and the initial part of iput_final().

instead of using the inode_lock to protect the inode during
iput_final, use the inode->i_lock instead. This protects the inode
against new references being taken while we change the inode state
to I_FREEING, as well as preventing prune_icache from grabbing the
inode while we are manipulating it. Hence we no longer need the
inode_lock in iput_final prior to setting I_FREEING on the inode.

For prune_icache, we no longer need the inode_lock to protect the
LRU list, and the inodes themselves are protected against freeing
races by the inode->i_lock. Hence we can lift the inode_lock from
prune_icache as well.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 5 changed files with 17 additions and 22 deletions Side-by-side Diff

Documentation/filesystems/Locking
... ... @@ -128,7 +128,7 @@
128 128 destroy_inode:
129 129 dirty_inode: (must not sleep)
130 130 write_inode:
131   -drop_inode: !!!inode_lock!!!
  131 +drop_inode: !!!inode->i_lock!!!
132 132 evict_inode:
133 133 put_super: write
134 134 write_super: read
Documentation/filesystems/porting
... ... @@ -298,11 +298,14 @@
298 298 remaining links or not. Caller does *not* evict the pagecache or inode-associated
299 299 metadata buffers; getting rid of those is responsibility of method, as it had
300 300 been for ->delete_inode().
301   - ->drop_inode() returns int now; it's called on final iput() with inode_lock
302   -held and it returns true if filesystems wants the inode to be dropped. As before,
303   -generic_drop_inode() is still the default and it's been updated appropriately.
304   -generic_delete_inode() is also alive and it consists simply of return 1. Note that
305   -all actual eviction work is done by caller after ->drop_inode() returns.
  301 +
  302 + ->drop_inode() returns int now; it's called on final iput() with
  303 +inode->i_lock held and it returns true if filesystems wants the inode to be
  304 +dropped. As before, generic_drop_inode() is still the default and it's been
  305 +updated appropriately. generic_delete_inode() is also alive and it consists
  306 +simply of return 1. Note that all actual eviction work is done by caller after
  307 +->drop_inode() returns.
  308 +
306 309 clear_inode() is gone; use end_writeback() instead. As before, it must
307 310 be called exactly once on each call of ->evict_inode() (as it used to be for
308 311 each call of ->delete_inode()). Unlike before, if you are using inode-associated
... ... @@ -394,6 +397,9 @@
394 397 Currently you can only have FALLOC_FL_PUNCH_HOLE with FALLOC_FL_KEEP_SIZE set,
395 398 so the i_size should not change when hole punching, even when puching the end of
396 399 a file off.
  400 +
  401 +--
  402 +[mandatory]
397 403  
398 404 --
399 405 [mandatory]
Documentation/filesystems/vfs.txt
... ... @@ -254,7 +254,7 @@
254 254 should be synchronous or not, not all filesystems check this flag.
255 255  
256 256 drop_inode: called when the last access to the inode is dropped,
257   - with the inode_lock spinlock held.
  257 + with the inode->i_lock spinlock held.
258 258  
259 259 This method should be either NULL (normal UNIX filesystem
260 260 semantics) or "generic_delete_inode" (for filesystems that do not
... ... @@ -650,7 +650,6 @@
650 650 unsigned long reap = 0;
651 651  
652 652 down_read(&iprune_sem);
653   - spin_lock(&inode_lock);
654 653 spin_lock(&inode_lru_lock);
655 654 for (nr_scanned = 0; nr_scanned < nr_to_scan; nr_scanned++) {
656 655 struct inode *inode;
657 656  
... ... @@ -676,8 +675,8 @@
676 675 */
677 676 if (atomic_read(&inode->i_count) ||
678 677 (inode->i_state & ~I_REFERENCED)) {
679   - spin_unlock(&inode->i_lock);
680 678 list_del_init(&inode->i_lru);
  679 + spin_unlock(&inode->i_lock);
681 680 inodes_stat.nr_unused--;
682 681 continue;
683 682 }
684 683  
685 684  
686 685  
... ... @@ -685,20 +684,18 @@
685 684 /* recently referenced inodes get one more pass */
686 685 if (inode->i_state & I_REFERENCED) {
687 686 inode->i_state &= ~I_REFERENCED;
688   - spin_unlock(&inode->i_lock);
689 687 list_move(&inode->i_lru, &inode_lru);
  688 + spin_unlock(&inode->i_lock);
690 689 continue;
691 690 }
692 691 if (inode_has_buffers(inode) || inode->i_data.nrpages) {
693 692 __iget(inode);
694 693 spin_unlock(&inode->i_lock);
695 694 spin_unlock(&inode_lru_lock);
696   - spin_unlock(&inode_lock);
697 695 if (remove_inode_buffers(inode))
698 696 reap += invalidate_mapping_pages(&inode->i_data,
699 697 0, -1);
700 698 iput(inode);
701   - spin_lock(&inode_lock);
702 699 spin_lock(&inode_lru_lock);
703 700  
704 701 if (inode != list_entry(inode_lru.next,
... ... @@ -724,7 +721,6 @@
724 721 else
725 722 __count_vm_events(PGINODESTEAL, reap);
726 723 spin_unlock(&inode_lru_lock);
727   - spin_unlock(&inode_lock);
728 724  
729 725 dispose_list(&freeable);
730 726 up_read(&iprune_sem);
... ... @@ -1082,7 +1078,6 @@
1082 1078  
1083 1079 struct inode *igrab(struct inode *inode)
1084 1080 {
1085   - spin_lock(&inode_lock);
1086 1081 spin_lock(&inode->i_lock);
1087 1082 if (!(inode->i_state & (I_FREEING|I_WILL_FREE))) {
1088 1083 __iget(inode);
... ... @@ -1096,7 +1091,6 @@
1096 1091 */
1097 1092 inode = NULL;
1098 1093 }
1099   - spin_unlock(&inode_lock);
1100 1094 return inode;
1101 1095 }
1102 1096 EXPORT_SYMBOL(igrab);
... ... @@ -1439,7 +1433,6 @@
1439 1433 const struct super_operations *op = inode->i_sb->s_op;
1440 1434 int drop;
1441 1435  
1442   - spin_lock(&inode->i_lock);
1443 1436 WARN_ON(inode->i_state & I_NEW);
1444 1437  
1445 1438 if (op && op->drop_inode)
1446 1439  
1447 1440  
... ... @@ -1452,16 +1445,13 @@
1452 1445 if (!(inode->i_state & (I_DIRTY|I_SYNC)))
1453 1446 inode_lru_list_add(inode);
1454 1447 spin_unlock(&inode->i_lock);
1455   - spin_unlock(&inode_lock);
1456 1448 return;
1457 1449 }
1458 1450  
1459 1451 if (!drop) {
1460 1452 inode->i_state |= I_WILL_FREE;
1461 1453 spin_unlock(&inode->i_lock);
1462   - spin_unlock(&inode_lock);
1463 1454 write_inode_now(inode, 1);
1464   - spin_lock(&inode_lock);
1465 1455 spin_lock(&inode->i_lock);
1466 1456 WARN_ON(inode->i_state & I_NEW);
1467 1457 inode->i_state &= ~I_WILL_FREE;
... ... @@ -1470,7 +1460,6 @@
1470 1460 inode->i_state |= I_FREEING;
1471 1461 inode_lru_list_del(inode);
1472 1462 spin_unlock(&inode->i_lock);
1473   - spin_unlock(&inode_lock);
1474 1463  
1475 1464 evict(inode);
1476 1465 }
... ... @@ -1489,7 +1478,7 @@
1489 1478 if (inode) {
1490 1479 BUG_ON(inode->i_state & I_CLEAR);
1491 1480  
1492   - if (atomic_dec_and_lock(&inode->i_count, &inode_lock))
  1481 + if (atomic_dec_and_lock(&inode->i_count, &inode->i_lock))
1493 1482 iput_final(inode);
1494 1483 }
1495 1484 }
... ... @@ -293,7 +293,7 @@
293 293 return ret;
294 294 }
295 295  
296   -/* called with inode_lock held */
  296 +/* called with inode->i_lock held */
297 297 static int logfs_drop_inode(struct inode *inode)
298 298 {
299 299 struct logfs_super *super = logfs_super(inode->i_sb);