[PATCH 3/4] hugetlb: add parse_pagesize_str()

From: Luiz Capitulino
Date: Thu Feb 13 2014 - 20:03:26 EST


From: Luiz capitulino <lcapitulino@xxxxxxxxxx>

This commit moves current setup_hugepagez() logic to function called
parse_pagesize_str(), so that it can be used by the next commit.

There should be no functional changes, except for the following:

- When calling memparse(), setup_hugepagesz() was passing the retptr
argument, but the result was unused. So parse_pagesize_str() pass NULL
instead

- Change printk(KERN_ERR) to pr_err() and make the error message a little
bit nicer for bad command-lines like "hugepagesz=1X"

Signed-off-by: Luiz capitulino <lcapitulino@xxxxxxxxxx>
---
arch/x86/mm/hugetlbpage.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
index 8c9f647..968db71 100644
--- a/arch/x86/mm/hugetlbpage.c
+++ b/arch/x86/mm/hugetlbpage.c
@@ -173,18 +173,31 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
#endif /* CONFIG_HUGETLB_PAGE */

#ifdef CONFIG_X86_64
-static __init int setup_hugepagesz(char *opt)
+static __init int parse_pagesize_str(char *str, unsigned *order)
{
- unsigned long ps = memparse(opt, &opt);
+ unsigned long ps = memparse(str, NULL);
if (ps == PMD_SIZE) {
- hugetlb_add_hstate(PMD_SHIFT - PAGE_SHIFT);
+ *order = PMD_SHIFT - PAGE_SHIFT;
} else if (ps == PUD_SIZE && cpu_has_gbpages) {
- hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
+ *order = PUD_SHIFT - PAGE_SHIFT;
} else {
- printk(KERN_ERR "hugepagesz: Unsupported page size %lu M\n",
- ps >> 20);
+ /* invalid page size */
+ return -1;
+ }
+
+ return 0;
+}
+
+static __init int setup_hugepagesz(char *opt)
+{
+ unsigned order;
+
+ if (parse_pagesize_str(opt, &order)) {
+ pr_err("hugepagesz: Unsupported page size %s\n", opt);
return 0;
}
+
+ hugetlb_add_hstate(order);
return 1;
}
__setup("hugepagesz=", setup_hugepagesz);
--
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/