From patchwork Tue Apr 30 06:06:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13648294 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 11FEAC4345F for ; Tue, 30 Apr 2024 06:06:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 919BD6B00A2; Tue, 30 Apr 2024 02:06:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8795A6B00A4; Tue, 30 Apr 2024 02:06:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CB426B00A5; Tue, 30 Apr 2024 02:06:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 439FA6B00A2 for ; Tue, 30 Apr 2024 02:06:50 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 070CAA0F29 for ; Tue, 30 Apr 2024 06:06:50 +0000 (UTC) X-FDA: 82065164580.29.B6ED7A1 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) by imf24.hostedemail.com (Postfix) with ESMTP id 5715618000D for ; Tue, 30 Apr 2024 06:06:48 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=rotHBScM; spf=pass (imf24.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.170 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=1714457208; 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=oQu7rbPfAQy6XdrYuqRfpS3viClFCHuzUf1lmpnIBnw=; b=eZBOBFuB6BVMIIZiFu/RpXa/O6vIelbF0J8prAuGQWtQo+gpc+bTbGBSdyJ3pawS8MFZgK Xb0ZyxnkkKLFeZeKkmkZQDp7Zk37G2GgNYTncEcpCiwIN1PW0PniS11tEdp/JmpjNIM2nr B5ofbUI1jhom8de+VrlWeWlnjFJKUdk= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=rotHBScM; spf=pass (imf24.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.170 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=1714457208; a=rsa-sha256; cv=none; b=y/2izXr1UwZgb/UpewhbWTy2ssRKtpZH/01HTI4yg2MO8u9/xDHtyjFVLHHkphJHJWFFLn CgszMfpBYEGQByW+/sp4P4drLzLeCEfwdEAlpX/MQH/w4Q82y6/eYg2ltsUZH42oqbKbzp 8jPmIDgMrkXS3BlXNcn6i+wsU60Y7j0= 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=1714457207; 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=oQu7rbPfAQy6XdrYuqRfpS3viClFCHuzUf1lmpnIBnw=; b=rotHBScM1JlySEyfeor2cpEW+V9EK+9UeCwpDcgSfKbo+f1dWWgvcQN7mi7VyWHyq1/fRf IzfXcU8ln7O4xZudZdXn5uue6q1VbcyhdHtiuhipO4lqg7CJmp+yB/63oyYllZKOXFUrxN tFEkBtSRbv0k1HFIJIKt5si+4wW9Xvk= 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 v3 8/8] memcg: use proper type for mod_memcg_state Date: Mon, 29 Apr 2024 23:06:12 -0700 Message-ID: <20240430060612.2171650-9-shakeel.butt@linux.dev> In-Reply-To: <20240430060612.2171650-1-shakeel.butt@linux.dev> References: <20240430060612.2171650-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: 5715618000D X-Rspamd-Server: rspam06 X-Stat-Signature: r5y6j7hra3crz5ac8kyoebcs9wb8944c X-HE-Tag: 1714457208-791498 X-HE-Meta: U2FsdGVkX18zMIgeuQpykdK45iD+5axM5jhuYVOELjmNmpg6IoF94YdeAAg4hWyJ9w81sRadUot18HheHh3gyl44RIajqQ+L8r9m2xl12aMOn5Twm2XBJKtzmAkF/3FOnv1mqR0XmsO0W2vRL24U/bDDiQ0wgzy6E39dcD11NSnFbmLCHni2h0emIexgdYSixnByJ4i8QZ1iNQB0GAAu1ZZJe6DYMCGjThzg48PzvJogFFBMB6gmfcSi/skfrzGvKuxs7F/Bw9DiowV+0rizcpHxmmzltlLH76rJNNmk25Ax+8JQpuYQFtlBMKPqcD0dN5n/n1yO4poEGK0t/ah+ZbPwAQfxqqn/Nndf8dvbIku4rKoM+IKTTC/RPvbU+f3JaTQT8tWvoxJJSnI0Mhod+hp7AtOVSKJ4o5w4Msms+0CIaKYE8liA8VPl/iSq7+qvkt5SFGehoQCoeygNZPWdMfJFtmZORE6/CdHLCoewR2/35wDIW+oN+xXhilESJyilslm7Vu7/60OobYYZ2yAJfdlb9lrqD4cQt+YlCpvfrqR2MA3urTR1r7RaG+vXKmwXwIuXj04DZQK9EnWq2vGVvB4kRWJXWQ89w1d/13xGtXZR7esehXJiCTB2MPlmtVq5g6D6HoNZ98YdXTetouzRuPxFiQyXPOkaEFjU2yH47mDw3AxcX/mG59U4i5M/+9JCA/F2NP2JL6h14PvOCUkKD+FcX3zL/z0Ige2u622lEovF9Kwd0vlwWqJaaV2sCNUAITeBJArfCej46/MJIzaHEV4EMMl80FdlZDc4zoPNjuLXzS08Dp42jd26B6QSyueQVOE9efYg6mnE7JHW8Q881bliPT3OS7lJkOXk/wwXxXDjoEEBSd3yiICsJPbodUBAIpk2EAaemzdoGKiEqi6F73kXnoRZCClkDHGf6j5f1yBaXRLBQGxGeHfSx/Jlj9Bb1+apV0fNKfVqee8Whwd Sb6dHqKm Waz2HQR2sVfJfu11ipdcqMtffqyWyeDNz5VhexDNmVZo1bz2UG1r+PweKlqjF+MgG49bzB0O7fU4GpXeAv1FXhu7fVx1VGRaIHx/khKNII0ptpyfLgjpGQv9LAZOhDFgBz7cC 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 --- Change since v2: - Fixed whitespace issue based on TJ's suggestion. 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 72e36977a96e..f5fc16b918ba 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);