From: Johannes Weiner <hannes@cmpxchg.org>
To: Muchun Song <songmuchun@bytedance.com>
Cc: akpm@linux-foundation.org, shakeelb@google.com, guro@fb.com,
mhocko@suse.com, laoar.shao@gmail.com, chris@chrisdown.name,
tj@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: memcontrol: fix missing wakeup polling thread
Date: Thu, 5 Nov 2020 10:50:28 -0500 [thread overview]
Message-ID: <20201105155028.GD744831@cmpxchg.org> (raw)
In-Reply-To: <20201104125558.49472-1-songmuchun@bytedance.com>
On Wed, Nov 04, 2020 at 08:55:58PM +0800, Muchun Song wrote:
> When wen poll the memory.swap.events, we can miss being waked up when the
> swap event occurs. Because we didn't notify.
>
> Fixes: f3a53a3a1e5b ("mm, memcontrol: implement memory.swap.events")
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Good catch!
> ---
> include/linux/memcontrol.h | 18 ++++++++++++++++--
> 1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 0f4dd7829fb2..2456cb737329 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -1071,15 +1071,29 @@ static inline void count_memcg_event_mm(struct mm_struct *mm,
> rcu_read_unlock();
> }
>
> +static inline bool is_swap_memory_event(enum memcg_memory_event event)
> +{
> + return event == MEMCG_SWAP_HIGH || event == MEMCG_SWAP_MAX ||
> + event == MEMCG_SWAP_FAIL;
> +}
Please inline this, it's not really worth the indirection.
> static inline void memcg_memory_event(struct mem_cgroup *memcg,
> enum memcg_memory_event event)
> {
> + bool swap_event = is_swap_memory_event(event);
> + struct cgroup_file *cfile;
> +
> atomic_long_inc(&memcg->memory_events_local[event]);
> - cgroup_file_notify(&memcg->events_local_file);
> + if (swap_event) {
> + cfile = &memcg->swap_events_file;
> + } else {
> + cfile = &memcg->events_file;
> + cgroup_file_notify(&memcg->events_local_file);
> + }
>
> do {
> atomic_long_inc(&memcg->memory_events[event]);
> - cgroup_file_notify(&memcg->events_file);
> + cgroup_file_notify(cfile);
This loop is a walk up the hierarchy and memcg keeps changing, so you
cannot cache cfile up front.
if (swap_event)
cgroup_file_notify(&memcg->swap_events_file);
else
cgroup_file_notify(&memcg->events_file);
next prev parent reply other threads:[~2020-11-05 15:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-04 12:55 [PATCH] mm: memcontrol: fix missing wakeup polling thread Muchun Song
2020-11-05 15:50 ` Johannes Weiner [this message]
2020-11-05 16:01 ` [External] " Muchun Song
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=20201105155028.GD744831@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.org \
--cc=chris@chrisdown.name \
--cc=guro@fb.com \
--cc=laoar.shao@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=shakeelb@google.com \
--cc=songmuchun@bytedance.com \
--cc=tj@kernel.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: 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