The bug of iput() removal from flusher thread?
Hi,
In 169ebd90131b2ffca74bb2dbe7eeacd39fb83714 commit, writeback doesn't __iget()/iput() anymore.
This means nobody moves the inode to lru list. I.e.
new_inode()
dirty_inode()
iput_final()
/* keep inode without adding lru */
flush indoes
/* clean inode is not on lru */I noticed this situation in my FS though, I think the same bug is on all FSes of linus tree too, after this commit.
Am I missing the something?
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Quoted 14 lines · OGAWA Hirofumi
Hi,
In
169ebd90131b2ffca74bb2dbe7eeacd39fb83714commit, writeback doesn't __iget()/iput() anymore.This means nobody moves the inode to lru list. I.e.
new_inode() dirty_inode() iput_final() /* keep inode without adding lru */ flush indoes /* clean inode is not on lru */
Quoted 4 lines
I noticed this situation in my FS though, I think the same bug is on all FSes of linus tree too, after this commit.
Am I missing the something?
This seems to be reproducible by the following,
#!/bin/sh
for i in $(seq -w 1000); do
for j in $(seq -w 1000); do
for k in $(seq -w 1000); do
mkdir -p $i/$j
echo $i/$j/$k > $i/$j/$k
echo 2 > /proc/sys/vm/drop_caches
done
donedone
Some inodes never be reclaimed, and ls -l frees those inodes (stat(2) does iget/iput).
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Jan Kara
reviewerQuoted 33 lines · OGAWA Hirofumi
Quoted 14 lines · OGAWA Hirofumi
Hi,
In
169ebd90131b2ffca74bb2dbe7eeacd39fb83714commit, writeback doesn't __iget()/iput() anymore.This means nobody moves the inode to lru list. I.e.
new_inode() dirty_inode() iput_final() /* keep inode without adding lru */ flush indoes /* clean inode is not on lru */Quoted 4 lines
I noticed this situation in my FS though, I think the same bug is on all FSes of linus tree too, after this commit.
Am I missing the something?
This seems to be reproducible by the following,
#!/bin/sh
for i in $(seq -w 1000); do
for j in $(seq -w 1000); do for k in $(seq -w 1000); do mkdir -p $i/$j echo $i/$j/$k > $i/$j/$k echo 2 > /proc/sys/vm/drop_caches done done
Quoted 4 lines
done
Some inodes never be reclaimed, and ls -l frees those inodes (stat(2) does iget/iput).
So looking into the code I agree we won't put inode into the LRU when it
is dirty or under writeback and after writeback is done it won't happen either. That's certainly a bug. But I have hard time reproducing your results because on my kernels even dcache doesn't get shrunk thus inodes are pinned in memory by it. Not sure what's going on yet but I'll investigate. Thanks for report!
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerQuoted 36 lines · Jan Kara
Quoted 35 lines · OGAWA Hirofumi
Quoted 14 lines · OGAWA Hirofumi
Hi,
In
169ebd90131b2ffca74bb2dbe7eeacd39fb83714commit, writeback doesn't __iget()/iput() anymore.This means nobody moves the inode to lru list. I.e.
new_inode() dirty_inode() iput_final() /* keep inode without adding lru */ flush indoes /* clean inode is not on lru */Quoted 4 lines
I noticed this situation in my FS though, I think the same bug is on all FSes of linus tree too, after this commit.
Am I missing the something?
This seems to be reproducible by the following,
#!/bin/sh
for i in $(seq -w 1000); do
for j in $(seq -w 1000); do for k in $(seq -w 1000); do mkdir -p $i/$j echo $i/$j/$k > $i/$j/$k echo 2 > /proc/sys/vm/drop_caches done donedone
Quoted 8 lines
Quoted 2 lines
Some inodes never be reclaimed, and ls -l frees those inodes (stat(2) does iget/iput).
So looking into the code I agree we won't put inode into the LRU when it
is dirty or under writeback and after writeback is done it won't happen either. That's certainly a bug. But I have hard time reproducing your results because on my kernels even dcache doesn't get shrunk thus inodes are pinned in memory by it. Not sure what's going on yet but I'll investigate. Thanks for report!
OK, that was just reclaim batching code standing in my way. After
figuring that out I could reproduce the issue and test my fix. It is attached.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 1 line
From
4fdc5d9a66dfe0286ef4f4a7f53fd3b15086470fMon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Mon, 19 Nov 2012 20:01:16 +0100
Subject: [PATCH] writeback: Put unused inodes to LRU after writeback completion
Commit 169ebd90 removed iget-iput pair from inode writeback. As a side effect, inodes that are dirty during iput_final() call won't be ever added to inode LRU (iput_final() doesn't add dirty inodes to LRU and later when the inode is cleaned there's noone to add the inode there). Thus inodes are effectively unreclaimable until someone looks them up again.
Practical effect of this bug is limited by the fact that inodes are pinned by a dentry for long enough that the inode gets cleaned. But still the bug can have nasty consequences leading up to OOM conditions under certain circumstances. Following can easily reproduce the problem:
for (( i = 0; i < 1000; i++ )); do
mkdir $i
for (( j = 0; j < 1000; j++ )); do
touch $i/$j
echo 2 > /proc/sys/vm/drop_caches
done
done
then one needs to run 'sync; ls -lR' to make inodes reclaimable again.
We fix the issue by inserting unused clean inodes into the LRU after writeback finishes in inode_sync_complete().
--- fs/fs-writeback.c | 3 +++ fs/inode.c | 2 +- fs/internal.h | 1 + 3 files changed, 5 insertions(+), 1 deletions(-)
fs/fs-writeback.c +3 -0
@@ -227,6 +227,9 @@ static void requeue_io(struct inode *inode, struct bdi_writeback *wb)static void inode_sync_complete (struct inode *inode) { +/* If inode is clean an unused, put it into LRU now. */ +if (!(inode->i_state &I_DIRTY ) && !atomic_read (&inode->i_count)) +inode_lru_list_add (inode); inode->i_state &= ~I_SYNC ;/* Waiters must see I_SYNC cleared before being woken up */ smp_mb ();
fs/inode.c +1 -1
@@ -397,7 +397,7 @@ void ihold(struct inode *inode) }EXPORT_SYMBOL (ihold); -static void inode_lru_list_add (struct inode *inode) +void inode_lru_list_add (struct inode *inode) {spin_lock (&inode->i_sb->s_inode_lru_lock);if (list_empty (&inode->i_lru)) {
fs/internal.h +1 -0
@@ -110,6 +110,7 @@ extern int open_check_o_direct(struct file *f);* inode.c */ extern spinlock_t inode_sb_list_lock; +extern void inode_lru_list_add (struct inode *inode);/* * fs-writeback.c
Signature · 1 line
1.7.1
Quoted 24 lines · Jan Kara
Quoted 1 line
From
4fdc5d9a66dfe0286ef4f4a7f53fd3b15086470fMon Sep 17 00:00:00 2001From: Jan Kara <[email protected]>
Date: Mon, 19 Nov 2012 20:01:16 +0100
Subject: [PATCH] writeback: Put unused inodes to LRU after writeback completionCommit
169ebd90removed iget-iput pair from inode writeback. As a side effect, inodes that are dirty duringiput_final()call won't be ever added to inode LRU (iput_final()doesn't add dirty inodes to LRU and later when the inode is cleaned there's noone to add the inode there). Thus inodes are effectively unreclaimable until someone looks them up again.Practical effect of this bug is limited by the fact that inodes are pinned by a dentry for long enough that the inode gets cleaned. But still the bug can have nasty consequences leading up to OOM conditions under certain circumstances. Following can easily reproduce the problem:
for (( i = 0; i < 1000; i++ )); do
mkdir $i
for (( j = 0; j < 1000; j++ )); do
touch $i/$j
echo 2 >/proc/sys/vm/drop_caches
done
done
Quoted 8 lines
then one needs to run 'sync; ls -lR' to make inodes reclaimable again.
We fix the issue by inserting unused clean inodes into the LRU after writeback finishes in
inode_sync_complete().CC Al Viro <[email protected]>Reported-by OGAWA Hirofumi <[email protected]>Signed-off-by Jan Kara <[email protected]>
Need to Cc to stable@
Quoted 11 lines
--- fs/fs-writeback.c | 3 +++ fs/inode.c | 2 +- fs/internal.h | 1 + 3 files changed, 5 insertions(+), 1 deletions(-)fs/fs-writeback.c +0
-0
fs/fs-writeback.c static void requeue_io(struct inode *inode, struct bdi_writeback *wb) · line 232
Quoted 6 lines
fs/fs-writeback.c +3
-0@@ -227,6 +227,9 @@ static void requeue_io(struct inode *inode, struct bdi_writeback *wb)static void inode_sync_complete (struct inode *inode) { +/* If inode is clean an unused, put it into LRU now. */ +if (!(inode->i_state &I_DIRTY ) && !atomic_read (&inode->i_count)) +inode_lru_list_add (inode);
IMHO, open coding this would be bad idea. And another one is I_REFERENCED. We really want to remove I_REFERENCED?
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Jan Kara
reviewerQuoted 28 lines · OGAWA Hirofumi
Quoted 26 lines · Jan Kara
Quoted 1 line
From
4fdc5d9a66dfe0286ef4f4a7f53fd3b15086470fMon Sep 17 00:00:00 2001From: Jan Kara <[email protected]>
Date: Mon, 19 Nov 2012 20:01:16 +0100
Subject: [PATCH] writeback: Put unused inodes to LRU after writeback completionCommit
169ebd90removed iget-iput pair from inode writeback. As a side effect, inodes that are dirty duringiput_final()call won't be ever added to inode LRU (iput_final()doesn't add dirty inodes to LRU and later when the inode is cleaned there's noone to add the inode there). Thus inodes are effectively unreclaimable until someone looks them up again.Practical effect of this bug is limited by the fact that inodes are pinned by a dentry for long enough that the inode gets cleaned. But still the bug can have nasty consequences leading up to OOM conditions under certain circumstances. Following can easily reproduce the problem:
for (( i = 0; i < 1000; i++ )); do
mkdir $i
for (( j = 0; j < 1000; j++ )); do
touch $i/$j
echo 2 >/proc/sys/vm/drop_caches
done
donethen one needs to run 'sync; ls -lR' to make inodes reclaimable again.
Quoted 8 lines
Quoted 6 lines
We fix the issue by inserting unused clean inodes into the LRU after writeback finishes in
inode_sync_complete().CC Al Viro <[email protected]>Reported-by OGAWA Hirofumi <[email protected]>Signed-off-by Jan Kara <[email protected]>Need to Cc to stable@
Yup, I'll add that. Thanks for reminder.
Quoted 12 lines
Quoted 12 lines
--- fs/fs-writeback.c | 3 +++ fs/inode.c | 2 +- fs/internal.h | 1 + 3 files changed, 5 insertions(+), 1 deletions(-)fs/fs-writeback.c +0
-0@@ -227,6 +227,9 @@ static void requeue_io(struct inode *inode, struct bdi_writeback *wb)
Quoted 7 lines
fs/fs-writeback.c static void requeue_io(struct inode *inode, struct bdi_writeback *wb) · line 232
Quoted 5 lines
fs/fs-writeback.c +3
-0static void inode_sync_complete (struct inode *inode) { +/* If inode is clean an unused, put it into LRU now. */ +if (!(inode->i_state &I_DIRTY ) && !atomic_read (&inode->i_count)) +inode_lru_list_add (inode);IMHO, open coding this would be bad idea.
Do you mean creating a separate function for the above two lines?
Quoted 1 line
And another one is
I_REFERENCED. We really want to removeI_REFERENCED?
We don't want I_REFERENCED set - noone used the inode. But looking into
the code with fresh eyes, the fix isn't as simple as I thought. First I need to check MS_ACTIVE and second I need to check I_FREEING... So the condition will be complex enough to warrant a separate function.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 8 lines · Jan Kara
Quoted 7 lines
fs/fs-writeback.c static void requeue_io(struct inode *inode, struct bdi_writeback *wb) · line 232
Quoted 5 lines
static void
inode_sync_complete(struct inode *inode){fs/fs-writeback.c +3
-0+/* If inode is clean an unused, put it into LRU now. */ +if (!(inode->i_state &I_DIRTY ) && !atomic_read (&inode->i_count)) +inode_lru_list_add (inode);IMHO, open coding this would be bad idea.
Do you mean creating a separate function for the above two lines?
Yes. And the intent is to consolidate "when adds inode to LRU" with iput_final()'s one.
Quoted 5 lines
Quoted 1 line
And another one is
I_REFERENCED. We really want to removeI_REFERENCED?We don't want
I_REFERENCEDset - noone used the inode. But looking into
the code with fresh eyes, the fix isn't as simple as I thought. First I need to checkMS_ACTIVEand second I need to checkI_FREEING... So the condition will be complex enough to warrant a separate function.
I can't see the issue (sync_filesystem() will wait I_DIRTY before MS_ACTIVE, and I_DIRTY prevents I_FREEING) though, it may be possible.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Jan Kara
reviewerQuoted 14 lines · OGAWA Hirofumi
Quoted 8 lines · Jan Kara
Quoted 7 lines
fs/fs-writeback.c static void requeue_io(struct inode *inode, struct bdi_writeback *wb) · line 232
Quoted 5 lines
static void
inode_sync_complete(struct inode *inode){fs/fs-writeback.c +3
-0+/* If inode is clean an unused, put it into LRU now. */ +if (!(inode->i_state &I_DIRTY ) && !atomic_read (&inode->i_count)) +inode_lru_list_add (inode);IMHO, open coding this would be bad idea.
Do you mean creating a separate function for the above two lines?
Yes. And the intent is to consolidate "when adds inode to LRU" with iput_final()'s one.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And another one is
I_REFERENCED. We really want to removeI_REFERENCED?We don't want
I_REFERENCEDset - noone used the inode. But looking into
the code with fresh eyes, the fix isn't as simple as I thought. First I need to checkMS_ACTIVEand second I need to checkI_FREEING... So the condition will be complex enough to warrant a separate function.I can't see the issue (
sync_filesystem()will waitI_DIRTYbeforeMS_ACTIVE, andI_DIRTYpreventsI_FREEING) though, it may be possible.
E.g. when inode is deleted it can be both I_DIRTY (and flusher thread
can be working on it) while it is also marked as I_FREEING. In such case we must avoid adding the inode to the LRU.
Regarding MS_ACTIVE - you are right that sync_filesystem() should clean
all dirty inodes but some filesystems dirty their internal inodes during umount so it's better to make flusher thread safe and not add such inodes to the LRU during umount.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerQuoted 23 lines · Jan Kara
Quoted 14 lines · OGAWA Hirofumi
Quoted 8 lines · Jan Kara
Quoted 7 lines
Review
Quoted 5 lines
static void
inode_sync_complete(struct inode *inode){(quoted diff) +3
-0+ /* If inode is clean an unused, put it into LRU now. */ + if (!(inode->i_state & I_DIRTY) && !atomic_read(&inode->i_count)) + inode_lru_list_add(inode);IMHO, open coding this would be bad idea.
Do you mean creating a separate function for the above two lines?
Yes. And the intent is to consolidate "when adds inode to LRU" with iput_final()'s one.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And another one is
I_REFERENCED. We really want to removeI_REFERENCED?We don't want
I_REFERENCEDset - noone used the inode. But looking into
the code with fresh eyes, the fix isn't as simple as I thought. First I need to checkMS_ACTIVEand second I need to checkI_FREEING... So the condition will be complex enough to warrant a separate function.I can't see the issue (
sync_filesystem()will waitI_DIRTYbeforeMS_ACTIVE, andI_DIRTYpreventsI_FREEING) though, it may be possible.
Quoted 8 lines
E.g. when inode is deleted it can be both
I_DIRTY(and flusher thread
can be working on it) while it is also marked asI_FREEING. In such case we must avoid adding the inode to the LRU.Regarding
MS_ACTIVE- you are right thatsync_filesystem()should clean
all dirty inodes but some filesystems dirty their internal inodes during umount so it's better to make flusher thread safe and not add such inodes to the LRU during umount.
Here's the patch I currently have BTW.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 1 line
From
00c9878ec690bb8e493582f0109e9aa6ee734ecbMon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Mon, 19 Nov 2012 20:01:16 +0100
Subject: [PATCH v2] writeback: Put unused inodes to LRU after writeback completion
Commit 169ebd90 removed iget-iput pair from inode writeback. As a side effect, inodes that are dirty during iput_final() call won't be ever added to inode LRU (iput_final() doesn't add dirty inodes to LRU and later when the inode is cleaned there's noone to add the inode there). Thus inodes are effectively unreclaimable until someone looks them up again.
Practical effect of this bug is limited by the fact that inodes are pinned by a dentry for long enough that the inode gets cleaned. But still the bug can have nasty consequences leading up to OOM conditions under certain circumstances. Following can easily reproduce the problem:
for (( i = 0; i < 1000; i++ )); do
mkdir $i
for (( j = 0; j < 1000; j++ )); do
touch $i/$j
echo 2 > /proc/sys/vm/drop_caches
done
done
then one needs to run 'sync; ls -lR' to make inodes reclaimable again.
We fix the issue by inserting unused clean inodes into the LRU after writeback finishes in inode_sync_complete().
--- fs/fs-writeback.c | 2 ++ fs/inode.c | 16 ++++++++++++++-- fs/internal.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-)
fs/fs-writeback.c +2 -0
@@ -228,6 +228,8 @@ static void requeue_io(struct inode *inode, struct bdi_writeback *wb)static void inode_sync_complete (struct inode *inode) { inode->i_state &= ~I_SYNC ; +/* If inode is clean an unused, put it into LRU now... */ +inode_add_lru (inode);/* Waiters must see I_SYNC cleared before being woken up */ smp_mb ();wake_up_bit (&inode->i_state, __I_SYNC);
fs/inode.c +14 -2
@@ -408,6 +408,19 @@ static void inode_lru_list_add(struct inode *inode)spin_unlock (&inode->i_sb->s_inode_lru_lock); } +/* +* Add inode to LRU if needed (inode is unused and clean). +* +* Needs inode->i_lock held. +*/ +void inode_add_lru (struct inode *inode) +{ +if (!(inode->i_state & (I_DIRTY |I_FREEING |I_SYNC )) && + !atomic_read (&inode->i_count) && inode->i_sb->s_flags &MS_ACTIVE ) +inode_lru_list_add (inode); +} + +static void inode_lru_list_del (struct inode *inode) {spin_lock (&inode->i_sb->s_inode_lru_lock);
@@ -1390,8 +1403,7 @@ static void iput_final(struct inode *inode)if (!drop && (sb->s_flags &MS_ACTIVE )) { inode->i_state |=I_REFERENCED ; -if (!(inode->i_state & (I_DIRTY |I_SYNC ))) -inode_lru_list_add (inode); +inode_add_lru (inode);spin_unlock (&inode->i_lock);return ; }
fs/internal.h +1 -0
@@ -110,6 +110,7 @@ extern int open_check_o_direct(struct file *f);* inode.c */ extern spinlock_t inode_sb_list_lock; +extern void inode_add_lru (struct inode *inode);/* * fs-writeback.c
Signature · 1 line
1.7.1
Quoted 22 lines · Jan Kara
fs/fs-writeback.c +2
-0@@ -228,6 +228,8 @@ static void requeue_io(struct inode *inode, struct bdi_writeback *wb)static void inode_sync_complete (struct inode *inode) { inode->i_state &= ~I_SYNC ; +/* If inode is clean an unused, put it into LRU now... */ +inode_add_lru (inode);/* Waiters must see I_SYNC cleared before being woken up */ smp_mb ();wake_up_bit (&inode->i_state, __I_SYNC);fs/inode.c +0
-0@@ -408,6 +408,19 @@ static void inode_lru_list_add(struct inode *inode)spin_unlock (&inode->i_sb->s_inode_lru_lock); }
fs/inode.c static void inode_lru_list_add(struct inode *inode) · line 420
Quoted 10 lines
fs/inode.c +10
-0+/* +* Add inode to LRU if needed (inode is unused and clean). +* +* Needs inode->i_lock held. +*/ +void inode_add_lru (struct inode *inode) +{ +if (!(inode->i_state & (I_DIRTY |I_FREEING |I_SYNC )) && + !atomic_read (&inode->i_count) && inode->i_sb->s_flags &MS_ACTIVE ) +inode_lru_list_add (inode);
Needs to avoid I_WILL_FREE as well. There's no point putting it on the LRU if we are writing from iput_final()....
Otherwise looks OK.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Jan Kara
reviewerQuoted 23 lines · Dave Chinner
Quoted 22 lines · Jan Kara
fs/fs-writeback.c +2
-0@@ -228,6 +228,8 @@ static void requeue_io(struct inode *inode, struct bdi_writeback *wb)static void inode_sync_complete (struct inode *inode) { inode->i_state &= ~I_SYNC ; +/* If inode is clean an unused, put it into LRU now... */ +inode_add_lru (inode);/* Waiters must see I_SYNC cleared before being woken up */ smp_mb ();wake_up_bit (&inode->i_state, __I_SYNC);fs/inode.c +0
-0@@ -408,6 +408,19 @@ static void inode_lru_list_add(struct inode *inode)spin_unlock (&inode->i_sb->s_inode_lru_lock); }
Quoted 13 lines
fs/inode.c static void inode_lru_list_add(struct inode *inode) · line 420
Quoted 10 lines
fs/inode.c +10
-0+/* +* Add inode to LRU if needed (inode is unused and clean). +* +* Needs inode->i_lock held. +*/ +void inode_add_lru (struct inode *inode) +{ +if (!(inode->i_state & (I_DIRTY |I_FREEING |I_SYNC )) && + !atomic_read (&inode->i_count) && inode->i_sb->s_flags &MS_ACTIVE ) +inode_lru_list_add (inode);Needs to avoid
I_WILL_FREEas well. There's no point putting it on the LRU if we are writing fromiput_final()....
Yeah, it won't cause any real problems but you are right it's not useful
to put such inodes into the LRU. I'll send v3 in a moment, now as a proper patch submission since we seem to agree...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
fs/inode.c static void inode_lru_list_add(struct inode *inode) · line 421
Quoted 11 lines · On Wed, 21 Nov 2012 02:48:51 +0100 Jan Kara <[email protected]> wrote:
fs/inode.c +11
-0+/* +* Add inode to LRU if needed (inode is unused and clean). +* +* Needs inode->i_lock held. +*/ +void inode_add_lru (struct inode *inode) +{ +if (!(inode->i_state & (I_DIRTY |I_FREEING |I_SYNC )) && + !atomic_read (&inode->i_count) && inode->i_sb->s_flags &MS_ACTIVE ) +inode_lru_list_add (inode); +}
Is i_lock sufficient to stabilise i_count?
<looks at the code a bit>
Is evict_inodes() wrong to test i_count outside i_lock?
invalidate_inodes() looks better.
can_unuse() must be called under i_lock, and is. Apparently this requirement was sufficiently obvious to not meed documenting.
prune_icache_sb() gets it right.
iput() gets it right.
So to answer my own question: yes, it is sufficient. But a) the comment for inode.i_lock is out of date and b) evict_inodes() looks fishy.
Quoted 16 lines · Andrew Morton
fs/inode.c static void inode_lru_list_add(struct inode *inode) · line 421
Quoted 11 lines · On Wed, 21 Nov 2012 02:48:51 +0100 Jan Kara <[email protected]> wrote:
fs/inode.c +11
-0+/* +* Add inode to LRU if needed (inode is unused and clean). +* +* Needs inode->i_lock held. +*/ +void inode_add_lru (struct inode *inode) +{ +if (!(inode->i_state & (I_DIRTY |I_FREEING |I_SYNC )) && + !atomic_read (&inode->i_count) && inode->i_sb->s_flags &MS_ACTIVE ) +inode_lru_list_add (inode); +}Is
i_locksufficient to stabilisei_count?
Quoted 8 lines
<looks at the code a bit>
Is
evict_inodes()wrong to testi_countoutsidei_lock?
invalidate_inodes()looks better.
can_unuse()must be called underi_lock, and is. Apparently this requirement was sufficiently obvious to not meed documenting.
It is documented. can_unuse looks at i_state and i_count, and both are documented as requiring the i_lock at the top of the file in the locking rules section. Also, see __iget(), also mentioned in the locking rules....
Quoted 6 lines
prune_icache_sb()gets it right.
iput()gets it right.So to answer my own question: yes, it is sufficient. But a) the comment for inode.i_lock is out of date
If you means the one in fs.h, then yeah, it's way out of date....
Quoted 3 lines
and b)
evict_inodes()looks
fishy.
As I understand it, evict_inodes() is special - it's only called from generic_shutdown_super() after the MS_ACTIVE flag has been removed from the filesytem, the dcache has been pruned and all the inodes cleaned. So there should be no new references to the inodes occurring, and hence we don't need to hold the lock to serialise against new references being taken....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
fs/fs-writeback.c static void requeue_io(struct inode *inode, struct bdi_writeback *wb) · line 232
Quoted 11 lines · Jan Kara
fs/fs-writeback.c +3
-0@@ -227,6 +227,9 @@ static void requeue_io(struct inode *inode, struct bdi_writeback *wb)static void inode_sync_complete (struct inode *inode) { +/* If inode is clean an unused, put it into LRU now. */ +if (!(inode->i_state &I_DIRTY ) && !atomic_read (&inode->i_count)) +inode_lru_list_add (inode);
Unsafe. Has to avoid I_FREEING|I_WILL_FREE (see warnings at start of writeback_single_inode()).
Also, if you do this after clearing the I_SYNC flag, you can use exactly the same logic as iput_final(). A helper function could be used for both cases at that point, and....
fs/inode.c void ihold(struct inode *inode) · line 400
Quoted 8 lines
fs/inode.c +1
-1@@ -397,7 +397,7 @@ void ihold(struct inode *inode) }EXPORT_SYMBOL (ihold); -static void inode_lru_list_add (struct inode *inode) +void inode_lru_list_add (struct inode *inode)
.... the inode lru list function can stay static.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Jan Kara
reviewerQuoted 16 lines · Dave Chinner
fs/fs-writeback.c static void requeue_io(struct inode *inode, struct bdi_writeback *wb) · line 232
Quoted 11 lines · Jan Kara
fs/fs-writeback.c +3
-0@@ -227,6 +227,9 @@ static void requeue_io(struct inode *inode, struct bdi_writeback *wb)static void inode_sync_complete (struct inode *inode) { +/* If inode is clean an unused, put it into LRU now. */ +if (!(inode->i_state &I_DIRTY ) && !atomic_read (&inode->i_count)) +inode_lru_list_add (inode);Unsafe. Has to avoid I_FREEING|I_WILL_FREE (see warnings at start of
writeback_single_inode()).
Quoted 3 lines
Also, if you do this after clearing the
I_SYNCflag, you can use exactly the same logic asiput_final(). A helper function could be used for both cases at that point, and....
Agreed. That's what I do in the current version of the patch (not posted
yet).
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR