]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
apparmor: cache buffers on percpu list if there is lock contention
authorJohn Johansen <john.johansen@canonical.com>
Tue, 25 Oct 2022 08:18:41 +0000 (01:18 -0700)
committerJohn Johansen <john.johansen@canonical.com>
Wed, 18 Oct 2023 23:00:45 +0000 (16:00 -0700)
commitea9bae12d02819556db63348db8bd8441eb316f2
tree8f2a31d41082be914673193fe991a4e8bee809cb
parentc4371d90633b73cf6e86aff43ff2b5d95ad2b9eb
apparmor: cache buffers on percpu list if there is lock contention

commit df323337e507 ("apparmor: Use a memory pool instead per-CPU caches")

changed buffer allocation to use a memory pool, however on a heavily
loaded machine there can be lock contention on the global buffers
lock. Add a percpu list to cache buffers on when lock contention is
encountered.

When allocating buffers attempt to use cached buffers first,
before taking the global buffers lock. When freeing buffers
try to put them back to the global list but if contention is
encountered, put the buffer on the percpu list.

The length of time a buffer is held on the percpu list is dynamically
adjusted based on lock contention.  The amount of hold time is
increased and decreased linearly.

v5:
- simplify base patch by removing: improvements can be added later
  - MAX_LOCAL and must lock
  - contention scaling.
v4:
- fix percpu ->count buffer count which had been spliced across a
  debug patch.
- introduce define for MAX_LOCAL_COUNT
- rework count check and locking around it.
- update commit message to reference commit that introduced the
  memory.
v3:
- limit number of buffers that can be pushed onto the percpu
  list. This avoids a problem on some kernels where one percpu
  list can inherit buffers from another cpu after a reschedule,
  causing more kernel memory to used than is necessary. Under
  normal conditions this should eventually return to normal
  but under pathelogical conditions the extra memory consumption
  may have been unbouanded
v2:
- dynamically adjust buffer hold time on percpu list based on
  lock contention.
v1:
- cache buffers on percpu list on lock contention

Reported-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Georgia Garcia <georgia.garcia@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
security/apparmor/lsm.c