All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/mbcache: make sure mb_cache_count() not return negative value.
@ 2018-01-08  2:00 Jiang Biao
  2018-01-08 10:44 ` Jan Kara
  0 siblings, 1 reply; 2+ messages in thread
From: Jiang Biao @ 2018-01-08  2:00 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: linux-ext4, tytso, ebiggers, akpm, jack, jiang.biao2, zhong.weidong

When running ltp stress test for 7*24 hours, vmscan occasionally emits the
following warning continuously:

mb_cache_scan+0x0/0x3f0 negative objects to delete
nr=-9232265467809300450
....

Trace info shows the freeable(mb_cache_count returns) is -1, which causes
the continuous accumulation and overflow of total_scan.

This patch makes sure that mb_cache_count() not return a negative value,
which makes the mbcache shrinker more robust.

Signed-off-by: Jiang Biao <jiang.biao2@zte.com.cn>
CC: "Theodore Ts'o" <tytso@mit.edu>
CC: Eric Biggers <ebiggers@google.com>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Jan Kara <jack@suse.cz>
---
 fs/mbcache.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/mbcache.c b/fs/mbcache.c
index b8b8b9c..c758458 100644
--- a/fs/mbcache.c
+++ b/fs/mbcache.c
@@ -238,7 +238,9 @@ void mb_cache_entry_delete(struct mb_cache *cache, u32 key, u64 value)
 			spin_lock(&cache->c_list_lock);
 			if (!list_empty(&entry->e_list)) {
 				list_del_init(&entry->e_list);
-				cache->c_entry_count--;
+				/*Make sure c_entry_count is not zero before dec*/
+				if (cache->c_entry_count != 0)
+					cache->c_entry_count--;
 				atomic_dec(&entry->e_refcnt);
 			}
 			spin_unlock(&cache->c_list_lock);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fs/mbcache: make sure mb_cache_count() not return negative value.
  2018-01-08  2:00 [PATCH] fs/mbcache: make sure mb_cache_count() not return negative value Jiang Biao
@ 2018-01-08 10:44 ` Jan Kara
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2018-01-08 10:44 UTC (permalink / raw)
  To: Jiang Biao
  Cc: linux-fsdevel, linux-ext4, tytso, ebiggers, akpm, jack, zhong.weidong

On Mon 08-01-18 10:00:42, Jiang Biao wrote:
> When running ltp stress test for 7*24 hours, vmscan occasionally emits the
> following warning continuously:
> 
> mb_cache_scan+0x0/0x3f0 negative objects to delete
> nr=-9232265467809300450
> ....
> 
> Trace info shows the freeable(mb_cache_count returns) is -1, which causes
> the continuous accumulation and overflow of total_scan.
> 
> This patch makes sure that mb_cache_count() not return a negative value,
> which makes the mbcache shrinker more robust.

Thanks for the patch. Couple of comments below.
 
> Signed-off-by: Jiang Biao <jiang.biao2@zte.com.cn>
> CC: "Theodore Ts'o" <tytso@mit.edu>
> CC: Eric Biggers <ebiggers@google.com>
> CC: Andrew Morton <akpm@linux-foundation.org>
> CC: Jan Kara <jack@suse.cz>
> ---
>  fs/mbcache.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/mbcache.c b/fs/mbcache.c
> index b8b8b9c..c758458 100644
> --- a/fs/mbcache.c
> +++ b/fs/mbcache.c
> @@ -238,7 +238,9 @@ void mb_cache_entry_delete(struct mb_cache *cache, u32 key, u64 value)
>  			spin_lock(&cache->c_list_lock);
>  			if (!list_empty(&entry->e_list)) {
>  				list_del_init(&entry->e_list);
> -				cache->c_entry_count--;
> +				/*Make sure c_entry_count is not zero before dec*/

The comment is useless, just delete it.

> +				if (cache->c_entry_count != 0)

cache->c_entry_count > 0 would be more logical...

> +					cache->c_entry_count--;

OK, but please also add:
				else
					WARN_ONCE(1, "mbcache: Entry count "
						  "going negative!");

Also as I said in another email I'd be actually more interested in
debugging how can entry count go to such huge value rather than trying to
paper over it...


								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-08 10:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-08  2:00 [PATCH] fs/mbcache: make sure mb_cache_count() not return negative value Jiang Biao
2018-01-08 10:44 ` Jan Kara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.