diff mbox series

[3/6] hugetlb_cgroup: hugetlbfs: use helper macro SZ_1{K,M,G}

Message ID 20220728121949.20985-4-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 macro SZ_1K, SZ_1M and SZ_1G to do the size conversion. Minor
readability improvement.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/hugetlb_cgroup.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Mina Almasry July 28, 2022, 5:48 p.m. UTC | #1
On Thu, Jul 28, 2022 at 5:20 AM Miaohe Lin <linmiaohe@huawei.com> wrote:
>
> Use helper macro SZ_1K, SZ_1M and SZ_1G to do the size conversion. Minor
> readability improvement.
>
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>

Thanks Miaohe,

Reviewed-by: Mina Almasry <almasrymina@google.com>

> ---
>  mm/hugetlb_cgroup.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
> index 99e9a367e1e5..7e0bca52c40f 100644
> --- a/mm/hugetlb_cgroup.c
> +++ b/mm/hugetlb_cgroup.c
> @@ -674,12 +674,12 @@ static ssize_t hugetlb_cgroup_reset(struct kernfs_open_file *of,
>
>  static char *mem_fmt(char *buf, int size, unsigned long hsize)
>  {
> -       if (hsize >= (1UL << 30))
> -               snprintf(buf, size, "%luGB", hsize >> 30);
> -       else if (hsize >= (1UL << 20))
> -               snprintf(buf, size, "%luMB", hsize >> 20);
> +       if (hsize >= SZ_1G)
> +               snprintf(buf, size, "%luGB", hsize / SZ_1G);
> +       else if (hsize >= SZ_1M)
> +               snprintf(buf, size, "%luMB", hsize / SZ_1M);
>         else
> -               snprintf(buf, size, "%luKB", hsize >> 10);
> +               snprintf(buf, size, "%luKB", hsize / SZ_1K);
>         return buf;
>  }
>
> --
> 2.23.0
>
diff mbox series

Patch

diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
index 99e9a367e1e5..7e0bca52c40f 100644
--- a/mm/hugetlb_cgroup.c
+++ b/mm/hugetlb_cgroup.c
@@ -674,12 +674,12 @@  static ssize_t hugetlb_cgroup_reset(struct kernfs_open_file *of,
 
 static char *mem_fmt(char *buf, int size, unsigned long hsize)
 {
-	if (hsize >= (1UL << 30))
-		snprintf(buf, size, "%luGB", hsize >> 30);
-	else if (hsize >= (1UL << 20))
-		snprintf(buf, size, "%luMB", hsize >> 20);
+	if (hsize >= SZ_1G)
+		snprintf(buf, size, "%luGB", hsize / SZ_1G);
+	else if (hsize >= SZ_1M)
+		snprintf(buf, size, "%luMB", hsize / SZ_1M);
 	else
-		snprintf(buf, size, "%luKB", hsize >> 10);
+		snprintf(buf, size, "%luKB", hsize / SZ_1K);
 	return buf;
 }