From patchwork Thu Jul 28 12:19:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12931195 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 51503C04A68 for ; Thu, 28 Jul 2022 12:20:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA8E26B0073; Thu, 28 Jul 2022 08:20:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B56676B0074; Thu, 28 Jul 2022 08:20:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1DC96B0075; Thu, 28 Jul 2022 08:20:10 -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 8716A6B0073 for ; Thu, 28 Jul 2022 08:20:10 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5BDD0A12E2 for ; Thu, 28 Jul 2022 12:20:10 +0000 (UTC) X-FDA: 79736415780.02.3B54FC8 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf24.hostedemail.com (Postfix) with ESMTP id BBB961800CC for ; Thu, 28 Jul 2022 12:20:09 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LtqRr3V2DzmVML; Thu, 28 Jul 2022 20:18:16 +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; Thu, 28 Jul 2022 20:20:06 +0800 From: Miaohe Lin To: CC: , , , , Subject: [PATCH 6/6] hugetlb_cgroup: use helper for_each_hstate and hstate_index Date: Thu, 28 Jul 2022 20:19:49 +0800 Message-ID: <20220728121949.20985-7-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220728121949.20985-1-linmiaohe@huawei.com> References: <20220728121949.20985-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659010810; a=rsa-sha256; cv=none; b=KzPFAJYTVx/fl9co+M6qeeRBdJ3A1J3uBv6xawkKo4h7mWeU5byvjQjM99TqsdoydXU/UI fkKy3aklSx1wORISVtv70oTeMB4jvzB8EqWITWuaiCqyh1hq2XHdVwLTMWAi0Ic5LbWt0g EdUWdMobrFHo6R00XIZPhqEb2YvK2zM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659010810; 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=ZpOzjgnlMlGSD2f0h+2bWNmv1PniCvgWU0Us6t7IIO8=; b=t+KdR3c4s6x7ssvwTA7PLBDI5X9WeLfT5EAPwByl2nZ05G/pT3YFZj4fneUPp8JsiBmd7N +mcR8tKyxrnhf/si+WZ2jKl6hye9bLuZ4xrmVfwhf5TngZ2P9jSu1k4FLiXxeP2FDMThP0 gb9zoxbKp1BMVb8534PzEAisEM5K+Sg= X-Stat-Signature: axg7m56wd1k7a68jghwmd7urfdt8j6iw X-Rspamd-Queue-Id: BBB961800CC Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1659010809-963283 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 13ec091385af..8f20082df4c8 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -74,11 +74,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; @@ -224,17 +224,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));