Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3846882pxj; Mon, 24 May 2021 16:44:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8G0T/o4kgKJBxagPvPL430jR77A7Amce2VLoQWsG5g63y2xXkhi1Nw+nesoWTq0hjXpK/ X-Received: by 2002:a17:906:84d:: with SMTP id f13mr26316095ejd.451.1621899876524; Mon, 24 May 2021 16:44:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621899876; cv=none; d=google.com; s=arc-20160816; b=pYclwARHGhiAaqyMfohM3Tjwo1EJQ6hU4h6Bj+zYm8ru68COrFVhUPWjOZ2cd0yZyD QiEhtXGdzDV1po4HBEfKe/TIhiJmOX2pDMp+C9f0iePpYiqlqtnBxrnV54SzHpDJrH8Y zqIA+dyOjglq2/fpnuYNL/w5QaNerp+ubomRfgudwakTPAEPasKdwr0LEGP2QvMCYSUU 3nxxrJ+0YRVoF/a2oDs2dNEpy0dq4M5GPMFJSu0qgiuP/iUzLZ+QvkSd11DP0FRDF3Oq NcHdmKvI76RxRzbu8TaQGnZEQ2zUYWv78S6YnOHZeF9dMN/VLMsouXp33Iw5bQbNzAOP WaYA== 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=iXYZ0XmyJo1s77mEmVIGo4bpg7kiXxTJU3yXSzPECSg=; b=arVCavH1Xg63+Zf2C7z23LU57gcFdeAiQ1DalceMGnVuymJE1Df+2jKh/YuDEHFXUL u/tKXMJb2eEqviI5WGwlKtsknlfqPPH6uMdVZjBQe+xMml8G5T4fgqSNpXsf0tBtClWS GNyFQvE58f3Z6d4r96NZxA3k2d3kyeljTJhHktI6Vjqj3q78htSf0jV0wwW27A639o0+ tPI4QI7viJNel3aSsfed5yjc1H3peVqcwL3dSI68jOBc3iGWaBI3kz+66NBo3lr0V3S2 GbevkG9fhb2B57f45mjUNyY3uf1El7ssLvuNKtlpkJY6yt9JHK4NYS3kQ5i2hHIXzRgW JcdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=SRwvF0mE; 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 zm10si17021034ejb.67.2021.05.24.16.44.13; Mon, 24 May 2021 16:44:36 -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=SRwvF0mE; 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 S230115AbhEXXm7 (ORCPT + 99 others); Mon, 24 May 2021 19:42:59 -0400 Received: from mx2.suse.de ([195.135.220.15]:50702 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229896AbhEXXmU (ORCPT ); Mon, 24 May 2021 19:42:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1621899648; 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=iXYZ0XmyJo1s77mEmVIGo4bpg7kiXxTJU3yXSzPECSg=; b=SRwvF0mEJl+6LGK27v+NfdSDi2Cw1DQJOHp+k0wotXXk/h+QHxemFLeWSRM1ITgAd0R1eV 7O8BRm/c1j5Z4JETsUaTxbB2rU2iLrY3/JWnaNoFEXLWux53XtjH9xexYj3SCTvxNsT68T VZNCPIALeo/PtYoJLORUnitojHUtP7E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1621899648; 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=iXYZ0XmyJo1s77mEmVIGo4bpg7kiXxTJU3yXSzPECSg=; b=L79Rx1NE2xitSbL33D7Sg35d1boSwbTibE/kbi5njl9DgqW11BL/utEVPx9kcO+vsNeNLP DSm0bnZhGjNXwZAw== Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 41A32AF2C; Mon, 24 May 2021 23:40:48 +0000 (UTC) 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 10/26] mm, slub: do initial checks in ___slab_alloc() with irqs enabled Date: Tue, 25 May 2021 01:39:30 +0200 Message-Id: <20210524233946.20352-11-vbabka@suse.cz> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524233946.20352-1-vbabka@suse.cz> References: <20210524233946.20352-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(), don't disable irqs until doing 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 might have replaced it. Signed-off-by: Vlastimil Babka --- mm/slub.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index c5f4f9282496..e243a991b15b 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2643,8 +2643,8 @@ 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 @@ -2653,6 +2653,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: @@ -2667,8 +2672,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; } } @@ -2677,12 +2681,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 of IRQ */ + local_irq_save(flags); + if (unlikely(page != c->page)) { + local_irq_restore(flags); + goto reread_page; + } freelist = c->freelist; if (freelist) goto load_freelist; @@ -2709,11 +2716,20 @@ 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: 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