diff mbox series

hugetlbfs: rework calculation code of Hugepage size in hugetlbfs_show_options()

Message ID 20210201082325.33875-1-linmiaohe@huawei.com (mailing list archive)
State New, archived
Headers show
Series hugetlbfs: rework calculation code of Hugepage size in hugetlbfs_show_options() | expand

Commit Message

Miaohe Lin Feb. 1, 2021, 8:23 a.m. UTC
Rework calculation code of the Hugepage size to make it more readable and
straightforward.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 fs/hugetlbfs/inode.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

David Hildenbrand Feb. 1, 2021, 10:56 a.m. UTC | #1
On 01.02.21 09:23, Miaohe Lin wrote:
> Rework calculation code of the Hugepage size to make it more readable and
> straightforward.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>   fs/hugetlbfs/inode.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 3a08fbae3b53..1be18de4b537 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -1014,11 +1014,12 @@ static int hugetlbfs_show_options(struct seq_file *m, struct dentry *root)
>   	if (sbinfo->max_inodes != -1)
>   		seq_printf(m, ",nr_inodes=%lu", sbinfo->max_inodes);
>   
> -	hpage_size /= 1024;
> -	mod = 'K';
> -	if (hpage_size >= 1024) {
> -		hpage_size /= 1024;
> +	if (hpage_size >= SZ_1M) {
> +		hpage_size /= SZ_1M;
>   		mod = 'M';
> +	} else {
> +		hpage_size /= SZ_1K;
> +		mod = 'K';
>   	}
>   	seq_printf(m, ",pagesize=%lu%c", hpage_size, mod);
>   	if (spool) {
> 

Looks correct but I am not convinced the old code was that complicated 
to understand.
Miaohe Lin Feb. 1, 2021, 11:19 a.m. UTC | #2
Hi:
On 2021/2/1 18:56, David Hildenbrand wrote:
> On 01.02.21 09:23, Miaohe Lin wrote:
>> Rework calculation code of the Hugepage size to make it more readable and
>> straightforward.
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>> ---
>>   fs/hugetlbfs/inode.c | 9 +++++----
>>   1 file changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
>> index 3a08fbae3b53..1be18de4b537 100644
>> --- a/fs/hugetlbfs/inode.c
>> +++ b/fs/hugetlbfs/inode.c
>> @@ -1014,11 +1014,12 @@ static int hugetlbfs_show_options(struct seq_file *m, struct dentry *root)
>>       if (sbinfo->max_inodes != -1)
>>           seq_printf(m, ",nr_inodes=%lu", sbinfo->max_inodes);
>>   -    hpage_size /= 1024;
>> -    mod = 'K';
>> -    if (hpage_size >= 1024) {
>> -        hpage_size /= 1024;
>> +    if (hpage_size >= SZ_1M) {
>> +        hpage_size /= SZ_1M;
>>           mod = 'M';
>> +    } else {
>> +        hpage_size /= SZ_1K;
>> +        mod = 'K';
>>       }
>>       seq_printf(m, ",pagesize=%lu%c", hpage_size, mod);
>>       if (spool) {
>>
> 
> Looks correct but I am not convinced the old code was that complicated to understand.
> 

The old code is not complicated but I think it may be better to use macro instead of well-known "magic number".
Many thanks for review.:)
diff mbox series

Patch

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 3a08fbae3b53..1be18de4b537 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -1014,11 +1014,12 @@  static int hugetlbfs_show_options(struct seq_file *m, struct dentry *root)
 	if (sbinfo->max_inodes != -1)
 		seq_printf(m, ",nr_inodes=%lu", sbinfo->max_inodes);
 
-	hpage_size /= 1024;
-	mod = 'K';
-	if (hpage_size >= 1024) {
-		hpage_size /= 1024;
+	if (hpage_size >= SZ_1M) {
+		hpage_size /= SZ_1M;
 		mod = 'M';
+	} else {
+		hpage_size /= SZ_1K;
+		mod = 'K';
 	}
 	seq_printf(m, ",pagesize=%lu%c", hpage_size, mod);
 	if (spool) {