percpu: rework memcg accounting
authorRoman Gushchin <guro@fb.com>
Thu, 3 Jun 2021 01:09:31 +0000 (18:09 -0700)
committerDennis Zhou <dennis@kernel.org>
Sat, 5 Jun 2021 20:43:15 +0000 (20:43 +0000)
commitfaf65dde844affa9e360ccaa4bd231c2a04b87ea
tree7c4741eb522798b08d75e9b0d5f209ce706fe49c
parent4d5c8aedc8aa6a1f5d1b06eb4f5517dc60dd9440
percpu: rework memcg accounting

The current implementation of the memcg accounting of the percpu
memory is based on the idea of having two separate sets of chunks for
accounted and non-accounted memory. This approach has an advantage
of not wasting any extra memory for memcg data for non-accounted
chunks, however it complicates the code and leads to a higher chunks
number due to a lower chunk utilization.

Instead of having two chunk types it's possible to declare all* chunks
memcg-aware unless the kernel memory accounting is disabled globally
by a boot option. The size of objcg_array is usually small in
comparison to chunks themselves (it obviously depends on the number of
CPUs), so even if some chunk will have no accounted allocations, the
memory waste isn't significant and will likely be compensated by
a higher chunk utilization. Also, with time more and more percpu
allocations will likely become accounted.

* The first chunk is initialized before the memory cgroup subsystem,
  so we don't know for sure whether we need to allocate obj_cgroups.
  Because it's small, let's make it free for use. Then we don't need
  to allocate obj_cgroups for it.

Signed-off-by: Roman Gushchin <guro@fb.com>
Signed-off-by: Dennis Zhou <dennis@kernel.org>
mm/percpu-internal.h
mm/percpu-km.c
mm/percpu-stats.c
mm/percpu-vm.c
mm/percpu.c