From patchwork Tue Apr 30 06:06:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13648287 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 162E4C10F16 for ; Tue, 30 Apr 2024 06:06:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 87B296B0095; Tue, 30 Apr 2024 02:06:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8039C6B0096; Tue, 30 Apr 2024 02:06:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67DEC6B0098; Tue, 30 Apr 2024 02:06:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 424A26B0095 for ; Tue, 30 Apr 2024 02:06:28 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E70B3120601 for ; Tue, 30 Apr 2024 06:06:27 +0000 (UTC) X-FDA: 82065163614.13.62CC85B Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [91.218.175.175]) by imf29.hostedemail.com (Postfix) with ESMTP id 3CC3012000D for ; Tue, 30 Apr 2024 06:06:25 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=gWysJ5rJ; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf29.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.175 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714457186; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Wvw793twJ1F4/KqGjGhIdLueYM54shZE8VvQWV77fqg=; b=uDFaCY5U+DWTA2x65uL5Ew++rbKHsU42tsILkQiQfNO04NkZ0ypUg33Ne0myuMBuZbeKmn Bj1f/TiIRkJwKCLcSbeoQMd9Y1ezDIjBj6QeLNQE4VBSVPEoIKRo5apk0oZREdbLwgTO/O mJNYkKTEvd5ZQ5q15D3PKFMCckKF194= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=gWysJ5rJ; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf29.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.175 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714457186; a=rsa-sha256; cv=none; b=KLGJ6VaNcfksP3ozprgSTagcqo4PV+09BoKmOlqV8ybt8XgGdLe3sA7CM2x3YvrAkh4yVB 6f/wEmq8zAkHL1Bwlx2oLQhXzCrPf+lXMJixtYvpHXILuOveYxLpONOa3+nVz0N5nOvgZw mZRVuOUAflSEkCueSuhOVfCpB4E2L50= 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=1714457184; 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=Wvw793twJ1F4/KqGjGhIdLueYM54shZE8VvQWV77fqg=; b=gWysJ5rJLgTNd7+7sPEXX3lDa/aX41N7fiFaoVJoqBw2GLQoTmpvYSXD+j56elG71KufDu 5H3chniFPjB0Kb5+t8HX4JvT1HtVlVG8HX9EX65NGXLDJ1eBuARlgTh71roMJCtj96Mtw2 +qgkfyNgcm3UlGBUDOM5HOeHYGXdz14= From: Shakeel Butt To: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Yosry Ahmed , "T . J . Mercier" Cc: kernel-team@meta.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/8] memcg: reduce memory size of mem_cgroup_events_index Date: Mon, 29 Apr 2024 23:06:05 -0700 Message-ID: <20240430060612.2171650-2-shakeel.butt@linux.dev> In-Reply-To: <20240430060612.2171650-1-shakeel.butt@linux.dev> References: <20240430060612.2171650-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3CC3012000D X-Stat-Signature: 3ruchfyspu55yk9io3137so3ppmmxe4w X-Rspam-User: X-HE-Tag: 1714457185-458312 X-HE-Meta: U2FsdGVkX18Rjxk3S5JGnX6f2/2xfzgByfRiZA+JkQfigbpUTWhAcYpPkHP8umIdgXaYdINfQWhyaZfC2x4tqCnCPoqwEoxK0x7hDNjqe75rgsvimguP6Uj1qhdaER0ANbIFJZWCA0UUfvRbBe3MirMPDFPq/GM6wUCfBDhx98zPC3RMP1ZbQdbZ0q/wOb3Irl/the1UnTcCXfv8IGi3wU+y09aUv+i84OYaCooxc93vULUcs1FwWQf8OIpZW0zr/4agH4E+GObFhgmCiJr/Y42eF0BkA3wSnEuTmikxOjTDnNVoHRyUEldP2QgDvwW8qE2+iI6Ls8IPGPCzbwFPlwYZTLHTsso9IX5m1kNscbSb5vWQaiQBoRFdMpY4FlHXsLZ7sCl0K3zU4go5xGkHG7qFsK6IdpmHAHPEyT0MjWjz7VipELc6BaeJ8TgCQQlwupDnmbdHm4yfNXVKWZbst/v2v5aefsciIOryufmisjZ03xgWkRU92+bUiqtdJYXqZ8znrk7kil8qhxEhgK4ZVAXRYmmDts/u1uVcIK2sL5efNv8NVT6+Ys3wR0qu0qzMur9nRJyS8EHob5Vm5D0GZF68CcHt4foeXPQKaMx6Z1LgEatfnWir5oiCecdEtzr0ZUV1FlRf08FwQhy98m64TJJPuj5RPZvnseH8wVxUm+e+rbS/E+sWTN2NaGkF7BBgu235Qai952Af5ZnMEPlipHsWWbP1Cp/9wB41cj6CRrWEjWPQBiv1/A3Y5N7sz6a7JuyDcde/r85ili3zQY8o7w8s1AlInhxTOd+xhGqiywGPQKGt8weXWMH63zBnDLfl+nWNHTRbcssgVrQDeM+DP5cjB2xgHH/oyxvsKLUn+Twf6WGnJEwf61wWpRRBfo1JR5T8V0KAqcAm+R4vWUnim0WxmeeFzeAb+cQbUWz3r7esjADwUbuD7Y68h0nQGlrk1T+UKYqLgvGazPm2HXo uE03bqrf H1kj3fUzp6XcuAsIfhXLEsaj7MrwBH6inWac7DacME5TBpuwdoFqJJzNNj+NIAY6OuttN5wXSrg/bplDh7GwllZdcc+2VKSjS5Otnzbh2Xi5DlelgNtD8/M+quY8/0awVson8 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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() and will switch to short once NR_VM_EVENT_ITEMS touches 127. Another benefit of this change is that the translation table fits in 2 cachelines while previously it would require 8 cachelines (assuming 64 bytes cachesline). Signed-off-by: Shakeel Butt Reviewed-by: Roman Gushchin Reviewed-by: Yosry Ahmed Reviewed-by: T.J. Mercier --- Changes since v2: - Used S8_MAX instead of 127 - Update commit message based on Yosry's feedback. 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;