From patchwork Sat Apr 27 00:37:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13645518 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 B05A8C4345F for ; Sat, 27 Apr 2024 00:38:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DAB86B009D; Fri, 26 Apr 2024 20:38:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 388766B009E; Fri, 26 Apr 2024 20:38:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2034A6B009F; Fri, 26 Apr 2024 20:38:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 02BB16B009D for ; Fri, 26 Apr 2024 20:38:04 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7653A406C4 for ; Sat, 27 Apr 2024 00:38:04 +0000 (UTC) X-FDA: 82053449688.16.9A51479 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) by imf18.hostedemail.com (Postfix) with ESMTP id BC1B31C0006 for ; Sat, 27 Apr 2024 00:38:02 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=sivGlrSp; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf18.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.177 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714178282; 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=Gx3PKav0CetNdFI0jFUffF6lUGwk4q4qKzC3INQ2E8A=; b=LNZPVg0gmZ2w/l6I3Cuq9bsGksDONVbQIJ75Ph07itG1cCgpUsyR9squtAty6JYVhEdvsw KAq2wS1e9dMHp6JQgDAtBFZzkbaaJxqjSrCicD50qo7HbUMOoWnHJaBbV5MAWlkwRAjDxZ Dyu7a5kpjfKsOuj//RHeNkKT4rHy5OA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714178282; a=rsa-sha256; cv=none; b=awXmOo8lzvdCLsn7g9ptHZRBHkWjHUtYfTCUYj4zeVKR2tAYT2MyOg6ElRI7sS9XD+k7l/ pVAIGV1L0U3j7Z8cSpRl2GkjquC4wX5WSmoCcTDvKPBEYa8VbyF4THecOe3WhnulyQpIWw flDWc9GAMC6VKxb9cfuNIeaRqNc7axg= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=sivGlrSp; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf18.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.177 as permitted sender) smtp.mailfrom=shakeel.butt@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=1714178280; 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=Gx3PKav0CetNdFI0jFUffF6lUGwk4q4qKzC3INQ2E8A=; b=sivGlrSpl81qjvi6K7a/ZlE+lX7x9zLqRfOxT3jTy3TpHNeCbRa/CRH5yGHNGDKvqIijXu BGuhy0LIWV81fc/WqvGITWNss9qyDo50w1qvtd+jaICAMwbaUac4gGWLUWsi6XL7uBHCmV pOaOEV7xvE4/E41E676iu4kaYa9KQZU= 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 6/7] memcg: use proper type for mod_memcg_state Date: Fri, 26 Apr 2024 17:37:32 -0700 Message-ID: <20240427003733.3898961-7-shakeel.butt@linux.dev> In-Reply-To: <20240427003733.3898961-1-shakeel.butt@linux.dev> References: <20240427003733.3898961-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: BC1B31C0006 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 681szb4xskrj9itiw1gbwreikhf3ahr9 X-HE-Tag: 1714178282-689502 X-HE-Meta: U2FsdGVkX1/Lj7Q2InDKv9G30ZyTmt7MRaScs7tckDyqV3ttDrUy43zEeq5GCv/ihoiUgJC4XKmHoEPWdsIvgyBc3Hc4HZyjn1pkOcDgWU+crtCeE8ZkBbxBsMxn4uVn6gfIX1bZ2MWRcfEC5m3lXOva9PweMIOJzm9xFqsoVkh8KeWX4TmLxxmMIejYbt1PapIlNUFWb9NlIVrEezx4LASJnUE0PvAJXLZtK3FmmjsFZVcvY8uKBJNnHpetbbKqWa1B74B9751vn4eDOZEV0kTqbWvpKVo6UTXVpmuqQbO3dRIUcjVRSCGuSPvc+vkcUHfVzvrg04C8p3fWOcveoOTeWSMIyIEzVVH0FD/kMw7tIlJx+P4iYKIK5d4ckJ7BhOrEtRn9OgnWZ5Lcyr1DLQb9zYDF/TBCFb7xkOXnQg8zZoaNplW7ynRss+urOIWAO+mVOpKJg/Iw2oO+EbGLGFOT/fdPMZhjkfqmxE7v0YMOtKo6j1N0hsDrede4e5WEVeRC5Bzp2QUbcdcXtdp3lIPI54+F6EUO5VIKg4c+q/oPBAf1FyPjYJp1E92ZPboD/rqodNFtDgw4Mlu0zi4xX/xc9U5aF2g+ZpqOFn5/0bBa11Pjr+2+YZrkhN9aAsA6UjxeUNKh420hlkBVws2AdQp1KenF9EJaFxFm8DK2rVRg+q06Mdw355q/LjUCP10kuvCK5yEN16Tw+5Pgczn3mr/Q4IqF1JSIBVb8nxnSvfExFDmPBvWFVcBbiz5r69ggz4kh3yxbPm4Y4WQ8Cf+mD5dmACkfn/a0H5rUw+q2HD9iZkAcHTLrsuG7zL2sVLZbaD5t+Lt+fGktQogia5J65SNHcdklE8Te9LKQ+NGtP9JrHvclGVVLimhX2ch6iCgKd4u+g55yT0dwGJYw4wUixE1QPqJvxPTi8GHvGYLtzOzZzrTm5RxiOTBpOZD8cbFMWajEaZPsn2OFpY4kGuH Wk7r8avo tH0OAbu7C9/9RL1NFb8z3toIZxjNRH/7bThwXa/Qej2Ib4/FsTs+6L7VOTVvZrWtcDXGe4zXqgrU1AHuYVY01FKrPkFJCM/DJkGqPTea2CQ9ts4tnogOJKDLInaglD8NcgQhu 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 ab8a6e884375..73cad69dfb5a 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 36145089dcf5..d11536ef59ef 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -961,7 +961,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);