2014-06-02 04:38:36

by Joonsoo Kim

[permalink] [raw]
Subject: Re: [PATCH -mm 8/8] slab: reap dead memcg caches aggressively

On Fri, May 30, 2014 at 05:51:11PM +0400, Vladimir Davydov wrote:
> There is no use in keeping free objects/slabs on dead memcg caches,
> because they will never be allocated. So let's make cache_reap() shrink
> as many free objects from such caches as possible.
>
> Note the difference between SLAB and SLUB handling of dead memcg caches.
> For SLUB, dead cache destruction is scheduled as soon as the last object
> is freed, because dead caches do not cache free objects. For SLAB, dead
> caches can keep some free objects on per cpu arrays, so that an empty
> dead cache will be hanging around until cache_reap() drains it.
>
> We don't disable free objects caching for SLAB, because it would force
> kfree to always take a spin lock, which would degrade performance
> significantly.
>
> Since cache_reap() drains all caches once ~4 secs on each CPU, empty
> dead caches will die quickly.
>
> Signed-off-by: Vladimir Davydov <[email protected]>
> ---
> mm/slab.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/mm/slab.c b/mm/slab.c
> index cecc01bba389..d81e46316c99 100644
> --- a/mm/slab.c
> +++ b/mm/slab.c
> @@ -3985,6 +3985,11 @@ static void cache_reap(struct work_struct *w)
> goto out;
>
> list_for_each_entry(searchp, &slab_caches, list) {
> + int force = 0;
> +
> + if (memcg_cache_dead(searchp))
> + force = 1;
> +
> check_irq_on();
>
> /*
> @@ -3996,7 +4001,7 @@ static void cache_reap(struct work_struct *w)
>
> reap_alien(searchp, n);
>
> - drain_array(searchp, n, cpu_cache_get(searchp), 0, node);
> + drain_array(searchp, n, cpu_cache_get(searchp), force, node);
>
> /*
> * These are racy checks but it does not matter
> @@ -4007,15 +4012,17 @@ static void cache_reap(struct work_struct *w)
>
> n->next_reap = jiffies + REAPTIMEOUT_NODE;
>
> - drain_array(searchp, n, n->shared, 0, node);
> + drain_array(searchp, n, n->shared, force, node);
>
> if (n->free_touched)
> n->free_touched = 0;
> else {
> - int freed;
> + int freed, tofree;
> +
> + tofree = force ? slabs_tofree(searchp, n) :
> + DIV_ROUND_UP(n->free_limit, 5 * searchp->num);

Hello,

According to my code reading, slabs_to_free() doesn't return number of
free slabs. This bug is introduced by 0fa8103b. I think that it is
better to fix it before applyting this patch. Otherwise, use n->free_objects
instead of slabs_tofree() to achieve your purpose correctly.

Thanks.


2014-06-02 12:10:47

by Vladimir Davydov

[permalink] [raw]
Subject: Re: [PATCH -mm 8/8] slab: reap dead memcg caches aggressively

On Mon, Jun 02, 2014 at 01:41:55PM +0900, Joonsoo Kim wrote:
> According to my code reading, slabs_to_free() doesn't return number of
> free slabs. This bug is introduced by 0fa8103b. I think that it is
> better to fix it before applyting this patch. Otherwise, use n->free_objects
> instead of slabs_tofree() to achieve your purpose correctly.

Hmm, I don't think slab_tofree() computes the number of free slabs
wrong. If we have N free objects, there may be
DIV_ROUND_UP(N,objs_per_slab) empty slabs at max, and that's exactly
what slab_tofree() does, no?

Thanks.

2014-06-02 14:01:59

by Joonsoo Kim

[permalink] [raw]
Subject: Re: [PATCH -mm 8/8] slab: reap dead memcg caches aggressively

2014-06-02 21:10 GMT+09:00 Vladimir Davydov <[email protected]>:
> On Mon, Jun 02, 2014 at 01:41:55PM +0900, Joonsoo Kim wrote:
>> According to my code reading, slabs_to_free() doesn't return number of
>> free slabs. This bug is introduced by 0fa8103b. I think that it is
>> better to fix it before applyting this patch. Otherwise, use n->free_objects
>> instead of slabs_tofree() to achieve your purpose correctly.
>
> Hmm, I don't think slab_tofree() computes the number of free slabs
> wrong. If we have N free objects, there may be
> DIV_ROUND_UP(N,objs_per_slab) empty slabs at max, and that's exactly
> what slab_tofree() does, no?

Oops... Sorry for wrong comment.
You are right. Please ignore my comment. :)

BTW, we don't need DIV_ROUND_UP. I think that just N / objs_per_slab is
sufficient to get number of empty slabs at max. Am I missing too?

Thanks.

2014-06-03 08:21:42

by Vladimir Davydov

[permalink] [raw]
Subject: Re: [PATCH -mm 8/8] slab: reap dead memcg caches aggressively

On Mon, Jun 02, 2014 at 11:01:55PM +0900, Joonsoo Kim wrote:
> 2014-06-02 21:10 GMT+09:00 Vladimir Davydov <[email protected]>:
> > On Mon, Jun 02, 2014 at 01:41:55PM +0900, Joonsoo Kim wrote:
> >> According to my code reading, slabs_to_free() doesn't return number of
> >> free slabs. This bug is introduced by 0fa8103b. I think that it is
> >> better to fix it before applyting this patch. Otherwise, use n->free_objects
> >> instead of slabs_tofree() to achieve your purpose correctly.
> >
> > Hmm, I don't think slab_tofree() computes the number of free slabs
> > wrong. If we have N free objects, there may be
> > DIV_ROUND_UP(N,objs_per_slab) empty slabs at max, and that's exactly
> > what slab_tofree() does, no?
>
[...]
> BTW, we don't need DIV_ROUND_UP. I think that just N / objs_per_slab is
> sufficient to get number of empty slabs at max. Am I missing too?

Yeah, you're right - DIV_ROUND_UP is obviously redundant, DIV would be
enough. Not a bug though.

Thanks.