aboutsummaryrefslogtreecommitdiffstats
path: root/mm/huge_memory.c
diff options
context:
space:
mode:
authorShaohua Li <shaohua.li@intel.com>2012-01-12 20:19:11 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-01-12 23:13:08 -0500
commit569e55900a5c3c30de6e25c3f259ae7c7dbadb96 (patch)
tree66bfd4d2ea26f1b9d77580d5397a07552a62e4fd /mm/huge_memory.c
parent0efc8eb9c6a177836dac88b2cbb8815f9e4f8d5a (diff)
thp: improve the error code path
Improve the error code path. Delete unnecessary sysfs file for example. Also remove the #ifdef xxx to make code better. Signed-off-by: Shaohua Li <shaohua.li@intel.com> Reviewed-by: Andrea Arcangeli <aarcange@redhat.com> Cc: David Rientjes <rientjes@google.com> Cc: Johannes Weiner <jweiner@redhat.com> Cc: Minchan Kim <minchan.kim@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/huge_memory.c')
-rw-r--r--mm/huge_memory.c71
1 files changed, 50 insertions, 21 deletions
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index db522e160cca..763711121ef5 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -487,41 +487,68 @@ static struct attribute_group khugepaged_attr_group = {
487 .attrs = khugepaged_attr, 487 .attrs = khugepaged_attr,
488 .name = "khugepaged", 488 .name = "khugepaged",
489}; 489};
490#endif /* CONFIG_SYSFS */
491 490
492static int __init hugepage_init(void) 491static int __init hugepage_init_sysfs(struct kobject **hugepage_kobj)
493{ 492{
494 int err; 493 int err;
495#ifdef CONFIG_SYSFS
496 static struct kobject *hugepage_kobj;
497#endif
498 494
499 err = -EINVAL; 495 *hugepage_kobj = kobject_create_and_add("transparent_hugepage", mm_kobj);
500 if (!has_transparent_hugepage()) { 496 if (unlikely(!*hugepage_kobj)) {
501 transparent_hugepage_flags = 0;
502 goto out;
503 }
504
505#ifdef CONFIG_SYSFS
506 err = -ENOMEM;
507 hugepage_kobj = kobject_create_and_add("transparent_hugepage", mm_kobj);
508 if (unlikely(!hugepage_kobj)) {
509 printk(KERN_ERR "hugepage: failed kobject create\n"); 497 printk(KERN_ERR "hugepage: failed kobject create\n");
510 goto out; 498 return -ENOMEM;
511 } 499 }
512 500
513 err = sysfs_create_group(hugepage_kobj, &hugepage_attr_group); 501 err = sysfs_create_group(*hugepage_kobj, &hugepage_attr_group);
514 if (err) { 502 if (err) {
515 printk(KERN_ERR "hugepage: failed register hugeage group\n"); 503 printk(KERN_ERR "hugepage: failed register hugeage group\n");
516 goto out; 504 goto delete_obj;
517 } 505 }
518 506
519 err = sysfs_create_group(hugepage_kobj, &khugepaged_attr_group); 507 err = sysfs_create_group(*hugepage_kobj, &khugepaged_attr_group);
520 if (err) { 508 if (err) {
521 printk(KERN_ERR "hugepage: failed register hugeage group\n"); 509 printk(KERN_ERR "hugepage: failed register hugeage group\n");
522 goto out; 510 goto remove_hp_group;
523 } 511 }
524#endif 512
513 return 0;
514
515remove_hp_group:
516 sysfs_remove_group(*hugepage_kobj, &hugepage_attr_group);
517delete_obj:
518 kobject_put(*hugepage_kobj);
519 return err;
520}
521
522static void __init hugepage_exit_sysfs(struct kobject *hugepage_kobj)
523{
524 sysfs_remove_group(hugepage_kobj, &khugepaged_attr_group);
525 sysfs_remove_group(hugepage_kobj, &hugepage_attr_group);
526 kobject_put(hugepage_kobj);
527}
528#else
529static inline int hugepage_init_sysfs(struct kobject **hugepage_kobj)
530{
531 return 0;
532}
533
534static inline void hugepage_exit_sysfs(struct kobject *hugepage_kobj)
535{
536}
537#endif /* CONFIG_SYSFS */
538
539static int __init hugepage_init(void)
540{
541 int err;
542 struct kobject *hugepage_kobj;
543
544 if (!has_transparent_hugepage()) {
545 transparent_hugepage_flags = 0;
546 return -EINVAL;
547 }
548
549 err = hugepage_init_sysfs(&hugepage_kobj);
550 if (err)
551 return err;
525 552
526 err = khugepaged_slab_init(); 553 err = khugepaged_slab_init();
527 if (err) 554 if (err)
@@ -545,7 +572,9 @@ static int __init hugepage_init(void)
545 572
546 set_recommended_min_free_kbytes(); 573 set_recommended_min_free_kbytes();
547 574
575 return 0;
548out: 576out:
577 hugepage_exit_sysfs(hugepage_kobj);
549 return err; 578 return err;
550} 579}
551module_init(hugepage_init) 580module_init(hugepage_init)