VFS: Go through the LRU list of inode from head
PATCH 1/1 VFS: Go through the LRU list of inode from head
Go through the LRU list of inode from head.
(I'm not sure whether there is any trick here I doesn't get. If yes, any one could explain it)
--- fs/inode.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/inode.c +1 -1
@@ -704,7 +704,7 @@ void prune_icache_sb(struct super_block *sb, int nr_to_scan)if (list_empty (&sb->s_inode_lru))break ; - inode = list_entry(sb->s_inode_lru.prev, struct inode, i_lru); + inode = list_entry(sb->s_inode_lru.next, struct inode, i_lru);/* * we are inverting the sb->s_inode_lru_lock/inode->i_lock here,
Signature · 1 line
1.7.5.4
Quoted 1 line · Cong Meng
Go through the LRU list of inode from head.
IIRC, prune_icache_sb is called(as a shrinker in shrink_slab) in page reclaim path, it is used to free icache. Tail entry in LRU(Least Recently Used) list is the least recently used inode object. When the inode cache has to shrink, the kernel removes entries from the tail.
Quoted 30 lines
(I'm not sure whether there is any trick here I doesn't get. If yes, any one could explain it)
Signed-off-by Cong Meng <[email protected]>---
fs/inode.c| 2 +-1 files changed, 1 insertions(+), 1 deletions(-)fs/inode.c +1
-1@@ -704,7 +704,7 @@ void prune_icache_sb(struct super_block *sb, int nr_to_scan)if (list_empty (&sb->s_inode_lru))break ; - inode = list_entry(sb->s_inode_lru.prev, struct inode, i_lru); + inode = list_entry(sb->s_inode_lru.next, struct inode, i_lru);/* * we are inverting the sb->s_inode_lru_lock/inode->i_lock here, Signature · 7 lines
1.7.5.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Jan Kara
reviewerQuoted 4 lines · Cong Meng
Go through the LRU list of inode from head.
(I'm not sure whether there is any trick here I doesn't get. If yes, any one could explain it)
Look at inode_lru_list_add(). It adds at the head of the list. So you
should take from the tail to get the least recently used element...
Honza
Quoted 26 lines
Signed-off-by Cong Meng <[email protected]>--- fs/inode.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)fs/inode.c +1
-1@@ -704,7 +704,7 @@ void prune_icache_sb(struct super_block *sb, int nr_to_scan)if (list_empty (&sb->s_inode_lru))break ; - inode = list_entry(sb->s_inode_lru.prev, struct inode, i_lru); + inode = list_entry(sb->s_inode_lru.next, struct inode, i_lru);/* * we are inverting the sb->s_inode_lru_lock/inode->i_lock here, Signature · 6 lines
1.7.5.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoting Jan Kara <[email protected]>:
Quoted 7 lines · Cong Meng
Quoted 4 lines
Go through the LRU list of inode from head.
(I'm not sure whether there is any trick here I doesn't get. If yes, any one could explain it)
Look at
inode_lru_list_add(). It adds at the head of the list. So you
should take from the tail to get the least recently used element...
I still have a quetion about the subsequent code and comment:
inode = list_entry(sb->s_inode_lru.prev, struct inode, i_lru); /*
* we are inverting the sb->s_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_tail(&inode->i_lru, &sb->s_inode_lru);
continue;
}Shouldn't the inode be moved to the head to avoid spin on it?
I note that list_move was replaced by list_move_tail purposely in a commit.
and below piece of code (at the bottom of prune_icache_sb()):
if (inode != list_entry(sb->s_inode_lru.next,
struct inode, i_lru))
continue; /* wrong inode or list_empty */
Should the inode be compared against to the tail of the list other than the head after re-get the lru lock?
thanks.
cong.
Quoted 33 lines
Honza
Quoted 23 lines
Signed-off-by Cong Meng <[email protected]>--- fs/inode.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)fs/inode.c +1
-1@@ -704,7 +704,7 @@ void prune_icache_sb(struct super_block *sb, int nr_to_scan)if (list_empty (&sb->s_inode_lru))break ; - inode = list_entry(sb->s_inode_lru.prev, struct inode, i_lru); + inode = list_entry(sb->s_inode_lru.next, struct inode, i_lru);/* * we are inverting the sb->s_inode_lru_lock/inode->i_lock here,
--
1.7.5.4Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
Jan Kara <[email protected]>
SUSE Labs, CR
Jan Kara
reviewerQuoted 18 lines · On Tue 26-06-12 03:35:46, [email protected] wrote:
Quoting Jan Kara <[email protected]>:
Quoted 7 lines · Cong Meng
Quoted 4 lines
Go through the LRU list of inode from head.
(I'm not sure whether there is any trick here I doesn't get. If yes, any one could explain it)
Look at
inode_lru_list_add(). It adds at the head of the list. So you
should take from the tail to get the least recently used element...I still have a quetion about the subsequent code and comment:
inode =
list_entry(sb->s_inode_lru.prev, struct inode, i_lru); /*
* we are inverting the sb->s_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. */
Quoted 6 lines
if (!spin_trylock(&inode->i_lock)) { list_move_tail(&inode->i_lru, &sb->s_inode_lru); continue; }Shouldn't the inode be moved to the head to avoid spin on it?
Yes, it should.
Quoted 1 line
I note that
list_movewas replaced bylist_move_tailpurposely in a commit.
Right, you are speaking about Christoph's commit 62a3ddef? I agree that
commit looks bogus and should be reverted AFAICT. Christoph?
Quoted 9 lines
and below piece of code (at the bottom of
prune_icache_sb()):if (inode != list_entry(sb->s_inode_lru.next,
struct inode,i_lru))
continue; /* wrong inode orlist_empty*/Should the inode be compared against to the tail of the list other than the head
after re-get the lru lock?
And you seem to be right here as well. Thanks for having a look!
Honza
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Signed-off-by Cong Meng <[email protected]>---
fs/inode.c| 2 +-1 files changed, 1 insertions(+), 1 deletions(-)fs/inode.c +1
-1@@ -704,7 +704,7 @@ void prune_icache_sb(struct super_block *sb, int nr_to_scan)if (list_empty (&sb->s_inode_lru))break ; - inode = list_entry(sb->s_inode_lru.prev, struct inode, i_lru); + inode = list_entry(sb->s_inode_lru.next, struct inode, i_lru);/* * we are inverting the sb->s_inode_lru_lock/inode->i_lock here,
--
1.7.5.4
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR