Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5039235pxj; Wed, 9 Jun 2021 07:50:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFkFuo0O9acHxsshSBi7ob4Vu7R8gN9L19CgRJZnsRTtABXUD4HPn4ICVl6cNPOC+Pp3wH X-Received: by 2002:a17:906:7f8d:: with SMTP id f13mr272621ejr.272.1623250244964; Wed, 09 Jun 2021 07:50:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623250244; cv=none; d=google.com; s=arc-20160816; b=Siyq4V/ViDMFu4P3EFKg7NGatd/MsBEv+hgTnkxrgv08dUd2ES/1k0xEUThY8rOCZu X0Y82sXNGF/xaRYTsZ6rsEs0GzR7UVEVPwR0eWf+TUXyU/QcONCsCSVZMAdyvF2yG7gQ R+hqnYN/yQ2QiqaKUroFmg+JsFFAzgpxoD/w14umEU8SW5MB109UkZR9Yk0wTJeB3vU0 e8+XMI6AJi8R2H+xqIJN3n8VQMG1wnR5t+qGuOEpVKdAkew1FNPQvirVCXpTM/1NFrpG 9PlMdKE2YUeDyPKo9JIG8r/o211dwpANkvYVLHVzrJcPZeUEh754lo4W+OUHpDasGH9x ut3w== 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=CxpLaMxa6ZmRdqzKDifZCdS7C7uCUIH4tSWBVxk980E=; b=pGnyvv2k1o830l1uNsVAKU/HnSTDIgpE2cIVKYWUkMdN/LaKSSp8mJT0RwcfOU9n2t 85KSgQePDktJZ69qqAaSCy+TnjmzBwITPejg75EDRh1mMNm334FYAROyt5SdoSBNwt8H K4n3GiLbGKw/WCGkr198EvHSsgoiiI+eNxotS9s/yv+o6j2CqRFt1K2ZLF0IZSiL+oI4 fEif49MBH0vAUSLJ/u26dDMFGvONkB8WeSDs5hmZ286MHAMz5k5WQtkkTBvm4EhlUkWc Z6cHajoh2rGV77rp35ROg0zR93djTcOTjYoKNJ3k1Gan5Hv18NCODKQetD+ETzJHFijQ EiSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=jynYDQ9t; dkim=neutral (no key) header.i=@suse.cz; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=jynYDQ9t; dkim=neutral (no key) header.i=@suse.cz header.b=GGhWiCyX; 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 s18si35290ejh.472.2021.06.09.07.50.20; Wed, 09 Jun 2021 07:50:44 -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=jynYDQ9t; dkim=neutral (no key) header.i=@suse.cz; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=jynYDQ9t; dkim=neutral (no key) header.i=@suse.cz header.b=GGhWiCyX; 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 S239305AbhFILmj (ORCPT + 99 others); Wed, 9 Jun 2021 07:42:39 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:47066 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239161AbhFILla (ORCPT ); Wed, 9 Jun 2021 07:41:30 -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-out2.suse.de (Postfix) with ESMTPS id 23B441FD67; Wed, 9 Jun 2021 11:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623238774; 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=CxpLaMxa6ZmRdqzKDifZCdS7C7uCUIH4tSWBVxk980E=; b=jynYDQ9tsDdezhA842kVnKvxitXrThZiCoy+eZDBBiQDMF8uVojY4yHKvEv/LPk8cmqbZn TVJLRj5fzZ5eJoACdeSS8sCZXHWVg5RE9gp6RW11VQ74OVG/sX++y6v6cg6dg//Y6l3H8e QOXupKg12nw5rn7/yhH3W6o4wvllfRk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623238774; 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=CxpLaMxa6ZmRdqzKDifZCdS7C7uCUIH4tSWBVxk980E=; b=GGhWiCyXSgVvskjNO5jxfCo8TtjhkArWCimS5dFBbW7eOi62CXHHHDT077tVrZcgPNIBBS 3qwvDkkfoccGniDw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id E8A2211A98; Wed, 9 Jun 2021 11:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623238774; 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=CxpLaMxa6ZmRdqzKDifZCdS7C7uCUIH4tSWBVxk980E=; b=jynYDQ9tsDdezhA842kVnKvxitXrThZiCoy+eZDBBiQDMF8uVojY4yHKvEv/LPk8cmqbZn TVJLRj5fzZ5eJoACdeSS8sCZXHWVg5RE9gp6RW11VQ74OVG/sX++y6v6cg6dg//Y6l3H8e QOXupKg12nw5rn7/yhH3W6o4wvllfRk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623238774; 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=CxpLaMxa6ZmRdqzKDifZCdS7C7uCUIH4tSWBVxk980E=; b=GGhWiCyXSgVvskjNO5jxfCo8TtjhkArWCimS5dFBbW7eOi62CXHHHDT077tVrZcgPNIBBS 3qwvDkkfoccGniDw== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id uCfPN3WowGD6XgAALh3uQQ (envelope-from ); Wed, 09 Jun 2021 11:39:33 +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 13/34] mm, slub: do initial checks in ___slab_alloc() with irqs enabled Date: Wed, 9 Jun 2021 13:38:42 +0200 Message-Id: <20210609113903.1421-14-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 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 4800d768d0d3..22b5bfef8aa6 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2622,8 +2622,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 @@ -2632,6 +2633,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: @@ -2646,8 +2652,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; } } @@ -2656,12 +2661,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; @@ -2677,6 +2685,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. @@ -2688,11 +2699,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.31.1