From patchwork Sat Apr 27 00:37:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13645512 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 09B03C4345F for ; Sat, 27 Apr 2024 00:37:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75ABD6B008A; Fri, 26 Apr 2024 20:37:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70A9A6B008C; Fri, 26 Apr 2024 20:37:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F8F56B0092; Fri, 26 Apr 2024 20:37:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4181C6B008A for ; Fri, 26 Apr 2024 20:37:47 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E96AA12142B for ; Sat, 27 Apr 2024 00:37:46 +0000 (UTC) X-FDA: 82053448932.23.FEB0349 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) by imf12.hostedemail.com (Postfix) with ESMTP id 3C62440019 for ; Sat, 27 Apr 2024 00:37:45 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Nm5yyRv3; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.187 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=1714178265; 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=Gfv3iMSIWQC4QbQ/6GXaLS8Cjd7JxtChDyD5rQgDX9Q=; b=8G70YkHb4xnktpG+TAUfIsPjUjDzsK1beDKpgUU46CpCVrCvw7Y2z+5kusceADYDNhJSj2 wQQZ46nsPap5Oa3NwXIuDQtA3gfDTOzHm+3wB3xsCAaOxuEG10/wk62Q9vIbgY2ysP7x7Y p+ZiqpF5Q2pVNwq5xB3VBPAvoWT5Izg= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Nm5yyRv3; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.187 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714178265; a=rsa-sha256; cv=none; b=Yep+GErOPdzU2jJxa/PYXHrkj310KGPyEuYNBqG7IUFdtkSeSFye0E0PWH28E7burLmaB2 3ok4LHWj8vXQ2U9Z3NSPYzx/wCQpGVcIas/jtx1DpAYhoAlF+xslnGswY3soLKLK8rNKNs SX3lcA1BDhR3kAFWUKps7BjCKR6nkVs= 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=1714178263; 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=Gfv3iMSIWQC4QbQ/6GXaLS8Cjd7JxtChDyD5rQgDX9Q=; b=Nm5yyRv30txwaGJ50+RpR3dkkQIdU/cAkah0rz5E9NaWS6JEnqIlf8pCbX0XdNDBFnxc6N Hbz4uF6xZb+psVAA6G6MVW0R9CvKnIaxzNY6sPTfTQEuMd3bY+WiOBBBHx+n4a1jgGVc7m SpP+ZPeUku+xQYxxAw2TOWgKmw/JcxQ= 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 1/7] memcg: reduce memory size of mem_cgroup_events_index Date: Fri, 26 Apr 2024 17:37:27 -0700 Message-ID: <20240427003733.3898961-2-shakeel.butt@linux.dev> In-Reply-To: <20240427003733.3898961-1-shakeel.butt@linux.dev> References: <20240427003733.3898961-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3C62440019 X-Stat-Signature: nb3dbthjtu76yaabpryxpxk8igfbf3r8 X-HE-Tag: 1714178265-144274 X-HE-Meta: U2FsdGVkX19y+cJB67p126E5ReOWKBKmTRpPREKVlT61q7yfPhNJpQ7F7O+MhYZ6Qc6swIuvs0OeiY6aybhnPlfqjfeigl2X5V1tJxjSV4NFzrYqUPI3o25KCQBVOcjsCcCxSFQvJnbADODDkX/ah+Regz/ZSFaYmV5QmcDBEE1yjLkt+noW0x03lZ9jGdj8SXz9MH/63PFkyRaNvCWV4evMaTWQQ+idjvPNitzVsehzNwR/BDK+zGHm03Rmmb0H8nL78ekUZ+INSyc8CINsvBAoWFxUi29uULvLmMS91+lSIAfrcZ6nd8a+8Uv9wQIn754uH1U3TFtqYStrWX+DBuIGma/FaQ1NLES1qlSMjubXZ7h1NExbKRadsyVzkQNMQ+L0LsmeQfGfyVcCbC+xGcuhNy4ayMyIRm6xgrj3rI/a2LWfPV0kDPwPKvMqbmsyEAQJMgOt9DBp9X6S8v+FDtJLSHJwxlbz+unVSutI4EuVUfZaCmZrXYqMhByAFo/f+uDEfjGTzuHKukPgQPbSttBsovMAnSxwXGvN4xZ54ij8x2ByCA2cIvW28NkkL07zUNQAiTOPFmLmHMx/ePqrMRB2XW71K7Tn4kus3l8l9DtgOWisXZ6I1obeq7r6VJ32NJiyf6oEnSSnLFJD3bSOLue1YRn/+MrRNIH3onIxjJddIj4EIpwNdspb7bsBgHxSv7WUvU+VZPotP/BiVMlGanYxNgFcYsF7XFicNa+OgrpMW22IO4nPxpa0aNEgJwxlB7MKkxITNLxUoBt58HA9mERtN7PXQTer2BDKvshnMaCJLA/m0hbO5xGkgayuLuWrf2BFRUBegLgpBuych4gdv1XmMAzNFHToRQxWDtuuisRSV/GAKwwZK6uNsujBai2IFhIlTfEOqKY59NcsxL9uL1Vf88fUHXNBh01e2oSXTzdYLxZSI36Eu5FqiZwXZ5QYD9/zruMRJlQVYB3vLyf F4Yh52bW FALujQj2tv+BGx31NNhdvPKYEX3WGm0/VnDF+0o6/PKhFC3JQXSRZqx3sX7XRHbQyr2uoNt+ZOh4Lr1XF1xb32NASw0JLMJ/lHoUiZwtnXgD1KlWahoyFoDZROA== 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. Signed-off-by: Shakeel Butt Reviewed-by: Roman Gushchin --- mm/memcontrol.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 602ad5faad4d..53769d06053f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -607,11 +607,14 @@ 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; + + /* Switch to short once this failure occurs. */ + BUILD_BUG_ON(NR_VM_EVENT_ITEMS >= 127 /* INT8_MAX */); for (i = 0; i < NR_MEMCG_EVENTS; ++i) mem_cgroup_events_index[memcg_vm_event_stat[i]] = i + 1;