Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2727304lqt; Mon, 22 Apr 2024 22:22:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXJJ/hGmGLu+6pjF6Lq/atk7TSouOl10yudSsSnNDAbvlL2kDx6j1gx/xxnbYzOR3P9jwTWCnCgULsJuycWLIxuDwaVPwHmDpAiVfFXMg== X-Google-Smtp-Source: AGHT+IFqBldU8Qn4V4oIXJ84WuWlTHcxGgV8o3blxhW6p/x0+erbED3OSy+fth9qoi49f5fGN1bO X-Received: by 2002:a50:8e5c:0:b0:56f:e71b:74e3 with SMTP id 28-20020a508e5c000000b0056fe71b74e3mr7718199edx.39.1713849765798; Mon, 22 Apr 2024 22:22:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713849765; cv=pass; d=google.com; s=arc-20160816; b=iXSUfu+eQ1IWgv0sOQ+/5DUU/bF7Jbty2LVAf4diU8e+ajOFLSTg0LSHvau8HF+8yh /1kedjn6eju5hzCxt3Gd0t3f6nCmofkFsY+1RWp1M8TtNYafRbGPkMh8I/goh8R6FCUZ ldM6Nzt46sG3Us5ny+HYtEW1wshjrK7+qqgbxzkIOpmojwjjrQ/datFRGLYHeQX4+3i0 4Uz5WSD49QCFOpjutx+ZPNToQzsvJfAdcbsFFf+6Irj0YDAQNuxJ8UH2kYgkzsdFg6vo zH4AEOvB6bC1N32azEHOIuI9943cAY8X+06VYOFwhP21VF2jjUyKy+9JezG8B8tonA7j K/yw== 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=Xvtrhcgh7fYw/hL4J7A9xLofIUItI4MUTx9KgzBK7Qg=; fh=RT6qUd/cFk7mA1daRZyPKZ73SkJUv705B/3NiEK9oSU=; b=kl731dDMvnYKfuBjyrlVrbNH/yTG14JVo6SpuVK8PaK4pnPc3ov+G5VTl891tVlHBT hz72Ns00VqeOgGvxsUjGspmc0kvW+ambRWHVKHmAYwHtAHMNN9qm2KNNYwb0VgKCYqbX VEPFKM2rRS9R4CIr5jlcZ7XFTwKRVrmJVSzHMnrJUeOEHeHF4xi7nRsq5VnNNQvkWp20 dG4pC8nsss2vkchrg7XaqxacAhkhwbTqHUJqj62zxiPCoKYslqiUV2B6NlN4h2uU6pKh WstHoRcyhGt4gCh3TpH+ht8OAq7bJjiTn2esS2HjfBQG0x+Zu7htaVlvfhNwg4lfshk1 /KMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Kg8z/ycj"; 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-154526-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154526-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a9-20020a50e709000000b00571bbbc746bsi6342084edn.412.2024.04.22.22.22.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 22:22:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154526-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Kg8z/ycj"; 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-154526-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154526-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 860E01F215CC for ; Tue, 23 Apr 2024 05:22:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DD11208CB; Tue, 23 Apr 2024 05:22:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Kg8z/ycj" Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) (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 EAE64208A0 for ; Tue, 23 Apr 2024 05:22:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713849758; cv=none; b=PAv8z6ripWSotpaR1X8RYLEhLWWDcupxAIm/Jpw/GTxe7a9s8o/654/qYOgWWpvIzjMXEdD+EDCKvwEeHog+1iFcRsogq6fVzHHb6xhrO4NmwETH+JiikBucwcBZbpk8qnnYu9TY18Z0CwkWGtgocuY4ixuGQJnfo9PxmlFEkJE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713849758; c=relaxed/simple; bh=9+XuYwg1r6PRnCEmtK+CYEcGE0jqRe3sapQcSZS+jlY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pDhW7XcgKeE9SOLf0sgc8tqUeEVNjfCE7lkHmsCaTLLgsfcJBglV/IiGK+z7bab79pd8FculE/cHlRwnKW5WXx860ARDG8dlEhgx9fvPk55aIzfiUDhqLPhWtFoFb0wUI66deRZz3mwbVJrjAgBDdXmyVmqEAnah3bgkyfh/X38= 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=Kg8z/ycj; arc=none smtp.client-ip=95.215.58.175 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=1713849755; 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=Xvtrhcgh7fYw/hL4J7A9xLofIUItI4MUTx9KgzBK7Qg=; b=Kg8z/ycj3MaZtANqRXeXZ1V1ivb5UyCYaTC6fzquwAx9gFlUEGBEKvzgDhNh7mEcTNL/k3 WRxxJuWwU3W+VgCJtRWkcSRsf/BEniqbK3VdB4qrShdr0rH/A2X69hcvnsLCoYAK8V9K8T zT2Y0SQoTIKTxVMMBKi3pnG3FszC4P0= 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 3/4] memcg: use proper type for mod_memcg_state Date: Mon, 22 Apr 2024 22:22:27 -0700 Message-ID: <20240423052227.804788-1-shakeel.butt@linux.dev> In-Reply-To: <20240423051826.791934-1-shakeel.butt@linux.dev> References: <20240423051826.791934-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 The memcg stats update functions can take arbitrary integer but the only input which make sense is enum memcg_stat_item and we don't want these functions to be called with arbitrary integer, so replace the parameter type with enum memcg_stat_item and compiler will be able to warn if memcg stat update functions are called with incorrect index value. Signed-off-by: Shakeel Butt --- include/linux/memcontrol.h | 13 +++++++------ mm/memcontrol.c | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index d68db7a0e829..1b4a6201c78c 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -991,7 +991,8 @@ void mem_cgroup_print_oom_group(struct mem_cgroup *memcg); void folio_memcg_lock(struct folio *folio); void folio_memcg_unlock(struct folio *folio); -void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val); +void __mod_memcg_state(struct mem_cgroup *memcg, enum memcg_stat_item idx, + int val); /* try to stablize folio_memcg() for all the pages in a memcg */ static inline bool mem_cgroup_trylock_pages(struct mem_cgroup *memcg) @@ -1012,7 +1013,7 @@ static inline void mem_cgroup_unlock_pages(void) /* idx can be of type enum memcg_stat_item or node_stat_item */ static inline void mod_memcg_state(struct mem_cgroup *memcg, - int idx, int val) + enum memcg_stat_item idx, int val) { unsigned long flags; @@ -1022,7 +1023,7 @@ static inline void mod_memcg_state(struct mem_cgroup *memcg, } static inline void mod_memcg_page_state(struct page *page, - int idx, int val) + enum memcg_stat_item idx, int val) { struct mem_cgroup *memcg; @@ -1541,19 +1542,19 @@ static inline void mem_cgroup_print_oom_group(struct mem_cgroup *memcg) } static inline void __mod_memcg_state(struct mem_cgroup *memcg, - int idx, + enum memcg_stat_item idx, int nr) { } static inline void mod_memcg_state(struct mem_cgroup *memcg, - int idx, + enum memcg_stat_item idx, int nr) { } static inline void mod_memcg_page_state(struct page *page, - int idx, int val) + enum memcg_stat_item idx, int val) { } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index bb1bbf417a46..4e991e913393 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -816,7 +816,8 @@ static int memcg_state_val_in_pages(int idx, int val) * @idx: the stat item - can be enum memcg_stat_item or enum node_stat_item * @val: delta to add to the counter, can be negative */ -void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val) +void __mod_memcg_state(struct mem_cgroup *memcg, enum memcg_stat_item idx, + int val) { if (mem_cgroup_disabled()) return; -- 2.43.0