Re: [PATCH] mm/slub: Run free_partial() outside of the kmem_cache_node->list_lock

From: Vladimir Davydov
Date: Tue Aug 09 2016 - 11:50:37 EST


On Tue, Aug 09, 2016 at 03:46:32PM +0100, Chris Wilson wrote:
...
> diff --git a/mm/slub.c b/mm/slub.c
> index 850737bdfbd8..22b2c1f3db0e 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -3629,11 +3629,15 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,
> */
> static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)
> {
> + LIST_HEAD(partial_list);
> struct page *page, *h;
>
> BUG_ON(irqs_disabled());
> spin_lock_irq(&n->list_lock);
> - list_for_each_entry_safe(page, h, &n->partial, lru) {
> + list_splice_init(&n->partial, &partial_list);
> + spin_unlock_irq(&n->list_lock);
> +
> + list_for_each_entry_safe(page, h, &partial_list, lru) {
> if (!page->inuse) {
> remove_partial(n, page);

remove_partial() must be called with n->list_lock held - it even has
lockdep_assert_held(). What you actually need to do is to move
discard_slab() out of the critical section, like __kmem_cache_shrink()
does.

> discard_slab(s, page);
> @@ -3642,7 +3646,6 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)
> "Objects remaining in %s on __kmem_cache_shutdown()");
> }
> }
> - spin_unlock_irq(&n->list_lock);
> }
>
> /*