Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp435797pxb; Wed, 14 Apr 2021 20:29:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyROcIbA0hS700RhmozIXpugLPbiocCKAuK+8rCTD4v8yGj14o0q+53qtGWSY+sEpxf4vVm X-Received: by 2002:a17:906:49d3:: with SMTP id w19mr1254205ejv.116.1618457372282; Wed, 14 Apr 2021 20:29:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618457372; cv=none; d=google.com; s=arc-20160816; b=q9xu2U++pi2TCPSYYC1FHREMLWG9syEeiacBjZgyxpgtdw4hUEdZzHSIDxumMBqfA4 jp3SfYZdw5tjQkVnNIacglKCXR3+F0aOzcgT7uj3Y3evwQVrf+f00IKcGPQABhpyKcMt s4xDrjrhfUk2mGn2ORq3YUkVsUTfNVA+YLjQMmtS2ShV1fu9MaCxwfrSNM9MKbu9s/eQ 4RbzYne3xi0YT/T+XbNy2667M1lKy9cM2CYB2hFJqxFwVkDSakDhJ+/43o/cRUSutF7E 4OhX+fTBXLnoA97q+TSPfw72A5TzxHW05KPzhgsorrLXSFRl1iZfaS1T4Vn60otTnUKj 4bjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZewygDwmHdq6xdev+sHHUZNlvlau4881WxunfG37r7A=; b=BTd2zXkv/1IEM4jk/NCKPM6+QUUwQNaXI6FSFGOHxQnfFEtiWpC6irP4Ia4uf0xZ2T 0PfDxqgHZGQ2PIKAQePUdfQYFQllfZgE+r5+RuHOXaecxRBQH5dUL/1AhzXe8t6HRS+9 G3paC3MaxeAchUKAiKaYKAuZ8ThLByz4Ovj6kWCgdSPI4PdHaiIAPgM1f4xnUfFE/O6M kWZa55r2CCY2MVu1BHeEcFGB/2UXOg9bEvV3XansnnWUnXHOMYPKHn5zaP/xkyhZPd7G xWFten76+rnSt+RYCIEHOU4JnwP1M4zMv4tllEwidu5G/HTayT6LMIN3ORxfuK5db79N G8Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rXthvvKp; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds7si1218881ejc.534.2021.04.14.20.29.09; Wed, 14 Apr 2021 20:29:32 -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=@gmail.com header.s=20161025 header.b=rXthvvKp; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229817AbhDOD2N (ORCPT + 99 others); Wed, 14 Apr 2021 23:28:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229467AbhDOD2M (ORCPT ); Wed, 14 Apr 2021 23:28:12 -0400 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DA98C061574; Wed, 14 Apr 2021 20:27:50 -0700 (PDT) Received: by mail-qv1-xf2e.google.com with SMTP id dp18so6409274qvb.5; Wed, 14 Apr 2021 20:27:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ZewygDwmHdq6xdev+sHHUZNlvlau4881WxunfG37r7A=; b=rXthvvKpJW5ubM3JhbMfyuP6GD/x2iw15KlAPPi8FDrLiadaHWY0VJ/vZqSA958+oi aYVuChvL8siJXaGEibL5KNTauCkk+/VUzBIZPBoVuo3PSWLFe2VZ9nMw+vO/UELzL989 QNolmx63Igls8yqbffc7aqyzqNT5UIv8Ouy9lz2LZPRmK3VUPZCUv+B8POIN362B+DPy HSdDXzt890ZNc+LwDnz6U0ZzeMu3Owidfux5884QxIk27FpTtZSR15bqZE3Hhv7ZFjTp KvyQ94lZtMioin31k203Q1a0ipkNda/kmwyZYoiCe/ZeCKZ7wNfJNixRkcWzUqevAdrm K1Aw== 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=ZewygDwmHdq6xdev+sHHUZNlvlau4881WxunfG37r7A=; b=Iq53mfkTht5bOLkLb9DUxa7tlt2Bl9+U4JZT0hvgz7GHGXO4NjDK5dqo+Jw2MEOdNb eaRhNDasBkTSgJyRw1xtREHI5sNBa8rRgPM9DxpMOpBWejZPTatyNgmoloKYlPzA5Pza jN1TM+sbYqssTdYyMH0uip+IXIhpb10r55pnncYWUpwJ9TG1sjEnyIy+vtoe2KQtakkr 8w0ExBQxl4mOGP5F621VCmxECt0inlL5FJ9gyQXkgwS7QY0Jk8HtEVc6ZRpFmo9Wrq7g w7UwOvNbbIgZIHMSGwRpkLl0jYaNbGeCY3ED+HYfSFVz2kFhljHHeQ5dnELLNGDRrAyr G4WA== X-Gm-Message-State: AOAM5322vPkzoM4PFvdKcDYwB5KEsJWoyizd3h4yqQP6gCS2koDyw2gS FJPATnRmaREocaXobAnRHg== X-Received: by 2002:a05:6214:12e4:: with SMTP id w4mr1306969qvv.30.1618457269576; Wed, 14 Apr 2021 20:27:49 -0700 (PDT) Received: from gabell (209-6-122-159.s2973.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [209.6.122.159]) by smtp.gmail.com with ESMTPSA id d62sm1102401qkg.55.2021.04.14.20.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Apr 2021 20:27:49 -0700 (PDT) Date: Wed, 14 Apr 2021 23:27:46 -0400 From: Masayoshi Mizuma To: Waiman Long Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Tejun Heo , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt , Muchun Song , Alex Shi , Chris Down , Yafang Shao , Wei Yang , Xing Zhengjun Subject: Re: [PATCH v3 2/5] mm/memcg: Introduce obj_cgroup_uncharge_mod_state() Message-ID: <20210415032746.hahhc5l5lbjhdvnr@gabell> References: <20210414012027.5352-1-longman@redhat.com> <20210414012027.5352-3-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210414012027.5352-3-longman@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 13, 2021 at 09:20:24PM -0400, Waiman Long wrote: > In memcg_slab_free_hook()/pcpu_memcg_free_hook(), obj_cgroup_uncharge() > is followed by mod_objcg_state()/mod_memcg_state(). Each of these > function call goes through a separate irq_save/irq_restore cycle. That > is inefficient. Introduce a new function obj_cgroup_uncharge_mod_state() > that combines them with a single irq_save/irq_restore cycle. > > Signed-off-by: Waiman Long > Reviewed-by: Shakeel Butt > Acked-by: Roman Gushchin > --- > include/linux/memcontrol.h | 2 ++ > mm/memcontrol.c | 31 +++++++++++++++++++++++++++---- > mm/percpu.c | 9 ++------- > mm/slab.h | 6 +++--- > 4 files changed, 34 insertions(+), 14 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 95f12996e66c..6890f999c1a3 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -1592,6 +1592,8 @@ struct obj_cgroup *get_obj_cgroup_from_current(void); > > int obj_cgroup_charge(struct obj_cgroup *objcg, gfp_t gfp, size_t size); > void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size); > +void obj_cgroup_uncharge_mod_state(struct obj_cgroup *objcg, size_t size, > + struct pglist_data *pgdat, int idx); > > extern struct static_key_false memcg_kmem_enabled_key; > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index d66e1e38f8ac..b19100c68aa0 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -3225,12 +3225,9 @@ static bool obj_stock_flush_required(struct memcg_stock_pcp *stock, > return false; > } > > -static void refill_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes) > +static void __refill_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes) > { > struct memcg_stock_pcp *stock; > - unsigned long flags; > - > - local_irq_save(flags); > > stock = this_cpu_ptr(&memcg_stock); > if (stock->cached_objcg != objcg) { /* reset if necessary */ > @@ -3243,7 +3240,14 @@ static void refill_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes) > > if (stock->nr_bytes > PAGE_SIZE) > drain_obj_stock(stock); > +} > + > +static void refill_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes) > +{ > + unsigned long flags; > > + local_irq_save(flags); > + __refill_obj_stock(objcg, nr_bytes); > local_irq_restore(flags); > } > > @@ -3292,6 +3296,25 @@ void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size) > refill_obj_stock(objcg, size); > } > > +void obj_cgroup_uncharge_mod_state(struct obj_cgroup *objcg, size_t size, > + struct pglist_data *pgdat, int idx) > +{ > + unsigned long flags; > + struct mem_cgroup *memcg; > + struct lruvec *lruvec = NULL; > + > + local_irq_save(flags); > + __refill_obj_stock(objcg, size); > + > + rcu_read_lock(); > + memcg = obj_cgroup_memcg(objcg); > + if (pgdat) > + lruvec = mem_cgroup_lruvec(memcg, pgdat); > + __mod_memcg_lruvec_state(memcg, lruvec, idx, -(int)size); > + rcu_read_unlock(); > + local_irq_restore(flags); > +} > + > #endif /* CONFIG_MEMCG_KMEM */ > > /* > diff --git a/mm/percpu.c b/mm/percpu.c > index 23308113a5ff..fd7aad6d7f90 100644 > --- a/mm/percpu.c > +++ b/mm/percpu.c > @@ -1631,13 +1631,8 @@ static void pcpu_memcg_free_hook(struct pcpu_chunk *chunk, int off, size_t size) > objcg = chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT]; > chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT] = NULL; > > - obj_cgroup_uncharge(objcg, size * num_possible_cpus()); > - > - rcu_read_lock(); > - mod_memcg_state(obj_cgroup_memcg(objcg), MEMCG_PERCPU_B, > - -(size * num_possible_cpus())); > - rcu_read_unlock(); > - > + obj_cgroup_uncharge_mod_state(objcg, size * num_possible_cpus(), > + NULL, MEMCG_PERCPU_B); > obj_cgroup_put(objcg); > } > > diff --git a/mm/slab.h b/mm/slab.h > index bc6c7545e487..677cdc52e641 100644 > --- a/mm/slab.h > +++ b/mm/slab.h > @@ -366,9 +366,9 @@ static inline void memcg_slab_free_hook(struct kmem_cache *s_orig, > continue; > > objcgs[off] = NULL; > - obj_cgroup_uncharge(objcg, obj_full_size(s)); > - mod_objcg_state(objcg, page_pgdat(page), cache_vmstat_idx(s), > - -obj_full_size(s)); > + obj_cgroup_uncharge_mod_state(objcg, obj_full_size(s), > + page_pgdat(page), > + cache_vmstat_idx(s)); > obj_cgroup_put(objcg); > } > } > -- > 2.18.1 > Please feel free to add: Tested-by: Masayoshi Mizuma Thanks! Masa