Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1176770imm; Sun, 15 Jul 2018 01:02:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdmGgfwWB7RtIjrAwNILlcN39LT9x9F1A12Enbtoa7p2KE7pE89vavZHxRW2GG2eYd4ly+g X-Received: by 2002:a63:1b17:: with SMTP id b23-v6mr11807576pgb.275.1531641776641; Sun, 15 Jul 2018 01:02:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531641776; cv=none; d=google.com; s=arc-20160816; b=y7St5CcudakdpJT/9uKB/tXy089CHgu4Il/BFm16tcMUoHFWGCYvfk8tkgSyJlaMn6 LIIyBaisiQxU6JlvBtht6SSu4lkQ8XqasM2qIFe4FmqGPFtxinp07eDyzajIk3RddKWI u6bUT4t96E+Y4HS/n/y+IS4q4BLZseWyU2ZbgJd+XmQYFGrr+aSEgYQ44qpqMzwksQv3 WYnAIZ2gQ2EzMODl1i5bIPnveN2lBai6/TYl/qq1DhsPfGmJhhXYIOtiEvUiuauaiC/b ZbM3yBJYNU8ovdHn3KEcc+YaUjRqHT2K+yKe1HIUadqUtff4UZn37o59qTuzdCDRsqGs NJqg== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=FDkr1xXrcgRA3MDnhm3HSG/gwPS7w5PE7zMtaHnyLbk=; b=ZQRYYfJSLGwpwtu+K+EErFGFFVEZKJaiqaMPsYcSt+uGx5XcwRrzYaoENkGBG16/KW PN9jKA0tz5oPqiX/1KCW8g5eg0lbGHpfSl73hsXNEMpLCOf+NKIet/0qMTEwdB7btc+v hUz1Rk0Dy1IphQGUTJVEs3N2mIkVGzCymZ6jL+PAN/gl736aGU4dAhE0wUTY7gXsYVxo XYEMYAs+fijdBT67ol2BHChIflNpK3TuvWEevFeRBZXc/EAOS7Qh5r9e5OVpGy63rRZ5 pHXB69+vabVyu+qh+WAcjly8RXlE4ThMgQPsvw3CdfptEFz6f42GVzrnQtNOfjDExxUy zzUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mO74vuxz; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z23-v6si27829353pfh.266.2018.07.15.01.02.41; Sun, 15 Jul 2018 01:02: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=@gmail.com header.s=20161025 header.b=mO74vuxz; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726260AbeGOIYM (ORCPT + 99 others); Sun, 15 Jul 2018 04:24:12 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:35014 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726081AbeGOIYM (ORCPT ); Sun, 15 Jul 2018 04:24:12 -0400 Received: by mail-io0-f196.google.com with SMTP id q4-v6so34951621iob.2; Sun, 15 Jul 2018 01:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=FDkr1xXrcgRA3MDnhm3HSG/gwPS7w5PE7zMtaHnyLbk=; b=mO74vuxzav3hj1VgJcb5aHoeekKeWuzOCnaUK46j2dckpE429qyjbRZtunB+BzkZXw 0qZ+dm4lUfBTNxPp7PucxNbKXi8ooViJFMm0dAFJ8dfAil0AexJQ2AwLwww/KVsiLC/S tXCukKMhTLFHG5PjkHJm3hT8/wjYnSOaH0UQPute/Zejav/nmKM1aqNi3wt90ibStM1i Yw+4osxlnRSEGcF/Issgu0ZrmLsa3X3S8ttW+uon/56IAFJ+GUdlae3RHd6fs7mI69Ur l0wjL0pGnGLqML7l6SrsKkNgOfq8oK/ubxIk4qTLsj8Oij/vSPLoYypEOPrJ/d6WITvj AbnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=FDkr1xXrcgRA3MDnhm3HSG/gwPS7w5PE7zMtaHnyLbk=; b=Pfzp2yGSGffBJ7amfeiM/wXGLaNGstvSxaseV5vrFiWUXQokBPZV0QB6NXMv7WhnGp um882NgG6zV4MqFPvlygyKdHNJULSS0UVeqATm9vnmOjsWPWuVaMt7UxoSM/Wk0QS0YD Vhhh6glvLH4duuB1HXqNKJXPtRjOTE2vnTWLe9GlIlC/k41bAzmytZnmECZfxTxRDuh2 NAD7KqZKM/q0jB0zswKBzlzfv9P1GsGMH4BICDCAemqs6CmmORp3JxcH4/yYW3hhZKsV Y74RnNF07D1bj/NCOxPe3BU28w6AeGNx+Mgg3SIvJcwYSga8wCc/iTaXsxmmYqP188aj fgRA== X-Gm-Message-State: APt69E1FM3TqeGKOtODd81+Vc6CbtcucVTduauTIarq3vA8bvabQisZI dJTH1c2h8+6rdyPyxCh+A0tQYwhfEjQJRrQC3Lk= X-Received: by 2002:a6b:c8c8:: with SMTP id y191-v6mr36032475iof.295.1531641727420; Sun, 15 Jul 2018 01:02:07 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:7a47:0:0:0:0:0 with HTTP; Sun, 15 Jul 2018 01:01:26 -0700 (PDT) In-Reply-To: References: <1531557122-12540-1-git-send-email-laoar.shao@gmail.com> From: Yafang Shao Date: Sun, 15 Jul 2018 16:01:26 +0800 Message-ID: Subject: Re: [PATCH] mm: avoid bothering interrupted task when charge memcg in softirq To: Shakeel Butt 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 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'. 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. At least we must judge that whether the memcg of 'current' is same with sk->sk_memcg if we still want to use current here. Thanks Yafang