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 31500C3F2C6 for ; Tue, 3 Mar 2020 09:32:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F2C6A21556 for ; Tue, 3 Mar 2020 09:32:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2C6A21556 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 8B8776B0005; Tue, 3 Mar 2020 04:32:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 869356B0006; Tue, 3 Mar 2020 04:32:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 755DC6B0007; Tue, 3 Mar 2020 04:32:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id 5CD636B0005 for ; Tue, 3 Mar 2020 04:32:54 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 080EE2BFC6 for ; Tue, 3 Mar 2020 09:32:54 +0000 (UTC) X-FDA: 76553536626.07.fruit78_8daf354727d34 X-HE-Tag: fruit78_8daf354727d34 X-Filterd-Recvd-Size: 5757 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 3 Mar 2020 09:32:53 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id z15so3451145wrl.1 for ; Tue, 03 Mar 2020 01:32:53 -0800 (PST) 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=XYpfou3pNPf/l+cdS9KAFxciOnURpc9US/Ck720UZHw=; b=IgM2hjIcWbr4NuJr7Zdnq8zevtnDEGXxquPZvs6IwOaSPiYKfeybSG2Y3dqeiN88R9 FmoZGM4M91WN20OlXSjnVpAiDxXx78xh/cHiPS2o7XTAv2AehxF6zW1pSWd4y/e0QZJu yEwVeF+uNVRMv8i+HsoVCnOnd31i+Tywqdkj6qiU5kazikUyCOuApN2Y+gpHU+CBYOpt 8zEtSgfB76RxI2bT4BNd2fni6xFBpFm0G0Ipia/PNSFcA4oWQpzRULdLNcoPFP7DT5LC e29ct/FLk/sbosXExsFrN+9qLs2w8OvXVxYNDkX77MyqXNkFKfFcNQiYWsH+ZFbRWsrJ URLw== X-Gm-Message-State: ANhLgQ0vDH16ltO7nuuXWzOrnjSjjzUqXR+NvnFEzU656vQp/GbElPSj bQPJEvXCyGhN3ZEBMDYZCoM= X-Google-Smtp-Source: ADFU+vtF+RbwIjqore5UHIM7atEL0jn316nOITsQv4Z2OqwFH4XPXNTPD5ODK8h9prUeZDx1qzGkkA== X-Received: by 2002:a5d:4088:: with SMTP id o8mr4722346wrp.144.1583227972535; Tue, 03 Mar 2020 01:32:52 -0800 (PST) Received: from localhost (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id f17sm12224197wrm.3.2020.03.03.01.32.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 01:32:51 -0800 (PST) Date: Tue, 3 Mar 2020 10:32:51 +0100 From: Michal Hocko To: Shakeel Butt Cc: Roman Gushchin , Johannes Weiner , Andrew Morton , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] memcg: css_tryget_online cleanups Message-ID: <20200303093251.GD4380@dhcp22.suse.cz> References: <20200302203109.179417-1-shakeelb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200302203109.179417-1-shakeelb@google.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 Mon 02-03-20 12:31:09, Shakeel Butt wrote: > Currently multiple locations in memcg code, css_tryget_online() is being > used. However it doesn't matter whether the cgroup is online for the > callers. Online used to matter when we had reparenting on offlining and > we needed a way to prevent new ones from showing up. > > The failure case for couple of these css_tryget_online usage is to > fallback to root_mem_cgroup which kind of make bypassing the memcg > limits possible for some workloads. For example creating an inotify > group in a subcontainer and then deleting that container after moving the > process to a different container will make all the event objects > allocated for that group to the root_mem_cgroup. So, using > css_tryget_online() is dangerous for such cases. > > Two locations still use the online version. The swapin of offlined > memcg's pages and the memcg kmem cache creation. The kmem cache indeed > needs the online version as the kernel does the reparenting of memcg > kmem caches. For the swapin case, it has been left for later as the > fallback is not really that concerning. Could you be more specific about the swap in case please? > Signed-off-by: Shakeel Butt Other than that nothing really jumped at me although I have to confess that I am far from deeply familiar with the sk_buff charging path. Acked-by: Michal Hocko > --- > > Changes since v1: > - replaced WARN_ON with WARN_ON_ONCE > > mm/memcontrol.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 62b574d0cd3c..75d8883bf975 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -656,7 +656,7 @@ __mem_cgroup_largest_soft_limit_node(struct mem_cgroup_tree_per_node *mctz) > */ > __mem_cgroup_remove_exceeded(mz, mctz); > if (!soft_limit_excess(mz->memcg) || > - !css_tryget_online(&mz->memcg->css)) > + !css_tryget(&mz->memcg->css)) > goto retry; > done: > return mz; > @@ -961,7 +961,8 @@ struct mem_cgroup *get_mem_cgroup_from_page(struct page *page) > return NULL; > > rcu_read_lock(); > - if (!memcg || !css_tryget_online(&memcg->css)) > + /* Page should not get uncharged and freed memcg under us. */ > + if (!memcg || WARN_ON_ONCE(!css_tryget(&memcg->css))) > memcg = root_mem_cgroup; > rcu_read_unlock(); > return memcg; > @@ -974,10 +975,13 @@ EXPORT_SYMBOL(get_mem_cgroup_from_page); > static __always_inline struct mem_cgroup *get_mem_cgroup_from_current(void) > { > if (unlikely(current->active_memcg)) { > - struct mem_cgroup *memcg = root_mem_cgroup; > + struct mem_cgroup *memcg; > > rcu_read_lock(); > - if (css_tryget_online(¤t->active_memcg->css)) > + /* current->active_memcg must hold a ref. */ > + if (WARN_ON_ONCE(!css_tryget(¤t->active_memcg->css))) > + memcg = root_mem_cgroup; > + else > memcg = current->active_memcg; > rcu_read_unlock(); > return memcg; > @@ -6732,7 +6736,7 @@ void mem_cgroup_sk_alloc(struct sock *sk) > goto out; > if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !memcg->tcpmem_active) > goto out; > - if (css_tryget_online(&memcg->css)) > + if (css_tryget(&memcg->css)) > sk->sk_memcg = memcg; > out: > rcu_read_unlock(); > -- > 2.25.0.265.gbab2e86ba0-goog -- Michal Hocko SUSE Labs