Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp621541lqm; Wed, 1 May 2024 10:26:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUi+7vieBtK+699oQkk8erI8aUEc+L3uWcaEa35KXpXHThC/WNiLORCozq1/Qhwvh64i2gFTKXI5ismEugQO9Bi9UwGU9rFEOk5LuUcFw== X-Google-Smtp-Source: AGHT+IGmgDzMcOPVy6aKmdU7vt+c/TyN12h94p7334FmjBN0wBaaZJrtaGMzE9XJt698DPzmibF/ X-Received: by 2002:a05:6808:7c4:b0:3c7:443f:1ae8 with SMTP id f4-20020a05680807c400b003c7443f1ae8mr3472064oij.41.1714584403678; Wed, 01 May 2024 10:26:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714584403; cv=pass; d=google.com; s=arc-20160816; b=GcHieC4Mgguq+Cd3sGci/c+Z7soIQlYoga27WHPGevXIAWjt3Ngm7mcWdmfel6HDdt HxUGoXPaAVw8YXeiZSpgbfqUDyU/3pfUSqFsd2kNM0XGyoCl5hjbRpK+c791in/tdEi0 vf8GILjur9pcBtWUqkxg3AuuCRDudSV4ITgaaAWjqyql0SVtz/p2rwja263IEeGLdtT9 HDCIawYZKUbTRT46IxMHJUFHVaGwWb8T55UNfh9EvCDtzjyb1SjpbJ5RLOSkayK7qOHP Lkqe3XVZSibKKOBXJ7akgJZUVydpy5Ywerjrs/SuA+bPMZW24VIWwYjYI8fY9mbYqwz+ zKyw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=d5S9dkOJqha+rpI1CHtwyB9wbo4t9Wc2EBy5O17ehws=; fh=wnfKuHOUY4Mz1NUoc5XDTD1KV85duf1XGuItoJ8zV0s=; b=ipDu4MdUlCklSNj+6kgXk7bkGQHbN6mvS5KJMYGK2BpYPUbQIgbndq6BdqCiEMrF4S 6ybz+KV/kglQq00HuNiGZpwciRf+s3rhCmXzxZ11y80TQopCJUDTcL7PI6DLOO2OjQXV 2IBZ0ZeVHbu4nCbjX9ReoDNGpUFTAzdXDqFP8VebF0nVhBlmx0xVSsNY5Y6VNx9Tr2Pn 6QQ2cjWTFPb+SGMxh/msmK0D4F6mGTXtT296SJ2MwTuY4/cfq+j5BmzkG26x9mfROROm +r4abutP/LR54//0mPUAJGeg+QBuk2iMB47MBe8yjYwWvdo0mQre1rv6zsEKN+YjIS8E uxmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=tIfgRTnl; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-165643-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165643-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g1-20020a0562141cc100b006a085e4a654si21580935qvd.352.2024.05.01.10.26.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 10:26:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165643-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=tIfgRTnl; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-165643-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165643-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 612D91C21410 for ; Wed, 1 May 2024 17:26:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A48D21BC44; Wed, 1 May 2024 17:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tIfgRTnl" Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 E9E9C18C38 for ; Wed, 1 May 2024 17:26:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714584391; cv=none; b=ixMNpbxQajp7wzjSeikhaA3pKXmCubng7LEsIbBEO59VlNv4gw8upS4RUEzJv2PKlQIwYICfSShdGM2RfRs460MKwf7S+UjP4ylsKsBc+7c9Ty7VcD/AofmlpckjumIXv/CSL2ghyJ+8XqpWCTHWjtJJ/h2hywHl95mvjPuJDoc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714584391; c=relaxed/simple; bh=bpoSOwCps3ekmNK8friHUBN0NbKjjhHpo4dFg6sHcXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C4/3QLn5OO/TEc7etRYmB8EGPrm3UNEw5Vmir9rDAoyOhmGAgef7FmnvSzaFEjoQ93xVaV2BQWadxOXsFi0BTw21dR1ZQrMeQyaNfDXlu4GNyVkFrUUppBMzw1xaJ2g0FExls4+47R7rqqP3kbsvxYluQ6/jLET6zi2z4XFfTn0= 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=tIfgRTnl; arc=none smtp.client-ip=91.218.175.179 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 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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; -- 2.43.0