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=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 2BDB5C43332 for ; Tue, 2 Mar 2021 08:50:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D2E3164DED for ; Tue, 2 Mar 2021 08:50:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382015AbhCBIsK (ORCPT ); Tue, 2 Mar 2021 03:48:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239262AbhCBENe (ORCPT ); Mon, 1 Mar 2021 23:13:34 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CA37C0617A7 for ; Mon, 1 Mar 2021 20:12:53 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id c19so1042306pjq.3 for ; Mon, 01 Mar 2021 20:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pJaPLF9X1F6hvOBAXTHBgh9HYMVdoLjPILjLEfD7bkc=; b=YEZ1cocgpsBHNkw0q+n3c+WrJ0f5ZYMWZ5GgZymplzz/JjXP3J3GP3MQPyOD+t7hxj AsK2COA53kOesfdd7nTgEuKuQJ7B+1JaLSiIWqINpSswz1f453uWWv5cf5Zy9QVnSZdd X0vMaEoLsxLAVk5K6hSFHHKSylttTe535bfBlRj9YLzzI2p9d5SVShpMsGrjNw3iULbC +mik6ICMk5ltsWjqpAmuGCd/qH7Pw0q8Y8kTUadbUjZeBEzXHeBTNP0c+D7LqoTso/Yu kjJIpeToFr5LIiD+nTQahXyU61ghaF6X5hl9rGGDki1aC/DUcXPcY0IZd4brRdl8pXp+ iUug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pJaPLF9X1F6hvOBAXTHBgh9HYMVdoLjPILjLEfD7bkc=; b=s6CV1C9NV1X/Ra6IJ/J7OY399huA20G6utfyguiLN3ycu3i00M0ZF5U5MH3pRLIa5n X1j4KHHz1sVp8nqfvsV/s3gVr+Q+vRx3475b+u43SydQtT/lmcaAsc2dzKFJlQ3cSCjk uTR1pqm91PU9fkYSq/ruLscNpQgmgi9qv3mfmL53qL2VnxTXvamz3aGFRPbo+qNNz/s9 LuaaS0akwPW0GdFUAFyHq1UO6d4atbKXeyQh4etXABj5PZd2V2UkIqK9c7X7zoo9cmGJ zZHrshCHB7cJDulMgKiby7Xiub9Z357G2bgy0x4YoK5cGaJfZzFqteFo5ZLSTVS5SiVd dzxA== X-Gm-Message-State: AOAM532Hq/IxwLb8sBqj5K9E1jUUnZpJ9yn4GEpb9gHywQveCiZGODwE hV7I90J7Na3Iop/jcLIbXklcowR6PRpmnZ9eCAaYPA== X-Google-Smtp-Source: ABdhPJw4yPDMdM9rw5cTzxwrZpXy5wEJz7YfOZ5x9bGXhm1fMxZCHjNMKhVkXo1trQ0xr49A64GmU+RJmU/bXtSc/g0= X-Received: by 2002:a17:902:d4c2:b029:e3:cb77:e51 with SMTP id o2-20020a170902d4c2b02900e3cb770e51mr18426342plg.20.1614658372860; Mon, 01 Mar 2021 20:12:52 -0800 (PST) MIME-Version: 1.0 References: <20210301062227.59292-1-songmuchun@bytedance.com> <20210301062227.59292-5-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Tue, 2 Mar 2021 12:12:16 +0800 Message-ID: Subject: Re: [External] Re: [PATCH 4/5] mm: memcontrol: move remote memcg charging APIs to CONFIG_MEMCG_KMEM To: Roman Gushchin Cc: Alexander Viro , Jan Kara , Amir Goldstein , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , kpsingh@kernel.org, Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , dietmar.eggemann@arm.com, Steven Rostedt , Benjamin Segall , Mel Gorman , bristot@redhat.com, Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Shakeel Butt , Alex Shi , alexander.h.duyck@linux.intel.com, Chris Down , Wei Yang , Vlastimil Babka , Mathieu Desnoyers , Peter Oskolkov , Jann Horn , Joonsoo Kim , Daniel Vetter , Waiman Long , Michel Lespinasse , Christian Brauner , "Eric W. Biederman" , Kees Cook , krisman@collabora.com, esyr@redhat.com, Suren Baghdasaryan , Marco Elver , linux-fsdevel , LKML , Networking , bpf , Cgroups , Linux Memory Management List , Xiongchun duan Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, Mar 2, 2021 at 9:15 AM Roman Gushchin wrote: > > On Mon, Mar 01, 2021 at 02:22:26PM +0800, Muchun Song wrote: > > The remote memcg charing APIs is a mechanism to charge kernel memory > > to a given memcg. So we can move the infrastructure to the scope of > > the CONFIG_MEMCG_KMEM. > > This is not a good idea, because there is nothing kmem-specific > in the idea of remote charging, and we definitely will see cases > when user memory is charged to the process different from the current. Got it. Thanks for your reminder. > > > > > As a bonus, on !CONFIG_MEMCG_KMEM build some functions and variables > > can be compiled out. > > > > Signed-off-by: Muchun Song > > --- > > include/linux/sched.h | 2 ++ > > include/linux/sched/mm.h | 2 +- > > kernel/fork.c | 2 +- > > mm/memcontrol.c | 4 ++++ > > 4 files changed, 8 insertions(+), 2 deletions(-) > > > > diff --git a/include/linux/sched.h b/include/linux/sched.h > > index ee46f5cab95b..c2d488eddf85 100644 > > --- a/include/linux/sched.h > > +++ b/include/linux/sched.h > > @@ -1314,7 +1314,9 @@ struct task_struct { > > > > /* Number of pages to reclaim on returning to userland: */ > > unsigned int memcg_nr_pages_over_high; > > +#endif > > > > +#ifdef CONFIG_MEMCG_KMEM > > /* Used by memcontrol for targeted memcg charge: */ > > struct mem_cgroup *active_memcg; > > #endif > > diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h > > index 1ae08b8462a4..64a72975270e 100644 > > --- a/include/linux/sched/mm.h > > +++ b/include/linux/sched/mm.h > > @@ -294,7 +294,7 @@ static inline void memalloc_nocma_restore(unsigned int flags) > > } > > #endif > > > > -#ifdef CONFIG_MEMCG > > +#ifdef CONFIG_MEMCG_KMEM > > DECLARE_PER_CPU(struct mem_cgroup *, int_active_memcg); > > /** > > * set_active_memcg - Starts the remote memcg charging scope. > > diff --git a/kernel/fork.c b/kernel/fork.c > > index d66cd1014211..d66718bc82d5 100644 > > --- a/kernel/fork.c > > +++ b/kernel/fork.c > > @@ -942,7 +942,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) > > tsk->use_memdelay = 0; > > #endif > > > > -#ifdef CONFIG_MEMCG > > +#ifdef CONFIG_MEMCG_KMEM > > tsk->active_memcg = NULL; > > #endif > > return tsk; > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index 39cb8c5bf8b2..092dc4588b43 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -76,8 +76,10 @@ EXPORT_SYMBOL(memory_cgrp_subsys); > > > > struct mem_cgroup *root_mem_cgroup __read_mostly; > > > > +#ifdef CONFIG_MEMCG_KMEM > > /* Active memory cgroup to use from an interrupt context */ > > DEFINE_PER_CPU(struct mem_cgroup *, int_active_memcg); > > +#endif > > > > /* Socket memory accounting disabled? */ > > static bool cgroup_memory_nosocket; > > @@ -1054,6 +1056,7 @@ struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm) > > } > > EXPORT_SYMBOL(get_mem_cgroup_from_mm); > > > > +#ifdef CONFIG_MEMCG_KMEM > > static __always_inline struct mem_cgroup *active_memcg(void) > > { > > if (in_interrupt()) > > @@ -1074,6 +1077,7 @@ static __always_inline bool memcg_kmem_bypass(void) > > > > return false; > > } > > +#endif > > > > /** > > * mem_cgroup_iter - iterate over memory cgroup hierarchy > > -- > > 2.11.0 > >