| From: Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| Date: Fri, 6 Mar 2020 15:59:06 +0100 |
| Subject: [PATCH] mm: Warn on memory allocation in non-preemptible context on |
| RT |
| |
| The memory allocation via kmalloc(, GFP_ATOMIC) in atomic context |
| (disabled preemption or interrupts) is not allowed on RT because the |
| buddy allocator is using sleeping locks which can't be acquired in this |
| context. |
| Such an an allocation may not trigger a warning in the buddy allocator |
| if it is always satisfied in the SLUB allocator. |
| |
| Add a warning on RT if a memory allocation was attempted in not |
| preemptible region. |
| |
| Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| Reviewed-by: Daniel Bristot de Oliveira <bristot@redhat.com> |
| --- |
| mm/slub.c | 6 ++++++ |
| 1 file changed, 6 insertions(+) |
| |
| --- a/mm/slub.c |
| +++ b/mm/slub.c |
| @@ -2767,6 +2767,9 @@ static __always_inline void *slab_alloc_ |
| struct page *page; |
| unsigned long tid; |
| |
| + if (IS_ENABLED(CONFIG_PREEMPT_RT) && IS_ENABLED(CONFIG_DEBUG_ATOMIC_SLEEP)) |
| + WARN_ON_ONCE(!preemptible() && system_state >= SYSTEM_SCHEDULING); |
| + |
| s = slab_pre_alloc_hook(s, gfpflags); |
| if (!s) |
| return NULL; |
| @@ -3229,6 +3232,9 @@ int kmem_cache_alloc_bulk(struct kmem_ca |
| LIST_HEAD(to_free); |
| int i; |
| |
| + if (IS_ENABLED(CONFIG_PREEMPT_RT) && IS_ENABLED(CONFIG_DEBUG_ATOMIC_SLEEP)) |
| + WARN_ON_ONCE(!preemptible() && system_state >= SYSTEM_SCHEDULING); |
| + |
| /* memcg and kmem_cache debug support */ |
| s = slab_pre_alloc_hook(s, flags); |
| if (unlikely(!s)) |