Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1128892imm; Sat, 14 Jul 2018 23:36:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeIrtPUTK3QoK9X3FIXqp9+7WJbRyM3yHCJZP2d22n8ezY4sX1J31lsqWV5W4Z8urEBgdQQ X-Received: by 2002:a63:5c10:: with SMTP id q16-v6mr11516147pgb.452.1531636616744; Sat, 14 Jul 2018 23:36:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531636616; cv=none; d=google.com; s=arc-20160816; b=a140lcvqNe2s5sbm845mm/SsZKhne21uNwFqhZ4EkZa49qgbQBYaxIUGe7weaHnlmt wACvbQRF+uOAxD33/WwG1UkvAruseg4zrfN2sPO4XflHgFat6iFteaTD/2eCsuTBMvdj XMNaIjO9z7dMJRFL6SKbSjYU6G3FfRkGgKvNISC6y77I+ef5IU55DrS26lf3x7lQXNMR A8iPjStud3vqldfxjWn6fbs9k95oeqzRCLIznS6gu+S/h+nFmEuCJu4pHjP3RL+Oq/dC tcz1UQ+TeJrGYgmGcQ7KO8yidgn69C6ckwmJT9cnfBF2cs9V2riKGB2ChYzEUzKar1Bq tKkg== 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=mmIuNlja9tDzGR6QcBr5a9H/E35pQe2boNboyM5YycU=; b=ADAX0hXy5yzqqZ3EvlbtTeX4rr5DTV/UwppGXHSYfHdKyGYirtJYeWNpdLZERVxoPb eYYutjx6zdZfjvEoc3c5ZEBveZfHnXRWQDHR5/arkdIbCSrNSd3P1Zy/8QcdFIzA8suT UdbIEoajPpD09lzf+4M6WcDQJCSRq1V2ct/Br03ANmcEZKTQIoaYWmnxNaDbSBvjVnRi jcQdD5lJOjKOyJRavEKBbUrJCypn0AOuVI7eCUW/uPWoKg4dDb//EnEXw3bgjRW574rN yBIkVkb/XBeG36xz80kK0SV8kiE62XtChM5Rd0JRprosasGNDOfZ4ZBWBgn1X4N0/uBg skNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ORzhQntN; 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 79-v6si29186810pfs.40.2018.07.14.23.36.14; Sat, 14 Jul 2018 23:36:56 -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=ORzhQntN; 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 S1726148AbeGOG4d (ORCPT + 99 others); Sun, 15 Jul 2018 02:56:33 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:37523 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbeGOG4c (ORCPT ); Sun, 15 Jul 2018 02:56:32 -0400 Received: by mail-wr1-f67.google.com with SMTP id q10-v6so28747232wrd.4 for ; Sat, 14 Jul 2018 23:34:43 -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=mmIuNlja9tDzGR6QcBr5a9H/E35pQe2boNboyM5YycU=; b=ORzhQntNnL8Cg1RLJTfCjISxzkZ7XFqWOD9ibmB9SkmlNY40airbQGtHlTpk4QR2jM yOT62OWBsPdwpcfMjJGwFLG4HPNYd/5yi6zkWzi0joSkOsMH5iNG8HNy1smVEBOcnR6M ACHy97RO1Jfd9iKoeXL3lZV5p/APZheaO+WYIfg82a7uM3Ip3eWAfIA++Ta+XhBHA6q0 pOK6uIwcueNjvEZvS6LkkttpzzKnN7c26Nt8L2Z8JelG4bKUC7U6JvLrqupssbtXuMoo YzShq2ZmkVpweDc8a/8uL2oNGbKyZIrnUaaX2qvEmsY0LXDXLTdRTwoVlXu9uS+WexMo YkSA== 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=mmIuNlja9tDzGR6QcBr5a9H/E35pQe2boNboyM5YycU=; b=LueG0dKCOcdfm0QWKeqW5U1KsxYgJZVhw5zfq6hvSnzWn6rcxMlSwG28fFIMMHFYUR H3ql1gNMSMwtQdDmugT6BSqyXKUtkUn4NBzSc7CvMJa4DWlwp4tRu5Y88r5hR/qozdzC NPC+TMsHREFFz8n1ldTGKMj1oRIC5V2/baNV1Xa5IQjpH4cm0bdvsMbmIVVEcTgeZsYC PEzPCqdV9BF4eZWYu7UH3fQJvI6Ak3i1jozeFUkQQPvK9F8IxLlgIvzmKdVE8YzlDbEB oEVJxFuhKvGXJYUcI4L4h+vHrh07L8M5xCvNSU9tPMEBOPet42GGfvtSkqh/FkXquvU5 rrNw== X-Gm-Message-State: AOUpUlHxmLlKRP54K5P1xwdnyPXR/NR7boQXFPrANVcfKlIUQ8m4wee4 6xBWyV+ugudVVHMuHlyYNg/9cx4PqwqpZI7N2cd6ow== X-Received: by 2002:a5d:4a07:: with SMTP id m7-v6mr9699921wrq.8.1531636482885; Sat, 14 Jul 2018 23:34:42 -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 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 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