linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RT] mm: Warn on memory allocation in non-preemptible context on RT
@ 2020-03-06 16:03 Sebastian Andrzej Siewior
  2020-03-06 16:40 ` Daniel Bristot de Oliveira
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Andrzej Siewior @ 2020-03-06 16:03 UTC (permalink / raw)
  To: linux-rt-users; +Cc: Steven Rostedt, Thomas Gleixner

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>
---
 mm/slub.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mm/slub.c b/mm/slub.c
index 2cff48d13e3a7..7b2773c45e1ff 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2742,6 +2742,9 @@ static __always_inline void *slab_alloc_node(struct kmem_cache *s,
 	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;
@@ -3202,6 +3205,9 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
 	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))
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH RT] mm: Warn on memory allocation in non-preemptible context on RT
  2020-03-06 16:03 [PATCH RT] mm: Warn on memory allocation in non-preemptible context on RT Sebastian Andrzej Siewior
@ 2020-03-06 16:40 ` Daniel Bristot de Oliveira
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Bristot de Oliveira @ 2020-03-06 16:40 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-rt-users; +Cc: Steven Rostedt, Thomas Gleixner

On 3/6/20 5:03 PM, Sebastian Andrzej Siewior wrote:
> 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>

Thanks!
-- Daniel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-06 16:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06 16:03 [PATCH RT] mm: Warn on memory allocation in non-preemptible context on RT Sebastian Andrzej Siewior
2020-03-06 16:40 ` Daniel Bristot de Oliveira

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).