Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp132160lqa; Fri, 26 Apr 2024 17:38:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVEIqpb56Z0wIycJHfqRjHMBoXr3c/AwPSNTQT4Q6OWtW6tz0y4nCwf9u2qC7QI2hvDN36nEtHcmi2vzMg/I1mxTTya65AjRa0eBx+tTA== X-Google-Smtp-Source: AGHT+IFIT+RQxSHcmCfJDIBtc3+SKhoHkIeS76N56RdXlkxWR/xDOZEgVgPp/Ic+VMQj0WTLAZxz X-Received: by 2002:a05:6a20:430c:b0:1a7:73ed:7f8d with SMTP id h12-20020a056a20430c00b001a773ed7f8dmr1606286pzk.38.1714178301641; Fri, 26 Apr 2024 17:38:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714178301; cv=pass; d=google.com; s=arc-20160816; b=bmAx6PUWwefgx8sw5qkLsiZThNsefEW+MYtzC6GoaSa5c7lJE62tO53gcNSEFr/M3N 4f8DR9eTTOvzKDVeyV5LsFg9Rs68uC92QqT59oThJEOIENICJ4JYl0y0O/zBU/0v7Fao hiGrSM02pPB7PlfBclLwUMkZ9y+HbtTZBkr90f5H+Fodn/ll1Kw3+/22bdtNkg4Bthr7 W/N8vYBMjQwukuNFZ9rTdpAS6KDs3Qgp1e5reIXC47BNCrvd3C6uF109ay2coBfWc4g8 N0DzwHpbFKoevuP3R6oKxxg5kUPdFl8EKfy7gD9LYVcL9T5SMrhsGNgzB0XYu5wbcdXT /uBQ== 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=Gfv3iMSIWQC4QbQ/6GXaLS8Cjd7JxtChDyD5rQgDX9Q=; fh=RT6qUd/cFk7mA1daRZyPKZ73SkJUv705B/3NiEK9oSU=; b=R79UofA8JG58hp08VEhfgeg/Uxw/W7cIs+ZKKfqE0UNXwRAyG6WFI12YQ3AtCSCfuW EO3vM+EFOzoq85SpxP6JIRm+XJANRYsJssDD8YpgUTiNrOZOHU6JQP6vx/6o1bGWnVMh nQULdfSWfqZG07xTiktT5Hc5jfcpqYsZXAXWos/6XaGMcr8KqEcgtYp/bRpI1HaV7vfa Zj+9R8ctnttQ/2HvpfMCx97WvvVjJYIyfuT7D1GnFsay6EeL8rVlssKItEvIFTSckTVd jeiVcooJBhDU/uMTw63VOpHy+KMbwqEkjeGuUueuZaSGzsI1tcWv5jSzn/zRCUBsOOGi UQEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Nm5yyRv3; 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-160820-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160820-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j71-20020a638b4a000000b005ff1b947573si10165256pge.758.2024.04.26.17.38.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 17:38:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160820-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Nm5yyRv3; 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-160820-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160820-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C724FB225FF for ; Sat, 27 Apr 2024 00:38:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34E442E62C; Sat, 27 Apr 2024 00:37:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Nm5yyRv3" Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) (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 92A7D2577B for ; Sat, 27 Apr 2024 00:37:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714178267; cv=none; b=azwWRG8Da2LcVUd5jqlbW25YFek6pzk4hhGirJuJMM2+mtLm9aYYe/zzheB8hpQH4ESgO1gQGYNVb3cPyDrKxohQ5ZNQIi1hom3B15LJW8PqQsSc0+LYVmdahF35sA8ep/iI3jaK0ejSQR9yaAZfTfsAAL02jMZR4iAMYQFg49o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714178267; c=relaxed/simple; bh=tJK4g+poJ9VBpRehNiwwG1ZwM1nTxzq5jA9+UhY0/zc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GgBcGdFGOHHsEYRpnhJ69VeN807mIMgJiM5VMAHve6EOflh18aImACHgChxzHjgeQR846Gi1X6FtsNitQclqN2l9L5lXwi6JVEyfdkBsOLnI/ZQJ6G9Pmh4t7V9jeiytMICmXpoXvS1QpnnwzFIqQ6SFP5tIS7V8LC9l1569MDs= 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=Nm5yyRv3; arc=none smtp.client-ip=95.215.58.181 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=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> 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() and will switch to short once NR_VM_EVENT_ITEMS touches 127. Signed-off-by: Shakeel Butt --- 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; -- 2.43.0