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,URIBL_BLOCKED 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 E8B84C2D0FA for ; Wed, 13 May 2020 11:29:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AAEBD206E5 for ; Wed, 13 May 2020 11:29:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AAEBD206E5 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 550AA900127; Wed, 13 May 2020 07:29:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 501DE9000F3; Wed, 13 May 2020 07:29:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 416E2900127; Wed, 13 May 2020 07:29:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0254.hostedemail.com [216.40.44.254]) by kanga.kvack.org (Postfix) with ESMTP id 2628B9000F3 for ; Wed, 13 May 2020 07:29:09 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C93248248047 for ; Wed, 13 May 2020 11:29:08 +0000 (UTC) X-FDA: 76811474376.05.cats06_32b6b22a52736 X-HE-Tag: cats06_32b6b22a52736 X-Filterd-Recvd-Size: 4466 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 May 2020 11:29:08 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id y3so20430843wrt.1 for ; Wed, 13 May 2020 04:29:08 -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=3llE+hJQ+seqQFgq9zbLo0/0zK+SZ7WYVbm/5bG7H5M=; b=kPuuHpjCAZC1oWQdgfWq4cmClFjmSadCzQt8hRZjm8kuWYh/RU6VUHcD+DqxJ11RLj IORQ5R+NG5DXPTOsiWYKgRXBJoU1sS2aQ5JVBD9B+u4N2zwcf95dAvq2IboAANFomDMS 5ADNXTNvUIbcFK3/kWWpiOlzltOGkVgX+kAGn45wWuRhlv6eyW5RDIla+5tuhWmCQo/B m04ZDsCmx3wQabNRt8imt/sRVkhcTG+rrBFpH1ryHhM6YN7/MbQwvDqiSm0kkDHlGa4G 52kLdy59npvYAQorWlXg3+yC5rbg+ffPGrBuja/yDUBZyoB3G0Ude9IQOR7eTnm82RJk vl6A== X-Gm-Message-State: AGi0Publy4GenD03Dy30cG9B3HZnECKdsEuOq+MOdGasHAS632+lRe04 1F2v+MKMuW5IABRylqKE4SQ= X-Google-Smtp-Source: APiQypIiTrg/yulPCYukZyBiZi2cwVpwClkPUU7J/CdQK1ygG8GD0tqOE20B9KXNTAgAcRSED3sVgA== X-Received: by 2002:adf:a704:: with SMTP id c4mr29943798wrd.303.1589369347321; Wed, 13 May 2020 04:29:07 -0700 (PDT) Received: from localhost (ip-37-188-249-36.eurotel.cz. [37.188.249.36]) by smtp.gmail.com with ESMTPSA id s15sm1341951wro.80.2020.05.13.04.29.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 04:29:06 -0700 (PDT) Date: Wed, 13 May 2020 13:29:05 +0200 From: Michal Hocko To: Zefan Li Cc: Johannes Weiner , Vladimir Davydov , Cgroups , linux-mm@kvack.org, Andrew Morton Subject: Re: [PATCH] memcg: Fix memcg_kmem_bypass() for remote memcg charging Message-ID: <20200513112905.GX29153@dhcp22.suse.cz> References: <20200513090502.GV29153@dhcp22.suse.cz> <76f71776-d049-7407-8574-86b6e9d80704@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <76f71776-d049-7407-8574-86b6e9d80704@huawei.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: [Cc Roman - initial email is http://lkml.kernel.org/r/e6927a82-949c-bdfd-d717-0a14743c6759@huawei.com] On Wed 13-05-20 19:19:56, Li Zefan wrote: > On 2020/5/13 17:05, Michal Hocko wrote: > > On Wed 13-05-20 15:28:28, Li Zefan 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. > >> > >> Signed-off-by: Zefan Li > >> --- > >> > >> No need to queue this for v5.7 as currently no upstream users of this memcg > >> feature suffer from this bug. > >> > >> --- > >> mm/memcontrol.c | 2 ++ > >> 1 file changed, 2 insertions(+) > >> > >> diff --git a/mm/memcontrol.c b/mm/memcontrol.c > >> index a3b97f1..db836fc 100644 > >> --- a/mm/memcontrol.c > >> +++ b/mm/memcontrol.c > >> @@ -2802,6 +2802,8 @@ static void memcg_schedule_kmem_cache_create(struct mem_cgroup *memcg, > >> > >> static inline bool memcg_kmem_bypass(void) > >> { > >> + if (unlikely(current->active_memcg)) > >> + return false; > > > > I am confused. Why the check below is insufficient? It checks for both mm > > and PF_KTHREAD? > > > > memalloc_use_memcg(memcg); > alloc_page(GFP_KERNEL_ACCOUNT); > memalloc_unuse_memcg(); > > If we run above code in a workqueue thread the memory won't be charged to the specific > memcg, because memcg_kmem_bypass() returns true in this case. Ohh, right I have misread your patch. Sorry about that. A comment for the above branch would make it more clear. Something like /* Allow memalloc_use_memcg usage from kthread contexts */ On the other hand adding a code for an out of tree code is usually not welcome. But in this particular case the branch is correct for the existing code already so I am OK with it. Roman is de-facto kmem implementation maintainer so I will defer to him. > >> if (in_interrupt() || !current->mm || (current->flags & PF_KTHREAD)) > >> return true; > >> return false; -- Michal Hocko SUSE Labs