diff mbox series

[6/6] hugetlb_cgroup: use helper for_each_hstate and hstate_index

Message ID 20220728121949.20985-7-linmiaohe@huawei.com (mailing list archive)
State New
Headers show
Series A few cleanup patches for hugetlb_cgroup | expand

Commit Message

Miaohe Lin July 28, 2022, 12:19 p.m. UTC
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(-)

Comments

Mina Almasry July 28, 2022, 6:04 p.m. UTC | #1
On Thu, Jul 28, 2022 at 5:20 AM Miaohe Lin <linmiaohe@huawei.com> wrote:
>
> 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>

Reviewed-by: Mina Almasry <almasrymina@google.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
>
diff mbox series

Patch

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));