From patchwork Fri Jul 29 08:01:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12932113 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 492BDC00144 for ; Fri, 29 Jul 2022 08:01:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A55C5940009; Fri, 29 Jul 2022 04:01:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DDD36B0073; Fri, 29 Jul 2022 04:01:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BB0F940008; Fri, 29 Jul 2022 04:01:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 63C2A6B0072 for ; Fri, 29 Jul 2022 04:01:28 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 37A0C4162C for ; Fri, 29 Jul 2022 08:01:28 +0000 (UTC) X-FDA: 79739392656.08.5A62D03 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf04.hostedemail.com (Postfix) with ESMTP id 3EABF400B6 for ; Fri, 29 Jul 2022 08:01:27 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LvKcR5KSkzWfh3; Fri, 29 Jul 2022 15:57:27 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 29 Jul 2022 16:01:23 +0800 From: Miaohe Lin To: CC: , , , , Subject: [PATCH v2 5/5] hugetlb_cgroup: use helper for_each_hstate and hstate_index Date: Fri, 29 Jul 2022 16:01:06 +0800 Message-ID: <20220729080106.12752-6-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220729080106.12752-1-linmiaohe@huawei.com> References: <20220729080106.12752-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659081687; a=rsa-sha256; cv=none; b=iIsMhnosLdUu9ZZ+3ADa7BGM4prVejYhDRz/oUvTS2S8Y7hHAs6uT9vi5ClO1lCSQ50v13 ihj0Xb8UKVvfvee4une7bts8bxhxHTL6JCKOpudIm2bbcQuH5fHipfDkr/GM4Pendsul4c JPAs7Qphx89CR93rG9EOwVe9ST1ePzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659081687; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ikpc0zhULSpAbZP0xG8e1oidk04jdkYGg3L5piSR690=; b=sqwvaWTTiescXsDrjGpJMuhfHiItDjWbK12pSs90vLin6+ZQE4LhGB/CHLPlH7hZqYPXmd mhJb4BXXl/IN2PjlN19vYw4SWCbbq6gIVGm+8etu4h6yW3PTpHWGFHr9EEn2rUcSfFW31I pCbsVlxo05FXgLc7R02TPHtw90L//uY= X-Rspamd-Server: rspam10 X-Rspam-User: Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Stat-Signature: yxjc4ni14h9dzjzu6gtctj6rxk3bp5c4 X-Rspamd-Queue-Id: 3EABF400B6 X-HE-Tag: 1659081687-571298 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: Use helper for_each_hstate and hstate_index to iterate the hstate and get the hstate index. Minor readability improvement. Signed-off-by: Miaohe Lin Reviewed-by: Mina Almasry --- mm/hugetlb_cgroup.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 2affccfe59f1..f61d132df52b 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -75,11 +75,11 @@ parent_hugetlb_cgroup(struct hugetlb_cgroup *h_cg) static inline bool hugetlb_cgroup_have_usage(struct hugetlb_cgroup *h_cg) { - int idx; + struct hstate *h; - for (idx = 0; idx < hugetlb_max_hstate; idx++) { + for_each_hstate(h) { if (page_counter_read( - hugetlb_cgroup_counter_from_cgroup(h_cg, idx))) + hugetlb_cgroup_counter_from_cgroup(h_cg, hstate_index(h)))) return true; } return false; @@ -225,17 +225,14 @@ static void hugetlb_cgroup_css_offline(struct cgroup_subsys_state *css) struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_css(css); struct hstate *h; struct page *page; - int idx; do { - idx = 0; for_each_hstate(h) { spin_lock_irq(&hugetlb_lock); list_for_each_entry(page, &h->hugepage_activelist, lru) - hugetlb_cgroup_move_parent(idx, h_cg, page); + hugetlb_cgroup_move_parent(hstate_index(h), h_cg, page); spin_unlock_irq(&hugetlb_lock); - idx++; } cond_resched(); } while (hugetlb_cgroup_have_usage(h_cg));