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().
Unified · Split
| @@ -3135,7 +3135,11 @@ unsigned long wp_shared_mapping_range(struct address_space *mapping, · 3134 unmodified lines | |||
| 3135 | 3135 | ||
| 3136 | extern int sysctl_nr_trim_pages; | 3136 | extern int sysctl_nr_trim_pages; |
| 3137 | 3137 | ||
| 3138 | #ifdef CONFIG_PRINTK | ||
| 3138 | void mem_dump_obj(void *object); | 3139 | void mem_dump_obj(void *object); |
| 3140 | #else | ||
| 3141 | static 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 */ |
| @@ -186,8 +186,10 @@ void kfree(const void *); · 185 unmodified lines | |||
| 186 | void kfree_sensitive(const void *); | 186 | void kfree_sensitive(const void *); |
| 187 | size_t __ksize(const void *); | 187 | size_t __ksize(const void *); |
| 188 | size_t ksize(const void *); | 188 | size_t ksize(const void *); |
| 189 | #ifdef CONFIG_PRINTK | ||
| 189 | bool kmem_valid_obj(void *object); | 190 | bool kmem_valid_obj(void *object); |
| 190 | void kmem_dump_obj(void *object); | 191 | void kmem_dump_obj(void *object); |
| 192 | #endif | ||
| 191 | 193 | ||
| 192 | #ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR | 194 | #ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR |
| 193 | void __check_heap_object(const void *ptr, unsigned long n, struct page *page, | 195 | void __check_heap_object(const void *ptr, unsigned long n, struct page *page, |
| @@ -241,7 +241,7 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) · 240 unmodified lines | |||
| 241 | int register_vmap_purge_notifier(struct notifier_block *nb); | 241 | int register_vmap_purge_notifier(struct notifier_block *nb); |
| 242 | int unregister_vmap_purge_notifier(struct notifier_block *nb); | 242 | int unregister_vmap_purge_notifier(struct notifier_block *nb); |
| 243 | 243 | ||
| 244 | #ifdef CONFIG_MMU | 244 | #if defined(CONFIG_MMU) && defined(CONFIG_PRINTK) |
| 245 | bool vmalloc_dump_obj(void *object); | 245 | bool vmalloc_dump_obj(void *object); |
| 246 | #else | 246 | #else |
| 247 | static inline bool vmalloc_dump_obj(void *object) { return false; } | 247 | static inline bool vmalloc_dump_obj(void *object) { return false; } |
| @@ -3651,6 +3651,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t flags, · 3650 unmodified lines | |||
| 3651 | EXPORT_SYMBOL(__kmalloc_node_track_caller); | 3651 | EXPORT_SYMBOL(__kmalloc_node_track_caller); |
| 3652 | #endif /* CONFIG_NUMA */ | 3652 | #endif /* CONFIG_NUMA */ |
| 3653 | 3653 | ||
| 3654 | #ifdef CONFIG_PRINTK | ||
| 3654 | void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page) | 3655 | void 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 memory | 3677 | * __do_kmalloc - allocate memory |
| @@ -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 16 | 623 | #define KS_ADDRS_COUNT 16 |
| 623 | struct kmem_obj_info { | 624 | struct 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 | }; |
| 632 | void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page); | 633 | void 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 */ |
| @@ -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_SLOB | 606 | #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 */ |
| @@ -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 | ||
| 464 | void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page) | 465 | void 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. |
| @@ -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 | ||
| 3966 | void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page) | 3967 | void 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 | #endif | 4003 | #endif |
| 4003 | #endif | 4004 | #endif |
| 4004 | } | 4005 | } |
| 4006 | #endif | ||
| 4005 | 4007 | ||
| 4006 | /******************************************************************** | 4008 | /******************************************************************** |
| 4007 | * Kmalloc subsystem | 4009 | * Kmalloc subsystem |
| @@ -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 information | 988 | * 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 | ||
| @@ -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 | ||
| 3453 | bool vmalloc_dump_obj(void *object) | 3454 | bool 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_FS | 3468 | #ifdef CONFIG_PROC_FS |
| 3467 | static void *s_start(struct seq_file *m, loff_t *pos) | 3469 | static void *s_start(struct seq_file *m, loff_t *pos) |