Skip to content

RFC mm: improve performance of kernel memory accounting

Roman Gushchin cgroups linux-mm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest5 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5mm: kmem: optimize get_obj_cgroup_from_current()mm/memcontrol.c+14 -200 replies
2/5mm: kmem: add direct objcg pointer to task_structinclude/linux/memcontrol.h include/linux/sched.h mm/memcontrol.c+112 -94 replies
3/5mm: kmem: make memcg keep a reference to the original objcginclude/linux/memcontrol.h mm/memcontrol.c+12 -10 replies
4/5mm: kmem: scoped objcg protectioninclude/linux/memcontrol.h mm/memcontrol.c mm/slab.h+53 -90 replies
5/5percpu: scoped objcg protectionmm/percpu.c+3 -50 replies

Reviews trailers per patch

1 of 5 patches has a Reviewed-by or Acked-by.

PatchShakeel Butt
1/5A-b
2/5
3/5
4/5
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH rfc 0/5] mm: improve performance of kernel memory accounting

This patchset improves the performance of the kernel memory accounting by ~30% as measured by a micro-benchmark [1]. The benchmark is very straightforward:
1M of 64 bytes-large kmalloc() allocations.

Below are results with the disabled kernel memory accounting, the original state and with this patchset applied.

|             | Kmem disabled | Original | Patched |  Delta |
|-------------+---------------+----------+---------+--------|
| User cgroup |         29764 |    84435 |   59385 | -29.6% |
| Root cgroup |         29742 |    48425 |   31573 | -34.8% |

As we can see, the patchset removes the majority of the overhead when there is no actual accounting (a task belongs to the root memory cgroup) and almost halves the accounting overhead. Overall it improves the speed of accounted allocations by ~30%.

The main idea is to get rid of unnecessary memcg->objcg conversions and switch to a scope-based protection of objcgs, which eliminates extra operations with objcg reference counters under a rcu read lock. More details are provided in individual commit descriptions.

--
[1]:

static int memory_alloc_test(struct seq_file *m, void *v)

{
       unsigned long i, j;
       void **ptrs;
       ktime_t start, end;
       s64 delta, min_delta = LLONG_MAX;

       ptrs = kvmalloc(sizeof(void *) * 1000000, GFP_KERNEL);
       if (!ptrs)
               return -ENOMEM;

       for (j = 0; j < 100; j++) {
               start = ktime_get();
               for (i = 0; i < 1000000; i++)
                       ptrs[i] = kmalloc(64, GFP_KERNEL_ACCOUNT);
               end = ktime_get();

               delta = ktime_us_delta(end, start);
               if (delta < min_delta)
                       min_delta = delta;

               for (i = 0; i < 1000000; i++)
                       kfree(ptrs[i]);
       }

       kvfree(ptrs);
       seq_printf(m, "%lld us\n", min_delta);

       return 0;
}

--

Roman Gushchin (5):
mm: kmem: optimize get_obj_cgroup_from_current()
mm: kmem: add direct objcg pointer to task_struct
mm: kmem: make memcg keep a reference to the original objcg
mm: kmem: scoped objcg protection
percpu: scoped objcg protection

 include/linux/memcontrol.h |  24 ++++-
 include/linux/sched.h      |   4 +
 mm/memcontrol.c            | 178 ++++++++++++++++++++++++++++++++-----
 mm/percpu.c                |   8 +-
 mm/slab.h                  |  10 +--
 5 files changed, 187 insertions(+), 37 deletions(-)
Signature · 1 line
2.42.0