]> git.baikalelectronics.ru Git - kernel.git/commit
percpu: optimize locking in pcpu_balance_workfn()
authorRoman Gushchin <guro@fb.com>
Thu, 17 Jun 2021 19:03:22 +0000 (12:03 -0700)
committerDennis Zhou <dennis@kernel.org>
Thu, 17 Jun 2021 23:05:24 +0000 (23:05 +0000)
commit64248e92106b24f50ffc81c4e67c543868c3fd3c
treeba3ec20752ce5ecc7e4e5185e466dea3e0f83e8d
parentbcf4ce6995d7d65bbb77d899016839fe6845b741
percpu: optimize locking in pcpu_balance_workfn()

pcpu_balance_workfn() unconditionally calls pcpu_balance_free(),
pcpu_reclaim_populated(), pcpu_balance_populated() and
pcpu_balance_free() again.

Each call to pcpu_balance_free() and pcpu_reclaim_populated() will
cause at least one acquisition of the pcpu_lock. So even if the
balancing was scheduled because of a failed atomic allocation,
pcpu_lock will be acquired at least 4 times. This obviously
increases the contention on the pcpu_lock.

To optimize the scheme let's grab the pcpu_lock on the upper level
(in pcpu_balance_workfn()) and keep it generally locked for the whole
duration of the scheduled work, but release conditionally to perform
any slow operations like chunk (de)population and creation of new
chunks.

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