Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1452117imm; Sun, 15 Jul 2018 08:05:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfXuvJZI+6yWEkdErKSRm3k+N/+jZQnmdykgX1z9pn2xV1UelxZqI7CsfswzbLJ3cQoJ4PU X-Received: by 2002:a63:f18:: with SMTP id e24-v6mr12737767pgl.320.1531667129362; Sun, 15 Jul 2018 08:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531667129; cv=none; d=google.com; s=arc-20160816; b=eUfI4vOx2nOx+tw8W4o/OweAzv/Bm4glqHHOxdaAA5FjtUz1JZzqONV11L8trMG4TZ 7QiqRNxfJ0L59sgdV8DPr9/SG/QID+Hdt5ZFheA3kPx8QwYH12sobwfvBrOhTmAgx9vW 5+CIH2PXSwMPaRALdtZfs3xxPfE6+uRF5TSRaueIRs72Qsf5w1mEnEcHp4f5r5ZorECM O/GjQonevvf7DyIxRqOkyGyKc4RCwpuHxU8WhL5cMUuyEH1CiH1Yg/HqfogN5RD0meWt FeRXE0Q7hra1+y3WRviRSMkeVA+rIDT2+BY5v8teasNONNYHv54/vbXdrtgtWK0EKaDq UNLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=KiVpzbUIdMnr/7Qi4XDDfIzppRHFLk8uvimEcOZb7nU=; b=Cu3xhAtvnCPUqw/gQasvtj+jMFxhdSD2AcMkJ8yiyjt44Js2o7DpACKnaXJu80ZpRw fD7XPMJEaDiYl4DsmcJ3VDJNvQrA71CNVSMVlPkX9+T+YBgjDeqtB6wvf0z3Y3E3jiHq EsTp7qe8Deb5rrO4uT+zF0qapUA+Ku7Fj+mUDhKmA4SO2pMKOY5/Ve3i6AaRFbx33wT4 CW0vUygJ2Eak25/nw8W3BX4RAc5kcUIJNwZRr2ncMYjkfjfmgaDR8l/1cz5Crs08W8jm 1Uv515qytxg8KvyNPNK4iwYp+yYdncBATeV1T4sCwZzzqhM/PmuL2n56fW6TXRmnz9AS Yeuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oPExDVCv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t191-v6si5098pgc.481.2018.07.15.08.05.13; Sun, 15 Jul 2018 08:05:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oPExDVCv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726735AbeGOP1x (ORCPT + 99 others); Sun, 15 Jul 2018 11:27:53 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:53572 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726333AbeGOP1w (ORCPT ); Sun, 15 Jul 2018 11:27:52 -0400 Received: by mail-wm0-f66.google.com with SMTP id s9-v6so5428836wmh.3 for ; Sun, 15 Jul 2018 08:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KiVpzbUIdMnr/7Qi4XDDfIzppRHFLk8uvimEcOZb7nU=; b=oPExDVCvEbA4l2ebxQG0mLkufq0C4ebM6EeB08H/iMiug3agRJAKA+s7DcILIYK74O WHUsBmY2kmLq1DQo1iGnQkYsZTzL5J2yiJjr1lY2XvtNA/yQTE7ccuIrVlUcEoVEGK7Y NX2HYcLdRdwu28ZzNvun6ydjYBwqa/qkmNZpLAB0cNOPbJuiPbdOVjuQPk/CH1MxSp/s f/bU4HJOvejfqGy1PVDP3wuuNI0fwC+TV43pDzu523xL5PhcqYZ+K0mD223jipRyvUGM 8nW/y2NK00Xfas6RZTnalodEk/5RH9RcD1aMKngdDHyZEQ0+gNC/BbHUwqrywx9Fmns+ wNSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KiVpzbUIdMnr/7Qi4XDDfIzppRHFLk8uvimEcOZb7nU=; b=qUOVvHbJ76vC/q9NNnrR5nUMNJ1V+JnHjZnEIMhdMCcoDLa3IXB/9PlcJhF0wF9C5g fB6okIPyFw3vFwMOk49mv/DUGmObEP9TMcfWvl3iLxKKKcn2vNjg04cD3CxJG0m5myQc bXDwbxc8gDUzimClYF3JwjqhipY7koCxIVYoa8KufF67MekHLgKLlU+hrxvwWKViyBjL tdJymeDFBLbhWBUp4bBQ78+8UUJrrJ3Svk22RtGrviZwYPDtXMSNTB9PDHnegx0f8Inr TmFfuL4cr9q2wpmwiz3RBZmJHFPRs/NC06MSMVpj7SHN9+dzPbxry5YCAdPs2qTZnxpz LjPg== X-Gm-Message-State: AOUpUlHLa/Tr8J1wniqCfDTJUNNuRITqzJk5jhbhh3iNYLG6Y83vvtg4 +xb0w3RHAaUKgLh66JBBkGGiX/5tZVcPz0+ailr2wg== X-Received: by 2002:a1c:8b81:: with SMTP id n123-v6mr7679904wmd.142.1531667075756; Sun, 15 Jul 2018 08:04:35 -0700 (PDT) MIME-Version: 1.0 References: <1531557122-12540-1-git-send-email-laoar.shao@gmail.com> In-Reply-To: From: Shakeel Butt Date: Sun, 15 Jul 2018 08:04:24 -0700 Message-ID: Subject: Re: [PATCH] mm: avoid bothering interrupted task when charge memcg in softirq To: Yafang Shao Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Cgroups , Linux MM , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 15, 2018 at 1:02 AM Yafang Shao wrote: > > On Sun, Jul 15, 2018 at 2:34 PM, Shakeel Butt wrote: > > 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. > > Yes. > > > 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? > > > > Let me show you the possible issues cause by this behavoir. > 1. In mem_cgroup_oom(), some members in 'current' is set. > That means an innocent task will be in task_in_memcg_oom state. > But this task may be in a different memcg, I mean the memcg of > the 'current' may be differenct with the sk->sk_memcg. > Then when this innocent 'current' do try_charge it will hit "if > (unlikely(task_in_memcg_oom(current)))" and -ENOMEM is returned, > While there're maybe some free memory (or some memory could be freed ) > in the memcg of the innocent 'task'. > No memory will be freed as try_charge() is in interrupt context. > 2. If the interrupted task was exiting or a fatal signal is pending > or oom victim, > it will directly goto force and 0 is returned, and then > mem_cgroup_charge_skmem() will return true. > But mem_cgroup_charge_skmem() maybe need to try the second time > and return false. > > That are all unexpected behavoir. > Yes, this is inconsistent behavior. Can you explain how this will affect network traffic? Basically mem_cgroup_charge_skmem() was supposed to return false but sometime based on the interrupted task, mem_cgroup_charge_skmem() returns true. How is this behavior bad for network traffic? Please note that I am not against this patch. I just want that the motivation/reason behind it is very clear. thanks, Shakeel