From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 336246B026D for ; Sun, 15 Jul 2018 02:34:45 -0400 (EDT) Received: by mail-wr1-f69.google.com with SMTP id g9-v6so6916642wrq.7 for ; Sat, 14 Jul 2018 23:34:45 -0700 (PDT) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id g12-v6sor2082675wrq.26.2018.07.14.23.34.43 for (Google Transport Security); Sat, 14 Jul 2018 23:34:43 -0700 (PDT) MIME-Version: 1.0 References: <1531557122-12540-1-git-send-email-laoar.shao@gmail.com> In-Reply-To: From: Shakeel Butt Date: Sat, 14 Jul 2018 23:34:30 -0700 Message-ID: Subject: Re: [PATCH] mm: avoid bothering interrupted task when charge memcg in softirq Content-Type: text/plain; charset="UTF-8" Sender: owner-linux-mm@kvack.org List-ID: To: Yafang Shao Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Cgroups , Linux MM , LKML On Sat, Jul 14, 2018 at 10:26 PM Yafang Shao wrote: > > On Sun, Jul 15, 2018 at 12:25 PM, Shakeel Butt wrote: > > On Sat, Jul 14, 2018 at 7:10 PM Yafang Shao wrote: > >> > >> On Sat, Jul 14, 2018 at 11:38 PM, Shakeel Butt wrote: > >> > On Sat, Jul 14, 2018 at 1:32 AM 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'. > >> >> > >> > > >> > Have you actually seen this occurring? > >> > >> Hi Shakeel, > >> > >> I'm trying to produce this issue, but haven't find it occur yet. > >> > >> > I am not very familiar with the > >> > network code but I can think of two ways try_charge() can be called > >> > from network code. Either through kmem charging or through > >> > mem_cgroup_charge_skmem() and both locations correctly handle > >> > interrupt context. > >> > > >> > >> Why do you say that mem_cgroup_charge_skmem() correctly hanle > >> interrupt context ? > >> > >> Let me show you why mem_cgroup_charge_skmem isn't hanling interrupt > >> context correctly. > >> > >> mem_cgroup_charge_skmem() is calling try_charge() twice. > >> The first one is with GFP_NOWAIT as the gfp_mask, and the second one > >> is with (GFP_NOWAIT | __GFP_NOFAIL) as the gfp_mask. > >> > >> If page_counter_try_charge() failes at the first time, -ENOMEM is returned. > >> Then mem_cgroup_charge_skmem() will call try_charge() once more with > >> __GFP_NOFAIL set, and this time if If page_counter_try_charge() failes > >> again the ' > >> force' label in try_charge() will be executed and 0 is returned. > >> > >> No matter what, the 'current' will be used and touched, that is > >> meaning mem_cgroup_charge_skmem() isn't hanling the interrupt context > >> correctly. > >> > > > > Hi Yafang, > > > > If you check mem_cgroup_charge_skmem(), the memcg passed is not > > 'current' but is from the sock object i.e. sk->sk_memcg for which the > > network buffer is allocated for. > > > > That's correct, the memcg if from the sock object. > But the point is, in this situation why 'current' is used in try_charge() ? > As 'current' is not related with the memcg, which is just a interrupted task. > Hmm so you mean the behavior of memcg charging in the interrupt context depends on the state of the interrupted task. As you have noted, mem_cgroup_charge_skmem() tries charging again with __GFP_NOFAIL and the charge succeeds. Basically the memcg charging by mem_cgroup_charge_skmem() will always succeed irrespective of the state of the interrupted task. However mem_cgroup_charge_skmem() can return true if the interrupted task was exiting or a fatal signal is pending or oom victim or reclaiming memory. Can you please explain why this is bad? Shakeel