Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 242342
b: refs/heads/master
c: 02afc41
h: refs/heads/master
v: v3
  • Loading branch information
Dave Chinner authored and Al Viro committed Mar 25, 2011
1 parent 890aad4 commit f845359
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b2b2af8e614b4dcd8aca1369d82ce5ad0461a7b1
refs/heads/master: 02afc410f363f98ac4f186341e38dcec13fc0e60
39 changes: 30 additions & 9 deletions trunk/fs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
*
* inode->i_lock protects:
* inode->i_state, inode->i_hash, __iget()
* inode_lru_lock protects:
* inode_lru, inode->i_lru
*
* Lock ordering:
* inode_lock
* inode->i_lock
* inode_lru_lock
*/

/*
Expand Down Expand Up @@ -85,6 +88,7 @@ static unsigned int i_hash_shift __read_mostly;
*/

static LIST_HEAD(inode_lru);
static DEFINE_SPINLOCK(inode_lru_lock);
static struct hlist_head *inode_hashtable __read_mostly;

/*
Expand Down Expand Up @@ -356,18 +360,22 @@ EXPORT_SYMBOL(ihold);

static void inode_lru_list_add(struct inode *inode)
{
spin_lock(&inode_lru_lock);
if (list_empty(&inode->i_lru)) {
list_add(&inode->i_lru, &inode_lru);
inodes_stat.nr_unused++;
}
spin_unlock(&inode_lru_lock);
}

static void inode_lru_list_del(struct inode *inode)
{
spin_lock(&inode_lru_lock);
if (!list_empty(&inode->i_lru)) {
list_del_init(&inode->i_lru);
inodes_stat.nr_unused--;
}
spin_unlock(&inode_lru_lock);
}

static inline void __inode_sb_list_add(struct inode *inode)
Expand Down Expand Up @@ -543,10 +551,9 @@ void evict_inodes(struct super_block *sb)
}

inode->i_state |= I_FREEING;
if (!(inode->i_state & (I_DIRTY | I_SYNC)))
inodes_stat.nr_unused--;
inode_lru_list_del(inode);
spin_unlock(&inode->i_lock);
list_move(&inode->i_lru, &dispose);
list_add(&inode->i_lru, &dispose);
}
spin_unlock(&inode_lock);

Expand Down Expand Up @@ -596,10 +603,9 @@ int invalidate_inodes(struct super_block *sb, bool kill_dirty)
}

inode->i_state |= I_FREEING;
if (!(inode->i_state & (I_DIRTY | I_SYNC)))
inodes_stat.nr_unused--;
inode_lru_list_del(inode);
spin_unlock(&inode->i_lock);
list_move(&inode->i_lru, &dispose);
list_add(&inode->i_lru, &dispose);
}
spin_unlock(&inode_lock);

Expand All @@ -623,7 +629,7 @@ static int can_unuse(struct inode *inode)

/*
* Scan `goal' inodes on the unused list for freeable ones. They are moved to a
* temporary list and then are freed outside inode_lock by dispose_list().
* temporary list and then are freed outside inode_lru_lock by dispose_list().
*
* Any inodes which are pinned purely because of attached pagecache have their
* pagecache removed. If the inode has metadata buffers attached to
Expand All @@ -645,6 +651,7 @@ static void prune_icache(int nr_to_scan)

down_read(&iprune_sem);
spin_lock(&inode_lock);
spin_lock(&inode_lru_lock);
for (nr_scanned = 0; nr_scanned < nr_to_scan; nr_scanned++) {
struct inode *inode;

Expand All @@ -653,11 +660,20 @@ static void prune_icache(int nr_to_scan)

inode = list_entry(inode_lru.prev, struct inode, i_lru);

/*
* we are inverting the inode_lru_lock/inode->i_lock here,
* so use a trylock. If we fail to get the lock, just move the
* inode to the back of the list so we don't spin on it.
*/
if (!spin_trylock(&inode->i_lock)) {
list_move(&inode->i_lru, &inode_lru);
continue;
}

/*
* Referenced or dirty inodes are still in use. Give them
* another pass through the LRU as we canot reclaim them now.
*/
spin_lock(&inode->i_lock);
if (atomic_read(&inode->i_count) ||
(inode->i_state & ~I_REFERENCED)) {
spin_unlock(&inode->i_lock);
Expand All @@ -676,17 +692,21 @@ static void prune_icache(int nr_to_scan)
if (inode_has_buffers(inode) || inode->i_data.nrpages) {
__iget(inode);
spin_unlock(&inode->i_lock);
spin_unlock(&inode_lru_lock);
spin_unlock(&inode_lock);
if (remove_inode_buffers(inode))
reap += invalidate_mapping_pages(&inode->i_data,
0, -1);
iput(inode);
spin_lock(&inode_lock);
spin_lock(&inode_lru_lock);

if (inode != list_entry(inode_lru.next,
struct inode, i_lru))
continue; /* wrong inode or list_empty */
spin_lock(&inode->i_lock);
/* avoid lock inversions with trylock */
if (!spin_trylock(&inode->i_lock))
continue;
if (!can_unuse(inode)) {
spin_unlock(&inode->i_lock);
continue;
Expand All @@ -703,6 +723,7 @@ static void prune_icache(int nr_to_scan)
__count_vm_events(KSWAPD_INODESTEAL, reap);
else
__count_vm_events(PGINODESTEAL, reap);
spin_unlock(&inode_lru_lock);
spin_unlock(&inode_lock);

dispose_list(&freeable);
Expand Down

0 comments on commit f845359

Please sign in to comment.