All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shakeel Butt <shakeel.butt@linux.dev>
To: Andrew Morton <akpm@linux-foundation.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Muchun Song <muchun.song@linux.dev>,
	Yosry Ahmed <yosryahmed@google.com>,
	"T . J . Mercier" <tjmercier@google.com>
Cc: kernel-team@meta.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH v4 1/8] memcg: reduce memory size of mem_cgroup_events_index
Date: Wed,  1 May 2024 10:26:10 -0700	[thread overview]
Message-ID: <20240501172617.678560-2-shakeel.butt@linux.dev> (raw)
In-Reply-To: <20240501172617.678560-1-shakeel.butt@linux.dev>

mem_cgroup_events_index is a translation table to get the right index of
the memcg relevant entry for the general vm_event_item. At the moment,
it is defined as integer array. However on a typical system the max
entry of vm_event_item (NR_VM_EVENT_ITEMS) is 113, so we don't need to
use int as storage type of the array. For now just use int8_t as type
and add a BUILD_BUG_ON().

Another benefit of this change is that the translation table fits in 2
cachelines while previously it would require 8 cachelines (assuming 64
bytes cacheline).

Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
Reviewed-by: T.J. Mercier <tjmercier@google.com>
---
Changes since v3:
- N/A

 mm/memcontrol.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 602ad5faad4d..c146187cda9c 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -607,11 +607,13 @@ static const unsigned int memcg_vm_event_stat[] = {
 };
 
 #define NR_MEMCG_EVENTS ARRAY_SIZE(memcg_vm_event_stat)
-static int mem_cgroup_events_index[NR_VM_EVENT_ITEMS] __read_mostly;
+static int8_t mem_cgroup_events_index[NR_VM_EVENT_ITEMS] __read_mostly;
 
 static void init_memcg_events(void)
 {
-	int i;
+	int8_t i;
+
+	BUILD_BUG_ON(NR_VM_EVENT_ITEMS >= S8_MAX);
 
 	for (i = 0; i < NR_MEMCG_EVENTS; ++i)
 		mem_cgroup_events_index[memcg_vm_event_stat[i]] = i + 1;
-- 
2.43.0



  reply	other threads:[~2024-05-01 17:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-01 17:26 [PATCH v4 0/8] memcg: reduce memory consumption by memcg stats Shakeel Butt
2024-05-01 17:26 ` Shakeel Butt [this message]
2024-05-01 17:26 ` [PATCH v4 2/8] memcg: dynamically allocate lruvec_stats Shakeel Butt
2024-05-01 23:19   ` Roman Gushchin
2024-05-01 17:26 ` [PATCH v4 3/8] mm: memcg: account memory used for memcg vmstats and lruvec stats Shakeel Butt
2024-05-01 17:26 ` [PATCH v4 4/8] memcg: reduce memory for the lruvec and memcg stats Shakeel Butt
2024-05-01 23:20   ` Roman Gushchin
2024-05-01 17:26 ` [PATCH v4 5/8] memcg: cleanup __mod_memcg_lruvec_state Shakeel Butt
2024-05-01 17:26 ` [PATCH v4 6/8] mm: cleanup WORKINGSET_NODES in workingset Shakeel Butt
2024-05-01 17:26 ` [PATCH v4 7/8] memcg: warn for unexpected events and stats Shakeel Butt
2024-05-01 23:23   ` Roman Gushchin
2024-05-01 17:26 ` [PATCH v4 8/8] memcg: use proper type for mod_memcg_state Shakeel Butt
2024-05-01 23:23   ` Roman Gushchin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240501172617.678560-2-shakeel.butt@linux.dev \
    --to=shakeel.butt@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=tjmercier@google.com \
    --cc=yosryahmed@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.