Skip to content

Commit

Permalink
kasan: resched in quarantine_remove_cache()
Browse files Browse the repository at this point in the history
commit 68fd814 upstream.

We see reported stalls/lockups in quarantine_remove_cache() on machines
with large amounts of RAM.  quarantine_remove_cache() needs to scan
whole quarantine in order to take out all objects belonging to the
cache.  Quarantine is currently 1/32-th of RAM, e.g.  on a machine with
256GB of memory that will be 8GB.  Moreover quarantine scanning is a
walk over uncached linked list, which is slow.

Add cond_resched() after scanning of each non-empty batch of objects.
Batches are specifically kept of reasonable size for quarantine_put().
On a machine with 256GB of RAM we should have ~512 non-empty batches,
each with 16MB of objects.

Link: http://lkml.kernel.org/r/20170308154239.25440-1-dvyukov@google.com
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Greg Thelen <gthelen@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Dmitry Vyukov authored and Greg Kroah-Hartman committed Mar 15, 2017
1 parent 44c9596 commit 0d9cc8a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mm/kasan/quarantine.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,15 @@ void quarantine_remove_cache(struct kmem_cache *cache)
on_each_cpu(per_cpu_remove_cache, cache, 1);

spin_lock_irqsave(&quarantine_lock, flags);
for (i = 0; i < QUARANTINE_BATCHES; i++)
for (i = 0; i < QUARANTINE_BATCHES; i++) {
if (qlist_empty(&global_quarantine[i]))
continue;
qlist_move_cache(&global_quarantine[i], &to_free, cache);
/* Scanning whole quarantine can take a while. */
spin_unlock_irqrestore(&quarantine_lock, flags);
cond_resched();
spin_lock_irqsave(&quarantine_lock, flags);
}
spin_unlock_irqrestore(&quarantine_lock, flags);

qlist_free_all(&to_free, cache);
Expand Down

0 comments on commit 0d9cc8a

Please sign in to comment.