All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/hugetlbfs: use macro SZ_1K to replace 1024
@ 2022-09-14 11:57 Xin Hao
  2022-09-14 14:03 ` SeongJae Park
  2022-09-14 16:43 ` Al Viro
  0 siblings, 2 replies; 5+ messages in thread
From: Xin Hao @ 2022-09-14 11:57 UTC (permalink / raw)
  To: sj; +Cc: akpm, damon, linux-mm, linux-kernel, xhao

Using macro SZ_1K in hugetlbfs_show_options() has no any functional
changes, just makes code more readable.

Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
---
 fs/hugetlbfs/inode.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index f7a5b5124d8a..9b9784ffe8de 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -1023,10 +1023,10 @@ 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;
+	hpage_size /= SZ_1K;
 	mod = 'K';
-	if (hpage_size >= 1024) {
-		hpage_size /= 1024;
+	if (hpage_size >= SZ_1K) {
+		hpage_size /= SZ_1K;
 		mod = 'M';
 	}
 	seq_printf(m, ",pagesize=%lu%c", hpage_size, mod);
--
2.31.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm/hugetlbfs: use macro SZ_1K to replace 1024
  2022-09-14 11:57 [PATCH] mm/hugetlbfs: use macro SZ_1K to replace 1024 Xin Hao
@ 2022-09-14 14:03 ` SeongJae Park
  2022-09-14 16:43 ` Al Viro
  1 sibling, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2022-09-14 14:03 UTC (permalink / raw)
  To: Xin Hao; +Cc: sj, akpm, damon, linux-mm, linux-kernel

On Wed, 14 Sep 2022 19:57:23 +0800 Xin Hao <xhao@linux.alibaba.com> wrote:

> Using macro SZ_1K in hugetlbfs_show_options() has no any functional
> changes, just makes code more readable.
> 
> Signed-off-by: Xin Hao <xhao@linux.alibaba.com>

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

> ---
>  fs/hugetlbfs/inode.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index f7a5b5124d8a..9b9784ffe8de 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -1023,10 +1023,10 @@ 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;
> +	hpage_size /= SZ_1K;
>  	mod = 'K';
> -	if (hpage_size >= 1024) {
> -		hpage_size /= 1024;
> +	if (hpage_size >= SZ_1K) {
> +		hpage_size /= SZ_1K;
>  		mod = 'M';
>  	}
>  	seq_printf(m, ",pagesize=%lu%c", hpage_size, mod);
> --
> 2.31.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm/hugetlbfs: use macro SZ_1K to replace 1024
  2022-09-14 11:57 [PATCH] mm/hugetlbfs: use macro SZ_1K to replace 1024 Xin Hao
  2022-09-14 14:03 ` SeongJae Park
@ 2022-09-14 16:43 ` Al Viro
  2022-09-15  2:44   ` haoxin
  1 sibling, 1 reply; 5+ messages in thread
From: Al Viro @ 2022-09-14 16:43 UTC (permalink / raw)
  To: Xin Hao; +Cc: sj, akpm, damon, linux-mm, linux-kernel

On Wed, Sep 14, 2022 at 07:57:23PM +0800, Xin Hao wrote:
> Using macro SZ_1K in hugetlbfs_show_options() has no any functional
> changes, just makes code more readable.

Why is it any more readable that way?

> Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
> ---
>  fs/hugetlbfs/inode.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index f7a5b5124d8a..9b9784ffe8de 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -1023,10 +1023,10 @@ 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;
> +	hpage_size /= SZ_1K;
>  	mod = 'K';
> -	if (hpage_size >= 1024) {
> -		hpage_size /= 1024;
> +	if (hpage_size >= SZ_1K) {
> +		hpage_size /= SZ_1K;
>  		mod = 'M';
>  	}
>  	seq_printf(m, ",pagesize=%lu%c", hpage_size, mod);
> --
> 2.31.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm/hugetlbfs: use macro SZ_1K to replace 1024
  2022-09-14 16:43 ` Al Viro
@ 2022-09-15  2:44   ` haoxin
  2022-09-16 11:47     ` David Laight
  0 siblings, 1 reply; 5+ messages in thread
From: haoxin @ 2022-09-15  2:44 UTC (permalink / raw)
  To: Al Viro
  Cc: akpm, linux-mm, linux-kernel, mike.kravetz, songmuchun, SeongJae Park


在 2022/9/15 上午12:43, Al Viro 写道:
> On Wed, Sep 14, 2022 at 07:57:23PM +0800, Xin Hao wrote:
>> Using macro SZ_1K in hugetlbfs_show_options() has no any functional
>> changes, just makes code more readable.
> Why is it any more readable that way?
The main purpose of this code is to convert size to 'K', and 'M'. I 
think using SZ_1k does look more appropriate than 1024, that's all.
>> Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
>> ---
>>   fs/hugetlbfs/inode.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
>> index f7a5b5124d8a..9b9784ffe8de 100644
>> --- a/fs/hugetlbfs/inode.c
>> +++ b/fs/hugetlbfs/inode.c
>> @@ -1023,10 +1023,10 @@ 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;
>> +	hpage_size /= SZ_1K;
>>   	mod = 'K';
>> -	if (hpage_size >= 1024) {
>> -		hpage_size /= 1024;
>> +	if (hpage_size >= SZ_1K) {
>> +		hpage_size /= SZ_1K;
>>   		mod = 'M';
>>   	}
>>   	seq_printf(m, ",pagesize=%lu%c", hpage_size, mod);
>> --
>> 2.31.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] mm/hugetlbfs: use macro SZ_1K to replace 1024
  2022-09-15  2:44   ` haoxin
@ 2022-09-16 11:47     ` David Laight
  0 siblings, 0 replies; 5+ messages in thread
From: David Laight @ 2022-09-16 11:47 UTC (permalink / raw)
  To: 'haoxin', Al Viro
  Cc: akpm, linux-mm, linux-kernel, mike.kravetz, songmuchun, SeongJae Park

From: haoxin
> Sent: 15 September 2022 03:45
> 
> 在 2022/9/15 上�12:43, Al Viro 写�:
> > On Wed, Sep 14, 2022 at 07:57:23PM +0800, Xin Hao wrote:
> >> Using macro SZ_1K in hugetlbfs_show_options() has no any functional
> >> changes, just makes code more readable.
> > Why is it any more readable that way?

> The main purpose of this code is to convert size to 'K', and 'M'. I
> think using SZ_1k does look more appropriate than 1024, that's all.

You'd need to use SZ_1M/SZ_1K if you want to be descriptive.
But really it just uses up more brain cycles to read.

Using named constants for things that are absolutely constant
isn't really necessary.

If you have '#define ONE 1' are you ever going to set it to
a different value?

And don't even think about what happens to systems that had
small integer constants at 'well known' addresses and then
managed to change one of them.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-16 11:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14 11:57 [PATCH] mm/hugetlbfs: use macro SZ_1K to replace 1024 Xin Hao
2022-09-14 14:03 ` SeongJae Park
2022-09-14 16:43 ` Al Viro
2022-09-15  2:44   ` haoxin
2022-09-16 11:47     ` David Laight

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.