From 5bbd800e31b71bad274585afe6b5a647dae02002 Mon Sep 17 00:00:00 2001 From: luzhongjun23 Date: Sun, 4 Jun 2023 18:24:31 +0800 Subject: [PATCH 1/3] mm: Enable SLUB for RT commit 4c7a8a89b8b16cb2733dc45aae256c0fda1c34c8 upstream. Avoid the memory allocation in IRQ section Signed-off-by: Thomas Gleixner [bigeasy: factor out everything except the kcalloc() workaorund ] Signed-off-by: Sebastian Andrzej Siewior --- mm/slub.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 7acc32253e90..d0364f8f005e 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3707,6 +3707,11 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page, const char *text) { #ifdef CONFIG_SLUB_DEBUG +#ifdef CONFIG_PREEMPT_RT_BASE + /* XXX move out of irq-off section */ + slab_err(s, page, text, s->name); +#else + void *addr = page_address(page); void *p; unsigned long *map = kcalloc(BITS_TO_LONGS(page->objects), @@ -3728,6 +3733,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page, slab_unlock(page); kfree(map); #endif +#endif } /* -- Gitee From 2c645bbf62b6dca6ff9f20b8a07dcd2664afdce7 Mon Sep 17 00:00:00 2001 From: luzhongjun23 Date: Sun, 4 Jun 2023 18:25:01 +0800 Subject: [PATCH 2/3] slub: Enable irqs for __GFP_WAIT commit 2d3739e2e7cae9db7fe6affbc747b7f06dc42613 upstream. SYSTEM_RUNNING might be too late for enabling interrupts. Allocations with GFP_WAIT can happen before that. So use this as an indicator. Signed-off-by: Thomas Gleixner --- mm/slub.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/slub.c b/mm/slub.c index d0364f8f005e..1daa6ef4c2dc 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1589,10 +1589,17 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node) void *start, *p; int idx, order; bool shuffle; + bool enableirqs = false; flags &= gfp_allowed_mask; if (gfpflags_allow_blocking(flags)) + enableirqs = true; +#ifdef CONFIG_PREEMPT_RT_FULL + if (system_state > SYSTEM_BOOTING) + enableirqs = true; +#endif + if (enableirqs) local_irq_enable(); flags |= s->allocflags; @@ -1651,7 +1658,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node) page->frozen = 1; out: - if (gfpflags_allow_blocking(flags)) + if (enableirqs) local_irq_disable(); if (!page) return NULL; -- Gitee From 160fa99e9b440620bbc519946413e80a6102c7ae Mon Sep 17 00:00:00 2001 From: luzhongjun23 Date: Sun, 4 Jun 2023 18:25:22 +0800 Subject: [PATCH 3/3] slub: Disable SLUB_CPU_PARTIAL commit d4993fa5aea9eed8f9fce53e94e226f2504eda18 upstream. |BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:915 |in_atomic(): 1, irqs_disabled(): 0, pid: 87, name: rcuop/7 |1 lock held by rcuop/7/87: | #0: (rcu_callback){......}, at: [] rcu_nocb_kthread+0x1ca/0x5d0 |Preemption disabled at:[] put_cpu_partial+0x29/0x220 | |CPU: 0 PID: 87 Comm: rcuop/7 Tainted: G W 4.0.0-rt0+ #477 |Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.7.5-20140531_083030-gandalf 04/01/2014 | 000000000007a9fc ffff88013987baf8 ffffffff817441c7 0000000000000007 | 0000000000000000 ffff88013987bb18 ffffffff810eee51 0000000000000000 | ffff88013fc10200 ffff88013987bb48 ffffffff8174a1c4 000000000007a9fc |Call Trace: | [] dump_stack+0x4f/0x90 | [] ___might_sleep+0x121/0x1b0 | [] rt_spin_lock+0x24/0x60 | [] __free_pages_ok+0xaa/0x540 | [] __free_pages+0x1d/0x30 | [] __free_slab+0xc5/0x1e0 | [] free_delayed+0x56/0x70 | [] put_cpu_partial+0x14d/0x220 | [] __slab_free+0x158/0x2c0 | [] kmem_cache_free+0x221/0x2d0 | [] file_free_rcu+0x2c/0x40 | [] rcu_nocb_kthread+0x243/0x5d0 | [] kthread+0xfc/0x120 | [] ret_from_fork+0x58/0x90 Signed-off-by: Sebastian Andrzej Siewior --- init/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/Kconfig b/init/Kconfig index d94fbe79c354..78ba2cfbfeef 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1800,7 +1800,7 @@ config SLAB_FREELIST_HARDENED config SLUB_CPU_PARTIAL default y - depends on SLUB && SMP + depends on SLUB && SMP && !PREEMPT_RT_FULL bool "SLUB per cpu partial cache" help Per cpu partial caches accellerate objects allocation and freeing -- Gitee