Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6095437pxv; Thu, 29 Jul 2021 06:26:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcetwqIBqfrCcVhBm6a7+OT0zRw9h0P70CMSNPym+7IiWwyRIaGe0vbWqHFen9PLZ/E5uq X-Received: by 2002:a05:6e02:1be8:: with SMTP id y8mr3666292ilv.161.1627565161708; Thu, 29 Jul 2021 06:26:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627565161; cv=none; d=google.com; s=arc-20160816; b=MFEutTA2+epZOwVBkU082IoPMLUBfO96mNLvbZO4RXRkkb+uQZU6MFwU/hYV8fK9bA ZjgmHAVF9FlTBJVHAWLvG8+yAunKwgDKLxyP4X0sA/kNfuIpYafEDgvocV+DWXJMwN+/ I0EX3bfhpsxrTjOUHgX3NvzH53FQCTVHhtSnWTBI8ZnL5yEY29BjDoijKaHFq8hjzMDx k0vp5v+KKeVNP9vSCmdqcPucTd1l5XGBBAA+zPDNHshSBhdQKtWqD61EdxTgIg3fgbbA PoXyobJB7tlRhqoS2EHSfdsEaR9W/T6HqNG7XkC5orIDbfeDldhfFKkBUSGwPyFl69oO I84g== 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=MZ/sz9DDZ8M0Vfi6nYCImhy5kj0wJxMVWRF79KcwjWk=; b=LxmCuhA9rR9WuJz9NV/nXlOK1GPU3NWedg9vXNHiC9va6m+52fXUsvCanghgp8HTxw kU/Hcf0wvgzPLovGlvDGWky3xhQ8B1+O753l29OrIzqz9x41/x6oLwK7Vzu5srj5P7kW keRVF+dENyfTx9anaFA6oCCNqqUWIiFVN2wUxrsn+wLtMN7p1T/A+B/t34r0Jzr8bmXP 9LruJOTKSfLxzLJHhMMBT2Rd9YGh9cp+qXMwMaJdFqQA/+qhB7dlk3sPo0AxJj2UsMdb pOWrPfPazReUyZYV4tfMmJCpxg5LL6pSMOCj2OthemcezN9TZG+UL4nAr6/K+7tDN0fR J+IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=V2IwvAMQ; dkim=neutral (no key) header.i=@suse.cz; 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 x90si3149787jah.3.2021.07.29.06.25.50; Thu, 29 Jul 2021 06:26:01 -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=V2IwvAMQ; dkim=neutral (no key) header.i=@suse.cz; 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 S237549AbhG2NXo (ORCPT + 99 others); Thu, 29 Jul 2021 09:23:44 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:38420 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237552AbhG2NVt (ORCPT ); Thu, 29 Jul 2021 09:21:49 -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-out1.suse.de (Postfix) with ESMTPS id D92B0223E0; Thu, 29 Jul 2021 13:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1627564905; 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=MZ/sz9DDZ8M0Vfi6nYCImhy5kj0wJxMVWRF79KcwjWk=; b=V2IwvAMQafwBMr/2XGH0yPJbdInAPR7n9UJMtW56m+/vi9RHxN/zVDSRg/EfQ6gfj0BRk+ iUSdm9bTUtxLFLQeStU8SOQ48MAibu+PVh5kyOSTbfAeqf0hJ1Mqg3zlVC35aVmsTQz+bV 2OffAIQYcK51dGKnssErGi6HSx5kGOQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1627564905; 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=MZ/sz9DDZ8M0Vfi6nYCImhy5kj0wJxMVWRF79KcwjWk=; b=um8EusyuXCCmwaUzVO1jwdTbE4TJIa5T21HzDXQsgiyvSbqwNKfecIn0c3tgBc4Tzv6cYU z+X0b6bt+Vm8AyAA== 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 AC7D213AF4; Thu, 29 Jul 2021 13:21:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0BN/KWmrAmF9AwAAMHmgww (envelope-from ); Thu, 29 Jul 2021 13:21:45 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Mike Galbraith , Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Jann Horn , Vlastimil Babka Subject: [PATCH v3 29/35] mm: slub: Move flush_cpu_slab() invocations __free_slab() invocations out of IRQ context Date: Thu, 29 Jul 2021 15:21:26 +0200 Message-Id: <20210729132132.19691-30-vbabka@suse.cz> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210729132132.19691-1-vbabka@suse.cz> References: <20210729132132.19691-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 9fbc5396f3e1..dbb74dbe1c1e 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