Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp652795pxt; Thu, 5 Aug 2021 08:28:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnag8qQ9VvQ3OqfI0lzlh6AhztvBxA1xhQhXTm/CWhfDpbEzThm+4BytI0+682AapYSo1y X-Received: by 2002:aa7:c98f:: with SMTP id c15mr7219862edt.286.1628177298431; Thu, 05 Aug 2021 08:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628177298; cv=none; d=google.com; s=arc-20160816; b=wlpTe2nCo7KVf+LaLJrN45W2E1xQIl6B5i6ZE0GoR8PC5lLqoTZAo/Wj4FkLQHu+Zf nOQqYM+2i0hOY/MpcwP0WIqRlaT01ymGpZ5F5PUnvr0KPH9F4yCOXL+WEGuPknbUD8aX GPtWJiU6MDqLphYNmZi8iJc1cXiPna7CUcgRex5b46YRbDrCJfFahCl4FqfUAAvhghbB WLUOEG1+cFKQZZIS1P505yGdBE233FKwBG4MdgCN/5AHhwsntMHcNf0LOm77Jdxllw6M yEJA9yMKvrVWYF3S5S8NNQOpsfTE6qWhscZIvriNxkAjm8W16r1r7tE+kdcDl9Q+xMnm GItQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=tA4/drj/b0LN3b02s0c7+xC8bza8ecQHQSMDr5lhwfk=; b=k6BWnirDii9K+s35of+leagLGfjX8JWJmyTATFQ7GknF4Y/Zp0T9nmUNQ3b21Ieivy 0dCP+dR1R64Kckk2KTTW8ahGKRb1AlTPPkZLtXu2XBSAW45fWokwcjgalXSgX5+0yJPw +x12FQdRx6+tunY0R5mtUvm/+Smb4zikSSsKmYsXmH9uYJOR1acqZNjMpEv6VbHb5AFu cxBn8ZyI4zxnfjlZmrvbwR33+YVlg5UyqxlDI4ti1Z9ixUe/R3ANhans+rO2dSfQ7GxN 7/GMRWY1C4GNG3/jBlVgJHMyTf0FHyFj89NAXdRa5ZzcDmeGL9PB9v/YVabqeuVTLGLS ibaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=QZCWRjka; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=ns+W+YCW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si5928876edt.311.2021.08.05.08.27.55; Thu, 05 Aug 2021 08:28:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=QZCWRjka; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=ns+W+YCW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242344AbhHEPZn (ORCPT + 99 others); Thu, 5 Aug 2021 11:25:43 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:59508 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242001AbhHEPUY (ORCPT ); Thu, 5 Aug 2021 11:20:24 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 991041FE6B; Thu, 5 Aug 2021 15:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1628176809; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tA4/drj/b0LN3b02s0c7+xC8bza8ecQHQSMDr5lhwfk=; b=QZCWRjkaD8Py2Cd2P7Jj88XG+Fy5Yj4hrO0LChabCUbZlntSIA3Hfd/a98uY31nzCI4R1K mOcJBEN06zhTEIq5xc1x4D++C3B/x1z/aEIC1Yz+wI4K1BKCcHafdihyaX0VH0HPq+arKm VgOzIwN9FApaMfmHXkmhGo6MD0Uyqag= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1628176809; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tA4/drj/b0LN3b02s0c7+xC8bza8ecQHQSMDr5lhwfk=; b=ns+W+YCW3vLlkhbEooaSvdryqpgEVha0A4qRl2Fyw5iU19hVWrlCqxai1pxOhZf8QnE2g9 9aEfNex0Vqo2IfDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6CAF513DAC; Thu, 5 Aug 2021 15:20:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iKHzGakBDGFDdQAAMHmgww (envelope-from ); Thu, 05 Aug 2021 15:20:09 +0000 From: Vlastimil Babka To: Andrew Morton , Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mike Galbraith , Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Jann Horn , Vlastimil Babka Subject: [PATCH v4 29/35] mm: slub: Move flush_cpu_slab() invocations __free_slab() invocations out of IRQ context Date: Thu, 5 Aug 2021 17:19:54 +0200 Message-Id: <20210805152000.12817-30-vbabka@suse.cz> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805152000.12817-1-vbabka@suse.cz> References: <20210805152000.12817-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sebastian Andrzej Siewior flush_all() flushes a specific SLAB cache on each CPU (where the cache is present). The deactivate_slab()/__free_slab() invocation happens within IPI handler and is problematic for PREEMPT_RT. The flush operation is not a frequent operation or a hot path. The per-CPU flush operation can be moved to within a workqueue. [vbabka@suse.cz: adapt to new SLUB changes] Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Vlastimil Babka --- mm/slub.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index dceb289cb052..da48ada3d17f 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2513,33 +2513,73 @@ static inline void __flush_cpu_slab(struct kmem_cache *s, int cpu) unfreeze_partials_cpu(s, c); } +struct slub_flush_work { + struct work_struct work; + struct kmem_cache *s; + bool skip; +}; + /* * Flush cpu slab. * - * Called from IPI handler with interrupts disabled. + * Called from CPU work handler with migration disabled. */ -static void flush_cpu_slab(void *d) +static void flush_cpu_slab(struct work_struct *w) { - struct kmem_cache *s = d; - struct kmem_cache_cpu *c = this_cpu_ptr(s->cpu_slab); + struct kmem_cache *s; + struct kmem_cache_cpu *c; + struct slub_flush_work *sfw; + + sfw = container_of(w, struct slub_flush_work, work); + + s = sfw->s; + c = this_cpu_ptr(s->cpu_slab); if (c->page) - flush_slab(s, c, false); + flush_slab(s, c, true); unfreeze_partials(s); } -static bool has_cpu_slab(int cpu, void *info) +static bool has_cpu_slab(int cpu, struct kmem_cache *s) { - struct kmem_cache *s = info; struct kmem_cache_cpu *c = per_cpu_ptr(s->cpu_slab, cpu); return c->page || slub_percpu_partial(c); } +static DEFINE_MUTEX(flush_lock); +static DEFINE_PER_CPU(struct slub_flush_work, slub_flush); + static void flush_all(struct kmem_cache *s) { - on_each_cpu_cond(has_cpu_slab, flush_cpu_slab, s, 1); + struct slub_flush_work *sfw; + unsigned int cpu; + + mutex_lock(&flush_lock); + cpus_read_lock(); + + for_each_online_cpu(cpu) { + sfw = &per_cpu(slub_flush, cpu); + if (!has_cpu_slab(cpu, s)) { + sfw->skip = true; + continue; + } + INIT_WORK(&sfw->work, flush_cpu_slab); + sfw->skip = false; + sfw->s = s; + schedule_work_on(cpu, &sfw->work); + } + + for_each_online_cpu(cpu) { + sfw = &per_cpu(slub_flush, cpu); + if (sfw->skip) + continue; + flush_work(&sfw->work); + } + + cpus_read_unlock(); + mutex_unlock(&flush_lock); } /* -- 2.32.0