History

mm: Don't build mm_dump_obj() on CONFIG_PRINTK=n kernels

The mem_dump_obj() functionality adds a few hundred bytes, which is a small price to pay. Except on kernels built with CONFIG_PRINTK=n, in which mem_dump_obj() messages will be suppressed. This commit therefore makes mem_dump_obj() be a static inline empty function on kernels built with CONFIG_PRINTK=n and excludes all of its support functions as well. This avoids kernel bloat on systems that cannot use mem_dump_obj().

Paul E. McKenney committed 5 years ago

Commit 5bb1bb31 parent a38fd8710 files · +21 −1Browse files

Unified · Split

10 files
  1. include/linux/mm.h +4 −0
  2. include/linux/slab.h +2 −0
  3. include/linux/vmalloc.h +1 −1
  4. mm/slab.c +2 −0
  5. mm/slab.h +2 −0
  6. mm/slab_common.c +2 −0
  7. mm/slob.c +2 −0
  8. mm/slub.c +2 −0
  9. mm/util.c +2 −0
  10. mm/vmalloc.c +2 −0
include/linux/mm.h+4−0
@@ -3135,7 +3135,11 @@ unsigned long wp_shared_mapping_range(struct address_space *mapping, · 3134 unmodified lines
3135 3135
3136extern int sysctl_nr_trim_pages;3136extern int sysctl_nr_trim_pages;
3137 3137
3138#ifdef CONFIG_PRINTK
3138void mem_dump_obj(void *object);3139void mem_dump_obj(void *object);
3140#else
3141static inline void mem_dump_obj(void *object) {}
3142#endif
3139 3143
3140#endif /* __KERNEL__ */3144#endif /* __KERNEL__ */
3141#endif /* _LINUX_MM_H */3145#endif /* _LINUX_MM_H */
include/linux/slab.h+2−0
@@ -186,8 +186,10 @@ void kfree(const void *); · 185 unmodified lines
186void kfree_sensitive(const void *);186void kfree_sensitive(const void *);
187size_t __ksize(const void *);187size_t __ksize(const void *);
188size_t ksize(const void *);188size_t ksize(const void *);
189#ifdef CONFIG_PRINTK
189bool kmem_valid_obj(void *object);190bool kmem_valid_obj(void *object);
190void kmem_dump_obj(void *object);191void kmem_dump_obj(void *object);
192#endif
191 193
192#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR194#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
193void __check_heap_object(const void *ptr, unsigned long n, struct page *page,195void __check_heap_object(const void *ptr, unsigned long n, struct page *page,
include/linux/vmalloc.h+1−1
@@ -241,7 +241,7 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) · 240 unmodified lines
241int register_vmap_purge_notifier(struct notifier_block *nb);241int register_vmap_purge_notifier(struct notifier_block *nb);
242int unregister_vmap_purge_notifier(struct notifier_block *nb);242int unregister_vmap_purge_notifier(struct notifier_block *nb);
243 243
244#ifdef CONFIG_MMU244#if defined(CONFIG_MMU) && defined(CONFIG_PRINTK)
245bool vmalloc_dump_obj(void *object);245bool vmalloc_dump_obj(void *object);
246#else246#else
247static inline bool vmalloc_dump_obj(void *object) { return false; }247static inline bool vmalloc_dump_obj(void *object) { return false; }
mm/slab.c+2−0
@@ -3651,6 +3651,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t flags, · 3650 unmodified lines
3651EXPORT_SYMBOL(__kmalloc_node_track_caller);3651EXPORT_SYMBOL(__kmalloc_node_track_caller);
3652#endif /* CONFIG_NUMA */3652#endif /* CONFIG_NUMA */
3653 3653
3654#ifdef CONFIG_PRINTK
3654void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)3655void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
3655{3656{
3656 struct kmem_cache *cachep;3657 struct kmem_cache *cachep;
@@ -3670,6 +3671,7 @@ void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page) · 13 unmodified lines
3670 if (DEBUG && cachep->flags & SLAB_STORE_USER)3671 if (DEBUG && cachep->flags & SLAB_STORE_USER)
3671 kpp->kp_ret = *dbg_userword(cachep, objp);3672 kpp->kp_ret = *dbg_userword(cachep, objp);
3672}3673}
3674#endif
3673 3675
3674/**3676/**
3675 * __do_kmalloc - allocate memory3677 * __do_kmalloc - allocate memory
mm/slab.h+2−0
@@ -619,6 +619,7 @@ static inline bool slab_want_init_on_free(struct kmem_cache *c) · 618 unmodified lines
619 return false;619 return false;
620}620}
621 621
622#ifdef CONFIG_PRINTK
622#define KS_ADDRS_COUNT 16623#define KS_ADDRS_COUNT 16
623struct kmem_obj_info {624struct kmem_obj_info {
624 void *kp_ptr;625 void *kp_ptr;
@@ -630,5 +631,6 @@ struct kmem_obj_info { · 5 unmodified lines
630 void *kp_stack[KS_ADDRS_COUNT];631 void *kp_stack[KS_ADDRS_COUNT];
631};632};
632void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page);633void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page);
634#endif
633 635
634#endif /* MM_SLAB_H */636#endif /* MM_SLAB_H */
mm/slab_common.c+2−0
@@ -526,6 +526,7 @@ bool slab_is_available(void) · 525 unmodified lines
526 return slab_state >= UP;526 return slab_state >= UP;
527}527}
528 528
529#ifdef CONFIG_PRINTK
529/**530/**
530 * kmem_valid_obj - does the pointer reference a valid slab object?531 * kmem_valid_obj - does the pointer reference a valid slab object?
531 * @object: pointer to query.532 * @object: pointer to query.
@@ -600,6 +601,7 @@ void kmem_dump_obj(void *object) · 68 unmodified lines
600 pr_info(" %pS\n", kp.kp_stack[i]);601 pr_info(" %pS\n", kp.kp_stack[i]);
601 }602 }
602}603}
604#endif
603 605
604#ifndef CONFIG_SLOB606#ifndef CONFIG_SLOB
605/* Create a cache during boot when no slab services are available yet */607/* Create a cache during boot when no slab services are available yet */
mm/slob.c+2−0
@@ -461,11 +461,13 @@ out: · 460 unmodified lines
461 spin_unlock_irqrestore(&slob_lock, flags);461 spin_unlock_irqrestore(&slob_lock, flags);
462}462}
463 463
464#ifdef CONFIG_PRINTK
464void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)465void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
465{466{
466 kpp->kp_ptr = object;467 kpp->kp_ptr = object;
467 kpp->kp_page = page;468 kpp->kp_page = page;
468}469}
470#endif
469 471
470/*472/*
471 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.473 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
mm/slub.c+2−0
@@ -3963,6 +3963,7 @@ int __kmem_cache_shutdown(struct kmem_cache *s) · 3962 unmodified lines
3963 return 0;3963 return 0;
3964}3964}
3965 3965
3966#ifdef CONFIG_PRINTK
3966void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)3967void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
3967{3968{
3968 void *base;3969 void *base;
@@ -4002,6 +4003,7 @@ void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page) · 33 unmodified lines
4002#endif4003#endif
4003#endif4004#endif
4004}4005}
4006#endif
4005 4007
4006/********************************************************************4008/********************************************************************
4007 * Kmalloc subsystem4009 * Kmalloc subsystem
mm/util.c+2−0
@@ -983,6 +983,7 @@ int __weak memcmp_pages(struct page *page1, struct page *page2) · 982 unmodified lines
983 return ret;983 return ret;
984}984}
985 985
986#ifdef CONFIG_PRINTK
986/**987/**
987 * mem_dump_obj - Print available provenance information988 * mem_dump_obj - Print available provenance information
988 * @object: object for which to find provenance information.989 * @object: object for which to find provenance information.
@@ -1013,3 +1014,4 @@ void mem_dump_obj(void *object) · 24 unmodified lines
1013 }1014 }
1014 pr_cont(" non-slab/vmalloc memory.\n");1015 pr_cont(" non-slab/vmalloc memory.\n");
1015}1016}
1017#endif
mm/vmalloc.c+2−0
@@ -3450,6 +3450,7 @@ void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) · 3449 unmodified lines
3450}3450}
3451#endif /* CONFIG_SMP */3451#endif /* CONFIG_SMP */
3452 3452
3453#ifdef CONFIG_PRINTK
3453bool vmalloc_dump_obj(void *object)3454bool vmalloc_dump_obj(void *object)
3454{3455{
3455 struct vm_struct *vm;3456 struct vm_struct *vm;
@@ -3462,6 +3463,7 @@ bool vmalloc_dump_obj(void *object) · 6 unmodified lines
3462 vm->nr_pages, (unsigned long)vm->addr, vm->caller);3463 vm->nr_pages, (unsigned long)vm->addr, vm->caller);
3463 return true;3464 return true;
3464}3465}
3466#endif
3465 3467
3466#ifdef CONFIG_PROC_FS3468#ifdef CONFIG_PROC_FS
3467static void *s_start(struct seq_file *m, loff_t *pos)3469static void *s_start(struct seq_file *m, loff_t *pos)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t