From: Wei Yang <richard.weiyang@gmail.com> To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, shakeelb@google.com, guro@fb.com, vbabka@suse.cz, willy@infradead.org, songmuchun@bytedance.com, shy828301@gmail.com, surenb@google.com Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Wei Yang <richard.weiyang@gmail.com> Subject: [PATCH 4/4] mm/memcg: refine mem_cgroup_threshold_ary->current_threshold calculation Date: Tue, 11 Jan 2022 01:03:02 +0000 [thread overview] Message-ID: <20220111010302.8864-4-richard.weiyang@gmail.com> (raw) In-Reply-To: <20220111010302.8864-1-richard.weiyang@gmail.com> mem_cgroup_threshold_ary->current_threshold points to the last entry who's threshold is less or equal to usage. Instead of iterating entries to get the correct index, we can leverage primary->current_threshold to get it. If the threshold added is less or equal to usage, current_threshold should increase by one. Otherwise, it doesn't change. Signed-off-by: Wei Yang <richard.weiyang@gmail.com> --- mm/memcontrol.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index a504616f904a..ce7060907df2 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4161,7 +4161,7 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg, struct mem_cgroup_threshold_ary *new; unsigned long threshold; unsigned long usage; - int i, size, ret; + int size, ret; ret = page_counter_memparse(args, "-1", &threshold); if (ret) @@ -4193,9 +4193,13 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg, new->size = size; /* Copy thresholds (if any) to new array */ - if (thresholds->primary) + if (thresholds->primary) { memcpy(new->entries, thresholds->primary->entries, flex_array_size(new, entries, size - 1)); + new->current_threshold = thresholds->primary->current_threshold; + } else { + new->current_threshold = -1; + } /* Add new threshold */ new->entries[size - 1].eventfd = eventfd; @@ -4205,18 +4209,17 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg, sort(new->entries, size, sizeof(*new->entries), compare_thresholds, NULL); - /* Find current threshold */ - new->current_threshold = -1; - for (i = 0; i < size; i++) { - if (new->entries[i].threshold <= usage) { - /* - * new->current_threshold will not be used until - * rcu_assign_pointer(), so it's safe to increment - * it here. - */ - ++new->current_threshold; - } else - break; + /* + * If the threshold added here is less or equal to usage, this means + * current_threshold need to increase by one. + */ + if (threshold <= usage) { + /* + * new->current_threshold will not be used until + * rcu_assign_pointer(), so it's safe to increment + * it here. + */ + new->current_threshold++; } /* Free old spare buffer and save old primary buffer as spare */ -- 2.33.1
WARNING: multiple messages have this Message-ID (diff)
From: Wei Yang <richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org, mhocko-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, vdavydov.dev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org, shakeelb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org, guro-b10kYP2dOMg@public.gmane.org, vbabka-AlSwsSmVLrQ@public.gmane.org, willy-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org, songmuchun-EC8Uxl6Npydl57MIdRCFDg@public.gmane.org, shy828301-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, surenb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, Wei Yang <richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> Subject: [PATCH 4/4] mm/memcg: refine mem_cgroup_threshold_ary->current_threshold calculation Date: Tue, 11 Jan 2022 01:03:02 +0000 [thread overview] Message-ID: <20220111010302.8864-4-richard.weiyang@gmail.com> (raw) In-Reply-To: <20220111010302.8864-1-richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> mem_cgroup_threshold_ary->current_threshold points to the last entry who's threshold is less or equal to usage. Instead of iterating entries to get the correct index, we can leverage primary->current_threshold to get it. If the threshold added is less or equal to usage, current_threshold should increase by one. Otherwise, it doesn't change. Signed-off-by: Wei Yang <richard.weiyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> --- mm/memcontrol.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index a504616f904a..ce7060907df2 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4161,7 +4161,7 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg, struct mem_cgroup_threshold_ary *new; unsigned long threshold; unsigned long usage; - int i, size, ret; + int size, ret; ret = page_counter_memparse(args, "-1", &threshold); if (ret) @@ -4193,9 +4193,13 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg, new->size = size; /* Copy thresholds (if any) to new array */ - if (thresholds->primary) + if (thresholds->primary) { memcpy(new->entries, thresholds->primary->entries, flex_array_size(new, entries, size - 1)); + new->current_threshold = thresholds->primary->current_threshold; + } else { + new->current_threshold = -1; + } /* Add new threshold */ new->entries[size - 1].eventfd = eventfd; @@ -4205,18 +4209,17 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg, sort(new->entries, size, sizeof(*new->entries), compare_thresholds, NULL); - /* Find current threshold */ - new->current_threshold = -1; - for (i = 0; i < size; i++) { - if (new->entries[i].threshold <= usage) { - /* - * new->current_threshold will not be used until - * rcu_assign_pointer(), so it's safe to increment - * it here. - */ - ++new->current_threshold; - } else - break; + /* + * If the threshold added here is less or equal to usage, this means + * current_threshold need to increase by one. + */ + if (threshold <= usage) { + /* + * new->current_threshold will not be used until + * rcu_assign_pointer(), so it's safe to increment + * it here. + */ + new->current_threshold++; } /* Free old spare buffer and save old primary buffer as spare */ -- 2.33.1
next prev parent reply other threads:[~2022-01-11 1:03 UTC|newest] Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-01-11 1:02 [PATCH 1/4] mm/memcg: use NUMA_NO_NODE to indicate allocation from unspecified node Wei Yang 2022-01-11 1:02 ` Wei Yang 2022-01-11 1:03 ` [PATCH 2/4] mm/memcg: mem_cgroup_per_node is already set to 0 on allocation Wei Yang 2022-01-11 2:25 ` Muchun Song 2022-01-11 2:25 ` Muchun Song 2022-01-11 8:41 ` Michal Hocko 2022-01-11 18:06 ` Roman Gushchin 2022-01-11 18:06 ` Roman Gushchin 2022-01-14 11:08 ` Mike Rapoport 2022-01-16 19:24 ` Shakeel Butt 2022-01-16 19:24 ` Shakeel Butt 2022-01-11 1:03 ` [PATCH 3/4] mm/memcg: retrieve parent memcg from css.parent Wei Yang 2022-01-11 1:03 ` Wei Yang 2022-01-11 3:12 ` Muchun Song 2022-01-11 3:12 ` Muchun Song 2022-01-11 8:43 ` Michal Hocko 2022-01-11 18:09 ` Roman Gushchin 2022-01-11 18:09 ` Roman Gushchin 2022-01-12 0:24 ` Wei Yang 2022-01-12 0:24 ` Wei Yang 2022-01-16 19:54 ` Shakeel Butt 2022-01-16 19:54 ` Shakeel Butt 2022-01-11 1:03 ` Wei Yang [this message] 2022-01-11 1:03 ` [PATCH 4/4] mm/memcg: refine mem_cgroup_threshold_ary->current_threshold calculation Wei Yang 2022-01-11 8:44 ` Michal Hocko 2022-01-11 18:23 ` Roman Gushchin 2022-01-11 18:23 ` Roman Gushchin 2022-01-12 0:25 ` Wei Yang 2022-01-12 0:25 ` Wei Yang 2022-01-11 2:23 ` [PATCH 1/4] mm/memcg: use NUMA_NO_NODE to indicate allocation from unspecified node Muchun Song 2022-01-11 2:23 ` Muchun Song 2022-01-11 8:40 ` Michal Hocko 2022-01-11 8:40 ` Michal Hocko 2022-01-12 0:46 ` Wei Yang 2022-01-12 0:46 ` Wei Yang 2022-01-12 8:56 ` Michal Hocko 2022-01-12 8:56 ` Michal Hocko 2022-01-14 0:29 ` Wei Yang 2022-01-14 0:29 ` Wei Yang 2022-01-14 8:51 ` Michal Hocko 2022-01-14 8:51 ` Michal Hocko 2022-01-15 22:10 ` Wei Yang 2022-01-15 22:10 ` Wei Yang 2022-01-16 19:23 ` Shakeel Butt 2022-01-16 19:23 ` Shakeel Butt 2022-01-11 18:05 ` Roman Gushchin 2022-01-11 18:05 ` Roman Gushchin 2022-01-14 11:07 ` Mike Rapoport 2022-01-14 11:07 ` Mike Rapoport 2022-01-31 1:47 ` Wei Yang 2022-01-31 1:47 ` Wei Yang 2022-01-31 22:36 ` Andrew Morton 2022-01-31 22:36 ` Andrew Morton 2022-02-01 0:42 ` Wei Yang 2022-02-01 0:42 ` Wei Yang
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220111010302.8864-4-richard.weiyang@gmail.com \ --to=richard.weiyang@gmail.com \ --cc=akpm@linux-foundation.org \ --cc=cgroups@vger.kernel.org \ --cc=guro@fb.com \ --cc=hannes@cmpxchg.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=mhocko@kernel.org \ --cc=shakeelb@google.com \ --cc=shy828301@gmail.com \ --cc=songmuchun@bytedance.com \ --cc=surenb@google.com \ --cc=vbabka@suse.cz \ --cc=vdavydov.dev@gmail.com \ --cc=willy@infradead.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.