From: Vladimir Davydov <vdavydov@virtuozzo.com>
To: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: linux-mm@kvack.org, Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Andrew Morton <akpm@linux-foundation.org>,
Christoph Lameter <cl@linux.com>
Subject: Re: [PATCH] slub: add missing kmem cgroup support to kmem_cache_free_bulk
Date: Thu, 5 Nov 2015 11:38:43 +0300 [thread overview]
Message-ID: <20151105083842.GA29259@esperanza> (raw)
In-Reply-To: <20151105050621.GC20374@js1304-P5Q-DELUXE>
On Thu, Nov 05, 2015 at 02:06:21PM +0900, Joonsoo Kim wrote:
> On Thu, Oct 29, 2015 at 02:05:31PM +0100, Jesper Dangaard Brouer wrote:
> > Initial implementation missed support for kmem cgroup support
> > in kmem_cache_free_bulk() call, add this.
> >
> > If CONFIG_MEMCG_KMEM is not enabled, the compiler should
> > be smart enough to not add any asm code.
> >
> > Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
> > ---
> > mm/slub.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/mm/slub.c b/mm/slub.c
> > index 9be12ffae9fc..9875864ad7b8 100644
> > --- a/mm/slub.c
> > +++ b/mm/slub.c
> > @@ -2845,6 +2845,9 @@ static int build_detached_freelist(struct kmem_cache *s, size_t size,
> > if (!object)
> > return 0;
> >
> > + /* Support for kmemcg */
> > + s = cache_from_obj(s, object);
> > +
> > /* Start new detached freelist */
> > set_freepointer(s, object, NULL);
> > df->page = virt_to_head_page(object);
>
> Hello,
>
> It'd better to add this 's = cache_from_obj()' on kmem_cache_free_bulk().
> Not only build_detached_freelist() but also slab_free() need proper
> cache.
Yeah, Joonsoo is right. Besides, there's a bug in kmem_cache_alloc_bulk:
> /* Note that interrupts must be enabled when calling this function. */
> bool kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
> void **p)
> {
> struct kmem_cache_cpu *c;
> int i;
>
> /*
> * Drain objects in the per cpu slab, while disabling local
> * IRQs, which protects against PREEMPT and interrupts
> * handlers invoking normal fastpath.
> */
> local_irq_disable();
> c = this_cpu_ptr(s->cpu_slab);
>
> for (i = 0; i < size; i++) {
> void *object = c->freelist;
>
> if (unlikely(!object)) {
> /*
> * Invoking slow path likely have side-effect
> * of re-populating per CPU c->freelist
> */
> p[i] = ___slab_alloc(s, flags, NUMA_NO_NODE,
> _RET_IP_, c);
> if (unlikely(!p[i]))
> goto error;
>
> c = this_cpu_ptr(s->cpu_slab);
> continue; /* goto for-loop */
> }
>
> /* kmem_cache debug support */
> s = slab_pre_alloc_hook(s, flags);
slab_pre_alloc_hook expects a global cache and returns per memcg one, so
calling this function from inside a kmemcg will result in hitting the
VM_BUG_ON in __memcg_kmem_get_cache, not saying about mis-accounting of
__slab_alloc.
memcg_kmem_get_cache should be called once, in the very beginning of
kmem_cache_alloc_bulk, and it should be matched by memcg_kmem_put_cache
when we are done.
Thanks,
Vladimir
> if (unlikely(!s))
> goto error;
>
> c->freelist = get_freepointer(s, object);
> p[i] = object;
>
> /* kmem_cache debug support */
> slab_post_alloc_hook(s, flags, object);
> }
> c->tid = next_tid(c->tid);
> local_irq_enable();
>
> /* Clear memory outside IRQ disabled fastpath loop */
> if (unlikely(flags & __GFP_ZERO)) {
> int j;
>
> for (j = 0; j < i; j++)
> memset(p[j], 0, s->object_size);
> }
>
> return true;
>
> error:
> __kmem_cache_free_bulk(s, i, p);
> local_irq_enable();
> return false;
> }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2015-11-05 8:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-29 13:05 [PATCH] slub: add missing kmem cgroup support to kmem_cache_free_bulk Jesper Dangaard Brouer
2015-11-05 5:06 ` Joonsoo Kim
2015-11-05 8:38 ` Vladimir Davydov [this message]
2015-11-05 13:19 ` Jesper Dangaard Brouer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151105083842.GA29259@esperanza \
--to=vdavydov@virtuozzo.com \
--cc=akpm@linux-foundation.org \
--cc=brouer@redhat.com \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.