All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
	Vladimir Davydov <vdavydov.dev@gmail.com>,
	Cgroups <cgroups@vger.kernel.org>, Linux MM <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mm: avoid bothering interrupted task when charge memcg in softirq
Date: Mon, 16 Jul 2018 17:45:06 +0800	[thread overview]
Message-ID: <CALOAHbD1+eYHDo5-q1--nsBTNj66ZX6iw2YU4koLgZD_0ZDy+w@mail.gmail.com> (raw)
In-Reply-To: <20180716075836.GC17280@dhcp22.suse.cz>

On Mon, Jul 16, 2018 at 3:58 PM, Michal Hocko <mhocko@kernel.org> wrote:
> On Sat 14-07-18 16:32:02, Yafang Shao wrote:
>> try_charge maybe executed in packet receive path, which is in interrupt
>> context.
>> In this situation, the 'current' is the interrupted task, which may has
>> no relation to the rx softirq, So it is nonsense to use 'current'.
>>
>> Avoid bothering the interrupted if page_counter_try_charge failes.
>
> I agree with Shakeel that this changelog asks for more information about
> "why it matters". Small inconsistencies should be tolerable because the
> state we rely on is so rarely set that it shouldn't make a visible
> difference in practice.
>

HI Michal,

No, it can make a visible difference in pratice.
The difference is in __sk_mem_raise_allocated().

Without this patch, if the random interrupted task is oom victim or
fatal signal pending or exiting, the charge will success anyway. That
means the cgroup limit doesn't work in this situation.

With this patch, in the same situation the charged memory will be
uncharged as it hits the memcg limit.

That is okay if the memcg of the interrupted task is same with the
sk->sk_memcg,  but it may not okay if they are difference.

I'm trying to prove it, but seems it's very hard to produce this issue.

>> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
>> ---
>>  mm/memcontrol.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>> index 68ef266..13f95db 100644
>> --- a/mm/memcontrol.c
>> +++ b/mm/memcontrol.c
>> @@ -2123,6 +2123,9 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
>>               goto retry;
>>       }
>>
>> +     if (in_softirq())
>> +             goto nomem;
>> +
>
> If anything would it make more sense to use in_interrupt() to be more
> bullet proof for future?
>
>>       /*
>>        * Unlike in global OOM situations, memcg is not in a physical
>>        * memory shortage.  Allow dying and OOM-killed tasks to
>> --
>> 1.8.3.1
>
> --
> Michal Hocko
> SUSE Labs

  reply	other threads:[~2018-07-16  9:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-14  8:32 [PATCH] mm: avoid bothering interrupted task when charge memcg in softirq Yafang Shao
2018-07-14 15:38 ` Shakeel Butt
2018-07-15  2:10   ` Yafang Shao
2018-07-15  2:25     ` Yafang Shao
2018-07-15  4:25     ` Shakeel Butt
2018-07-15  5:25       ` Yafang Shao
2018-07-15  6:34         ` Shakeel Butt
2018-07-15  8:01           ` Yafang Shao
2018-07-15 15:04             ` Shakeel Butt
2018-07-16  1:49               ` Yafang Shao
2018-07-16  3:09                 ` Shakeel Butt
2018-07-16  3:38                   ` Yafang Shao
2018-07-16  7:58 ` Michal Hocko
2018-07-16  9:45   ` Yafang Shao [this message]
2018-07-16 11:08     ` 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=CALOAHbD1+eYHDo5-q1--nsBTNj66ZX6iw2YU4koLgZD_0ZDy+w@mail.gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.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 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.