diff options
author | Shakeel Butt <shakeel.butt@linux.dev> | 2024-08-14 22:04:48 -0700 |
---|---|---|
committer | Andrew Morton <akpm@linux-foundation.org> | 2024-09-01 20:26:19 -0700 |
commit | 41213dd0f81654f0a7863bb5b07a2ebaaf732ebe (patch) | |
tree | 7d4ff6361d4a97dee4a7526e1870345bcb1e46a5 /mm/memcontrol-v1.c | |
parent | 5d383b69a04e2eb2e0ae06e91821fd82cb9acf73 (diff) | |
download | lwn-41213dd0f81654f0a7863bb5b07a2ebaaf732ebe.tar.gz lwn-41213dd0f81654f0a7863bb5b07a2ebaaf732ebe.zip |
memcg: move mem_cgroup_event_ratelimit to v1 code
There are no callers of mem_cgroup_event_ratelimit() in the v2 code. Move
it to v1 only code and rename it to memcg1_event_ratelimit().
Link: https://lkml.kernel.org/r/20240815050453.1298138-3-shakeel.butt@linux.dev
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: T.J. Mercier <tjmercier@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/memcontrol-v1.c')
-rw-r--r-- | mm/memcontrol-v1.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c index 417c96f2da28..38809a26089a 100644 --- a/mm/memcontrol-v1.c +++ b/mm/memcontrol-v1.c @@ -1439,6 +1439,34 @@ static void mem_cgroup_threshold(struct mem_cgroup *memcg) } } +#define THRESHOLDS_EVENTS_TARGET 128 +#define SOFTLIMIT_EVENTS_TARGET 1024 + +static bool memcg1_event_ratelimit(struct mem_cgroup *memcg, + enum mem_cgroup_events_target target) +{ + unsigned long val, next; + + val = __this_cpu_read(memcg->events_percpu->nr_page_events); + next = __this_cpu_read(memcg->events_percpu->targets[target]); + /* from time_after() in jiffies.h */ + if ((long)(next - val) < 0) { + switch (target) { + case MEM_CGROUP_TARGET_THRESH: + next = val + THRESHOLDS_EVENTS_TARGET; + break; + case MEM_CGROUP_TARGET_SOFTLIMIT: + next = val + SOFTLIMIT_EVENTS_TARGET; + break; + default: + break; + } + __this_cpu_write(memcg->events_percpu->targets[target], next); + return true; + } + return false; +} + /* * Check events in order. * @@ -1449,11 +1477,11 @@ void memcg1_check_events(struct mem_cgroup *memcg, int nid) return; /* threshold event is triggered in finer grain than soft limit */ - if (unlikely(mem_cgroup_event_ratelimit(memcg, + if (unlikely(memcg1_event_ratelimit(memcg, MEM_CGROUP_TARGET_THRESH))) { bool do_softlimit; - do_softlimit = mem_cgroup_event_ratelimit(memcg, + do_softlimit = memcg1_event_ratelimit(memcg, MEM_CGROUP_TARGET_SOFTLIMIT); mem_cgroup_threshold(memcg); if (unlikely(do_softlimit)) |