rcu/tree: Add a shrinker to prevent OOM due to kfree_rcu() batching
authorJoel Fernandes (Google) <joel@joelfernandes.org>
Mon, 16 Mar 2020 16:32:27 +0000 (12:32 -0400)
committerPaul E. McKenney <paulmck@kernel.org>
Mon, 27 Apr 2020 18:02:50 +0000 (11:02 -0700)
commit9154244c1ab6c9db4f1f25ac8f73bd46dba64287
treebd72579e4247c2e741a446646b88634faff633f8
parentf87dc808009ac86c790031627698ef1a34c31e25
rcu/tree: Add a shrinker to prevent OOM due to kfree_rcu() batching

To reduce grace periods and improve kfree() performance, we have done
batching recently dramatically bringing down the number of grace periods
while giving us the ability to use kfree_bulk() for efficient kfree'ing.

However, this has increased the likelihood of OOM condition under heavy
kfree_rcu() flood on small memory systems. This patch introduces a
shrinker which starts grace periods right away if the system is under
memory pressure due to existence of objects that have still not started
a grace period.

With this patch, I do not observe an OOM anymore on a system with 512MB
RAM and 8 CPUs, with the following rcuperf options:

rcuperf.kfree_loops=20000 rcuperf.kfree_alloc_num=8000
rcuperf.kfree_rcu_test=1 rcuperf.kfree_mult=2

Otherwise it easily OOMs with the above parameters.

NOTE:
1. On systems with no memory pressure, the patch has no effect as intended.
2. In the future, we can use this same mechanism to prevent grace periods
   from happening even more, by relying on shrinkers carefully.

Cc: urezki@gmail.com
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/tree.c