zsmalloc: do not take class lock in zs_shrinker_count()
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Tue, 8 Sep 2015 22:04:52 +0000 (15:04 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 8 Sep 2015 22:35:28 +0000 (15:35 -0700)
We can avoid taking class ->lock around zs_can_compact() in
zs_shrinker_count(), because the number that we return back is outdated
in general case, by design.  We have different sources that are able to
change class's state right after we return from zs_can_compact() --
ongoing I/O operations, manually triggered compaction, or two of them
happening simultaneously.

We re-do this calculations during compaction on a per class basis
anyway.

zs_unregister_shrinker() will not return until we have an active
shrinker, so classes won't unexpectedly disappear while
zs_shrinker_count() iterates them.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/zsmalloc.c

index ce08d043becd22dd65b832cd99d4a617dd53c3c0..c19b99c8a45722c1d0a4e975fc76f1d58b0fe399 100644 (file)
@@ -1710,8 +1710,6 @@ static struct page *isolate_source_page(struct size_class *class)
  *
  * Based on the number of unused allocated objects calculate
  * and return the number of pages that we can free.
- *
- * Should be called under class->lock.
  */
 static unsigned long zs_can_compact(struct size_class *class)
 {
@@ -1834,9 +1832,7 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker,
                if (class->index != i)
                        continue;
 
-               spin_lock(&class->lock);
                pages_to_free += zs_can_compact(class);
-               spin_unlock(&class->lock);
        }
 
        return pages_to_free;