Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1447981lqt; Sat, 20 Apr 2024 16:25:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUFqjpFujOngHFB47bZch4xUQR18bNSOKigSIZtfR/aRjx0KnRUtCxx/Aj0fNd82liskL8Q3+yw6X1NIaAD8BryeZ7S7QlZzdZyP2YnpQ== X-Google-Smtp-Source: AGHT+IHC5ahbQgCDv6fpuRxf3NE6aZ0h2rH5Wxp2x3hU1/aKA/oU2d+PErccxx9xDa0J8k+m4H68 X-Received: by 2002:a05:6512:12cd:b0:518:c902:f992 with SMTP id p13-20020a05651212cd00b00518c902f992mr5106162lfg.9.1713655541467; Sat, 20 Apr 2024 16:25:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713655541; cv=pass; d=google.com; s=arc-20160816; b=T564mq+j1BCL6PYMwrzDi2fZe7H8/HBZEdA5r8W76gYH8jwDnx5rButmAhKHCxNRj+ 3/xa3bNZjkpu9cGA+c9xGLVKICQ4msNucVoThn9o0wmxUa1IenGtQ9BytOwYFDgfZkv3 zzK4XQcxZbH/0Yiv1Em8D2bqeU4PGATzaMEtgAvKNKpUHhqx/sBreKT+fXm4ogM9HayW NyOLPAvGINusHwR3zAMKSFtSj95+Ki2hD5ozPsBPc60jh/u+tedZx7uJ8wz7AftyTI+0 n5c1zyUkwvR74s1W+wUi3RzCcolgG47WvgeVwYbNxoJLINrPyGiGo3Xd2jsAqFe0Q2Ny HzFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=9YG0Yr27rZjU0OlmRSCmu8viB0Ry44abch6JPf2G2gw=; fh=RT6qUd/cFk7mA1daRZyPKZ73SkJUv705B/3NiEK9oSU=; b=ptsa/FaneCf07YclPkOFB5SACVUbA9QIwK4bpxlkZoTO9KYKbt21x8M8ZtjJNlcrjI Ig9St/TMyJ9HPkjAxTGbhsSOrtADYr0pLo5iNMXwuz/+NTlTCi/viEe50xRo+gW4Xive bg6XpLFAtvvwwuyFmwTQ2ADOySB5jm6WBLYCQNsCqdlHip0IEKyVMmB0oIqKLOqwSzot Yo6HWuouw9jg5Eej4A4E0tw0YtJ95k18da/0ybT4LuaDEgvqu/GSPxfNur6hYjUbw/RD cAy1TfEDVAw9LkDuojOPAfAnvtT4MLFDO71jOfBn8+FxRvg5jKSVVGPP9Pgj1nyfhDRZ E7dw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=UrIDxFRy; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-152392-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152392-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id hr15-20020a1709073f8f00b00a5588c75626si2442507ejc.15.2024.04.20.16.25.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Apr 2024 16:25:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152392-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=UrIDxFRy; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-152392-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152392-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0A1241F214A6 for ; Sat, 20 Apr 2024 23:25:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0085B4CE19; Sat, 20 Apr 2024 23:25:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="UrIDxFRy" Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1A6C205E35 for ; Sat, 20 Apr 2024 23:25:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713655533; cv=none; b=gjwwuZd/Ml94pS2xY+Yepo39URuJx3vyL6DTBBRAbMfjkeQ0hBxZ5fabyl48ObIEhiFPFJeAa8Xws+xlPEOX4N1IZL0tiyVc76Vb1ZU8BUQOMHjEPjIltJ5g6J1a12VO7wUGVs7tZRFiujwrPx+vl7CfZiE20rsaGBM/oVaT3ck= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713655533; c=relaxed/simple; bh=TLhSsMbuwT2Yz/2MlPtFCCCHWs6N6gnMcwOfD6CpG8w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=PPhqcvN+fm8P9FC1IFbE5F/1cJFYrTuVFQvPznLfBdN1BE84rbrPviFG1QSFNOPOwg/qAj6I22R/PeeerHq/1qAJH7UY/+VWd7i8eHLc9g15N+a3aKnw3MMMMYv60vMPh6l4QsO/eRKSyl/o74XOFALEqcQ0/MCiT5GfkSmP7Gk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=UrIDxFRy; arc=none smtp.client-ip=91.218.175.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1713655528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=9YG0Yr27rZjU0OlmRSCmu8viB0Ry44abch6JPf2G2gw=; b=UrIDxFRykQOLXhTrCXQVev4LjYc/8/H9kEh1rvTsseAeBhhlphYEqRsghwbXuveza5V3lH o+5T9aWRXHdAs6mJK1Bt/+nYlurFrKwr5iMKCEVxkueeO7U2zhFx6HlTUZNoC+STYR0heG JtP0UgIiBasmIEeChd/jHiEA6SZVpw0= From: Shakeel Butt To: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] memcg: simple cleanup of stats update functions Date: Sat, 20 Apr 2024 16:25:05 -0700 Message-ID: <20240420232505.2768428-1-shakeel.butt@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT mod_memcg_lruvec_state() is never called from outside of memcontrol.c and with always irq disabled. So, replace it with the irq disabled version and add an assert that irq is disabled in the caller. Similarly mod_objcg_state() is not called from outside of memcontrol.c, so simply make it static and change it's name to __mod_objcg_state(). Signed-off-by: Shakeel Butt Acked-by: Johannes Weiner --- Change since v1: - Change mod_objcg_state to __mod_objcg_state as per the naming convention (suggested by Johannes). include/linux/memcontrol.h | 17 ----------------- mm/memcontrol.c | 31 +++++++++++++++---------------- mm/slab.h | 2 -- 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 8f332b4ae84c..9aba0d0462ca 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1077,8 +1077,6 @@ static inline unsigned long lruvec_page_state_local(struct lruvec *lruvec, void mem_cgroup_flush_stats(struct mem_cgroup *memcg); void mem_cgroup_flush_stats_ratelimited(struct mem_cgroup *memcg); -void __mod_memcg_lruvec_state(struct lruvec *lruvec, enum node_stat_item idx, - int val); void __mod_lruvec_kmem_state(void *p, enum node_stat_item idx, int val); static inline void mod_lruvec_kmem_state(void *p, enum node_stat_item idx, @@ -1091,16 +1089,6 @@ static inline void mod_lruvec_kmem_state(void *p, enum node_stat_item idx, local_irq_restore(flags); } -static inline void mod_memcg_lruvec_state(struct lruvec *lruvec, - enum node_stat_item idx, int val) -{ - unsigned long flags; - - local_irq_save(flags); - __mod_memcg_lruvec_state(lruvec, idx, val); - local_irq_restore(flags); -} - void __count_memcg_events(struct mem_cgroup *memcg, enum vm_event_item idx, unsigned long count); @@ -1594,11 +1582,6 @@ static inline void mem_cgroup_flush_stats_ratelimited(struct mem_cgroup *memcg) { } -static inline void __mod_memcg_lruvec_state(struct lruvec *lruvec, - enum node_stat_item idx, int val) -{ -} - static inline void __mod_lruvec_kmem_state(void *p, enum node_stat_item idx, int val) { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7703ced535a3..833d09c1d523 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -837,8 +837,9 @@ static unsigned long memcg_page_state_local(struct mem_cgroup *memcg, int idx) return x; } -void __mod_memcg_lruvec_state(struct lruvec *lruvec, enum node_stat_item idx, - int val) +static void __mod_memcg_lruvec_state(struct lruvec *lruvec, + enum node_stat_item idx, + int val) { struct mem_cgroup_per_node *pn; struct mem_cgroup *memcg; @@ -2983,21 +2984,19 @@ void mem_cgroup_commit_charge(struct folio *folio, struct mem_cgroup *memcg) #ifdef CONFIG_MEMCG_KMEM -/* - * mod_objcg_mlstate() may be called with irq enabled, so - * mod_memcg_lruvec_state() should be used. - */ -static inline void mod_objcg_mlstate(struct obj_cgroup *objcg, - struct pglist_data *pgdat, - enum node_stat_item idx, int nr) +static inline void __mod_objcg_mlstate(struct obj_cgroup *objcg, + struct pglist_data *pgdat, + enum node_stat_item idx, int nr) { struct mem_cgroup *memcg; struct lruvec *lruvec; + lockdep_assert_irqs_disabled(); + rcu_read_lock(); memcg = obj_cgroup_memcg(objcg); lruvec = mem_cgroup_lruvec(memcg, pgdat); - mod_memcg_lruvec_state(lruvec, idx, nr); + __mod_memcg_lruvec_state(lruvec, idx, nr); rcu_read_unlock(); } @@ -3317,7 +3316,7 @@ void __memcg_kmem_uncharge_page(struct page *page, int order) obj_cgroup_put(objcg); } -void mod_objcg_state(struct obj_cgroup *objcg, struct pglist_data *pgdat, +static void mod_objcg_state(struct obj_cgroup *objcg, struct pglist_data *pgdat, enum node_stat_item idx, int nr) { struct memcg_stock_pcp *stock; @@ -3345,12 +3344,12 @@ void mod_objcg_state(struct obj_cgroup *objcg, struct pglist_data *pgdat, struct pglist_data *oldpg = stock->cached_pgdat; if (stock->nr_slab_reclaimable_b) { - mod_objcg_mlstate(objcg, oldpg, NR_SLAB_RECLAIMABLE_B, + __mod_objcg_mlstate(objcg, oldpg, NR_SLAB_RECLAIMABLE_B, stock->nr_slab_reclaimable_b); stock->nr_slab_reclaimable_b = 0; } if (stock->nr_slab_unreclaimable_b) { - mod_objcg_mlstate(objcg, oldpg, NR_SLAB_UNRECLAIMABLE_B, + __mod_objcg_mlstate(objcg, oldpg, NR_SLAB_UNRECLAIMABLE_B, stock->nr_slab_unreclaimable_b); stock->nr_slab_unreclaimable_b = 0; } @@ -3376,7 +3375,7 @@ void mod_objcg_state(struct obj_cgroup *objcg, struct pglist_data *pgdat, } } if (nr) - mod_objcg_mlstate(objcg, pgdat, idx, nr); + __mod_objcg_mlstate(objcg, pgdat, idx, nr); local_unlock_irqrestore(&memcg_stock.stock_lock, flags); obj_cgroup_put(old); @@ -3442,13 +3441,13 @@ static struct obj_cgroup *drain_obj_stock(struct memcg_stock_pcp *stock) */ if (stock->nr_slab_reclaimable_b || stock->nr_slab_unreclaimable_b) { if (stock->nr_slab_reclaimable_b) { - mod_objcg_mlstate(old, stock->cached_pgdat, + __mod_objcg_mlstate(old, stock->cached_pgdat, NR_SLAB_RECLAIMABLE_B, stock->nr_slab_reclaimable_b); stock->nr_slab_reclaimable_b = 0; } if (stock->nr_slab_unreclaimable_b) { - mod_objcg_mlstate(old, stock->cached_pgdat, + __mod_objcg_mlstate(old, stock->cached_pgdat, NR_SLAB_UNRECLAIMABLE_B, stock->nr_slab_unreclaimable_b); stock->nr_slab_unreclaimable_b = 0; diff --git a/mm/slab.h b/mm/slab.h index e32d9cf1077a..5f8f47c5bee0 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -578,8 +578,6 @@ bool __memcg_slab_post_alloc_hook(struct kmem_cache *s, struct list_lru *lru, gfp_t flags, size_t size, void **p); void __memcg_slab_free_hook(struct kmem_cache *s, struct slab *slab, void **p, int objects, struct slabobj_ext *obj_exts); -void mod_objcg_state(struct obj_cgroup *objcg, struct pglist_data *pgdat, - enum node_stat_item idx, int nr); #endif size_t __ksize(const void *objp); -- 2.43.0