Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp651512pxt; Thu, 5 Aug 2021 08:26:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxC63k8q8WgZ0Z530KDq9IUTSZtOey72wL4SXi/1crZ9Ob/WLKZl673RolfXEepx9mcmkug X-Received: by 2002:a17:907:98c1:: with SMTP id kd1mr5453215ejc.51.1628177188601; Thu, 05 Aug 2021 08:26:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628177188; cv=none; d=google.com; s=arc-20160816; b=EvNVyHZpzf+dJMoLhPha7i2NwJ1SdzNx+yH3hg1KNHqvaf/pLcAHUTz8oMHuznkqmE Lon+ruaA5s+Yjs3fDVkqF29Geo3RmXPCv1G5gLYcdIN7pp3h0wY0AXFnn2VzQJ+j5+hk 5fauWW7FIY8VO/R3J1taknASIIJoKckcQUFaKxQJsYVALorB/xuiWx8reTejj4omgL1S j9Q9L9eI6XMdsk2btfdEfR/8CkJhYvP/Gb6JkKptjkio1El2DaQIoU27jF7rT9BYxIDc nsY/a1dPpeQyNHRAzxey/aMnJ6bD+ieJiG27vmGjB+7CMkPA/ynrigFx0TKEXKPNrNv5 G0/w== 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=NpSEnfFVipeLYsm5P4IZ48437eDIJVCmfiiW+1mKvCY=; b=vAAYWSdX166XgAQ8z/4pCanwA5iOZo1mrgHi1RQ4MPcpVduQD6Tloe1ovtID9Zz6YN ItygP+t0tn/5wbqd49EZXQ6Cw99/nN0VjYKHIp4kLXsCLLddROaRT1cQwYme4te1oRik C2HnGeATNridhvszhh2q2UdYRrp8gXDy2k6xU9LXzwmpesy379tuG/AEv2yA5Tg+c/UB xKkbRxm614gWX92h++TF8wJLkcM4/TgY9/gu5xyRovzpueVpxDymDCKrZQo5ihEEnLAA j7EnYKh1M3zMh/2AIDVUaaa3f4s+q4ee+gOdG3jQyNJvU+nB3UB6ujZ2p4nYv/L92y+4 uOxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=crx31kre; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 cw8si5652890edb.20.2021.08.05.08.26.05; Thu, 05 Aug 2021 08:26: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=crx31kre; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 S242240AbhHEPYm (ORCPT + 99 others); Thu, 5 Aug 2021 11:24:42 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34046 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241961AbhHEPUW (ORCPT ); Thu, 5 Aug 2021 11:20:22 -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 973AD223DD; Thu, 5 Aug 2021 15:20:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1628176806; 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=NpSEnfFVipeLYsm5P4IZ48437eDIJVCmfiiW+1mKvCY=; b=crx31kreGLzmTCyMpzpenqoTiUtihEXS+TB9EIlN13eBZ9O4832HU2ARkE+g5XXoII7xv3 Bwarc8I/5lAZcy7G0X8b2LqCdap1bOAkTYdPY7NJ4CyKembxkE/tuSc7jB5OX1/Eb4NaTc H2zIQbO5DpXqfimqqpqBXsU0MNoWk+c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1628176806; 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=NpSEnfFVipeLYsm5P4IZ48437eDIJVCmfiiW+1mKvCY=; b=eeQLEkGRoF2i2i29Lye4HDJvdzP955C3+cSMl9jG91ge1zgVnSu58A76ft2I1803HKOawb TrsO8ToKeQjXz0Ag== 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 6965E13DAC; Thu, 5 Aug 2021 15:20:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cGgYGaYBDGFDdQAAMHmgww (envelope-from ); Thu, 05 Aug 2021 15:20:06 +0000 From: Vlastimil Babka To: Andrew Morton , Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mike Galbraith , Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Jann Horn , Vlastimil Babka Subject: [PATCH v4 13/35] mm, slub: do initial checks in ___slab_alloc() with irqs enabled Date: Thu, 5 Aug 2021 17:19:38 +0200 Message-Id: <20210805152000.12817-14-vbabka@suse.cz> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805152000.12817-1-vbabka@suse.cz> References: <20210805152000.12817-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As another step of shortening irq disabled sections in ___slab_alloc(), delay disabling irqs until we pass the initial checks if there is a cached percpu slab and it's suitable for our allocation. Now we have to recheck c->page after actually disabling irqs as an allocation in irq handler might have replaced it. Signed-off-by: Vlastimil Babka Acked-by: Mel Gorman --- mm/slub.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index db03cb972c11..7eb06fe9d7a0 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2665,8 +2665,9 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, stat(s, ALLOC_SLOWPATH); - local_irq_save(flags); - page = c->page; +reread_page: + + page = READ_ONCE(c->page); if (!page) { /* * if the node is not online or has no normal memory, just @@ -2675,6 +2676,11 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, if (unlikely(node != NUMA_NO_NODE && !node_isset(node, slab_nodes))) node = NUMA_NO_NODE; + local_irq_save(flags); + if (unlikely(c->page)) { + local_irq_restore(flags); + goto reread_page; + } goto new_slab; } redo: @@ -2689,8 +2695,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, goto redo; } else { stat(s, ALLOC_NODE_MISMATCH); - deactivate_slab(s, page, c->freelist, c); - goto new_slab; + goto deactivate_slab; } } @@ -2699,12 +2704,15 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, * PFMEMALLOC but right now, we are losing the pfmemalloc * information when the page leaves the per-cpu allocator */ - if (unlikely(!pfmemalloc_match(page, gfpflags))) { - deactivate_slab(s, page, c->freelist, c); - goto new_slab; - } + if (unlikely(!pfmemalloc_match(page, gfpflags))) + goto deactivate_slab; - /* must check again c->freelist in case of cpu migration or IRQ */ + /* must check again c->page in case IRQ handler changed it */ + local_irq_save(flags); + if (unlikely(page != c->page)) { + local_irq_restore(flags); + goto reread_page; + } freelist = c->freelist; if (freelist) goto load_freelist; @@ -2720,6 +2728,9 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, stat(s, ALLOC_REFILL); load_freelist: + + lockdep_assert_irqs_disabled(); + /* * freelist is pointing to the list of objects to be used. * page is pointing to the page from which the objects are obtained. @@ -2731,11 +2742,23 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, local_irq_restore(flags); return freelist; +deactivate_slab: + + local_irq_save(flags); + if (page != c->page) { + local_irq_restore(flags); + goto reread_page; + } + deactivate_slab(s, page, c->freelist, c); + new_slab: + lockdep_assert_irqs_disabled(); + if (slub_percpu_partial(c)) { page = c->page = slub_percpu_partial(c); slub_set_percpu_partial(c, page); + local_irq_restore(flags); stat(s, CPU_PARTIAL_ALLOC); goto redo; } -- 2.32.0