From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AD3EC433DF for ; Fri, 15 May 2020 06:56:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5551120760 for ; Fri, 15 May 2020 06:56:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5551120760 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1CB508004F; Fri, 15 May 2020 02:56:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17B5E8E0005; Fri, 15 May 2020 02:56:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 042768004F; Fri, 15 May 2020 02:56:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id DCD228E0005 for ; Fri, 15 May 2020 02:56:49 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 96AE3281F for ; Fri, 15 May 2020 06:56:49 +0000 (UTC) X-FDA: 76818045738.10.cart00_75c8084ed7c09 X-HE-Tag: cart00_75c8084ed7c09 X-Filterd-Recvd-Size: 5242 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 May 2020 06:56:49 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id w64so1358597wmg.4 for ; Thu, 14 May 2020 23:56:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Gv3CAFaRo/QH/SVWR5TaA0G+kc4MrXfRuIx/6zYFIgQ=; b=elyy+39koLUNwT51VLaqpAr8m0h/e2ngE3qVBs61lCrGyKPb/Tot13YMKn4iUo/HWj HHO8Brl/t9lLc9Mxdq64fqE3cRXqA2nYXkE2YxAMQxWHtzFRggjCHKjbS5ove1quWSUY QHjLjjamg163ljTqFB30E/PYgE1xpQU6nlYKpqv/MEfWRNPypXP33dCVrLXqMWFU4he2 NWiLondslcMPTRYFcetL014AqPVxht8SAeCNwzlnoMveIAQ4765eRb6AHQSRHW8z5f8p WoZxbizP2wAw9sva+DIYqzf4MnUbcIcCVDXP6vj//Unx+zrSLwpEkGq3PeL/Ze5u5ehe /rvg== X-Gm-Message-State: AOAM530YZ1Y5Ieql4cfVlEgOcUTbwqwTxzzszHVFXOEbsPJwBf3rDecm HUbbXaX9xpwjq2NJPzY6qJQ= X-Google-Smtp-Source: ABdhPJzjCT4vjcl+lkSt/Wi/Vn1pYsK94iWAL5HN1AB4bgaVqT7HiDVpBfZYZ0h9PQLWoMo+SMTjcg== X-Received: by 2002:a1c:9e51:: with SMTP id h78mr2461655wme.177.1589525808157; Thu, 14 May 2020 23:56:48 -0700 (PDT) Received: from localhost (ip-37-188-249-36.eurotel.cz. [37.188.249.36]) by smtp.gmail.com with ESMTPSA id x6sm2050690wrv.57.2020.05.14.23.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 23:56:47 -0700 (PDT) Date: Fri, 15 May 2020 08:56:45 +0200 From: Michal Hocko To: Roman Gushchin Cc: Zefan Li , Johannes Weiner , Vladimir Davydov , Cgroups , linux-mm@kvack.org, Andrew Morton , Shakeel Butt Subject: Re: [PATCH v2] memcg: Fix memcg_kmem_bypass() for remote memcg charging Message-ID: <20200515065645.GD29153@dhcp22.suse.cz> References: <20200513090502.GV29153@dhcp22.suse.cz> <76f71776-d049-7407-8574-86b6e9d80704@huawei.com> <20200513112905.GX29153@dhcp22.suse.cz> <3a721f62-5a66-8bc5-247b-5c8b7c51c555@huawei.com> <20200513161110.GA70427@carbon.DHCP.thefacebook.com> <20e89344-cf00-8b0c-64c3-0ac7efd601e6@huawei.com> <20200514225259.GA81563@carbon.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200514225259.GA81563@carbon.dhcp.thefacebook.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu 14-05-20 15:52:59, Roman Gushchin wrote: > On Thu, May 14, 2020 at 09:16:29AM +0800, Zefan Li wrote: > > On 2020/5/14 0:11, Roman Gushchin wrote: > > > On Wed, May 13, 2020 at 07:47:49PM +0800, Zefan Li wrote: > > >> While trying to use remote memcg charging in an out-of-tree kernel module > > >> I found it's not working, because the current thread is a workqueue thread. > > >> > > >> As we will probably encounter this issue in the future as the users of > > >> memalloc_use_memcg() grow, it's better we fix it now. > > >> > > >> Signed-off-by: Zefan Li > > >> --- > > >> > > >> v2: add a comment as sugguested by Michal. and add changelog to explain why > > >> upstream kernel needs this fix. > > >> > > >> --- > > >> > > >> mm/memcontrol.c | 3 +++ > > >> 1 file changed, 3 insertions(+) > > >> > > >> diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > >> index a3b97f1..43a12ed 100644 > > >> --- a/mm/memcontrol.c > > >> +++ b/mm/memcontrol.c > > >> @@ -2802,6 +2802,9 @@ static void memcg_schedule_kmem_cache_create(struct mem_cgroup *memcg, > > >> > > >> static inline bool memcg_kmem_bypass(void) > > >> { > > >> + /* Allow remote memcg charging in kthread contexts. */ > > >> + if (unlikely(current->active_memcg)) > > >> + return false; > > >> if (in_interrupt() || !current->mm || (current->flags & PF_KTHREAD)) > > >> return true; > > > > > > Shakeel is right about interrupts. How about something like this? > > > > > > static inline bool memcg_kmem_bypass(void) > > > { > > > if (in_interrupt()) > > > return true; > > > > > > if ((!current->mm || current->flags & PF_KTHREAD) && !current->active_memcg) > > > return true; > > > > > > return false; > > > } > > > > > > > I thought the user should ensure not do this, but now I think it makes sense to just bypass > > the interrupt case. > > I think now it's mostly a legacy of the opt-out kernel memory accounting. > Actually we can relax this requirement by forcibly overcommit the memory cgroup > if the allocation is happening from the irq context, and punish it afterwards. > Idk how much we wanna this, hopefully nobody is allocating large non-temporarily > objects from an irq. I do not think we want to pretend that remote charging from the IRQ context is supported. Why don't we simply WARN_ON(in_interrupt()) there? > > Will you send a v3? > > Thanks! -- Michal Hocko SUSE Labs