Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5154127pxj; Wed, 9 Jun 2021 10:20:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5DnScg2VNvTnbjowArS+zu9YiJ3UVNX53aZ9UG2M+ZYFDMmK8sEKOcCSTyKyBV1ZF3+zv X-Received: by 2002:a17:907:20ee:: with SMTP id rh14mr854389ejb.461.1623259213756; Wed, 09 Jun 2021 10:20:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623259213; cv=none; d=google.com; s=arc-20160816; b=iz9JtKOHaBqITPNq4NDkx5BV3x/FAtHBhh8xKeLzIEKySXAdp+57M+LmfxEWXcm/bj 2Flan5/m2HY7ZDjEPWkmyD+2wXjOf0N/qeqksQySriSu+qRNyZQcjgCO/9L8cTsNs5QD jtl1kOycBRs9wq/F5zvFHJxF6ReeiRpq0gIzFYi3A28kF1aQYc1IGhuBAf3sNI28aPxK 4du50IzWB8VqNQwqtoTFGECKC42rVRodFA9O2dZnjXhZC0TeEeQR7QVJ3yqCnPO3wwyL PRSWMkG6HK8R10+nXMrueZrjIbwvnKuVwQGm98y4+VQuowZ5PqXCAJnZfLDC8jFFxLZ4 QMjQ== 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:dkim-signature:dkim-signature; bh=qfMFwj7ppgCWhaxJh1K1eYLeFIE8J8e6h1Q7xkpTECo=; b=zeI+SekCaUQj769QDffK13JGCHdW48SHurUAmvKqNLC+rycHX9Nyclug1YIFB9G3ly EQ7YdVh4RmAm68L4VIylXLnAlR1l5twESWPTdbyqUMQW+h2pYf3wBnyxC5swJKQCG+tH mDt/uCS2mLu3Nk1F+xOmJm4IiJh/B50biLoByHLyrht4beAlCn/UWabuZuYwQB/o9U4J sPvjz3NDPFu65x5pkArpr3By+3shw2ncxeIUDN+C88bDfSIyk26uDx76JP8YX/6Ebwn0 OhNCRUYzzbIfS5Og571k+e1KekQ3xeUn1Jl6JTbIHwMFPfbXtpXEDj7QiE93JiGmK1H9 avYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=0PD5fXKp; dkim=neutral (no key) header.i=@suse.cz header.b=aCiRQyu4; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=0PD5fXKp; 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 4si247977ejr.444.2021.06.09.10.19.49; Wed, 09 Jun 2021 10:20:13 -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=0PD5fXKp; dkim=neutral (no key) header.i=@suse.cz header.b=aCiRQyu4; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=0PD5fXKp; 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 S239327AbhFILnH (ORCPT + 99 others); Wed, 9 Jun 2021 07:43:07 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:54662 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239177AbhFILlc (ORCPT ); Wed, 9 Jun 2021 07:41:32 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 58E50219ED; Wed, 9 Jun 2021 11:39:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623238777; 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=qfMFwj7ppgCWhaxJh1K1eYLeFIE8J8e6h1Q7xkpTECo=; b=0PD5fXKpoeabe6dUZOIO/Z/5nY6DrOvynM1KuMFVcTyoJfmZ8VGXgpLmhe4uBjV11+D5em 4Hxy+e67kwQOxuAoWYePnfUFacJgkkdyG+VJPEIh0ekY5MhFCNIPa6MajEgBPjam6iOh6S n3okn6meKDgqv213Jv6q0qEvxYG3nFw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623238777; 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=qfMFwj7ppgCWhaxJh1K1eYLeFIE8J8e6h1Q7xkpTECo=; b=aCiRQyu4/Yyi+HLIruMVy41bQEpCaA8+Fqp5qjFR1SOVLyXuGg55cZl3duhSMQMD/KUMJx ORaRnRU599yma8AA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 274CC11A98; Wed, 9 Jun 2021 11:39:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623238777; 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=qfMFwj7ppgCWhaxJh1K1eYLeFIE8J8e6h1Q7xkpTECo=; b=0PD5fXKpoeabe6dUZOIO/Z/5nY6DrOvynM1KuMFVcTyoJfmZ8VGXgpLmhe4uBjV11+D5em 4Hxy+e67kwQOxuAoWYePnfUFacJgkkdyG+VJPEIh0ekY5MhFCNIPa6MajEgBPjam6iOh6S n3okn6meKDgqv213Jv6q0qEvxYG3nFw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623238777; 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=qfMFwj7ppgCWhaxJh1K1eYLeFIE8J8e6h1Q7xkpTECo=; b=aCiRQyu4/Yyi+HLIruMVy41bQEpCaA8+Fqp5qjFR1SOVLyXuGg55cZl3duhSMQMD/KUMJx ORaRnRU599yma8AA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id KJweCXmowGD6XgAALh3uQQ (envelope-from ); Wed, 09 Jun 2021 11:39:37 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Peter Zijlstra , Jann Horn , Vlastimil Babka Subject: [RFC v2 29/34] mm: slub: Move flush_cpu_slab() invocations __free_slab() invocations out of IRQ context Date: Wed, 9 Jun 2021 13:38:58 +0200 Message-Id: <20210609113903.1421-30-vbabka@suse.cz> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210609113903.1421-1-vbabka@suse.cz> References: <20210609113903.1421-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 5c70fc17e9be..6e747e0d7dcd 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2474,33 +2474,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; + + cpus_read_lock(); + mutex_lock(&flush_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); + } + + mutex_unlock(&flush_lock); + cpus_read_unlock(); } /* -- 2.31.1