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=-11.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no 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 92EBBC433E0 for ; Mon, 22 Jun 2020 21:04:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4EB1A2073E for ; Mon, 22 Jun 2020 21:04:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="anju6xJ8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4EB1A2073E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EDF246B0005; Mon, 22 Jun 2020 17:04:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E680B6B0006; Mon, 22 Jun 2020 17:04:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D56646B002D; Mon, 22 Jun 2020 17:04:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0082.hostedemail.com [216.40.44.82]) by kanga.kvack.org (Postfix) with ESMTP id B9F496B0005 for ; Mon, 22 Jun 2020 17:04:43 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 7F9EB180AD80F for ; Mon, 22 Jun 2020 21:04:43 +0000 (UTC) X-FDA: 76958076846.26.fifth05_330b6f126e35 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 5475F18198C5E for ; Mon, 22 Jun 2020 21:04:43 +0000 (UTC) X-HE-Tag: fifth05_330b6f126e35 X-Filterd-Recvd-Size: 6501 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Mon, 22 Jun 2020 21:04:42 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id i3so20995261ljg.3 for ; Mon, 22 Jun 2020 14:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fYVGKPR2yU3JPe9oC0azgd3CTmHpa/y89mhXYHW9wOc=; b=anju6xJ8xizXgJoCiTCnr62/0hAVWt3tpba4VyB6Uu9GK/quThrDtveIseHGA5X+Hx MHhJEkugGqGAwkV9gvcFL823g5O30pgKXNXrG4xWoULSSZzNLLxOtI6FgXpRuA6sf8S2 XX2bzJ0RDkZCbbWp3CYgUrn64SoCpHtmwPCtIrBFS9D/7vKecrd68meKjXc2bmaRGm1A yMglRixHcYUZGT9f0vSdR+PyagzF0x0vh4HwUk4N5ak+B0bz5n2os88+AM9Oe4Nhf0tN zAzlI4J0w8zw1CvOFKRuACxatkqhNujZhqsHG6+FQPTjpxgkPTYC7MiWUx+anq6pESfq l7hQ== 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=fYVGKPR2yU3JPe9oC0azgd3CTmHpa/y89mhXYHW9wOc=; b=RDXT/CwH1l+3b8Kt8KCSGJo0vgLIX0KOxW8ZXSUtRN4jUGOrn+DR0MPHNVHPPRiczq kE80Ynl2kdTQOJ9Ijz8ta4zHJCFrLnK+3gldIGPJ/211ybrKkERjbIUP91CaMzA+MRcn Pm2TFgU1hQ9P6A440YdsZ35guuWBhxGsj00RSnlkLFdY1El00D+96FHoNuKcb3I1sLoH wwNFfIJgayc0ya4xqUEv535EbNnEO+GtkaFTUCcWtDNQWPoTXvM+QWtXnlGvBNzc0Upm D6aTg8aAp4c4cMuNWiEZgoz/G0/OKfEG2DAj12PHQOpx/Uw598eE3QG1zdifyBuBbXYb 5qjA== X-Gm-Message-State: AOAM533ya5tIMJWy9axapy60eEFFLeIj+ZTulrQS3oQW+czYgruZVM48 WcKJ73UJb7TlR+p0esRl00MDDcDog6vfJTOO0Exx9g== X-Google-Smtp-Source: ABdhPJz9bNAC+mLgBDdJqkEuTqKjqlvEz9k5KOq+isP5jeWorPFWcbqMRtUoB41EmAVXoOuyUixh03WTuQhHHbZe3n8= X-Received: by 2002:a2e:960b:: with SMTP id v11mr9655771ljh.77.1592859881138; Mon, 22 Jun 2020 14:04:41 -0700 (PDT) MIME-Version: 1.0 References: <20200608230654.828134-1-guro@fb.com> <20200608230654.828134-18-guro@fb.com> <20200622203739.GD301338@carbon.dhcp.thefacebook.com> In-Reply-To: <20200622203739.GD301338@carbon.dhcp.thefacebook.com> From: Shakeel Butt Date: Mon, 22 Jun 2020 14:04:29 -0700 Message-ID: Subject: Re: [PATCH v6 17/19] mm: memcg/slab: use a single set of kmem_caches for all allocations To: Roman Gushchin Cc: Andrew Morton , Christoph Lameter , Johannes Weiner , Michal Hocko , Linux MM , Vlastimil Babka , Kernel Team , LKML Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 5475F18198C5E X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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, Jun 22, 2020 at 1:37 PM Roman Gushchin wrote: > > On Mon, Jun 22, 2020 at 12:21:28PM -0700, Shakeel Butt wrote: > > On Mon, Jun 8, 2020 at 4:07 PM Roman Gushchin wrote: > > > > > > Instead of having two sets of kmem_caches: one for system-wide and > > > non-accounted allocations and the second one shared by all accounted > > > allocations, we can use just one. > > > > > > The idea is simple: space for obj_cgroup metadata can be allocated > > > on demand and filled only for accounted allocations. > > > > > > It allows to remove a bunch of code which is required to handle > > > kmem_cache clones for accounted allocations. There is no more need > > > to create them, accumulate statistics, propagate attributes, etc. > > > It's a quite significant simplification. > > > > > > Also, because the total number of slab_caches is reduced almost twice > > > (not all kmem_caches have a memcg clone), some additional memory > > > savings are expected. On my devvm it additionally saves about 3.5% > > > of slab memory. > > > > > > Suggested-by: Johannes Weiner > > > Signed-off-by: Roman Gushchin > > > Reviewed-by: Vlastimil Babka > > > --- > > [snip] > > > static inline void memcg_slab_post_alloc_hook(struct kmem_cache *s, > > > struct obj_cgroup *objcg, > > > - size_t size, void **p) > > > + gfp_t flags, size_t size, > > > + void **p) > > > { > > > struct page *page; > > > unsigned long off; > > > size_t i; > > > > > > + if (!objcg) > > > + return; > > > + > > > + flags &= ~__GFP_ACCOUNT; > > > for (i = 0; i < size; i++) { > > > if (likely(p[i])) { > > > page = virt_to_head_page(p[i]); > > > + > > > + if (!page_has_obj_cgroups(page) && > > > > The page is already linked into the kmem_cache, don't you need > > synchronization for memcg_alloc_page_obj_cgroups(). > > Hm, yes, in theory we need it. I guess the reason behind why I've never seen any issues > here is the SLUB percpu partial list. > > So in theory we need something like: > > diff --git a/mm/slab.h b/mm/slab.h > index 0a31600a0f5c..44bf57815816 100644 > --- a/mm/slab.h > +++ b/mm/slab.h > @@ -237,7 +237,10 @@ static inline int memcg_alloc_page_obj_cgroups(struct page *page, > if (!vec) > return -ENOMEM; > > - page->obj_cgroups = (struct obj_cgroup **) ((unsigned long)vec | 0x1UL); > + if (cmpxchg(&page->obj_cgroups, 0, > + (struct obj_cgroup **) ((unsigned long)vec | 0x1UL))) > + kfree(vec); > + > return 0; > } > > > But I wonder if we might put it under #ifdef CONFIG_SLAB? > Or any other ideas how to make it less expensive? > > > What's the reason to remove this from charge_slab_page()? > > Because at charge_slab_page() we don't know if we'll ever need > page->obj_cgroups. Some caches might have only few or even zero > accounted objects. > If slab_pre_alloc_hook() returns a non-NULL objcg then we definitely need page->obj_cgroups. The charge_slab_page() happens between slab_pre_alloc_hook() & slab_post_alloc_hook(), so, we should be able to tell if page->obj_cgroups is needed.