Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1067277ybj; Thu, 7 May 2020 14:05:59 -0700 (PDT) X-Google-Smtp-Source: APiQypKKOTQYy2nlIjb8LHmtFo7J9bDlptMrtTM5ZMVG/CHv/vogTmJJDkTGsZnkgPLYt8YdD1AF X-Received: by 2002:a05:6402:221c:: with SMTP id cq28mr13136675edb.50.1588885559749; Thu, 07 May 2020 14:05:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588885559; cv=none; d=google.com; s=arc-20160816; b=S046lNh24ipNWfb6P3LMDErwyw85g72HK3TvmkdDyMcg7blqV4wW4QUbluxBO6/6St WV0YwaRVXze2qFkz+ZhjLPuVd5WNkBkejp8KEMPCiYw2f2cSzbJDbIhKNLfq6jnGrM3y /LDsbEDpWACzHAihMR9NVE68u57p59blSZYvDS/Z1eHGHoQs3nnyvzxMVo/NmqRfTU4M TQv6hL2KpPD7GZpGOUY4FrrTKFDHWVqDqHQGxNOT+QDkEssMmoo6FQJUKM3Wz1ozXNS2 4VKoK8ox/fSGuIprY1EhAMXauIBn8GqOaGUSCQvlpzZOBciaLEMWdJuYOejMuXNUJvnh 205g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=qcKYLVt6/NNJuQkZbbwTmTKpZql0R6iO8Dr7nx85OkM=; b=oQcoJwrJOl8/2Jcm8jifSIKtLgxmHO6llMPTUHXaG0/4tkDTiaxmyVfI7HUnUBRAnl WT59gYplIQ9m0fGSYDC13pGD4zN9oVWDPjreVg4GQmRa9XVQXYmKd5kuxJgdP1yliqwQ ZEfWe2EpjxIsLY20XQPeEU2TFq9LDX0pYbJ93a+qlHZaiZHXTD71xBJch0ildwDOXraX YKovzKrx4IQ8o8nQKrTTMEirLLY+RNUGCXjv63ayn4+pBkqYU00yA1wmJwORyZY9nkq+ WVDQyYmbgpskv3KVsudWPQvJkX1REkEWtajQjL6foAqvGAA5j5nKhJk0vAycf2pX4gnK hQ5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=I8fAtO4C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e8si4280234ejt.23.2020.05.07.14.05.36; Thu, 07 May 2020 14:05:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=I8fAtO4C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726580AbgEGVDc (ORCPT + 99 others); Thu, 7 May 2020 17:03:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726218AbgEGVDb (ORCPT ); Thu, 7 May 2020 17:03:31 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B670C05BD43 for ; Thu, 7 May 2020 14:03:31 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id g185so1030868qke.7 for ; Thu, 07 May 2020 14:03:31 -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; bh=qcKYLVt6/NNJuQkZbbwTmTKpZql0R6iO8Dr7nx85OkM=; b=I8fAtO4ClEbBWt+UUO3Dwt+srJXW10D9hX2anKmgKYvAo4vvj4pxdGmu17H/mzJ6mn FAg81y3+hc6lkj085UoPx4ih3+p+IMmEZFpbiZKE1l7Y6nNExdpBkeczCez7DVX+EO7M gUZTcSRWuZkQMZXUkCBgHteJyr51toiodbFaZL4gZqez/5V8kp9Zfj93sgH2L2KRwZfH +aPXM9V7cmMy8kPifCYLzy53IybZC/67MsJO3X3nuLGocXZpO4C7xL9Z2fpa65sXg/Al 6Xyvi8JWx9Ml5Myj9DY/ItaJRUrFepMxsmAh+bDewEx2JXKnD7Jj0aAAWsWLCJO2euk7 Z4Ow== 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=qcKYLVt6/NNJuQkZbbwTmTKpZql0R6iO8Dr7nx85OkM=; b=pYHjpP4QgBUpq1hwJXhDK20+qoaTszG7GcXUo6MfS3tug0ae6KFAJC+4BnFPZ7gQG/ neT+tPdYeXoLWZN8CQOPgBkZlJmkpFck/ZtFLnZO/8jL1KDj+JNIp8BpVOFklnXb9VUT UPdmjccBlV3Np/oW2FOVQbsy3kJifir+tm8CrLEInWPau156lJJa8Dbp/zsLCuN0boMg EKeGppIEsY3Oa7BP7otqSFlual2qTelRAuxycdphGjAP5QVBa/sxe4liZi2QKNdCvwz9 dDjPyIriokMLJE+mKZTurJ5vFrJ2q3R5bHR8Z8nQeoClcgfm7k/sKIUMBtZ1dAllmNYW 5bWQ== X-Gm-Message-State: AGi0PuZGpbtuqhzENM355j1yBhX0oHKSMJ9As8fqwA3PLafCNWyo4QGj WlYcr3Sv++wJGjEiF2Tog1hlaA== X-Received: by 2002:a05:620a:12dc:: with SMTP id e28mr17201367qkl.38.1588885410496; Thu, 07 May 2020 14:03:30 -0700 (PDT) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id 14sm5128001qkd.70.2020.05.07.14.03.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 14:03:29 -0700 (PDT) Date: Thu, 7 May 2020 17:03:14 -0400 From: Johannes Weiner To: Roman Gushchin Cc: Andrew Morton , Michal Hocko , linux-mm@kvack.org, kernel-team@fb.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 06/19] mm: memcg/slab: obj_cgroup API Message-ID: <20200507210314.GD161043@cmpxchg.org> References: <20200422204708.2176080-1-guro@fb.com> <20200422204708.2176080-7-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200422204708.2176080-7-guro@fb.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 22, 2020 at 01:46:55PM -0700, Roman Gushchin wrote: > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -257,6 +257,78 @@ struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr) > } > > #ifdef CONFIG_MEMCG_KMEM > +extern spinlock_t css_set_lock; > + > +static void obj_cgroup_release(struct percpu_ref *ref) > +{ > + struct obj_cgroup *objcg = container_of(ref, struct obj_cgroup, refcnt); > + struct mem_cgroup *memcg; > + unsigned int nr_bytes; > + unsigned int nr_pages; > + unsigned long flags; > + > + nr_bytes = atomic_read(&objcg->nr_charged_bytes); > + WARN_ON_ONCE(nr_bytes & (PAGE_SIZE - 1)); > + nr_pages = nr_bytes >> PAGE_SHIFT; What guarantees that we don't have a partial page in there at this point? I guess any outstanding allocations would pin the objcg, so when it's released all objects have been freed. But if that's true, how can we have full pages remaining in there now? > @@ -2723,6 +2820,30 @@ struct mem_cgroup *mem_cgroup_from_obj(void *p) > return page->mem_cgroup; > } > > +__always_inline struct obj_cgroup *get_obj_cgroup_from_current(void) > +{ > + struct obj_cgroup *objcg = NULL; > + struct mem_cgroup *memcg; > + > + if (unlikely(!current->mm)) > + return NULL; > + > + rcu_read_lock(); > + if (unlikely(current->active_memcg)) > + memcg = rcu_dereference(current->active_memcg); > + else > + memcg = mem_cgroup_from_task(current); > + > + for (; memcg != root_mem_cgroup; memcg = parent_mem_cgroup(memcg)) { > + objcg = rcu_dereference(memcg->objcg); > + if (objcg && obj_cgroup_tryget(objcg)) > + break; > + } > + rcu_read_unlock(); > + > + return objcg; > +} Thanks for moving this here from one of the later patches, it helps understanding the life cycle of obj_cgroup better. > +int obj_cgroup_charge(struct obj_cgroup *objcg, gfp_t gfp, size_t size) > +{ > + struct mem_cgroup *memcg; > + unsigned int nr_pages, nr_bytes; > + int ret; > + > + if (consume_obj_stock(objcg, size)) > + return 0; > + > + rcu_read_lock(); > + memcg = obj_cgroup_memcg(objcg); > + css_get(&memcg->css); > + rcu_read_unlock(); > + > + nr_pages = size >> PAGE_SHIFT; > + nr_bytes = size & (PAGE_SIZE - 1); > + > + if (nr_bytes) > + nr_pages += 1; > + > + ret = __memcg_kmem_charge(memcg, gfp, nr_pages); If consume_obj_stock() fails because some other memcg is cached, should this try to consume the partial page in objcg->nr_charged_bytes before getting more pages? > + if (!ret && nr_bytes) > + refill_obj_stock(objcg, PAGE_SIZE - nr_bytes); This will put the cgroup into the cache if the allocation resulted in a partially free page. But if this was a page allocation, we may have objcg->nr_cache_bytes from a previous subpage allocation that we should probably put back into the stock. It's not a common case, I'm just trying to understand what objcg->nr_cache_bytes holds and when it does so. The rest of this patch looks good to me!