Skip to contentSkip to conversation

mm/hugetlbfs: use macro SZ_1K to replace 1024

PATCH In review Xin Hao 4 participants 5 messages Sep 14, 2022 – Sep 16, 2022

Subsystems (3)
lore
Share & tools
lore

Xin Hao

author
#0 lore raw

PATCH 1/1 mm/hugetlbfs: use macro SZ_1K to replace 1024

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

---
 fs/hugetlbfs/inode.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/hugetlbfs/inode.c +3 -3
index f7a5b5124d8a..9b9784ffe8de 100644
@@ -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

maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · On Wed, 14 Sep 2022 19:57:23 +0800 Xin Hao <[email protected]> wrote:

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

Thanks,
SJ

Quoted 24 lines
---
 fs/hugetlbfs/inode.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/hugetlbfs/inode.c +3 -4
index f7a5b5124d8a..9b9784ffe8de 100644
@@ -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

#2 lore raw
In reply to Xin Hao
Quoted 2 lines · Xin Hao

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?

Quoted 25 lines
---
 fs/hugetlbfs/inode.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/hugetlbfs/inode.c +3 -4
index f7a5b5124d8a..9b9784ffe8de 100644
@@ -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

author
#3 lore raw
Quoted 4 lines · Al Viro
Quoted 2 lines · Xin Hao

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.

Quoted 25 lines
Quoted 25 lines
---
  fs/hugetlbfs/inode.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
fs/hugetlbfs/inode.c +3 -4
index f7a5b5124d8a..9b9784ffe8de 100644
@@ -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

#4 lore raw

From: haoxin

Quoted 10 lines

Sent: 15 September 2022 03:45

在 2022/9/15 上�12:43, Al Viro 写�:

Quoted 4 lines · Xin Hao
Quoted 2 lines

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)