Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp445408imn; Thu, 28 Jul 2022 05:45:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uEdAKJxmlq4JyIvdwIaLIseLZMOCUsMiP0vwQCRZ+/hWOCTKb5INczXnFfXhrewjQrEuWK X-Received: by 2002:a17:907:1361:b0:72b:3554:4f7 with SMTP id yo1-20020a170907136100b0072b355404f7mr21413875ejb.420.1659012341292; Thu, 28 Jul 2022 05:45:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659012341; cv=none; d=google.com; s=arc-20160816; b=mFez7VLq/Lg4YApqHb2u83PEV0lfXTZ0B/a7NYj5G4BTz8T+h285e6FKSlsOc8hS6v gLy8vkX5VGjXzqqhcBOILdtQNnXPO8b5ODJws4YT86z/wxS6tSLO5k3/iVPjPCXnmPbM UaLEawhKDxyfy1cRsN4Z7b3ksvDDjPBLOaquGgIe5/m3gg5BdwuXlBSlLVeRq3s3Shs+ 66Cu2K2qivBNp6iFPC6pDAdUfTrVrnAH0VJKawjZxzql6pRQBNKr8ZJ/PjxZob1DoXKT 2Du8WmxB+LuxddcrDqvbFcrtXJbpnO2ujGJ9Q9ixvlhW9XeaLF8BpEW14pO6GJPC7Zus s85g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ZpOzjgnlMlGSD2f0h+2bWNmv1PniCvgWU0Us6t7IIO8=; b=mh10VHIW8t44JagohJ1cHVwKEOA/8YU20HQqnIdpLS1ZNkJhDlM6LCj/9LgQFMnJDV NC1sOjhn45PgcjN922cnykVn7VpS0LNeMEgu8RHT+ezmMmwnQCxDr5vToHw5hLlQiYY6 S8cwMM6Hd7IuHdCCeINDxNF4ml2bMBaC5R/no6BL8asqXHgJ5kvJaYRSJpwQN2yzqmC/ 2HZqWVsnk1KDIh4LaJJSMJujxVvy/l7iw0Xf8PQ0z3o3ikBv7OWUueTULwD8I9nW8I6c yWe/TgBXJNMt/2Lqw0Vog3JTZXF0NoaA/zrcrXNQ5jKsSLgdwRUn1jTHwmEpsnxJXffq ZdtA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g22-20020a056402321600b0043cfcf25a48si482594eda.489.2022.07.28.05.45.16; Thu, 28 Jul 2022 05:45:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238240AbiG1MUd (ORCPT + 99 others); Thu, 28 Jul 2022 08:20:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236307AbiG1MUJ (ORCPT ); Thu, 28 Jul 2022 08:20:09 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA78A1142 for ; Thu, 28 Jul 2022 05:20:08 -0700 (PDT) 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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)); -- 2.23.0