From patchwork Wed May 13 11:47:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zefan Li X-Patchwork-Id: 11545911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A78F90 for ; Wed, 13 May 2020 11:48:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 210652176D for ; Wed, 13 May 2020 11:48:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 210652176D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 34781900129; Wed, 13 May 2020 07:48:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2F6229000F3; Wed, 13 May 2020 07:48:05 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20C0F900129; Wed, 13 May 2020 07:48:05 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0232.hostedemail.com [216.40.44.232]) by kanga.kvack.org (Postfix) with ESMTP id 048BC9000F3 for ; Wed, 13 May 2020 07:48:04 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B46C72C93 for ; Wed, 13 May 2020 11:48:04 +0000 (UTC) X-FDA: 76811522088.24.stone55_4672915afe515 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,lizefan@huawei.com,,RULES_HIT:30054,0,RBL:45.249.212.35:@huawei.com:.lbl8.mailshell.net-64.95.201.95 62.18.2.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: stone55_4672915afe515 X-Filterd-Recvd-Size: 2558 Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 May 2020 11:48:03 +0000 (UTC) Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 0302926D489EF7EEA254; Wed, 13 May 2020 19:47:56 +0800 (CST) Received: from [10.133.206.78] (10.133.206.78) by smtp.huawei.com (10.3.19.207) with Microsoft SMTP Server (TLS) id 14.3.487.0; Wed, 13 May 2020 19:47:50 +0800 Subject: [PATCH v2] memcg: Fix memcg_kmem_bypass() for remote memcg charging To: Michal Hocko CC: Johannes Weiner , Vladimir Davydov , Cgroups , , Andrew Morton , "Roman Gushchin" , Shakeel Butt References: <20200513090502.GV29153@dhcp22.suse.cz> <76f71776-d049-7407-8574-86b6e9d80704@huawei.com> <20200513112905.GX29153@dhcp22.suse.cz> From: Zefan Li Message-ID: <3a721f62-5a66-8bc5-247b-5c8b7c51c555@huawei.com> Date: Wed, 13 May 2020 19:47:49 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: <20200513112905.GX29153@dhcp22.suse.cz> X-Originating-IP: [10.133.206.78] X-CFilter-Loop: Reflected 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: 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 Acked-by: Johannes Weiner --- 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; return false;