Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3382892pxb; Wed, 14 Apr 2021 04:23:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVT3lMcC1ybuN8KrerMeyrOdQaIKrrjJ6wPH5p14+Tza9qWKXMx73UOkiol0+LqUyz2V0M X-Received: by 2002:a05:6402:2208:: with SMTP id cq8mr40536825edb.122.1618399438710; Wed, 14 Apr 2021 04:23:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618399438; cv=none; d=google.com; s=arc-20160816; b=J2n1qLPk37C1wPdKmM37XpxkWzNdCx4/5cDYF49AouDOaril0I4qs2e7ZNvu6X0Ll8 /AtdXrFsS6j9puuKvTHos6TVfN5n4ZeK+TtemWx/612nceuTuZ0ufwG4SjGoVhbnEW6V t1yePW8OaXifyV3oDqaoiMhoN+QLu2nQ9cOFfB1OXHy6RnSE1fVVFIt2+SrYa3oewQm9 IekLO2O2ZgnYw7mt8E2JH1FgMHFL5j1T8crIYMOyWfxVGLG0fDpwjvC1BrlVzMxtSaNn AmUbB15VHVh4omPlfrB8P1HwUe0+yXSHDesLzKxcAHW6hBHDvI/Kj7sp3SdPgHE7qloA 5NaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=QdR/wq0xqseV4lLF7yqZuKNGdvCcqiv/u3SIR9Qd35U=; b=Ie+JavFaGLFR0mjBjPd9Ik6s4rGWt1rhx/9OlBRKtJB6JOcPQP153m0Fko/12M0fqG 9hRoMhUnLvYONr8sTNdloE5b98+LwTJ3o/E5xNxpm+X6I/6VLEdWwh7g9/TwbcvnVJGT 1KL0wJAzm3xsHNvirLpoMGDzpNhpWyyGEURFvDnrVL/6mVmBNxWlcFRlug/ylmRaeUH7 2EP5+LjRQt9xW06L3Wbfq5yIAapdkBu2b2nG/w6Bj9U3bLgrmGy3ZMzifRNEWq9S4W10 hRGQx59AJ9BywszxhRpaZ1RDy2vxZrBSE940kbQXAQdeeXTbyW1EVmmqySTnt0FWE4LX XHUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S0f+BbTD; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gn42si14565114ejc.583.2021.04.14.04.23.35; Wed, 14 Apr 2021 04:23:58 -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=@redhat.com header.s=mimecast20190719 header.b=S0f+BbTD; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348996AbhDNBVW (ORCPT + 99 others); Tue, 13 Apr 2021 21:21:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47628 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348988AbhDNBVV (ORCPT ); Tue, 13 Apr 2021 21:21:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618363260; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=QdR/wq0xqseV4lLF7yqZuKNGdvCcqiv/u3SIR9Qd35U=; b=S0f+BbTDrnyQFUnZ+uUwXsVsYEDTcreU3Rb8f9mHfdJN2XPNdN41yonVmeSo65ZSLm6Co8 6OmdoK+qAqMY/NF83QKBzuwZUYFslEoIZrxCl/T60XFvn+FhcFVUl3Q39YCaEGPr+Fpe/G 2IV8bLbwlPYwGVRY5bSt9jqs+LYdnQc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-571-rlg0yT7TPpGIsYCIn9XV8Q-1; Tue, 13 Apr 2021 21:20:59 -0400 X-MC-Unique: rlg0yT7TPpGIsYCIn9XV8Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D945187A826; Wed, 14 Apr 2021 01:20:55 +0000 (UTC) Received: from llong.com (ovpn-113-4.rdu2.redhat.com [10.10.113.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id A300C1A7D9; Wed, 14 Apr 2021 01:20:53 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Tejun Heo , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin Cc: 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 , Masayoshi Mizuma , Xing Zhengjun , Waiman Long Subject: [PATCH v3 4/5] mm/memcg: Separate out object stock data into its own struct Date: Tue, 13 Apr 2021 21:20:26 -0400 Message-Id: <20210414012027.5352-5-longman@redhat.com> In-Reply-To: <20210414012027.5352-1-longman@redhat.com> References: <20210414012027.5352-1-longman@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The object stock data stored in struct memcg_stock_pcp are independent of the other page based data stored there. Separating them out into their own struct to highlight the independency. Signed-off-by: Waiman Long Acked-by: Roman Gushchin Reviewed-by: Shakeel Butt --- mm/memcontrol.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 539c3b632e47..69f728383efe 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2214,17 +2214,22 @@ void unlock_page_memcg(struct page *page) } EXPORT_SYMBOL(unlock_page_memcg); -struct memcg_stock_pcp { - struct mem_cgroup *cached; /* this never be root cgroup */ - unsigned int nr_pages; - +struct obj_stock { #ifdef CONFIG_MEMCG_KMEM struct obj_cgroup *cached_objcg; struct pglist_data *cached_pgdat; unsigned int nr_bytes; int vmstat_idx; int vmstat_bytes; +#else + int dummy[0]; #endif +}; + +struct memcg_stock_pcp { + struct mem_cgroup *cached; /* this never be root cgroup */ + unsigned int nr_pages; + struct obj_stock obj; struct work_struct work; unsigned long flags; @@ -2234,12 +2239,12 @@ static DEFINE_PER_CPU(struct memcg_stock_pcp, memcg_stock); static DEFINE_MUTEX(percpu_charge_mutex); #ifdef CONFIG_MEMCG_KMEM -static void drain_obj_stock(struct memcg_stock_pcp *stock); +static void drain_obj_stock(struct obj_stock *stock); static bool obj_stock_flush_required(struct memcg_stock_pcp *stock, struct mem_cgroup *root_memcg); #else -static inline void drain_obj_stock(struct memcg_stock_pcp *stock) +static inline void drain_obj_stock(struct obj_stock *stock) { } static bool obj_stock_flush_required(struct memcg_stock_pcp *stock, @@ -2249,6 +2254,13 @@ static bool obj_stock_flush_required(struct memcg_stock_pcp *stock, } #endif +static inline struct obj_stock *current_obj_stock(void) +{ + struct memcg_stock_pcp *stock = this_cpu_ptr(&memcg_stock); + + return &stock->obj; +} + /** * consume_stock: Try to consume stocked charge on this cpu. * @memcg: memcg to consume from. @@ -2315,7 +2327,7 @@ static void drain_local_stock(struct work_struct *dummy) local_irq_save(flags); stock = this_cpu_ptr(&memcg_stock); - drain_obj_stock(stock); + drain_obj_stock(&stock->obj); drain_stock(stock); clear_bit(FLUSHING_CACHED_CHARGE, &stock->flags); @@ -3177,13 +3189,13 @@ static inline void mod_objcg_state(struct obj_cgroup *objcg, static bool consume_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes) { - struct memcg_stock_pcp *stock; + struct obj_stock *stock; unsigned long flags; bool ret = false; local_irq_save(flags); - stock = this_cpu_ptr(&memcg_stock); + stock = current_obj_stock(); if (objcg == stock->cached_objcg && stock->nr_bytes >= nr_bytes) { stock->nr_bytes -= nr_bytes; ret = true; @@ -3194,7 +3206,7 @@ static bool consume_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes) return ret; } -static void drain_obj_stock(struct memcg_stock_pcp *stock) +static void drain_obj_stock(struct obj_stock *stock) { struct obj_cgroup *old = stock->cached_objcg; @@ -3242,8 +3254,8 @@ static bool obj_stock_flush_required(struct memcg_stock_pcp *stock, { struct mem_cgroup *memcg; - if (stock->cached_objcg) { - memcg = obj_cgroup_memcg(stock->cached_objcg); + if (stock->obj.cached_objcg) { + memcg = obj_cgroup_memcg(stock->obj.cached_objcg); if (memcg && mem_cgroup_is_descendant(memcg, root_memcg)) return true; } @@ -3253,9 +3265,8 @@ static bool obj_stock_flush_required(struct memcg_stock_pcp *stock, static void __refill_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes) { - struct memcg_stock_pcp *stock; + struct obj_stock *stock = current_obj_stock(); - stock = this_cpu_ptr(&memcg_stock); if (stock->cached_objcg != objcg) { /* reset if necessary */ drain_obj_stock(stock); obj_cgroup_get(objcg); @@ -3280,7 +3291,7 @@ static void refill_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes) static void __mod_obj_stock_state(struct obj_cgroup *objcg, struct pglist_data *pgdat, int idx, int nr) { - struct memcg_stock_pcp *stock = this_cpu_ptr(&memcg_stock); + struct obj_stock *stock = current_obj_stock(); if (stock->cached_objcg != objcg) { /* Output the current data as is */ -- 2.18.1