Skip to contentSkip to conversation

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

PATCH In review Miaohe Lin 2 participants 3 messages Feb 1, 2021

Subsystems (2)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

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

Rework calculation code of the Hugepage size to make it more readable and straightforward.

---
 fs/hugetlbfs/inode.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/hugetlbfs/inode.c +5 -4
index 3a08fbae3b53..1be18de4b537 100644
@@ -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) {
Signature · 1 line
2.19.1
#1 lore raw
Quoted 20 lines · Miaohe Lin

Rework calculation code of the Hugepage size to make it more readable and straightforward.

---
  fs/hugetlbfs/inode.c | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)
fs/hugetlbfs/inode.c +0 -3
index 3a08fbae3b53..1be18de4b537 100644
@@ -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) {

fs/hugetlbfs/inode.c static int hugetlbfs_show_options(struct seq_file *m, struct dentry *root) · line 1025

Quoted 10 lines
fs/hugetlbfs/inode.c +5 -1
-		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.

Signature · 3 lines
Thanks,

David / dhildenb
author
#2 lore raw

Hi:

Quoted 24 lines · David Hildenbrand
Quoted 23 lines · Miaohe Lin

Rework calculation code of the Hugepage size to make it more readable and straightforward.

---
  fs/hugetlbfs/inode.c | 9 +++++----

  1 file changed, 5 insertions(+), 4 deletions(-)
fs/hugetlbfs/inode.c +3 -3
index 3a08fbae3b53..1be18de4b537 100644
@@ -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 {
Quoted 9 lines

fs/hugetlbfs/inode.c static int hugetlbfs_show_options(struct seq_file *m, struct dentry *root) · line 1025

Quoted 6 lines
fs/hugetlbfs/inode.c +2 -0
+        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.:)