Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1225314pxb; Sat, 4 Sep 2021 04:00:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMIj7xNxNcXNITvmD+dECJ34Yb8MzINd2My9QwLdDmQr0jY+McSjoNoZkGaE18/hrK2tqa X-Received: by 2002:aa7:c60e:: with SMTP id h14mr3625039edq.43.1630753228990; Sat, 04 Sep 2021 04:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630753228; cv=none; d=google.com; s=arc-20160816; b=YyyL0KfvQIkiNde87NMAj3LxeRfODaEWCWx86v9dlAGQJKubOe63T46V/MR0+YEExQ JFXUthi/w6o/XdZnuzvl22/Xy4qKoaarknEqIWt4yzdM6qWiym5GyKUsqmT53OZvc7lX ULPmCkdEDhGbEUug549nCygB61be2Voy64X/FMEBab5pANWrW4pWEM+mcMriHBond7i+ HwGgjwSsR96Wtn0T5bDFu1N320MoWjtzOIL7iOfASlIQs4vzoFjg+9ZfKCLvpYSPFrUH UeK2vEpskLijCsiJQ4GXna5ERJBfVbsgGYMzwfMo/d0BlrqIYwQhJmguwMmZJPHCUjS6 rdOg== 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=Wxqu+c89VG9DoYJNyUJRNgh/yw176T+4qGGNhwkbH4M=; b=k6tnyTv787gC4qL8fOSjmVOAv3tOvsjG6NL9CSadTs671Sxcj1pOlgaavdJ+S55j+x qtdb84I5GzOPOOAzbGwVNbQeX6KmbAF95X/BwuKyPQbczc2yCEiOZexzh/cFpEDjUNWn mW1hhnpU98Y4g4wIgu5dqImGTIwhGSPK760A3HjE+nZEXMg94sGE0WrUfvTDN38z7Ann YLrXG/KafCW28HND/IIDmAaTfhbX5scu58krx4P/KayWs+f4hcAkdwesynzLvEB9A5aj df34Vhz4ehKQoLp+x6c71gW1vLDcWRzH3jyIaPd+Fl84DSH/c46TSeghlJsC0pP61pzF TA/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=uqxX4T7a; 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 i13si2010093ejo.692.2021.09.04.04.00.05; Sat, 04 Sep 2021 04:00:28 -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=uqxX4T7a; 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 S1351267AbhIDKxJ (ORCPT + 99 others); Sat, 4 Sep 2021 06:53:09 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:59902 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236301AbhIDKvR (ORCPT ); Sat, 4 Sep 2021 06:51:17 -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 008B5226A7; Sat, 4 Sep 2021 10:50:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630752615; 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=Wxqu+c89VG9DoYJNyUJRNgh/yw176T+4qGGNhwkbH4M=; b=uqxX4T7aYXPjr3QPXMtSdHg0ANyzMr6U8RmIOCAlIO1BSialElvg6SMXCkFdF24nVqkbBj 4vRTcVzjZapBzoYhlOl5u4lro2dnXj44t3102dINN6Ub2GuTOnhql5myuoHpKAiplRWKoR ePKPHtnwjGlZZONJyYbATrFV6zbfxcI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630752615; 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=Wxqu+c89VG9DoYJNyUJRNgh/yw176T+4qGGNhwkbH4M=; b=4HaDGN6rwYv8kvG026cSarFzaIXTP1B31u/57N2Pg8A1Ahzv+TKgYPVqEyZNcsWb4jsUND XQZo5Y3BH1WKZKAA== 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 C71EE1348A; Sat, 4 Sep 2021 10:50:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cCcBMGZPM2HoUQAAMHmgww (envelope-from ); Sat, 04 Sep 2021 10:50:14 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Andrew Morton , linux-kernel@vger.kernel.org, Mike Galbraith , Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Vlastimil Babka Subject: [PATCH v6 32/33] mm, slub: use migrate_disable() on PREEMPT_RT Date: Sat, 4 Sep 2021 12:50:02 +0200 Message-Id: <20210904105003.11688-33-vbabka@suse.cz> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210904105003.11688-1-vbabka@suse.cz> References: <20210904105003.11688-1-vbabka@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4032; h=from:subject; bh=crWmsfhiukvJBjI7JeFpgvjeU9uh5gNw3mnG85pJx5A=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBhM09WvGkqHoAKTdWQMCoVmTvp4iA1B9iMZPnr/A5d KBbx1NaJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYTNPVgAKCRDgIcpz8YmpELEXB/ 4sdKJopvDqomCkMiXYdfNj7/eUKaehnGWlOZtx7GcFTCYA5rGGGep+jU2uZ8+Q2eZJW6dw0OmteBVe VpDqyf/cIXBBsZT7UIeRAnzKpXAweYGWbRXLcuje7xHuZEa84/hs4/CeAswqmgvnIGVJwnYh/8c9Lp ySo8ZJkQ+nvNhYI50TNmo4ZAZ01dj09aDVCnZGRsFsIp8G9TZzw/idJsORatAwO5uDlL6wK46B/ryO 7wzUGifMJelEYeAPvMpqIvChthd+ZGIngnms+8QxtOw6wG53Je78AjKUIMfm/v0I2Z9KrKtygY/2Q0 l2At2btNzsj8Xf7vdzWoEIh2DcNTxb X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We currently use preempt_disable() (directly or via get_cpu_ptr()) to stabilize the pointer to kmem_cache_cpu. On PREEMPT_RT this would be incompatible with the list_lock spinlock. We can use migrate_disable() instead, but that increases overhead on !PREEMPT_RT as it's an unconditional function call. In order to get the best available mechanism on both PREEMPT_RT and !PREEMPT_RT, introduce private slub_get_cpu_ptr() and slub_put_cpu_ptr() wrappers and use them. Signed-off-by: Vlastimil Babka --- mm/slub.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index f4b33d2fddc1..38d4cc51e880 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -118,6 +118,26 @@ * the fast path and disables lockless freelists. */ +/* + * We could simply use migrate_disable()/enable() but as long as it's a + * function call even on !PREEMPT_RT, use inline preempt_disable() there. + */ +#ifndef CONFIG_PREEMPT_RT +#define slub_get_cpu_ptr(var) get_cpu_ptr(var) +#define slub_put_cpu_ptr(var) put_cpu_ptr(var) +#else +#define slub_get_cpu_ptr(var) \ +({ \ + migrate_disable(); \ + this_cpu_ptr(var); \ +}) +#define slub_put_cpu_ptr(var) \ +do { \ + (void)(var); \ + migrate_enable(); \ +} while (0) +#endif + #ifdef CONFIG_SLUB_DEBUG #ifdef CONFIG_SLUB_DEBUG_ON DEFINE_STATIC_KEY_TRUE(slub_debug_enabled); @@ -2852,7 +2872,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, if (unlikely(!pfmemalloc_match_unsafe(page, gfpflags))) goto deactivate_slab; - /* must check again c->page in case IRQ handler changed it */ + /* must check again c->page in case we got preempted and it changed */ local_irq_save(flags); if (unlikely(page != c->page)) { local_irq_restore(flags); @@ -2911,7 +2931,8 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, } if (unlikely(!slub_percpu_partial(c))) { local_irq_restore(flags); - goto new_objects; /* stolen by an IRQ handler */ + /* we were preempted and partial list got empty */ + goto new_objects; } page = c->page = slub_percpu_partial(c); @@ -2927,9 +2948,9 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, if (freelist) goto check_new_page; - put_cpu_ptr(s->cpu_slab); + slub_put_cpu_ptr(s->cpu_slab); page = new_slab(s, gfpflags, node); - c = get_cpu_ptr(s->cpu_slab); + c = slub_get_cpu_ptr(s->cpu_slab); if (unlikely(!page)) { slab_out_of_memory(s, gfpflags, node); @@ -3012,12 +3033,12 @@ static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, * cpu before disabling preemption. Need to reload cpu area * pointer. */ - c = get_cpu_ptr(s->cpu_slab); + c = slub_get_cpu_ptr(s->cpu_slab); #endif p = ___slab_alloc(s, gfpflags, node, addr, c); #ifdef CONFIG_PREEMPT_COUNT - put_cpu_ptr(s->cpu_slab); + slub_put_cpu_ptr(s->cpu_slab); #endif return p; } @@ -3546,7 +3567,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size, * IRQs, which protects against PREEMPT and interrupts * handlers invoking normal fastpath. */ - c = get_cpu_ptr(s->cpu_slab); + c = slub_get_cpu_ptr(s->cpu_slab); local_irq_disable(); for (i = 0; i < size; i++) { @@ -3592,7 +3613,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size, } c->tid = next_tid(c->tid); local_irq_enable(); - put_cpu_ptr(s->cpu_slab); + slub_put_cpu_ptr(s->cpu_slab); /* * memcg and kmem_cache debug support and memory initialization. @@ -3602,7 +3623,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size, slab_want_init_on_alloc(flags, s)); return i; error: - put_cpu_ptr(s->cpu_slab); + slub_put_cpu_ptr(s->cpu_slab); slab_post_alloc_hook(s, objcg, flags, i, p, false); __kmem_cache_free_bulk(s, i, p); return 0; -- 2.33.0