Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5155347pxj; Wed, 9 Jun 2021 10:21:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkjQuWeTUPi5REbabTNMXeaYwRtgY/hWlYlsfK/xFLsG1gC7tBb43jPJ0APhhgSgPaAnvJ X-Received: by 2002:a17:906:914f:: with SMTP id y15mr934423ejw.354.1623259317212; Wed, 09 Jun 2021 10:21:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623259317; cv=none; d=google.com; s=arc-20160816; b=t8P9a3QAjSc0bJlflB2gafZvDS1k94Faaimi4CHYmVrpI13/6JZVRXIQVLuVKJDX1c kG0IOpmq0YZY1DH7/vjFuCo9hcM+9d3V3pu1xZShoRfd82xC3bbHziemRDb7ZuPFCPYW YHr3E4jGOkf3uV/JsKdm4kY5rEjqTHLo6Iak79Mu95jNnVOxjMTeqO7eqhudar+5SGYm EhazHCPZPwcKZCQkWbCvpJ+8K6H1H2dwfkLpBDDZET/biFn88eusgU8nuSYHFOfpTtw2 pdI775JmdoEPRlei9N72g+oacLrFYjJkcVn2Tb8DCyJ6+/hgrRTxJLZ4NYyGlfwuwxhY HBuQ== 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=HCgR6cFavL9oqyY6iyzsui86wbbyKVk3bDILLJY4HV8=; b=UNwKRQJE4OHVYjDdzpEjE3J9GlS+owVKD2QIUYuBlGEtJCCBCIpePWJugfU/zGi3uw z/uqr89baPCT6SGooXdwqvlY/EkBoMMopnWv/c2otqZgz16AEG2cHh7vq8EVWTppC29K byBs2AdkT2wQQbRbKEpxx6V301eUsDn9b+zRFE5Mcq3JMUPmj9qdWl90WYWxc3Onysfr LwQ2Tj/9XeFR7/bSqXIau9A871MpMiMg2b0lr3ux44iPfPW8xiYz2OVAzHDWbwUgWite wxIFVF5f0u3dMUsyLl9YMDSss19kgrn7s9XGWYjhaAKUF8sfxOes23q4yKiKnK0fIcZ/ e/Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=crODmQTD; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=qm804xEy; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=crODmQTD; dkim=neutral (no key) header.i=@suse.cz header.b=qm804xEy; 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 d6si284395ejz.127.2021.06.09.10.21.33; Wed, 09 Jun 2021 10:21:57 -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=crODmQTD; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=qm804xEy; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=crODmQTD; dkim=neutral (no key) header.i=@suse.cz header.b=qm804xEy; 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 S239376AbhFILnP (ORCPT + 99 others); Wed, 9 Jun 2021 07:43:15 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:54894 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238259AbhFILld (ORCPT ); Wed, 9 Jun 2021 07:41:33 -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 2C545219F2; Wed, 9 Jun 2021 11:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623238778; 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=HCgR6cFavL9oqyY6iyzsui86wbbyKVk3bDILLJY4HV8=; b=crODmQTDxbTwm6t6lBpB0byfYSMxf74yooLAtc8lHbpb02RPkSiJUlnPHtU0eqQWMH+Lf8 VvwMsDiBPjK1FO9Nd/XM2vLQf6QQsEKM+p4CC1qINFqFVrM0Iw1NyZbmmQhRyaVsodYED1 o6XOuU7FkM8BcM/XBWb//mhRRCdLZtE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623238778; 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=HCgR6cFavL9oqyY6iyzsui86wbbyKVk3bDILLJY4HV8=; b=qm804xEyxAArw/n+EZ//Bk8Fdtsa5qLcfGQx11svOjsk97fnIHk8vBEA7nQJAAl6JCYA7I q8Epun7nFiweTgCw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id ED49B11A98; 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=1623238778; 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=HCgR6cFavL9oqyY6iyzsui86wbbyKVk3bDILLJY4HV8=; b=crODmQTDxbTwm6t6lBpB0byfYSMxf74yooLAtc8lHbpb02RPkSiJUlnPHtU0eqQWMH+Lf8 VvwMsDiBPjK1FO9Nd/XM2vLQf6QQsEKM+p4CC1qINFqFVrM0Iw1NyZbmmQhRyaVsodYED1 o6XOuU7FkM8BcM/XBWb//mhRRCdLZtE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623238778; 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=HCgR6cFavL9oqyY6iyzsui86wbbyKVk3bDILLJY4HV8=; b=qm804xEyxAArw/n+EZ//Bk8Fdtsa5qLcfGQx11svOjsk97fnIHk8vBEA7nQJAAl6JCYA7I q8Epun7nFiweTgCw== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id GC5sOXmowGD6XgAALh3uQQ (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 33/34] mm, slub: use migrate_disable() on PREEMPT_RT Date: Wed, 9 Jun 2021 13:39:02 +0200 Message-Id: <20210609113903.1421-34-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 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 even though it's ultimately a migrate_disable() there. 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 | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 12e966f07f19..caa206213e72 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -115,6 +115,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. + */ +#ifdef 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); @@ -2419,7 +2439,7 @@ static void put_cpu_partial(struct kmem_cache *s, struct page *page, int drain) int pages; int pobjects; - preempt_disable(); + slub_get_cpu_ptr(s->cpu_slab); do { pages = 0; pobjects = 0; @@ -2450,7 +2470,7 @@ static void put_cpu_partial(struct kmem_cache *s, struct page *page, int drain) } while (this_cpu_cmpxchg(s->cpu_slab->partial, oldpage, page) != oldpage); - preempt_enable(); + slub_put_cpu_ptr(s->cpu_slab); #endif /* CONFIG_SLUB_CPU_PARTIAL */ } @@ -2759,7 +2779,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, if (unlikely(!pfmemalloc_match(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); @@ -2818,7 +2838,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); @@ -2834,9 +2855,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); @@ -2919,12 +2940,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_PREEMPTION - put_cpu_ptr(s->cpu_slab); + slub_put_cpu_ptr(s->cpu_slab); #endif return p; } @@ -3445,7 +3466,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++) { @@ -3491,7 +3512,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. -- 2.31.1