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=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, 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 9F620C3524D for ; Mon, 3 Feb 2020 19:53:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5EC6D20658 for ; Mon, 3 Feb 2020 19:53:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="LktNJs6w" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5EC6D20658 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EA2406B0003; Mon, 3 Feb 2020 14:53:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E2BC36B0005; Mon, 3 Feb 2020 14:53:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1AEA6B0006; Mon, 3 Feb 2020 14:53:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0008.hostedemail.com [216.40.44.8]) by kanga.kvack.org (Postfix) with ESMTP id B50076B0003 for ; Mon, 3 Feb 2020 14:53:34 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6C2438248047 for ; Mon, 3 Feb 2020 19:53:34 +0000 (UTC) X-FDA: 76449865548.01.roof35_59546043fa621 X-HE-Tag: roof35_59546043fa621 X-Filterd-Recvd-Size: 6060 Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Mon, 3 Feb 2020 19:53:33 +0000 (UTC) Received: by mail-qt1-f193.google.com with SMTP id t13so12457676qto.3 for ; Mon, 03 Feb 2020 11:53:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Tg9AEPjwHF9SzQm7/+VD4BLr83zEfWvtOKbloqzkYR8=; b=LktNJs6wHQ6rCBrdTj45rfZkoSxgswrqWizRzWa5zrzlBSsMuWAm9UIPkK6wGbq8aA Jn9uM3xeWbvmYpEQGW2xJMYZzrlWaDEX+P1uApDUPcWujm8yhNDVNpSLYoGdK04556Lm luz+sPx7H6fzR1i6EOJpjOdKmg5UkJD4CDL18KhiPPYEB1sJxsOct8eC+ovIXgHqSWun JyzLth2dfq7lLeiSL0kODvo6U2J3CXls0jiHcS+knnRqf5rqX/B+guH44M7CXgzUXVPP 6i2QqnvE+/RcJHUPxFQW6y3uvjy0EpCAJ8RWxJbIsTkLbMfM4lR2JMJpVChPBL7VCYsU zsGA== 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=Tg9AEPjwHF9SzQm7/+VD4BLr83zEfWvtOKbloqzkYR8=; b=Ot9jshWP/A0uU7AlJ5DgZN/FZF08M434V0aTpTQaCSLVdqF8WOUjo4F8yxlTMN71gb GidIJE4qv3rHoNeHoBH7H2oLeOk0NpEhzv+8E034et12ugtG636Z6V5guqhYd2Ms/gbx OARGOjLMyVMDx8wOPtXuhNHgNMRkbpUZg91uMOfFl6dLI622gbZYCV2HtIA2ur6uUsvG 5BuSq7fsgXnkQwXNrLNhHZGtsDcJq8BKy3EH+S2ebAWAvshmqBTJP2N06mYW5mzhXbbQ kqChhdznZ1SMp7JcPTVtSN9ekDRsWgrCdavATxKVJV8F4oXIwZs+w7TR4zgIQhp8Xgxn XfCg== X-Gm-Message-State: APjAAAWAsmC4QSGKDE6gchnofiqxbMv7/Tvdk5mLDfwL8Bmtjh2EZmyI pXyDM5pgD0wg0K8fscX0WhKmZw== X-Google-Smtp-Source: APXvYqw4M2if1fYGbOJyF3RGiD+07i2yIoXnqs4pXRy5lRiylx/TmRICoQj3WNP7+zcwMoOWVlR7oA== X-Received: by 2002:ac8:390a:: with SMTP id s10mr24850033qtb.31.1580759613137; Mon, 03 Feb 2020 11:53:33 -0800 (PST) Received: from localhost ([2620:10d:c091:500::2:6320]) by smtp.gmail.com with ESMTPSA id 201sm9950888qkf.10.2020.02.03.11.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 11:53:32 -0800 (PST) Date: Mon, 3 Feb 2020 14:53:31 -0500 From: Johannes Weiner To: Roman Gushchin Cc: linux-mm@kvack.org, Andrew Morton , Michal Hocko , Shakeel Butt , Vladimir Davydov , linux-kernel@vger.kernel.org, kernel-team@fb.com, Bharata B Rao , Yafang Shao Subject: Re: [PATCH v2 17/28] mm: memcg/slab: save obj_cgroup for non-root slab objects Message-ID: <20200203195331.GB4396@cmpxchg.org> References: <20200127173453.2089565-1-guro@fb.com> <20200127173453.2089565-18-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200127173453.2089565-18-guro@fb.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, Jan 27, 2020 at 09:34:42AM -0800, Roman Gushchin wrote: > Store the obj_cgroup pointer in the corresponding place of > page->obj_cgroups for each allocated non-root slab object. > Make sure that each allocated object holds a reference to obj_cgroup. > > Objcg pointer is obtained from the memcg->objcg dereferencing > in memcg_kmem_get_cache() and passed from pre_alloc_hook to > post_alloc_hook. Then in case of successful allocation(s) it's > getting stored in the page->obj_cgroups vector. > > The objcg obtaining part look a bit bulky now, but it will be simplified > by next commits in the series. > > Signed-off-by: Roman Gushchin > --- > include/linux/memcontrol.h | 3 +- > mm/memcontrol.c | 14 +++++++-- > mm/slab.c | 18 +++++++----- > mm/slab.h | 60 ++++++++++++++++++++++++++++++++++---- > mm/slub.c | 14 +++++---- > 5 files changed, 88 insertions(+), 21 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 30bbea3f85e2..54bfb26b5016 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -1431,7 +1431,8 @@ static inline void memcg_set_shrinker_bit(struct mem_cgroup *memcg, > } > #endif > > -struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep); > +struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep, > + struct obj_cgroup **objcgp); > void memcg_kmem_put_cache(struct kmem_cache *cachep); > > #ifdef CONFIG_MEMCG_KMEM > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 94337ab1ebe9..0e9fe272e688 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -2896,7 +2896,8 @@ static inline bool memcg_kmem_bypass(void) > * done with it, memcg_kmem_put_cache() must be called to release the > * reference. > */ > -struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep) > +struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep, > + struct obj_cgroup **objcgp) > { > struct mem_cgroup *memcg; > struct kmem_cache *memcg_cachep; > @@ -2952,8 +2953,17 @@ struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep) > */ > if (unlikely(!memcg_cachep)) > memcg_schedule_kmem_cache_create(memcg, cachep); > - else if (percpu_ref_tryget(&memcg_cachep->memcg_params.refcnt)) > + else if (percpu_ref_tryget(&memcg_cachep->memcg_params.refcnt)) { > + struct obj_cgroup *objcg = rcu_dereference(memcg->objcg); > + > + if (!objcg || !obj_cgroup_tryget(objcg)) { > + percpu_ref_put(&memcg_cachep->memcg_params.refcnt); > + goto out_unlock; > + } As per the reply to the previous patch: I don't understand why the objcg requires a pulse check here. As long as the memcg is alive and can be charged with memory, how can the objcg disappear?