linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Miaohe Lin <linmiaohe@huawei.com>
To: <akpm@linux-foundation.org>
Cc: <mike.kravetz@oracle.com>, <almasrymina@google.com>,
	<linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
	<linmiaohe@huawei.com>
Subject: [PATCH 6/6] hugetlb_cgroup: use helper for_each_hstate and hstate_index
Date: Thu, 28 Jul 2022 20:19:49 +0800	[thread overview]
Message-ID: <20220728121949.20985-7-linmiaohe@huawei.com> (raw)
In-Reply-To: <20220728121949.20985-1-linmiaohe@huawei.com>

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 <linmiaohe@huawei.com>
---
 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



  parent reply	other threads:[~2022-07-28 12:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-28 12:19 [PATCH 0/6] A few cleanup patches for hugetlb_cgroup Miaohe Lin
2022-07-28 12:19 ` [PATCH 1/6] hugetlb_cgroup: remove unneeded nr_pages > 0 check Miaohe Lin
2022-07-28 17:44   ` Mina Almasry
2022-07-28 12:19 ` [PATCH 2/6] hugetlb_cgroup: remove unneeded header file Miaohe Lin
2022-07-28 17:45   ` Mina Almasry
2022-07-28 18:02     ` Mina Almasry
2022-07-29  1:07       ` Miaohe Lin
2022-07-28 12:19 ` [PATCH 3/6] hugetlb_cgroup: hugetlbfs: use helper macro SZ_1{K,M,G} Miaohe Lin
2022-07-28 17:48   ` Mina Almasry
2022-07-28 12:19 ` [PATCH 4/6] hugetlb_cgroup: remove unneeded return value Miaohe Lin
2022-07-28 22:35   ` Mike Kravetz
2022-07-28 12:19 ` [PATCH 5/6] hugetlb_cgroup: use helper macro NUMA_NO_NODE Miaohe Lin
2022-07-28 18:00   ` Mina Almasry
2022-07-28 12:19 ` Miaohe Lin [this message]
2022-07-28 18:04   ` [PATCH 6/6] hugetlb_cgroup: use helper for_each_hstate and hstate_index Mina Almasry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220728121949.20985-7-linmiaohe@huawei.com \
    --to=linmiaohe@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=almasrymina@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox