mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
UPSTREAM: memcg: do not flush stats in irq context
Currently, the only context in which we can invoke an rstat flush from irq
context is through mem_cgroup_usage() on the root memcg when called from
memcg_check_events(). An rstat flush is an expensive operation that
should not be done in irq context, so do not flush stats and use the stale
stats in this case.
Arguably, usage threshold events are not reliable on the root memcg anyway
since its usage is ill-defined.
Link: https://lkml.kernel.org/r/20230330191801.1967435-4-yosryahmed@google.com
Change-Id: If230311168f126e3741afaeab1f20cb1949190f0
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Suggested-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Koutný <mkoutny@suse.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vasily Averin <vasily.averin@linux.dev>
Cc: Zefan Li <lizefan.x@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit a2174e95cc)
Bug: 322544714
Signed-off-by: T.J. Mercier <tjmercier@google.com>
This commit is contained in:
committed by
T.J. Mercier
parent
a77a4ca4f4
commit
86ff69608f
@@ -3667,7 +3667,21 @@ static unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap)
|
|||||||
unsigned long val;
|
unsigned long val;
|
||||||
|
|
||||||
if (mem_cgroup_is_root(memcg)) {
|
if (mem_cgroup_is_root(memcg)) {
|
||||||
mem_cgroup_flush_stats();
|
/*
|
||||||
|
* We can reach here from irq context through:
|
||||||
|
* uncharge_batch()
|
||||||
|
* |--memcg_check_events()
|
||||||
|
* |--mem_cgroup_threshold()
|
||||||
|
* |--__mem_cgroup_threshold()
|
||||||
|
* |--mem_cgroup_usage
|
||||||
|
*
|
||||||
|
* rstat flushing is an expensive operation that should not be
|
||||||
|
* done from irq context; use stale stats in this case.
|
||||||
|
* Arguably, usage threshold events are not reliable on the root
|
||||||
|
* memcg anyway since its usage is ill-defined.
|
||||||
|
*/
|
||||||
|
if (in_task())
|
||||||
|
mem_cgroup_flush_stats();
|
||||||
val = memcg_page_state(memcg, NR_FILE_PAGES) +
|
val = memcg_page_state(memcg, NR_FILE_PAGES) +
|
||||||
memcg_page_state(memcg, NR_ANON_MAPPED);
|
memcg_page_state(memcg, NR_ANON_MAPPED);
|
||||||
if (swap)
|
if (swap)
|
||||||
|
|||||||
Reference in New Issue
Block a user