• Joel Fernandes (Google)'s avatar
    rcu/tree: Add a shrinker to prevent OOM due to kfree_rcu() batching · 9154244c
    Joel Fernandes (Google) authored
    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: default avatarJoel Fernandes (Google) <joel@joelfernandes.org>
    Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
    9154244c
tree.c 130 KB