hugetlbfs: make hugepage size conversion more readable
Subsystems (2)
PATCH 1/1 hugetlbfs: make hugepage size conversion more readable
The calculation 1U << (h->order + PAGE_SHIFT - 10) is actually equal to (PAGE_SHIFT << (h->order)) >> 10. So we can make it more readable by replace it with huge_page_size(h) / SZ_1K.
--- fs/hugetlbfs/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/hugetlbfs/inode.c +2 -2
@@ -1519,8 +1519,8 @@ static struct vfsmount *__init mount_one_hugetlbfs(struct hstate *h)put_fs_context (fc); }if (IS_ERR (mnt)) -pr_err ("Cannot mount internal hugetlbfs for page size %uK" , -1U << (h->order +PAGE_SHIFT -10 )); +pr_err ("Cannot mount internal hugetlbfs for page size %luK" , +huge_page_size (h) /SZ_1K );return mnt; }
Signature · 1 line
2.19.1
Quoted 14 lines · Miaohe Lin
The calculation 1U << (
h->order+PAGE_SHIFT- 10) is actually equal to (PAGE_SHIFT<< (h->order)) >> 10. So we can make it more readable by replace it withhuge_page_size(h)/SZ_1K.Signed-off-by Miaohe Lin <[email protected]>--- fs/hugetlbfs/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/hugetlbfs/inode.c +0
-0
fs/hugetlbfs/inode.c static struct vfsmount *__init mount_one_hugetlbfs(struct hstate *h) · line 1523
Quoted 7 lines
fs/hugetlbfs/inode.c +2
-2@@ -1519,8 +1519,8 @@ static struct vfsmount *__init mount_one_hugetlbfs(struct hstate *h)put_fs_context (fc); }if (IS_ERR (mnt)) -pr_err ("Cannot mount internal hugetlbfs for page size %uK" , -1U << (h->order +PAGE_SHIFT -10 )); +pr_err ("Cannot mount internal hugetlbfs for page size %luK" , +huge_page_size (h) /SZ_1K );
I appreciate the effort to make the code more readable. The existing calculation does take a minute to understand. However, it is correct and anyone modifying the code should be able to understand.
With my compiler, your proposed change adds an additional instruction to the routine mount_one_hugetlbfs. I know this is not significant, but still it does increase the kernel size for a change that is of questionable value.
In the kernel, size in KB is often calculated as (size << (PAGE_SHIFT - 10)). If you change the calculation in the hugetlb code to be:
huge_page_size(h) << (PAGE_SHIFT - 10)
my compiler will actually reduce the size of the routine by one instruction.
Signature · 1 line
Mike Kravetz
Quoted 4 lines
fs/hugetlbfs/inode.c +0
-0return mnt; }
Hi:
Quoted 27 lines · Mike Kravetz
Quoted 14 lines · Miaohe Lin
The calculation 1U << (
h->order+PAGE_SHIFT- 10) is actually equal to (PAGE_SHIFT<< (h->order)) >> 10. So we can make it more readable by replace it withhuge_page_size(h)/SZ_1K.Signed-off-by Miaohe Lin <[email protected]>--- fs/hugetlbfs/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/hugetlbfs/inode.c +0
-0fs/hugetlbfs/inode.c static struct vfsmount *__init mount_one_hugetlbfs(struct hstate *h) · line 1523
Quoted 7 lines
fs/hugetlbfs/inode.c +2
-2@@ -1519,8 +1519,8 @@ static struct vfsmount *__init mount_one_hugetlbfs(struct hstate *h)put_fs_context (fc); }if (IS_ERR (mnt)) -pr_err ("Cannot mount internal hugetlbfs for page size %uK" , -1U << (h->order +PAGE_SHIFT -10 )); +pr_err ("Cannot mount internal hugetlbfs for page size %luK" , +huge_page_size (h) /SZ_1K );I appreciate the effort to make the code more readable. The existing calculation does take a minute to understand. However, it is correct and anyone modifying the code should be able to understand.
Quoted 2 lines
With my compiler, your proposed change adds an additional instruction to the routine
mount_one_hugetlbfs. I know this is not significant, but still
I thought compiler would generate the same code...
Quoted 5 lines
it does increase the kernel size for a change that is of questionable value.
In the kernel, size in KB is often calculated as (size << (
PAGE_SHIFT- 10)). If you change the calculation in the hugetlb code to be:Quoted 1 line
fs/hugetlbfs/inode.c +0
-0huge_page_size (h) << (PAGE_SHIFT -10 )
I'am sorry but this looks not really correct. I think the calculation shoud be huge_page_size(h) >> 10. What do you think?
Quoted 3 lines
my compiler will actually reduce the size of the routine by one instruction.
Many thanks.
Quoted 34 lines · Miaohe Lin
Hi:
Quoted 27 lines · Mike Kravetz
Quoted 14 lines · Miaohe Lin
The calculation 1U << (
h->order+PAGE_SHIFT- 10) is actually equal to (PAGE_SHIFT<< (h->order)) >> 10. So we can make it more readable by replace it withhuge_page_size(h)/SZ_1K.Signed-off-by Miaohe Lin <[email protected]>--- fs/hugetlbfs/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/hugetlbfs/inode.c +0
-0fs/hugetlbfs/inode.c static struct vfsmount *__init mount_one_hugetlbfs(struct hstate *h) · line 1523
Quoted 7 lines
fs/hugetlbfs/inode.c +2
-2@@ -1519,8 +1519,8 @@ static struct vfsmount *__init mount_one_hugetlbfs(struct hstate *h)put_fs_context (fc); }if (IS_ERR (mnt)) -pr_err ("Cannot mount internal hugetlbfs for page size %uK" , -1U << (h->order +PAGE_SHIFT -10 )); +pr_err ("Cannot mount internal hugetlbfs for page size %luK" , +huge_page_size (h) /SZ_1K );I appreciate the effort to make the code more readable. The existing calculation does take a minute to understand. However, it is correct and anyone modifying the code should be able to understand.
Quoted 2 lines
With my compiler, your proposed change adds an additional instruction to the routine
mount_one_hugetlbfs. I know this is not significant, but stillI thought compiler would generate the same code...
Quoted 8 lines
Quoted 5 lines
it does increase the kernel size for a change that is of questionable value.
In the kernel, size in KB is often calculated as (size << (
PAGE_SHIFT- 10)). If you change the calculation in the hugetlb code to be:Quoted 1 line
fs/hugetlbfs/inode.c +0
-0huge_page_size (h) << (PAGE_SHIFT -10 )I'am sorry but this looks not really correct. I think the calculation shoud be
huge_page_size(h)>> 10. What do you think?
My bad! I was looking at code that converts page counts to KB. Sorry.
Yes, huge_page_size(h) >> 10 is correct.
Signature · 1 line
Mike Kravetz
Hi:
Quoted 39 lines · Mike Kravetz
Quoted 38 lines · Miaohe Lin
Hi:
Quoted 27 lines · Mike Kravetz
Quoted 14 lines · Miaohe Lin
The calculation 1U << (
h->order+PAGE_SHIFT- 10) is actually equal to (PAGE_SHIFT<< (h->order)) >> 10. So we can make it more readable by replace it withhuge_page_size(h)/SZ_1K.Signed-off-by Miaohe Lin <[email protected]>--- fs/hugetlbfs/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/hugetlbfs/inode.c +0
-0fs/hugetlbfs/inode.c static struct vfsmount *__init mount_one_hugetlbfs(struct hstate *h) · line 1523
Quoted 7 lines
fs/hugetlbfs/inode.c +2
-2@@ -1519,8 +1519,8 @@ static struct vfsmount *__init mount_one_hugetlbfs(struct hstate *h)put_fs_context (fc); }if (IS_ERR (mnt)) -pr_err ("Cannot mount internal hugetlbfs for page size %uK" , -1U << (h->order +PAGE_SHIFT -10 )); +pr_err ("Cannot mount internal hugetlbfs for page size %luK" , +huge_page_size (h) /SZ_1K );I appreciate the effort to make the code more readable. The existing calculation does take a minute to understand. However, it is correct and anyone modifying the code should be able to understand.
Quoted 2 lines
With my compiler, your proposed change adds an additional instruction to the routine
mount_one_hugetlbfs. I know this is not significant, but stillI thought compiler would generate the same code...
Quoted 4 lines
it does increase the kernel size for a change that is of questionable value.
In the kernel, size in KB is often calculated as (size << (
PAGE_SHIFT- 10)). If you change the calculation in the hugetlb code to be:
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
fs/hugetlbfs/inode.c static struct vfsmount *__init mount_one_hugetlbfs(struct hstate *h) · line 1524
Quoted 1 line
fs/hugetlbfs/inode.c +0
-0huge_page_size (h) << (PAGE_SHIFT -10 )I'am sorry but this looks not really correct. I think the calculation shoud be
huge_page_size(h)>> 10. What do you think?My bad! I was looking at code that converts page counts to KB. Sorry.
Yes,
huge_page_size(h)>> 10 is correct.
So I will send v2 with this change. Many thanks.