• Yosry Ahmed's avatar
    memcg: calculate root usage from global state · f82a7a86
    Yosry Ahmed authored
    Currently, we approximate the root usage by adding the memcg stats for
    anon, file, and conditionally swap (for memsw).  To read the memcg stats
    we need to invoke an rstat flush.  rstat flushes can be expensive, they
    scale with the number of cpus and cgroups on the system.
    
    mem_cgroup_usage() is called by memcg_events()->mem_cgroup_threshold()
    with irqs disabled, so such an expensive operation with irqs disabled can
    cause problems.
    
    Instead, approximate the root usage from global state.  This is not 100%
    accurate, but the root usage has always been ill-defined anyway.
    
    Link: https://lkml.kernel.org/r/20230421174020.2994750-4-yosryahmed@google.comSigned-off-by: default avatarYosry Ahmed <yosryahmed@google.com>
    Reviewed-by: default avatarMichal Koutný <mkoutny@suse.com>
    Acked-by: default avatarShakeel Butt <shakeelb@google.com>
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: Christian Brauner <brauner@kernel.org>
    Cc: Jan Kara <jack@suse.cz>
    Cc: Jens Axboe <axboe@kernel.dk>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Michal Hocko <mhocko@kernel.org>
    Cc: Muchun Song <songmuchun@bytedance.com>
    Cc: Roman Gushchin <roman.gushchin@linux.dev>
    Cc: Tejun Heo <tj@kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    f82a7a86
memcontrol.c 204 KB