From nobody Wed Feb 11 03:41:51 2026 Received: from out-176.mta0.migadu.com (out-176.mta0.migadu.com [91.218.175.176]) (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 C140F1B966 for ; Tue, 23 Apr 2024 05:19:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713849546; cv=none; b=qLWoGcheoqwzpFDcmpr1IONeCo9XNtN3CFscGhqCf2WOEyVnV6j+MW3afEuOUjG+1tZ5yKVEpRmmSfgYDDkCCo7tKsOVznk0ZieJ8KKQMxLIjpQLiQPTwFCYhwpLGTXFLE20xm4UBq1FuFJNLlWQ7VrZxanxMIuSTaPl6wHtFnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713849546; c=relaxed/simple; bh=eiXcrRuZw4LtEHNUEA4exwXwssnNKo06rp7vQRI3atg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L6HSOHcIdOSZQ5arMvYM0Vh7T5yyJCzbuSJJ5T2f8CKYWpF5PAYfQ0WuPOfP/Dnw0EOD36YDSryG9U+HJWJsgCI7SP8K5QCrGTB7IR4hBWDcJcX6+CXTOeix9cvZ92kZvD1mdL3QsLHiG6dgcQNfHIFe6YFWgORLZt5ms/uepLo= 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=I4F4bHP1; arc=none smtp.client-ip=91.218.175.176 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="I4F4bHP1" 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=1713849540; 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: in-reply-to:in-reply-to:references:references; bh=bmlC5V1svJt9xuRUdyZMky0nyZvqteAMmSbcGNRQ+Ug=; b=I4F4bHP1pHL9StE0oEfUCq18gVSk6V5wUHsNH2r4mbFqr3BWQqPEZJK6aDP5C5HBbpIZbm 7qNg7St16OMmZI9IF5XHvpKb6ahSRJqZ0Zorrf3bW8J+CXso/2RX9xjYMLMCnj2Tim11hK zgXSePbl3UN1y1lt9gtQCIJB2FGhKJk= 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 1/4] mm: rearrange node_stat_item to put memcg stats at start Date: Mon, 22 Apr 2024 22:18:23 -0700 Message-ID: <20240423051826.791934-2-shakeel.butt@linux.dev> In-Reply-To: <20240423051826.791934-1-shakeel.butt@linux.dev> References: <20240423051826.791934-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: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" At the moment the memcg stats are sized based on the size of enum node_stat_item but not all fields in node_stat_item corresponds to memcg stats. So, rearrage the contents of node_stat_item such that all the memcg specific stats are at the top and then the later patches will make sure that the memcg code will not waste space for non-memcg stats. Signed-off-by: Shakeel Butt --- include/linux/mmzone.h | 25 +++++++++++++------------ mm/vmstat.c | 24 ++++++++++++------------ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 8f9c9590a42c..989ca97402c6 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -166,9 +166,6 @@ enum node_stat_item { NR_UNEVICTABLE, /* " " " " " */ NR_SLAB_RECLAIMABLE_B, NR_SLAB_UNRECLAIMABLE_B, - NR_ISOLATED_ANON, /* Temporary isolated pages from anon lru */ - NR_ISOLATED_FILE, /* Temporary isolated pages from file lru */ - WORKINGSET_NODES, WORKINGSET_REFAULT_BASE, WORKINGSET_REFAULT_ANON =3D WORKINGSET_REFAULT_BASE, WORKINGSET_REFAULT_FILE, @@ -179,39 +176,43 @@ enum node_stat_item { WORKINGSET_RESTORE_ANON =3D WORKINGSET_RESTORE_BASE, WORKINGSET_RESTORE_FILE, WORKINGSET_NODERECLAIM, + NR_PAGETABLE, /* used for pagetables */ + NR_SECONDARY_PAGETABLE, /* secondary pagetables, KVM & IOMMU */ + NR_KERNEL_STACK_KB, /* measured in KiB */ NR_ANON_MAPPED, /* Mapped anonymous pages */ NR_FILE_MAPPED, /* pagecache pages mapped into pagetables. only modified from process context */ NR_FILE_PAGES, +#ifdef CONFIG_SWAP + NR_SWAPCACHE, +#endif NR_FILE_DIRTY, NR_WRITEBACK, - NR_WRITEBACK_TEMP, /* Writeback using temporary buffers */ NR_SHMEM, /* shmem pages (included tmpfs/GEM pages) */ NR_SHMEM_THPS, - NR_SHMEM_PMDMAPPED, NR_FILE_THPS, - NR_FILE_PMDMAPPED, NR_ANON_THPS, + /* No memcg stats for the following fields. */ + NR_SHMEM_PMDMAPPED, + NR_FILE_PMDMAPPED, + NR_WRITEBACK_TEMP, /* Writeback using temporary buffers */ NR_VMSCAN_WRITE, NR_VMSCAN_IMMEDIATE, /* Prioritise for reclaim when writeback ends */ + NR_ISOLATED_ANON, /* Temporary isolated pages from anon lru */ + NR_ISOLATED_FILE, /* Temporary isolated pages from file lru */ + WORKINGSET_NODES, NR_DIRTIED, /* page dirtyings since bootup */ NR_WRITTEN, /* page writings since bootup */ NR_THROTTLED_WRITTEN, /* NR_WRITTEN while reclaim throttled */ NR_KERNEL_MISC_RECLAIMABLE, /* reclaimable non-slab kernel pages */ NR_FOLL_PIN_ACQUIRED, /* via: pin_user_page(), gup flag: FOLL_PIN */ NR_FOLL_PIN_RELEASED, /* pages returned via unpin_user_page() */ - NR_KERNEL_STACK_KB, /* measured in KiB */ #if IS_ENABLED(CONFIG_SHADOW_CALL_STACK) NR_KERNEL_SCS_KB, /* measured in KiB */ #endif - NR_PAGETABLE, /* used for pagetables */ - NR_SECONDARY_PAGETABLE, /* secondary pagetables, KVM & IOMMU */ #ifdef CONFIG_IOMMU_SUPPORT NR_IOMMU_PAGES, /* # of pages allocated by IOMMU */ #endif -#ifdef CONFIG_SWAP - NR_SWAPCACHE, -#endif #ifdef CONFIG_NUMA_BALANCING PGPROMOTE_SUCCESS, /* promote successfully */ PGPROMOTE_CANDIDATE, /* candidate pages to promote */ diff --git a/mm/vmstat.c b/mm/vmstat.c index 8507c497218b..4eac2f6322a3 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1206,9 +1206,6 @@ const char * const vmstat_text[] =3D { "nr_unevictable", "nr_slab_reclaimable", "nr_slab_unreclaimable", - "nr_isolated_anon", - "nr_isolated_file", - "workingset_nodes", "workingset_refault_anon", "workingset_refault_file", "workingset_activate_anon", @@ -1216,38 +1213,41 @@ const char * const vmstat_text[] =3D { "workingset_restore_anon", "workingset_restore_file", "workingset_nodereclaim", + "nr_page_table_pages", + "nr_sec_page_table_pages", + "nr_kernel_stack", "nr_anon_pages", "nr_mapped", "nr_file_pages", +#ifdef CONFIG_SWAP + "nr_swapcached", +#endif "nr_dirty", "nr_writeback", - "nr_writeback_temp", "nr_shmem", "nr_shmem_hugepages", - "nr_shmem_pmdmapped", "nr_file_hugepages", - "nr_file_pmdmapped", "nr_anon_transparent_hugepages", + "nr_shmem_pmdmapped", + "nr_file_pmdmapped", + "nr_writeback_temp", "nr_vmscan_write", "nr_vmscan_immediate_reclaim", + "nr_isolated_anon", + "nr_isolated_file", + "workingset_nodes", "nr_dirtied", "nr_written", "nr_throttled_written", "nr_kernel_misc_reclaimable", "nr_foll_pin_acquired", "nr_foll_pin_released", - "nr_kernel_stack", #if IS_ENABLED(CONFIG_SHADOW_CALL_STACK) "nr_shadow_call_stack", #endif - "nr_page_table_pages", - "nr_sec_page_table_pages", #ifdef CONFIG_IOMMU_SUPPORT "nr_iommu_pages", #endif -#ifdef CONFIG_SWAP - "nr_swapcached", -#endif #ifdef CONFIG_NUMA_BALANCING "pgpromote_success", "pgpromote_candidate", --=20 2.43.0 From nobody Wed Feb 11 03:41:51 2026 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (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 48F6C225A2 for ; Tue, 23 Apr 2024 05:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713849551; cv=none; b=UQr8UnyRasN37wMk52LTyE/2iU39tuqQxGRjh+wxsv78a233qIJtq5RYaNRwTvxvGryjqwwMquViTyCzpEIuTx9Lv4Wv/JQuuEjnhmafW9gbIqrBbPAElguyeFFmSTaGWQsLvsUxOV+H4VXIjiNMNGiOhNkLHnLeSDEQ+h3XfTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713849551; c=relaxed/simple; bh=Wmvq48LEHKtnsh9tlioUOV+HIKXT4mpP0GExGJRNVys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lNqgdC3PyNDBdKlbg+29NMwF32Jco7MKLtsSPVHsD0N+zN4YVIWxubSrp14yvMMfrB/JbO1fQDFpUxBgURlB2DXDy+SCDaqG3sew4Fg6RuaeHHEblvuUGLNqaZ/wohR2kPWu9lc4TItc3/m6CW/AgVX7Vr2oTWcMR75l+1Iqehk= 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=rs11xhPn; arc=none smtp.client-ip=95.215.58.187 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="rs11xhPn" 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=1713849547; 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: in-reply-to:in-reply-to:references:references; bh=mPVb/7bJYg0jCXHlUHlEkoC8VRMDznvlUA6F/qpq0LU=; b=rs11xhPnd+9ujJmxyiwAvIbaHbCvJYdPVIddaFlw5SnCPmRJf2G7uYXy12IKeEAF5st3Lj b59FvyJ5wKuhH/XVQ6PnB0vVo8qJTGEnv4SY4rfkSAgFn0xbURo2o9NiV0/PjYCL0/JEeB Uv0DlU5Nl1YornvPTybWThJ/C1flxus= 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 2/4] memcg: reduce memory for the lruvec and memcg stats Date: Mon, 22 Apr 2024 22:18:24 -0700 Message-ID: <20240423051826.791934-3-shakeel.butt@linux.dev> In-Reply-To: <20240423051826.791934-1-shakeel.butt@linux.dev> References: <20240423051826.791934-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: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" At the moment, the amount of memory allocated for stats related structs in the mem_cgroup corresponds to the size of enum node_stat_item. However not all fields in enum node_stat_item has corresponding memcg stats. The fields of enum node_stat_item is sorted in such a way that all the fields with corresponding memcg stats are at the start of the enum node_stat_item. So, let's just make an explicit boundary within enum node_stat_item and use that boundary to allocate memory for stats related structs of memcgs. For a given x86_64 config, the size of stats with and without patch is: structs size in bytes w/o with struct lruvec_stats 1128 648 struct lruvec_stats_percpu 752 432 struct memcg_vmstats 1832 1352 struct memcg_vmstats_percpu 1280 960 The memory savings is further compounded by the fact that these structs are allocated for each cpu and for node. To be precise, for each memcg, the memory saved would be: Memory saved =3D ((21 * 3 * NR_NODES) + (21 * 2 * NR_NODS * NR_CPUS) + (21 * 3) + (21 * 2 * NR_CPUS)) * sizeof(long) Where 21 is the number of fields eliminated. Signed-off-by: Shakeel Butt --- include/linux/memcontrol.h | 12 ++++++------ include/linux/mmzone.h | 8 ++++++-- mm/memcontrol.c | 5 ++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 9aba0d0462ca..d68db7a0e829 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -32,7 +32,7 @@ struct kmem_cache; =20 /* Cgroup-specific page state, on top of universal node page state */ enum memcg_stat_item { - MEMCG_SWAP =3D NR_VM_NODE_STAT_ITEMS, + MEMCG_SWAP =3D NR_VM_NODE_MEMCG_STAT_ITEMS, MEMCG_SOCK, MEMCG_PERCPU_B, MEMCG_VMALLOC, @@ -92,21 +92,21 @@ struct mem_cgroup_reclaim_iter { =20 struct lruvec_stats_percpu { /* Local (CPU and cgroup) state */ - long state[NR_VM_NODE_STAT_ITEMS]; + long state[NR_VM_NODE_MEMCG_STAT_ITEMS]; =20 /* Delta calculation for lockless upward propagation */ - long state_prev[NR_VM_NODE_STAT_ITEMS]; + long state_prev[NR_VM_NODE_MEMCG_STAT_ITEMS]; }; =20 struct lruvec_stats { /* Aggregated (CPU and subtree) state */ - long state[NR_VM_NODE_STAT_ITEMS]; + long state[NR_VM_NODE_MEMCG_STAT_ITEMS]; =20 /* Non-hierarchical (CPU aggregated) state */ - long state_local[NR_VM_NODE_STAT_ITEMS]; + long state_local[NR_VM_NODE_MEMCG_STAT_ITEMS]; =20 /* Pending child counts during tree propagation */ - long state_pending[NR_VM_NODE_STAT_ITEMS]; + long state_pending[NR_VM_NODE_MEMCG_STAT_ITEMS]; }; =20 /* diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 989ca97402c6..59592f3c7d9b 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -192,8 +192,12 @@ enum node_stat_item { NR_SHMEM_THPS, NR_FILE_THPS, NR_ANON_THPS, - /* No memcg stats for the following fields. */ - NR_SHMEM_PMDMAPPED, + /* + * No memcg stats for the following fields. Please add stats which have + * memcg counterpart above NR_VM_NODE_MEMCG_STAT_ITEMS. + */ + NR_VM_NODE_MEMCG_STAT_ITEMS, + NR_SHMEM_PMDMAPPED =3D NR_VM_NODE_MEMCG_STAT_ITEMS, NR_FILE_PMDMAPPED, NR_WRITEBACK_TEMP, /* Writeback using temporary buffers */ NR_VMSCAN_WRITE, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 833d09c1d523..bb1bbf417a46 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1648,6 +1648,9 @@ static void memcg_stat_format(struct mem_cgroup *memc= g, struct seq_buf *s) { int i; =20 + /* Reduce by 1 for MEMCG_SWAP as that is not exposed in v2. */ + BUILD_BUG_ON(ARRAY_SIZE(memory_stats) !=3D MEMCG_NR_STAT - 1); + /* * Provide statistics on the state of the memory subsystem as * well as cumulative event counters that show past behavior. @@ -5869,7 +5872,7 @@ static void mem_cgroup_css_rstat_flush(struct cgroup_= subsys_state *css, int cpu) =20 lstatc =3D per_cpu_ptr(pn->lruvec_stats_percpu, cpu); =20 - for (i =3D 0; i < NR_VM_NODE_STAT_ITEMS; i++) { + for (i =3D 0; i < NR_VM_NODE_MEMCG_STAT_ITEMS; i++) { delta =3D pn->lruvec_stats.state_pending[i]; if (delta) pn->lruvec_stats.state_pending[i] =3D 0; --=20 2.43.0 From nobody Wed Feb 11 03:41:51 2026 Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) (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 EAE64208A0 for ; Tue, 23 Apr 2024 05:22:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713849758; cv=none; b=PAv8z6ripWSotpaR1X8RYLEhLWWDcupxAIm/Jpw/GTxe7a9s8o/654/qYOgWWpvIzjMXEdD+EDCKvwEeHog+1iFcRsogq6fVzHHb6xhrO4NmwETH+JiikBucwcBZbpk8qnnYu9TY18Z0CwkWGtgocuY4ixuGQJnfo9PxmlFEkJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713849758; c=relaxed/simple; bh=9+XuYwg1r6PRnCEmtK+CYEcGE0jqRe3sapQcSZS+jlY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pDhW7XcgKeE9SOLf0sgc8tqUeEVNjfCE7lkHmsCaTLLgsfcJBglV/IiGK+z7bab79pd8FculE/cHlRwnKW5WXx860ARDG8dlEhgx9fvPk55aIzfiUDhqLPhWtFoFb0wUI66deRZz3mwbVJrjAgBDdXmyVmqEAnah3bgkyfh/X38= 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=Kg8z/ycj; arc=none smtp.client-ip=95.215.58.175 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Kg8z/ycj" 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=1713849755; 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: in-reply-to:in-reply-to:references:references; bh=Xvtrhcgh7fYw/hL4J7A9xLofIUItI4MUTx9KgzBK7Qg=; b=Kg8z/ycj3MaZtANqRXeXZ1V1ivb5UyCYaTC6fzquwAx9gFlUEGBEKvzgDhNh7mEcTNL/k3 WRxxJuWwU3W+VgCJtRWkcSRsf/BEniqbK3VdB4qrShdr0rH/A2X69hcvnsLCoYAK8V9K8T zT2Y0SQoTIKTxVMMBKi3pnG3FszC4P0= 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 3/4] memcg: use proper type for mod_memcg_state Date: Mon, 22 Apr 2024 22:22:27 -0700 Message-ID: <20240423052227.804788-1-shakeel.butt@linux.dev> In-Reply-To: <20240423051826.791934-1-shakeel.butt@linux.dev> References: <20240423051826.791934-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: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The memcg stats update functions can take arbitrary integer but the only input which make sense is enum memcg_stat_item and we don't want these functions to be called with arbitrary integer, so replace the parameter type with enum memcg_stat_item and compiler will be able to warn if memcg stat update functions are called with incorrect index value. Signed-off-by: Shakeel Butt --- include/linux/memcontrol.h | 13 +++++++------ mm/memcontrol.c | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index d68db7a0e829..1b4a6201c78c 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -991,7 +991,8 @@ void mem_cgroup_print_oom_group(struct mem_cgroup *memc= g); void folio_memcg_lock(struct folio *folio); void folio_memcg_unlock(struct folio *folio); =20 -void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val); +void __mod_memcg_state(struct mem_cgroup *memcg, enum memcg_stat_item idx, + int val); =20 /* try to stablize folio_memcg() for all the pages in a memcg */ static inline bool mem_cgroup_trylock_pages(struct mem_cgroup *memcg) @@ -1012,7 +1013,7 @@ static inline void mem_cgroup_unlock_pages(void) =20 /* idx can be of type enum memcg_stat_item or node_stat_item */ static inline void mod_memcg_state(struct mem_cgroup *memcg, - int idx, int val) + enum memcg_stat_item idx, int val) { unsigned long flags; =20 @@ -1022,7 +1023,7 @@ static inline void mod_memcg_state(struct mem_cgroup = *memcg, } =20 static inline void mod_memcg_page_state(struct page *page, - int idx, int val) + enum memcg_stat_item idx, int val) { struct mem_cgroup *memcg; =20 @@ -1541,19 +1542,19 @@ static inline void mem_cgroup_print_oom_group(struc= t mem_cgroup *memcg) } =20 static inline void __mod_memcg_state(struct mem_cgroup *memcg, - int idx, + enum memcg_stat_item idx, int nr) { } =20 static inline void mod_memcg_state(struct mem_cgroup *memcg, - int idx, + enum memcg_stat_item idx, int nr) { } =20 static inline void mod_memcg_page_state(struct page *page, - int idx, int val) + enum memcg_stat_item idx, int val) { } =20 diff --git a/mm/memcontrol.c b/mm/memcontrol.c index bb1bbf417a46..4e991e913393 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -816,7 +816,8 @@ static int memcg_state_val_in_pages(int idx, int val) * @idx: the stat item - can be enum memcg_stat_item or enum node_stat_item * @val: delta to add to the counter, can be negative */ -void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val) +void __mod_memcg_state(struct mem_cgroup *memcg, enum memcg_stat_item idx, + int val) { if (mem_cgroup_disabled()) return; --=20 2.43.0 From nobody Wed Feb 11 03:41:51 2026 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (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 8DEFA1C2AD for ; Tue, 23 Apr 2024 05:23:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713849831; cv=none; b=dKm8osVSCojrfnetg1j4zbZX8gSIifP0YX2LGsgPlKrSXkReHiXmUfr6Yg04NBEVXYq8BWxwSYJf5029KB/9Ivx75BcqJebVA2P7p5yxEzb3WuVFg0q7tp0RsPXwQMo2fMy0oa+x/25UKEeEXsykNAwwAYXKo2Trw2QKH1cH3bQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713849831; c=relaxed/simple; bh=99EfjvqpzFog+KcyejWyS1acNRGTXkB7Y1R/IpDMIK8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ecUBIyRPZawdOFD8l3jNdqX0kzi6e+KMNb4B4gfEHtkwRbPdrjemV7yjRY6JZTvIj27GCL/g4lmTH3alE0TGZKJAFcnc3k02zxyRsTFtldXjSb77h4PKrVQj135j7o2J2TetAjB8LIrrra+7uFeFdsy6k8qxxXvjGQCV+3nzCz8= 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=OvsiSo2V; arc=none smtp.client-ip=91.218.175.174 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="OvsiSo2V" 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=1713849827; 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: in-reply-to:in-reply-to:references:references; bh=7wZMRsMyHQHXjFKrcDnWCD1NMGczgsTlPNC9ZrGXAJ8=; b=OvsiSo2VciEz80V+ECLlsVWhu9VrKAZMMiT5JyhaIJpiJCaRlCFNPBSSnIM/oQ0A13NJ6j Q0M6ktSc75eUe/FEsbEGO8Xw0LzcxsIBnDqZmgTIXd3X28/O0v+b8GHm92PPzMRnAkJ0U6 /BuPKk6hpDPgJz/MbeeRSvhhJ5MUOLI= 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 4/4] memcg: restrict __mod_memcg_lruvec_state to memcg stats Date: Mon, 22 Apr 2024 22:23:43 -0700 Message-ID: <20240423052343.811563-1-shakeel.butt@linux.dev> In-Reply-To: <20240423051826.791934-1-shakeel.butt@linux.dev> References: <20240423051826.791934-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: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Currently __mod_memcg_lruvec_state takes enum node_stat_item as a parameter and enum node_stat_item contains both memcg and non-memcg stats but __mod_memcg_lruvec_state can only handle the memcg stats, so simply only call __mod_memcg_lruvec_state for memcg stats. Signed-off-by: Shakeel Butt --- mm/memcontrol.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 4e991e913393..531b6ff711c7 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -860,8 +860,6 @@ static void __mod_memcg_lruvec_state(struct lruvec *lru= vec, case NR_ANON_MAPPED: case NR_FILE_MAPPED: case NR_ANON_THPS: - case NR_SHMEM_PMDMAPPED: - case NR_FILE_PMDMAPPED: if (WARN_ON_ONCE(!in_task())) pr_warn("stat item index: %d\n", idx); break; @@ -899,7 +897,7 @@ void __mod_lruvec_state(struct lruvec *lruvec, enum nod= e_stat_item idx, __mod_node_page_state(lruvec_pgdat(lruvec), idx, val); =20 /* Update memcg and lruvec */ - if (!mem_cgroup_disabled()) + if (!mem_cgroup_disabled() && idx < NR_VM_NODE_MEMCG_STAT_ITEMS) __mod_memcg_lruvec_state(lruvec, idx, val); } =20 --=20 2.43.0