History

hugetlbfs: move hugepagesz= parsing to arch independent code

Now that architectures provide arch_hugetlb_valid_size(), parsing of "hugepagesz=" can be done in architecture independent code. Create a single routine to handle hugepagesz= parsing and remove all arch specific routines. We can also remove the interface hugetlb_bad_size() as this is no longer used outside arch independent code. This also provides consistent behavior of hugetlbfs command line options. The hugepagesz= option should only be specified once for a specific size, but some architectures allow multiple instances. This appears to be more of an oversight when code was added by some architectures to set up ALL huge pages sizes.

Mike Kravetz committed 6 years ago

Commit 359f2541 parent ae94da88 files · +17 −109Browse files

Unified · Split

8 files
  1. arch/arm64/mm/hugetlbpage.c +0 −15
  2. arch/powerpc/mm/hugetlbpage.c +0 −15
  3. arch/riscv/mm/hugetlbpage.c +0 −16
  4. arch/s390/mm/hugetlbpage.c +0 −18
  5. arch/sparc/mm/init_64.c +0 −22
  6. arch/x86/mm/hugetlbpage.c +0 −16
  7. include/linux/hugetlb.h +0 −1
  8. mm/hugetlb.c +17 −6
arch/arm64/mm/hugetlbpage.c+0−15
@@ -478,18 +478,3 @@ bool __init arch_hugetlb_valid_size(unsigned long size) · 477 unmodified lines
478 478
479 return false;479 return false;
480}480}
481
482static __init int setup_hugepagesz(char *opt)
483{
484 unsigned long ps = memparse(opt, &opt);
485
486 if (arch_hugetlb_valid_size(ps)) {
487 add_huge_page_size(ps);
488 return 1;
489 }
490
491 hugetlb_bad_size();
492 pr_err("hugepagesz: Unsupported page size %lu K\n", ps >> 10);
493 return 0;
494}
495__setup("hugepagesz=", setup_hugepagesz);
arch/powerpc/mm/hugetlbpage.c+0−15
@@ -589,21 +589,6 @@ static int __init add_huge_page_size(unsigned long long size) · 588 unmodified lines
589 return 0;589 return 0;
590}590}
591 591
592static int __init hugepage_setup_sz(char *str)
593{
594 unsigned long long size;
595
596 size = memparse(str, &str);
597
598 if (add_huge_page_size(size) != 0) {
599 hugetlb_bad_size();
600 pr_err("Invalid huge page size specified(%llu)\n", size);
601 }
602
603 return 1;
604}
605__setup("hugepagesz=", hugepage_setup_sz);
606
607static int __init hugetlbpage_init(void)592static int __init hugetlbpage_init(void)
608{593{
609 bool configured = false;594 bool configured = false;
arch/riscv/mm/hugetlbpage.c+0−16
@@ -22,22 +22,6 @@ bool __init arch_hugetlb_valid_size(unsigned long size) · 21 unmodified lines
22 return false;22 return false;
23}23}
24 24
25static __init int setup_hugepagesz(char *opt)
26{
27 unsigned long ps = memparse(opt, &opt);
28
29 if (arch_hugetlb_valid_size(ps)) {
30 hugetlb_add_hstate(ilog2(ps) - PAGE_SHIFT);
31 return 1;
32 }
33
34 hugetlb_bad_size();
35 pr_err("hugepagesz: Unsupported page size %lu M\n", ps >> 20);
36 return 0;
37
38}
39__setup("hugepagesz=", setup_hugepagesz);
40
41#ifdef CONFIG_CONTIG_ALLOC25#ifdef CONFIG_CONTIG_ALLOC
42static __init int gigantic_pages_init(void)26static __init int gigantic_pages_init(void)
43{27{
arch/s390/mm/hugetlbpage.c+0−18
@@ -264,24 +264,6 @@ bool __init arch_hugetlb_valid_size(unsigned long size) · 263 unmodified lines
264 return false;264 return false;
265}265}
266 266
267static __init int setup_hugepagesz(char *opt)
268{
269 unsigned long size;
270 char *string = opt;
271
272 size = memparse(opt, &opt);
273 if (arch_hugetlb_valid_size(size)) {
274 hugetlb_add_hstate(ilog2(size) - PAGE_SHIFT);
275 } else {
276 hugetlb_bad_size();
277 pr_err("hugepagesz= specifies an unsupported page size %s\n",
278 string);
279 return 0;
280 }
281 return 1;
282}
283__setup("hugepagesz=", setup_hugepagesz);
284
285static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,267static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
286 unsigned long addr, unsigned long len,268 unsigned long addr, unsigned long len,
287 unsigned long pgoff, unsigned long flags)269 unsigned long pgoff, unsigned long flags)
arch/sparc/mm/init_64.c+0−22
@@ -397,28 +397,6 @@ bool __init arch_hugetlb_valid_size(unsigned long size) · 396 unmodified lines
397 397
398 return true;398 return true;
399}399}
400
401static int __init setup_hugepagesz(char *string)
402{
403 unsigned long long hugepage_size;
404 int rc = 0;
405
406 hugepage_size = memparse(string, &string);
407
408 if (!arch_hugetlb_valid_size((unsigned long)hugepage_size)) {
409 hugetlb_bad_size();
410 pr_err("hugepagesz=%llu not supported by MMU.\n",
411 hugepage_size);
412 goto out;
413 }
414
415 add_huge_page_size(hugepage_size);
416 rc = 1;
417
418out:
419 return rc;
420}
421__setup("hugepagesz=", setup_hugepagesz);
422#endif /* CONFIG_HUGETLB_PAGE */400#endif /* CONFIG_HUGETLB_PAGE */
423 401
424void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep)402void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep)
arch/x86/mm/hugetlbpage.c+0−16
@@ -191,22 +191,6 @@ bool __init arch_hugetlb_valid_size(unsigned long size) · 190 unmodified lines
191 return false;191 return false;
192}192}
193 193
194static __init int setup_hugepagesz(char *opt)
195{
196 unsigned long ps = memparse(opt, &opt);
197
198 if (arch_hugetlb_valid_size(ps)) {
199 hugetlb_add_hstate(ilog2(ps) - PAGE_SHIFT);
200 } else {
201 hugetlb_bad_size();
202 printk(KERN_ERR "hugepagesz: Unsupported page size %lu M\n",
203 ps >> 20);
204 return 0;
205 }
206 return 1;
207}
208__setup("hugepagesz=", setup_hugepagesz);
209
210#ifdef CONFIG_CONTIG_ALLOC194#ifdef CONFIG_CONTIG_ALLOC
211static __init int gigantic_pages_init(void)195static __init int gigantic_pages_init(void)
212{196{
include/linux/hugetlb.h+0−1
@@ -519,7 +519,6 @@ int huge_add_to_page_cache(struct page *page, struct address_space *mapping, · 518 unmodified lines
519int __init __alloc_bootmem_huge_page(struct hstate *h);519int __init __alloc_bootmem_huge_page(struct hstate *h);
520int __init alloc_bootmem_huge_page(struct hstate *h);520int __init alloc_bootmem_huge_page(struct hstate *h);
521 521
522void __init hugetlb_bad_size(void);
523void __init hugetlb_add_hstate(unsigned order);522void __init hugetlb_add_hstate(unsigned order);
524bool __init arch_hugetlb_valid_size(unsigned long size);523bool __init arch_hugetlb_valid_size(unsigned long size);
525struct hstate *size_to_hstate(unsigned long size);524struct hstate *size_to_hstate(unsigned long size);
mm/hugetlb.c+17−6
@@ -3262,12 +3262,6 @@ bool __init __attribute((weak)) arch_hugetlb_valid_size(unsigned long size) · 3261 unmodified lines
3262 return size == HPAGE_SIZE;3262 return size == HPAGE_SIZE;
3263}3263}
3264 3264
3265/* Should be called on processing a hugepagesz=... option */
3266void __init hugetlb_bad_size(void)
3267{
3268 parsed_valid_hugepagesz = false;
3269}
3270
3271void __init hugetlb_add_hstate(unsigned int order)3265void __init hugetlb_add_hstate(unsigned int order)
3272{3266{
3273 struct hstate *h;3267 struct hstate *h;
@@ -3337,6 +3331,23 @@ static int __init hugetlb_nrpages_setup(char *s) · 63 unmodified lines
3337}3331}
3338__setup("hugepages=", hugetlb_nrpages_setup);3332__setup("hugepages=", hugetlb_nrpages_setup);
3339 3333
3334static int __init hugepagesz_setup(char *s)
3335{
3336 unsigned long size;
3337
3338 size = (unsigned long)memparse(s, NULL);
3339
3340 if (!arch_hugetlb_valid_size(size)) {
3341 parsed_valid_hugepagesz = false;
3342 pr_err("HugeTLB: unsupported hugepagesz %s\n", s);
3343 return 0;
3344 }
3345
3346 hugetlb_add_hstate(ilog2(size) - PAGE_SHIFT);
3347 return 1;
3348}
3349__setup("hugepagesz=", hugepagesz_setup);
3350
3340static int __init default_hugepagesz_setup(char *s)3351static int __init default_hugepagesz_setup(char *s)
3341{3352{
3342 unsigned long size;3353 unsigned long size;