From: Wei Yang <richard.weiyang@gmail.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Wei Yang <richard.weiyang@gmail.com>,
mhocko@kernel.org, vdavydov.dev@gmail.com,
akpm@linux-foundation.org, cgroups@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH 2/3] mm/memcg: set pos to prev unconditionally
Date: Wed, 30 Mar 2022 00:47:50 +0000 [thread overview]
Message-ID: <20220330004750.fx4jr4bnehz4ynpf@master> (raw)
In-Reply-To: <YkNUZYrSHPjJ1XOb@cmpxchg.org>
On Tue, Mar 29, 2022 at 02:48:05PM -0400, Johannes Weiner wrote:
>On Fri, Feb 25, 2022 at 12:34:36AM +0000, Wei Yang wrote:
>> Current code set pos to prev based on condition (prev && !reclaim),
>> while we can do this unconditionally.
>>
>> Since:
>>
>> * If !reclaim, pos is the same as prev no matter it is NULL or not.
>> * If reclaim, pos would be set properly from iter->position.
>>
>> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>> ---
>> mm/memcontrol.c | 5 +----
>> 1 file changed, 1 insertion(+), 4 deletions(-)
>>
>> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>> index 9464fe2aa329..03399146168f 100644
>> --- a/mm/memcontrol.c
>> +++ b/mm/memcontrol.c
>> @@ -980,7 +980,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,
>> struct mem_cgroup_reclaim_iter *iter;
>> struct cgroup_subsys_state *css = NULL;
>> struct mem_cgroup *memcg = NULL;
>> - struct mem_cgroup *pos = NULL;
>> + struct mem_cgroup *pos = prev;
>
>I don't like this so much. It suggests pos always starts with prev, no
>matter what. But this isn't true for reclaim mode, which overrides the
>initialized value again.
>
>> if (mem_cgroup_disabled())
>> return NULL;
>> @@ -988,9 +988,6 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,
>> if (!root)
>> root = root_mem_cgroup;
>>
>> - if (prev && !reclaim)
>> - pos = prev;
>
>How about making the reclaim vs non-reclaim mode explicit and do:
>
> if (reclaim) {
> ...
> pos = iter->position;
> ...
> } else {
> pos = prev;
> }
Something like this?
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index eed9916cdce5..5d433b79ba47 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1005,9 +1005,6 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,
if (!root)
root = root_mem_cgroup;
- if (prev && !reclaim)
- pos = prev;
-
rcu_read_lock();
if (reclaim) {
@@ -1033,6 +1030,8 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,
*/
(void)cmpxchg(&iter->position, pos, NULL);
}
+ } else if (prev) {
+ pos = prev;
}
if (pos)
--
Wei Yang
Help you, Help me
next prev parent reply other threads:[~2022-03-30 0:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-25 0:34 [PATCH 0/3] mm/memcg: some cleanup for mem_cgroup_iter() Wei Yang
2022-02-25 0:34 ` [PATCH 1/3] mm/memcg: set memcg after css verified and got reference Wei Yang
2022-03-29 18:44 ` Johannes Weiner
2022-02-25 0:34 ` [PATCH 2/3] mm/memcg: set pos to prev unconditionally Wei Yang
2022-03-29 18:48 ` Johannes Weiner
2022-03-30 0:47 ` Wei Yang [this message]
2022-03-30 12:08 ` Johannes Weiner
2022-03-30 14:22 ` Wei Yang
2022-02-25 0:34 ` [PATCH 3/3] mm/memcg: move generation assignment and comparison together Wei Yang
2022-03-30 15:57 ` Johannes Weiner
2022-03-30 23:04 ` Wei Yang
2022-02-25 8:13 ` [PATCH 0/3] mm/memcg: some cleanup for mem_cgroup_iter() Michal Hocko
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=20220330004750.fx4jr4bnehz4ynpf@master \
--to=richard.weiyang@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=vdavydov.dev@gmail.com \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox