Skip to contentSkip to conversation

hugetlbfs: show pagesize in unit of GB if possible

PATCH NAK Miaohe Lin 2 participants 5 messages Jan 30, 2021 – Feb 2, 2021

Subsystems (2)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 hugetlbfs: show pagesize in unit of GB if possible

Hugepage size in unit of GB is supported. We could show pagesize in unit of GB to make it more friendly to read. Also rework the calculation code of page size unit to make it more readable.

---
 fs/hugetlbfs/inode.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/hugetlbfs/inode.c +8 -4
index 3a08fbae3b53..40a9795f250a 100644
@@ -1014,11 +1014,15 @@ 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_1G) {
+		hpage_size /= SZ_1G;
+		mod = 'G';
+	} else 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 23 lines · Miaohe Lin

Hugepage size in unit of GB is supported. We could show pagesize in unit of GB to make it more friendly to read. Also rework the calculation code of page size unit to make it more readable.

---
 fs/hugetlbfs/inode.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/hugetlbfs/inode.c +2 -4
index 3a08fbae3b53..40a9795f250a 100644
@@ -1014,11 +1014,15 @@ 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_1G) {
+		hpage_size /= SZ_1G;

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

Quoted 10 lines
fs/hugetlbfs/inode.c +6 -0
+		mod = 'G';
+	} else 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) {

NACK, this can break existing userspace parsing.

author
#2 lore raw

Hi:

Quoted 30 lines · David Rientjes
Quoted 28 lines · Miaohe Lin

Hugepage size in unit of GB is supported. We could show pagesize in unit of GB to make it more friendly to read. Also rework the calculation code of page size unit to make it more readable.

---
 fs/hugetlbfs/inode.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/hugetlbfs/inode.c +6 -4
index 3a08fbae3b53..40a9795f250a 100644
@@ -1014,11 +1014,15 @@ 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_1G) {
+		hpage_size /= SZ_1G;
+		mod = 'G';
+	} else 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 1028

Quoted 5 lines
fs/hugetlbfs/inode.c +2 -0
+		hpage_size /= SZ_1K;
+		mod = 'K';
 	}
 	seq_printf(m, ",pagesize=%lu%c", hpage_size, mod);
 	if (spool) {

NACK, this can break existing userspace parsing.
.

I see. I should take care of this. Many thanks.

#3 lore raw
Quoted 38 lines · Miaohe Lin
Quoted 28 lines
Quoted 28 lines

Hugepage size in unit of GB is supported. We could show pagesize in unit of GB to make it more friendly to read. Also rework the calculation code of page size unit to make it more readable.

---
 fs/hugetlbfs/inode.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/hugetlbfs/inode.c +6 -4
index 3a08fbae3b53..40a9795f250a 100644
@@ -1014,11 +1014,15 @@ 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_1G) {
+		hpage_size /= SZ_1G;
+		mod = 'G';
+	} else 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 1028

Quoted 5 lines
fs/hugetlbfs/inode.c +2 -0
+		hpage_size /= SZ_1K;
+		mod = 'K';
 	}
 	seq_printf(m, ",pagesize=%lu%c", hpage_size, mod);
 	if (spool) {

NACK, this can break existing userspace parsing.
.

Quoted 2 lines

I see. I should take care of this. Many thanks.

Thanks. It's an important point to emphasize because it shows how important user-facing interfaces are. Once the hugetlbfs mount options are printed in the way they are, it becomes very difficult to change them because there can be userspace in the wild that would break as a result. This is why it's crucial to be very careful when specifying user-facing interfaces the first time so they are extensible.

author
#4 lore raw

Hi:

Quoted 43 lines · David Rientjes
Quoted 38 lines · Miaohe Lin
Quoted 28 lines
Quoted 28 lines

Hugepage size in unit of GB is supported. We could show pagesize in unit of GB to make it more friendly to read. Also rework the calculation code of page size unit to make it more readable.

---
 fs/hugetlbfs/inode.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/hugetlbfs/inode.c +6 -4
index 3a08fbae3b53..40a9795f250a 100644
@@ -1014,11 +1014,15 @@ 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_1G) {
+		hpage_size /= SZ_1G;
+		mod = 'G';
+	} else 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 1028

Quoted 5 lines
fs/hugetlbfs/inode.c +2 -0
+		hpage_size /= SZ_1K;
+		mod = 'K';
 	}
 	seq_printf(m, ",pagesize=%lu%c", hpage_size, mod);
 	if (spool) {

NACK, this can break existing userspace parsing.
.

Quoted 2 lines

I see. I should take care of this. Many thanks.

Quoted 8 lines

Thanks. It's an important point to emphasize because it shows how important user-facing interfaces are. Once the hugetlbfs mount options are printed in the way they are, it becomes very difficult to change them because there can be userspace in the wild that would break as a result. This is why it's crucial to be very careful when specifying user-facing interfaces the first time so they are extensible.
.

Many thanks for detailed explanation! I will keep this in mind! Thanks again.