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
31353135
31363136 extern int sysctl_nr_trim_pages;
31373137
3138+#ifdef CONFIG_PRINTK
31383139 void mem_dump_obj(void *object);
3140+#else
3141+static inline void mem_dump_obj(void *object) {}
3142+#endif
31393143
31403144 #endif /* __KERNEL__ */
31413145 #endif /* _LINUX_MM_H */
include/linux/slab.h+2−0
@@ -186,8 +186,10 @@ void kfree(const void *); · 185 unmodified lines
186186 void kfree_sensitive(const void *);
187187 size_t __ksize(const void *);
188188 size_t ksize(const void *);
189+#ifdef CONFIG_PRINTK
189190 bool kmem_valid_obj(void *object);
190191 void kmem_dump_obj(void *object);
192+#endif
191193
192194 #ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
193195 void __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
241241 int register_vmap_purge_notifier(struct notifier_block *nb);
242242 int unregister_vmap_purge_notifier(struct notifier_block *nb);
243243
244−#ifdef CONFIG_MMU
244+#if defined(CONFIG_MMU) && defined(CONFIG_PRINTK)
245245 bool vmalloc_dump_obj(void *object);
246246 #else
247247 static 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
36513651 EXPORT_SYMBOL(__kmalloc_node_track_caller);
36523652 #endif /* CONFIG_NUMA */
36533653
3654+#ifdef CONFIG_PRINTK
36543655 void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
36553656 {
36563657 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
36703671 if (DEBUG && cachep->flags & SLAB_STORE_USER)
36713672 kpp->kp_ret = *dbg_userword(cachep, objp);
36723673 }
3674+#endif
36733675
36743676 /**
36753677 * __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
619619 return false;
620620 }
621621
622+#ifdef CONFIG_PRINTK
622623 #define KS_ADDRS_COUNT 16
623624 struct kmem_obj_info {
624625 void *kp_ptr;
@@ -630,5 +631,6 @@ struct kmem_obj_info { · 5 unmodified lines
630631 void *kp_stack[KS_ADDRS_COUNT];
631632 };
632633 void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page);
634+#endif
633635
634636 #endif /* MM_SLAB_H */
mm/slab_common.c+2−0
@@ -526,6 +526,7 @@ bool slab_is_available(void) · 525 unmodified lines
526526 return slab_state >= UP;
527527 }
528528
529+#ifdef CONFIG_PRINTK
529530 /**
530531 * kmem_valid_obj - does the pointer reference a valid slab object?
531532 * @object: pointer to query.
@@ -600,6 +601,7 @@ void kmem_dump_obj(void *object) · 68 unmodified lines
600601 pr_info(" %pS\n", kp.kp_stack[i]);
601602 }
602603 }
604+#endif
603605
604606 #ifndef CONFIG_SLOB
605607 /* 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
461461 spin_unlock_irqrestore(&slob_lock, flags);
462462 }
463463
464+#ifdef CONFIG_PRINTK
464465 void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
465466 {
466467 kpp->kp_ptr = object;
467468 kpp->kp_page = page;
468469 }
470+#endif
469471
470472 /*
471473 * 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
39633963 return 0;
39643964 }
39653965
3966+#ifdef CONFIG_PRINTK
39663967 void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
39673968 {
39683969 void *base;
@@ -4002,6 +4003,7 @@ void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page) · 33 unmodified lines
40024003 #endif
40034004 #endif
40044005 }
4006+#endif
40054007
40064008 /********************************************************************
40074009 * Kmalloc subsystem
mm/util.c+2−0
@@ -983,6 +983,7 @@ int __weak memcmp_pages(struct page *page1, struct page *page2) · 982 unmodified lines
983983 return ret;
984984 }
985985
986+#ifdef CONFIG_PRINTK
986987 /**
987988 * mem_dump_obj - Print available provenance information
988989 * @object: object for which to find provenance information.
@@ -1013,3 +1014,4 @@ void mem_dump_obj(void *object) · 24 unmodified lines
10131014 }
10141015 pr_cont(" non-slab/vmalloc memory.\n");
10151016 }
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
34503450 }
34513451 #endif /* CONFIG_SMP */
34523452
3453+#ifdef CONFIG_PRINTK
34533454 bool vmalloc_dump_obj(void *object)
34543455 {
34553456 struct vm_struct *vm;
@@ -3462,6 +3463,7 @@ bool vmalloc_dump_obj(void *object) · 6 unmodified lines
34623463 vm->nr_pages, (unsigned long)vm->addr, vm->caller);
34633464 return true;
34643465 }
3466+#endif
34653467
34663468 #ifdef CONFIG_PROC_FS
34673469 static 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