From patchwork Tue Apr 23 05:22: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: 13639357 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 86461C4345F for ; Tue, 23 Apr 2024 05:22:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B6726B00BC; Tue, 23 Apr 2024 01:22:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 166EF6B00BD; Tue, 23 Apr 2024 01:22:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02ED36B00BE; Tue, 23 Apr 2024 01:22:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D85B06B00BC for ; Tue, 23 Apr 2024 01:22:38 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 71781140CB8 for ; Tue, 23 Apr 2024 05:22:38 +0000 (UTC) X-FDA: 82039651596.20.CE38B3F Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) by imf05.hostedemail.com (Postfix) with ESMTP id 9678B100007 for ; Tue, 23 Apr 2024 05:22:36 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="Kg8z/ycj"; spf=pass (imf05.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.174 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=1713849756; a=rsa-sha256; cv=none; b=gRAb1TM4rk22cENo5G+P/Pk2vLcPIUJE6+en4eocXWKO5+IOcnzpMng8kym1UnxmuQqs48 HkYpFFc3jw/0lUVCpD/W3rYeqx+OGoK/2GD9xvkE+Q20V3Q5eB7FN8+tRFhVRbllLECWJL CvsEqq3xjP0PCQWnZrt1TNg8wHEUelY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="Kg8z/ycj"; spf=pass (imf05.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.174 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=1713849756; 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=Xvtrhcgh7fYw/hL4J7A9xLofIUItI4MUTx9KgzBK7Qg=; b=hRmxz7DRoCur8Rd4JyQPs4kgtXcdx0S3myhGlbWn1+4HtOUoG2it5Mf2gMvpU/N8cH0r2k 7v1XT4mttvHnu2rq6RcD6OZlC9MXMtUVnOfybzd3+gLLZpOwrqZbjDuJl9BKtfDiPEJBi/ VHu06zpgtiJUv0FqU+ZsAx7ong+vFBc= 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> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9678B100007 X-Stat-Signature: r7mxqaa43cij9kpehk4jjiy19m3wghxz X-Rspam-User: X-HE-Tag: 1713849756-126764 X-HE-Meta: U2FsdGVkX1/ArWSadMvgiOBhFUCAOIRbXbYW+JnOlHDuc6lE9nKn1rtCyfJIZ4MU0s/CWwLU1tjkqEvS3cxtozTA6eQh9BrCK1jwWQ8RmZT713aDCGhj5svooxGbSF5yjoQossNnPPILIxPoM04e9P3Mpq5SAmvQ0EDkGmup+n5QbknN+dLwYKhBu7F6ZwFPrWczaoK77LORJDf6Oy2oEUe6pdBa1TN97eRxB2mvmbD6BTL5jJkVMiSy0SUmlER5pNpbDv06CKhq5nYMwcoL/zZ5Q2i7rb7RGUAdgzd+8p7LRqCzmWMxJSVuKq57aOe5ChGYAfzx1C+C+Tvmsk7f9sr8mrL3W46zZjJA1PlWPw73gqRDzLk15DR2M7nIAhePFsBJiJYaRj9OkJgwi6RUA9yxTXVaqGI0iqceyCn649I9bphajOBMZXDLGSIzmVwFchS9ow5SH7pdbNN5O+dV9efPJG5k73v4AAx0bTgxzCuBoQpB7AGxdAG/ywj0/GRi/oxHKydd/HKSmX2kYgAfWmmpJnrjDpHbWfrHqlXM3ku9Ze3KnJD3O0JXbTZG/9HHh/uhpyToGYkMKxNqNik9GoVAkDWkv4kI5wfyxS/F79bCUzfUq5MzMtXKflMKvXhJH6grvuL0YhPiim8kZHFhveUQ11+Iy6YmuBWi6iNovFCUodvcIlsImr2afdJTllsZEvTrlwDNm0zbxCdtvMJnKSF6cPoF4PcXsX1CA1wZi1dSDEiA4A+fQpFWrHq8J5mqSr66FtMea2rr4EIXukxQkSwyWtZ3mKl8afsdYHfSw3966Xy5EmfMi2FFETCh567i598VOlSSl0U9AwTg91UIQGPPRJJGaOeKXWpUGpL9hFJ7gq9EdWdLAZlds+4BmQe+ZxX0Twx4LTnlcP00WjdGBDcDxXyiMEvanOH8sca8gTQzGza7OYO78dd8I/jJIjfdW+5AO78O8T6eegSqOLE l9AyrrNB 5RQjhFIQx/kiWEnn0x0/PrIzTU5uHxe+uimGz2TNlOYAzMk7PYhgQs9Y5XJevR+60BwFRO83XujXGXEA7T/H/Ayat/9xdR0SW0pYVQHj9Xj4zry7dy6nfVdiykG9OlyDGDaKH 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: 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;