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=-2.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 746D2CA9EBC for ; Fri, 25 Oct 2019 20:52:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1E9AB21E6F for ; Fri, 25 Oct 2019 20:52:43 +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="XKKhV1Oj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E9AB21E6F 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 707696B0003; Fri, 25 Oct 2019 16:52:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B68A6B0006; Fri, 25 Oct 2019 16:52:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A5AD6B0007; Fri, 25 Oct 2019 16:52:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0183.hostedemail.com [216.40.44.183]) by kanga.kvack.org (Postfix) with ESMTP id 382E26B0003 for ; Fri, 25 Oct 2019 16:52:43 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id E8F718E41 for ; Fri, 25 Oct 2019 20:52:42 +0000 (UTC) X-FDA: 76083505764.12.girls86_6eeacbeaac81b X-HE-Tag: girls86_6eeacbeaac81b X-Filterd-Recvd-Size: 6663 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Fri, 25 Oct 2019 20:52:42 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id 3so2362933pfb.10 for ; Fri, 25 Oct 2019 13:52:41 -0700 (PDT) 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:user-agent; bh=zxh1OzG1sSzHAUy26sb63UfIm38Fki5GgDTIvxkjxAA=; b=XKKhV1Oj3KXRjwfmXPbF2FqyVlFo+ODP5O2WVCX7F3XzqMkYJmeLPZL67CvdF65SCW y86KKIXUn2w8N3N8W6KVPzcp249O/SWe4POcTOkRTCGvEfdc6Eywbp1ho8zth5WiGAes 7aj1TCVWDi42fxLA9yLTRdm1OJqWjsJwemlqEhb2n3A7xmKJB4WdT80dCXuNiK2+XfT8 lmDceltOJx39GeB4+unCbyaSdMI6fHPm22TySWjq7j6agOgaa3lTuKP7kCs01rcnREAF nD+U8Jl9HuEvLk0ngINl88MocL0d5b5QD4uhNGmmQxcex7EQ9Xgv6kAW/tMeSKxUPCK2 Cacg== 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:user-agent; bh=zxh1OzG1sSzHAUy26sb63UfIm38Fki5GgDTIvxkjxAA=; b=QWGHdfo5fDM7KPq2zT+uKdn1byyTOrfun4++J1qgxyUqhXfzuRX3vRNgKfshj99ZOx LVSRm9IlghAWfmb7xHD/t1iJtlkuU4kCUDexgFGkSAoY8AKz2O0m4qwxZkzgqBwNPpk7 XEmHx9RIL6Myqb5HWOqmSYiZ09ALsWHaj552FZPSUQLDwtmiBQpzP8OW5R/mqHbWK6J4 36m5YFBH+FzI48V2XRFcCJHeZo9UP2NHEPkAtiinNjq2aANREzlMBUfMnNYCs5SphQbr ex0IZtfUvkM+lWD89skBKtgL5AL6m0+qsouM2cUg+L9l2uWMhyBHhMx3T5Ccuq/yTTib QKMQ== X-Gm-Message-State: APjAAAXJWSwwGzMQ7AF0jnvk5hh2UNB77tZXLFoNxBF0D3AVy6bAe3nN KjOQvtiKGA5htZCZC1ByrJRT9Q== X-Google-Smtp-Source: APXvYqyIzshTgnZ8NZSL6NFQcEW0E90cm6s9Qp3+WD+7UHDepE3Je97CkXYtKRaZhbQwcs3pAxHMQA== X-Received: by 2002:a63:1f4e:: with SMTP id q14mr6808030pgm.144.1572036759831; Fri, 25 Oct 2019 13:52:39 -0700 (PDT) Received: from localhost ([2620:10d:c090:180::7fa3]) by smtp.gmail.com with ESMTPSA id l3sm4422260pgi.57.2019.10.25.13.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 13:52:39 -0700 (PDT) Date: Fri, 25 Oct 2019 16:52:37 -0400 From: Johannes Weiner To: Roman Gushchin Cc: "linux-mm@kvack.org" , Michal Hocko , "linux-kernel@vger.kernel.org" , Kernel Team , Shakeel Butt , Vladimir Davydov , Waiman Long , Christoph Lameter Subject: Re: [PATCH 09/16] mm: memcg/slab: charge individual slab objects instead of pages Message-ID: <20191025205237.GA2010@cmpxchg.org> References: <20191018002820.307763-1-guro@fb.com> <20191018002820.307763-10-guro@fb.com> <20191025194118.GA393641@cmpxchg.org> <20191025200020.GA8325@castle.DHCP.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191025200020.GA8325@castle.DHCP.thefacebook.com> User-Agent: Mutt/1.12.2 (2019-09-21) 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 Fri, Oct 25, 2019 at 08:00:32PM +0000, Roman Gushchin wrote: > On Fri, Oct 25, 2019 at 03:41:18PM -0400, Johannes Weiner wrote: > > On Thu, Oct 17, 2019 at 05:28:13PM -0700, Roman Gushchin wrote: > > > +static inline struct kmem_cache *memcg_slab_pre_alloc_hook(struct kmem_cache *s, > > > + struct mem_cgroup **memcgp, > > > + size_t size, gfp_t flags) > > > +{ > > > + struct kmem_cache *cachep; > > > + > > > + cachep = memcg_kmem_get_cache(s, memcgp); > > > + if (is_root_cache(cachep)) > > > + return s; > > > + > > > + if (__memcg_kmem_charge_subpage(*memcgp, size * s->size, flags)) { > > > + mem_cgroup_put(*memcgp); > > > + memcg_kmem_put_cache(cachep); > > > + cachep = NULL; > > > + } > > > + > > > + return cachep; > > > +} > > > + > > > static inline void memcg_slab_post_alloc_hook(struct kmem_cache *s, > > > struct mem_cgroup *memcg, > > > size_t size, void **p) > > > { > > > struct mem_cgroup_ptr *memcg_ptr; > > > + struct lruvec *lruvec; > > > struct page *page; > > > unsigned long off; > > > size_t i; > > > @@ -439,6 +393,11 @@ static inline void memcg_slab_post_alloc_hook(struct kmem_cache *s, > > > off = obj_to_index(s, page, p[i]); > > > mem_cgroup_ptr_get(memcg_ptr); > > > page->mem_cgroup_vec[off] = memcg_ptr; > > > + lruvec = mem_cgroup_lruvec(page_pgdat(page), memcg); > > > + mod_lruvec_memcg_state(lruvec, cache_vmstat_idx(s), > > > + s->size); > > > + } else { > > > + __memcg_kmem_uncharge_subpage(memcg, s->size); > > > } > > > } > > > mem_cgroup_ptr_put(memcg_ptr); > > > > The memcg_ptr as a collection vessel for object references makes a lot > > of sense. But this code showcases that it should be a first-class > > memory tracking API that the allocator interacts with, rather than > > having to deal with a combination of memcg_ptr and memcg. > > > > In the two hunks here, on one hand we charge bytes to the memcg > > object, and then handle all the refcounting through a different > > bucketing object. To support that in the first place, we have to > > overload the memcg API all the way down to try_charge() to support > > bytes and pages. This is difficult to follow throughout all layers. > > > > What would be better is for this to be an abstraction layer for a > > subpage object tracker that sits on top of the memcg page tracker - > > not unlike the page allocator and the slab allocators themselves. > > > > And then the slab allocator would only interact with the subpage > > object tracker, and the object tracker would deal with the memcg page > > tracker under the hood. > > Yes, the idea makes total sense to me. I'm not sure I like the new naming > (I have to spend some time with it first), but the idea of moving > stocks and leftovers to the memcg_ptr/obj_cgroup level is really good. I'm not set on the naming, it was just to illustrate the structuring. I picked something that has cgroup in it, is not easily confused with the memcg API, and shortens nicely to local variable names (obj_cgroup -> objcg), but I'm all for a better name. > I'll include something based on your proposal into the next version > of the patchset. Thanks, looking forward to it.