From patchwork Wed May 1 17:26:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13651039 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 AB528C25B4F for ; Wed, 1 May 2024 17:26:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C50A6B008C; Wed, 1 May 2024 13:26:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22DD16B0095; Wed, 1 May 2024 13:26:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED5946B0092; Wed, 1 May 2024 13:26:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C52B96B008A for ; Wed, 1 May 2024 13:26:33 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 41D6814096C for ; Wed, 1 May 2024 17:26:33 +0000 (UTC) X-FDA: 82070506266.16.AD4B988 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) by imf03.hostedemail.com (Postfix) with ESMTP id D051920049 for ; Wed, 1 May 2024 17:26:29 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tIfgRTnl; spf=pass (imf03.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714584390; 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=d5S9dkOJqha+rpI1CHtwyB9wbo4t9Wc2EBy5O17ehws=; b=l08xoFlAQzy6LqQkIhsh+5OoZYBreNrw7DPZ/vDN8xT04yvhfALdipe2om8NIwXepup5r8 GJfuSvYlCx/YIPJtRFF/xqad0ZJrVs+yevpoYp7pzUc2a5z/mjlB1IEuroAp/29AJDvPAI tLjbRrtXqqoZLm4+JDmuX1tz97y9wWM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tIfgRTnl; spf=pass (imf03.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714584390; a=rsa-sha256; cv=none; b=JHdvtzTUTLt8ov1Hd55YpZ0Efyy///DMyaEoMIla7SMmPxowaKbyGqAe4gPZBGX+9d4n4A wAvo998YAOunNX9TLVKl9XzL+ZG4fi8pZCudH5HEwSCu3uQfS6lz/KvZyJDJBpVm/9Z8S1 OTp0DEUiVCDYyf9/CGUIgvXO4ef14Fw= 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=1714584387; 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=d5S9dkOJqha+rpI1CHtwyB9wbo4t9Wc2EBy5O17ehws=; b=tIfgRTnl/mhCgo0S97RFAXjLL/WVu5BE3Xyfq+9Mm73A1FvvUmiRo1lxo7b4Xy3VsjEWSv x7EoZ6cGnTqWTDf9G9b6HpQZYMpFZEEwHjoreUm7T9cMzcP9nw8sl2uOSArKJ1uG3TCahI /Jtd6f/SoU72qn5FtRtSozJCOvm6c/w= 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 v4 1/8] memcg: reduce memory size of mem_cgroup_events_index Date: Wed, 1 May 2024 10:26:10 -0700 Message-ID: <20240501172617.678560-2-shakeel.butt@linux.dev> In-Reply-To: <20240501172617.678560-1-shakeel.butt@linux.dev> References: <20240501172617.678560-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: n5yd68eh6cy8h5asry8xw9zbdwzsxgn4 X-Rspam-User: X-Rspamd-Queue-Id: D051920049 X-Rspamd-Server: rspam05 X-HE-Tag: 1714584389-13334 X-HE-Meta: U2FsdGVkX19UgfjsdgBd6FCoxjKyA9c9NH7bwuTivu6oInlrRjlx2Rg+qX1T6DwyHMHeyruISZriQYlHes8YcHtf0e1DiuSCmSFTJX8leSweQO9YnowvZoYgz3qFaszlsLnlXQ4g05G7r61L+e2F13jWShOo+GXFPlRRmuDLp+4Olkf0KtxTEIe1g7vEhcXCObr7+LzP0UJ8cjpTALryVOry/L3N+zV94KHbNRfTrBOG6ioHA7C7fskAJm9Egf6SpQkphJzc7sNIu4zQdr47El5cwB8MW5EEBBpUaBrLgr6mL/+eVcxHY0fbcYDmQXKNxZOHpVf/52eH20WufZWtmaYpqfokvYSNAVa5s7Kk/AC8LVub3wIvS4Jano1qjQz2vnrFemAdZ4nUGmrdAkKgimGA6gnffBiPf2zl8KSLgfAcsjL5rOGCPzVlbDWezAyk3Tu/49pDCnOsYumou/O4SAPW7njHhAKVaoYGUPTSzj9pzLIEOBxpjbH7UxWefzvCTWlUhFwnKbGyh5ZP1gj872IoOXWhHHO6VlNanK0SrUawk3aHRT1VnSvrdy9aq/+WnQj/TWX45p6TaGMQ6w73BpVnE5fhVgExXWZ55cwz9xO1R5DS+zmWvO8NsOqQnd6TOyvLFakmM3fSB62UkNqIRWVYrOArIayGnK0SzZrcS6wGp8XKpv6cxjrJ9SG6/Xd1RaTolWcuqv1+2l4c6DsZE6KHxpvqwTvagACsEbTISyxv0otVQlONH3r8ifBAljraeLETchKJMtrg+YQ6nuI3ICcov+HiLQe4KfMnXvmQkLF+oiailj5On0TAa2UMHBd2x/tssDqwH83v1xA5RJufwpmTdnaEjpTwaTNYhp7joBoXF/BNfSQp2lTLDRkGmEaAFdzig1nR+YiVX/Vkah7gTGxeESN+c7Jg3vTYilxEMGbS+OKnXm0llx5LBnDx2G7aAAos/yQEzUnwnsLEHHw pAqi6+1s YGlrK7EkVtMnDVzsklC1R7q3GsRKMTNo9OSxbMuTR2d42y3oHutR6eSNm0KSfudPKaQf1d940Uuof6d905vM9l7CHfm7uS68f0Q/8vUqx0IGsbAQTkn2zj9NI1cfbWqwcZ3rl2+E6cPU/WrnXNbvX0XiFWA== 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(). 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 Reviewed-by: Roman Gushchin Reviewed-by: Yosry Ahmed Reviewed-by: T.J. Mercier --- 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;