From patchwork Wed May 1 17:26:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13651046 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 77976C4345F for ; Wed, 1 May 2024 17:26:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FB636B00A1; Wed, 1 May 2024 13:26:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AA9A6B00A2; Wed, 1 May 2024 13:26:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 539846B00A3; Wed, 1 May 2024 13:26:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3142B6B00A1 for ; Wed, 1 May 2024 13:26:55 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D67A0A16BF for ; Wed, 1 May 2024 17:26:54 +0000 (UTC) X-FDA: 82070507148.15.CE4A45C Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) by imf25.hostedemail.com (Postfix) with ESMTP id 31DEDA0018 for ; Wed, 1 May 2024 17:26:52 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=YISvIA9+; spf=pass (imf25.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.189 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=1714584413; a=rsa-sha256; cv=none; b=BUeUp2of3IbnXud6YUkU1lH/Q3dSLlfqjaoJLPAJ+CrFfdqKoho77qysTBsVR44ladBQu/ wXf19tOe8Q9gfcdIQmSO0Teh1BpWPphXPKka5y+6umuTkWG5VpCS89GUjfiCOAIuHaakx+ arLUYqjPusKw4y5uEmxHkxWmYepg2AA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=YISvIA9+; spf=pass (imf25.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.189 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=1714584413; 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=tCoAbtrV5bh5IqBSP9ezmAWDh3uY8sBNqfpz/AA9bcI=; b=sXjLQSUo8LMswyUzAV2baAIHAXHca6d4a2OOF032YpXWfUHlhSxaI1QGvKaTmf1HDtLC5f 9alQyw7KsO7ot1j7nEVcOUOjHdhA8YDlJAiFUCxgFNR4JbK4OpDg9WxYjvXL99AfTZe0+C flsJHJBAjbJK0MApZiZFmkxeab62g8U= 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=1714584411; 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=tCoAbtrV5bh5IqBSP9ezmAWDh3uY8sBNqfpz/AA9bcI=; b=YISvIA9+kLtsFEh8MdixEMDSsd8PoXaMrMDODnf1eEjM6JbuLCUks/ImDQ8J8NJ2jIUepy HiLDsiFIiMZF5j0TtXoAglBooeB6fZvdFyN7ggcqruY6WnAoev3cXxwgDUVNyvSM4NV8On wbeqCV6XdRAOfOrUrhbc9rSs7VW6dGg= 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 8/8] memcg: use proper type for mod_memcg_state Date: Wed, 1 May 2024 10:26:17 -0700 Message-ID: <20240501172617.678560-9-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: tdkuweenaoontfk6dsumudksya7d3z3m X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 31DEDA0018 X-HE-Tag: 1714584412-821849 X-HE-Meta: U2FsdGVkX19qzMy78n/sLlA4CcusGtMH2zwG+4DeQFFOV1+A+C4HwTxuvMJFwYSWUNYw39Ew5MnChvsbbog0AaQNBDKEVWxXalYSeAvzhAUVamJrrf28KlEcWM/drLQV2qED8V/QvoRYvRdEm8q2Pfjz36g1/a6btQn2exjZuCqqBqfnBba9Fv9ZM7HVAQkfNgBnxirUOO4/FFB5xfSQDie/od3KSXqhJzMQmJa408X1ehWcKRK6N6/TU9r8rQmVVyUWwbkksooCQXbm1XNmWIzbPDDPoPIsNLO1Ftq3QRn9nVoie0cfAtwM8XkNjfS+A6P93OLJb3EtLDhpQeaEqKvNs1h5l8mcH+9ue8cjK6Nm8bvOkXvZRtPh39gEvfOmW7mYAIlrAQ1KvTgLBSOB2WnxgcjFNP9BxMkhpf5P3TPNlkeSJBbZVTbOAskP2L1zUaDuKqxL8h4QtpkYi8F/uZGDfN63WwgRnFNyHDvWWGXaCtRMgS+nO2h5Zp2TJBpb///66rJLzwoa0PttDfk1vkbYjTV9Bo4+to/gepxIouurszvE8LUZemAzVAtQUyqC4LQHpQ4qlxTv6Fa6Q5u0ED+DCDv4xAcDu9RXekXklad9ERxEUq1LPxgMqbWtsFzSZKetnNzJiWoMWBPwOLQQNZ/7wePI82WvylWi+vCNqJJowG3Np6ouZH0mUD2KZbsockeCDUN392BT8ciE5WEmAAhBedTpjQUaC+KhXCHSXqmhxcvjC+j63glPmJZqIeSJKxz/lWUI4NQccntSMzD9fKEo+xqqnFSObpr++tpLFaoR/2iaR6BPaI976pUsiSKKV0XB7lmlekUiDLq4D+SSvRgtrK5zqxhOvuC7u5KwvJHOFI8PqhkrPSyy6DlGykSWoHnEGmiuXTaRjg0Xhad+3AI1OriiDiNocGrv+AfiMVIHrnB3v8ZmNhCvWVF+OncN2qeEn2bTmIwPCeqRfvP IW2C0uCU JfQzEBeLhX+qIJyeKxKt8Ob50/C7dAyQx/v7hRoyOiXxY30ofYhCukjfT8Rf8dyrvF7xYDMlVNM8yEQbQocxYfH+RnEi3V9cEo5ORup1wPLLLhqhy4jtt2U8RKwN4yq8SWKHxpzT7rAuj8BlNfxOwwByu4g== 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 Reviewed-by: T.J. Mercier Reviewed-by: Roman Gushchin --- Changes since v3: - N/A 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 ab8a6e884375..030d34e9d117 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -974,7 +974,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) @@ -995,7 +996,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; @@ -1005,7 +1006,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; @@ -1491,19 +1492,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 b4a1b4bb599d..39f8b0df46f6 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -956,7 +956,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) { int i = memcg_stats_index(idx);