Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5207929pxj; Wed, 9 Jun 2021 11:42:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiZOlHI4+B2GL1N17W8ObTd2FcxQqh8XK7Qrvi25ZYy1S1sJuEQXkaaku8Lj7x+PimrrWk X-Received: by 2002:a17:906:5053:: with SMTP id e19mr1147688ejk.251.1623264176857; Wed, 09 Jun 2021 11:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623264176; cv=none; d=google.com; s=arc-20160816; b=Wrex9oQNisC1G+x3Q72Ht4NWUB0xC6web7bak7SefTXY/YfENbOUsIV4F4/jsFRJqJ cefboo7hxKnKqXCmNHGpRotxynG7l4gV9NT7YYRS5MSIAYEuuFla37emKGDxEYSOhyND kfkBVap+WHtvL7kr7NfMCGetBYQKtRcJGAHajauQzgowIuCb5ypKCIWoTWgd8cNjnGaN RJlllyUYD/SOz1FVbFyLspU1mp2j5yyGyiOMr2gU9iEiSFGOvTkyK9Qt4Ik+XofZv780 dE8C/AkvKw+zr+uVBiv+Qva9g94RUhD5jYN61E/PkiDHas/RdhstyQjlHQX59liz+cZh bVRw== 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=YFfv9gYBIZkYhNj/PZ5egAELChMxeu671JHTmH9zWkc=; b=MgXONPK/r6HbAfSacLvF7Pp5YwJfRQiDCfnlU3aFtjhmGMA1jEypWwDYo13MysBt2v H/UoE3m6GlIbLN0mEgyh3C6DCkf5heJf78IKJUVqCVBvmEkUPDMt5XrnPN3zVIQyEC0x WqPJPPLcCNC2xTx+cLQnY1vuqmCFcFH4j5eUQ1iNlGcDdvBdmOnKWUGHiMQXr9RCRbC3 CHpLQGmv+qgGS/XF+uBDsdHKXs30YkEv04jV5MqeU0lvmNzMPYocViGzczXQQ2wBDrZk 6kHyZJXUX4/DP3JHIjXH9FE8GnHizqA2t3gkkF8i16+e0uxfp10WgRFh117Jh1HdqdSg KSfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=GGaUqfxw; dkim=neutral (no key) header.i=@suse.cz; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=GGaUqfxw; 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 r15si398854edw.110.2021.06.09.11.42.26; Wed, 09 Jun 2021 11:42:56 -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=GGaUqfxw; dkim=neutral (no key) header.i=@suse.cz; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=GGaUqfxw; 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 S239460AbhFILnK (ORCPT + 99 others); Wed, 9 Jun 2021 07:43:10 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:54850 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239183AbhFILlc (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 B9ABE219EF; 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=YFfv9gYBIZkYhNj/PZ5egAELChMxeu671JHTmH9zWkc=; b=GGaUqfxwVSalM5ZguMtRJiHeQlalVkpBzXOaK6Qllk204MGMoM38zdwJ3taDQjy2m5hVSN eQmPidgMgA39L4chluB/i8a80PrtqXFIF7b+KRIewsrKdkQY0DJ/FK7dd/QaPZrKOuuG0M BLiOxqqcoHsy/+c98klTRE3PY2GBRek= 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=YFfv9gYBIZkYhNj/PZ5egAELChMxeu671JHTmH9zWkc=; b=8jqAorfI47DCQxUHvRbKOyNIQBqCTSAg0whUvcnu2IT8aECFfYaU0gkabMZMgNIPYiQRwH 1Ph+kO0oCYi2PgAA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 8A2B311A98; 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=YFfv9gYBIZkYhNj/PZ5egAELChMxeu671JHTmH9zWkc=; b=GGaUqfxwVSalM5ZguMtRJiHeQlalVkpBzXOaK6Qllk204MGMoM38zdwJ3taDQjy2m5hVSN eQmPidgMgA39L4chluB/i8a80PrtqXFIF7b+KRIewsrKdkQY0DJ/FK7dd/QaPZrKOuuG0M BLiOxqqcoHsy/+c98klTRE3PY2GBRek= 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=YFfv9gYBIZkYhNj/PZ5egAELChMxeu671JHTmH9zWkc=; b=8jqAorfI47DCQxUHvRbKOyNIQBqCTSAg0whUvcnu2IT8aECFfYaU0gkabMZMgNIPYiQRwH 1Ph+kO0oCYi2PgAA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id 4EVFIXmowGD6XgAALh3uQQ (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 31/34] mm, slub: optionally save/restore irqs in slab_[un]lock()/ Date: Wed, 9 Jun 2021 13:39:00 +0200 Message-Id: <20210609113903.1421-32-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 For PREEMPT_RT we will need to disable irqs for this bit spinlock. As a preparation, add a flags parameter, and an internal version that takes additional bool parameter to control irq saving/restoring (the flags parameter is compile-time unused if the bool is a constant false). Convert ___cmpxchg_double_slab(), which also comes with the same bool parameter, to use the internal version. Signed-off-by: Vlastimil Babka --- mm/slub.c | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index cfd5a7660375..6721169f816d 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -353,18 +353,35 @@ static inline unsigned int oo_objects(struct kmem_cache_order_objects x) /* * Per slab locking using the pagelock */ -static __always_inline void slab_lock(struct page *page) +static __always_inline void +__slab_lock(struct page *page, unsigned long *flags, bool disable_irqs) { VM_BUG_ON_PAGE(PageTail(page), page); + if (disable_irqs) + local_irq_save(*flags); bit_spin_lock(PG_locked, &page->flags); } -static __always_inline void slab_unlock(struct page *page) +static __always_inline void +__slab_unlock(struct page *page, unsigned long *flags, bool disable_irqs) { VM_BUG_ON_PAGE(PageTail(page), page); + if (disable_irqs) + local_irq_restore(*flags); __bit_spin_unlock(PG_locked, &page->flags); } +static __always_inline void +slab_lock(struct page *page, unsigned long *flags) +{ + __slab_lock(page, flags, false); +} + +static __always_inline void slab_unlock(struct page *page, unsigned long *flags) +{ + __slab_unlock(page, flags, false); +} + static inline bool ___cmpxchg_double_slab(struct kmem_cache *s, struct page *page, void *freelist_old, unsigned long counters_old, void *freelist_new, unsigned long counters_new, @@ -384,21 +401,15 @@ static inline bool ___cmpxchg_double_slab(struct kmem_cache *s, struct page *pag { unsigned long flags; - if (disable_irqs) - local_irq_save(flags); - slab_lock(page); + __slab_lock(page, &flags, disable_irqs); if (page->freelist == freelist_old && page->counters == counters_old) { page->freelist = freelist_new; page->counters = counters_new; - slab_unlock(page); - if (disable_irqs) - local_irq_restore(flags); + __slab_unlock(page, &flags, disable_irqs); return true; } - slab_unlock(page); - if (disable_irqs) - local_irq_restore(flags); + __slab_unlock(page, &flags, disable_irqs); } cpu_relax(); @@ -1214,11 +1225,11 @@ static noinline int free_debug_processing( struct kmem_cache_node *n = get_node(s, page_to_nid(page)); void *object = head; int cnt = 0; - unsigned long flags; + unsigned long flags, flags2; int ret = 0; spin_lock_irqsave(&n->list_lock, flags); - slab_lock(page); + slab_lock(page, &flags2); if (s->flags & SLAB_CONSISTENCY_CHECKS) { if (!check_slab(s, page)) @@ -1251,7 +1262,7 @@ static noinline int free_debug_processing( slab_err(s, page, "Bulk freelist count(%d) invalid(%d)\n", bulk_cnt, cnt); - slab_unlock(page); + slab_unlock(page, &flags2); spin_unlock_irqrestore(&n->list_lock, flags); if (!ret) slab_fix(s, "Object at 0x%p not freed", object); @@ -4007,9 +4018,10 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page, void *addr = page_address(page); unsigned long *map; void *p; + unsigned long flags; slab_err(s, page, text, s->name); - slab_lock(page); + slab_lock(page, &flags); map = get_map(s, page); for_each_object(p, s, addr, page->objects) { @@ -4020,7 +4032,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page, } } put_map(map); - slab_unlock(page); + slab_unlock(page, &flags); #endif } @@ -4736,8 +4748,9 @@ static void validate_slab(struct kmem_cache *s, struct page *page, { void *p; void *addr = page_address(page); + unsigned long flags; - slab_lock(page); + slab_lock(page, &flags); if (!check_slab(s, page) || !on_freelist(s, page, NULL)) goto unlock; @@ -4752,7 +4765,7 @@ static void validate_slab(struct kmem_cache *s, struct page *page, break; } unlock: - slab_unlock(page); + slab_unlock(page, &flags); } static int validate_slab_node(struct kmem_cache *s, -- 2.31.1