• Sebastian Andrzej Siewior's avatar
    mm/memcg: disable migration instead of preemption in drain_all_stock(). · 0790ed62
    Sebastian Andrzej Siewior authored
    Before the for-each-CPU loop, preemption is disabled so that so that
    drain_local_stock() can be invoked directly instead of scheduling a
    worker.  Ensuring that drain_local_stock() completed on the local CPU is
    not correctness problem.  It _could_ be that the charging path will be
    forced to reclaim memory because cached charges are still waiting for
    their draining.
    
    Disabling preemption before invoking drain_local_stock() is problematic
    on PREEMPT_RT due to the sleeping locks involved.  To ensure that no CPU
    migrations happens across for_each_online_cpu() it is enouhg to use
    migrate_disable() which disables migration and keeps context preemptible
    to a sleeping lock can be acquired.  A race with CPU hotplug is not a
    problem because pcp data is not going away.  In the worst case we just
    schedule draining of an empty stock.
    
    Use migrate_disable() instead of get_cpu() around the
    for_each_online_cpu() loop.
    
    Link: https://lkml.kernel.org/r/20220226204144.1008339-7-bigeasy@linutronix.deSigned-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
    Acked-by: default avatarMichal Hocko <mhocko@suse.com>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: kernel test robot <oliver.sang@intel.com>
    Cc: Michal Hocko <mhocko@kernel.org>
    Cc: Michal Koutný <mkoutny@suse.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Roman Gushchin <roman.gushchin@linux.dev>
    Cc: Shakeel Butt <shakeelb@google.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
    Cc: Waiman Long <longman@redhat.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    0790ed62
memcontrol.c 194 KB