Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1002403imm; Sat, 14 Jul 2018 19:26:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfc47Ltw26WFsVCMn0fSNgjOuyinDvlVqpoin+ZY4Y9scCuKN6EGLFBtUATCIQOM6JdhRd7 X-Received: by 2002:a63:3d41:: with SMTP id k62-v6mr11195365pga.254.1531621598576; Sat, 14 Jul 2018 19:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531621598; cv=none; d=google.com; s=arc-20160816; b=LpvpPnc69+Xg1jvX/xAOPE/ttQeL2nsZFIuQIyrJA9X3Eoh9oODbb3E9GxJ27e0Sci ruI7+9mV/ltKGn4ztPHLrJa6NwxSsVYmSZ73Jt2UPOZybVbzR1kxRuaf1suOmwQ1V/cH 7KaEbu4Y6i44QdBRJMelWPXjiQKX/CaMPDmXslljX72DrXtbEODmpyS1mQOpRxCLYMbP eG0dQB1NMoVDlT2SN8YmkqktKtDZ1BAE3o2FT5Ax60GfOS4VXmgF1i4ggwXzlOIJYU/E 5qUKZdYL1+9sN9o39wTIzYgdzJNGNfNcprEP0ZdVJbEc+uSi+sgTSjfOSCcrUGLnUJ3O 71Qg== 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=o7Uj+8OHr/w92FSAO+0rbmG2vNuuu8yFVUa8EREwXEE=; b=dsQ7LtNCPqpF/WX0O+L53q6VqdfT1tZqRS4PK/453MqXI93fXJxJ8Nl+Y9p/JM8fLt Np/0ZQH0l+7NK0urY74KJ6ZmhR/4ycqC4KoY5I3ADi5aERv2OBWVFFEcpRqs/h2b/B66 IkyBDY7RT46IY5iSVDVTKTS57yjHAddF8lUEQAr4vBqopQm2r9HkuSTpFZSALLn+YDoA 7tF0nPdQLOnZ1g7vZexcW6C79ZlkJCD2fU7hlLaTeJqjAHuMXzq8+txeU/5uA+5R5xdg reLUQKMkXZRHUgshMFJqzSaL5LbWkwCBvnM8LmOu7LMMrXDCdWIDm89F34py2YO7Fdi6 133Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lvXvm1BY; 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 x1-v6si26976970plb.8.2018.07.14.19.26.23; Sat, 14 Jul 2018 19:26:38 -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=lvXvm1BY; 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 S1732980AbeGOCrB (ORCPT + 99 others); Sat, 14 Jul 2018 22:47:01 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:33066 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731985AbeGOCrB (ORCPT ); Sat, 14 Jul 2018 22:47:01 -0400 Received: by mail-io0-f196.google.com with SMTP id z20-v6so34649131iol.0; Sat, 14 Jul 2018 19:25:50 -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=o7Uj+8OHr/w92FSAO+0rbmG2vNuuu8yFVUa8EREwXEE=; b=lvXvm1BYY1CkHypyukRfwIfRiQ9Xc7eL2XVbTzwBmLODpXk3HmF5iJ+fHddx5mny7t FcKcmitv+vAeKOSGBf5j70FRFuRfOP2gIT/fWkC9tpz2Jrc1l//2uLVr3Z/Cn5OZubsu bbdt7x0Fwxt+JgsOGp2ILCAt2SxLMlMFgmdTC8nZmbjCy5gbFuR+PDnhxmImQwKftU6j WcrsxlJj7swVEMWc9azO/bRXTQfLR7th9gXlT736ps9f4Us26s2odUg4oM5yngMDGWBH xKlQwX0ybatD6E3ZpSljseTtBtltUh0PnnzRpw3yk4nYZn9cutdbOn6Iy0azgYVhNBav x7AQ== 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=o7Uj+8OHr/w92FSAO+0rbmG2vNuuu8yFVUa8EREwXEE=; b=s2rfmjBly60MC/0gDUZ9GjSXn6OfIEUODE4Ml5Z7hJsx7S9FGY3kBYPr7cDnw1OuGW ksOpiEwEiBvIS64/ciAwSwe35rFObxw+V4ZU1U+89bK2N2/VHtTchTMIt+qOqkGZtBWA p10Fn2Fv8qdLtWGkIldau/DLlCSkNu4qg3QzosFMW461ly5khVBOsBxHHi8Oda8cv8p5 9osaz6IoRVDLJzU6bsdAnt9zvnaV3vzHnDDm5TVyPLzYNYNPQLBoQlwiClVv3rTsS8Z2 NsyrKic6j3qUP5pERvSFzvWOlMdWce5Ut4hgC0L6Uu5hG1lzIyv0teWC07xsqvRm8foY jkig== X-Gm-Message-State: APt69E30g4R4AECp/dHH6bUm4GhjAL2Jl7zhRAiVjnJJnPofHqxRIxLk eAP7qbTbefIjd6S1ValICaOEi4THQ8OOsGozTzU= X-Received: by 2002:a6b:c8c8:: with SMTP id y191-v6mr35537933iof.295.1531621550139; Sat, 14 Jul 2018 19:25:50 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:7a47:0:0:0:0:0 with HTTP; Sat, 14 Jul 2018 19:25:09 -0700 (PDT) In-Reply-To: References: <1531557122-12540-1-git-send-email-laoar.shao@gmail.com> From: Yafang Shao Date: Sun, 15 Jul 2018 10:25:09 +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 10:10 AM, 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. > > Pls. let me know if I miss something. > > Maybe bellow change is better, @@ -2123,6 +2123,9 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, goto retry; } + if (!gfpflags_allow_blocking(gfp_mask)) + goto nomem; + /* * Unlike in global OOM situations, memcg is not in a physical * memory shortage. Allow dying and OOM-killed tasks to @@ -2146,9 +2149,6 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, if (unlikely(task_in_memcg_oom(current))) goto nomem; - if (!gfpflags_allow_blocking(gfp_mask)) - goto nomem; Thanks Yafang