Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6093881pxv; Thu, 29 Jul 2021 06:24:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2ZV++sH22ah/nd7rm4kg2cHTyYPLA7cyxNimk2Ko5E4b8/UeDzvAoBQcwtmP+gmfiQ+LI X-Received: by 2002:a02:a38f:: with SMTP id y15mr4599249jak.108.1627565041511; Thu, 29 Jul 2021 06:24:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627565041; cv=none; d=google.com; s=arc-20160816; b=rwOvMW5iYjSLRGxnt7hXajHJcsCgZQgNZYTHCdnjUafiKO6t6sLb4mOTOifmkg7DcM +jBgdUgpkY8HEC/S3IRFxnfqombY4ZwcpLbrJzBuf1Vlcys0wd6Er6tK4Ihy9Q3xQD6t Vjm0Lx35e6GK8VhJinakJzzXCN/74mGcGKiDAjHh7F6/5Dh5Chp0X58+zwI6FwHkRfFh 1KyJ4UHkrrC4yku4YFzcQsruCXLxbhSyY7OU+09HQLBX9rIH2GCtCJO2y7HzdyTEyCON xKaYu7Q997sf06ABBbOfTw8BdkVtrwLkV/IvkzC0YhgpsHKp8Z4YUHuEtKft2tQ5uT87 MXkQ== 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=nlAqPsEkB+TaxJN88gWtIIOVpIDjtByvKEzbcoIUzRs=; b=C0ZfNFsXpkXr0pACqNml97rZzj72eSz9mtzlr2UkJLwJZFmNv8vR9OgkHiCZcfuNZg VpQA4zSdP1K5t5gIYUDQxz2XlPSwOFIM/npXek56DtLTvOR+B0mqw+fPuARMvrMOiNQ1 0xO9Zl9TB/DUETjB2X+mUfpBugbSF6FNhh+CDux7t147ap49vz7wVkAGKcioBTOpUQAg FH9ZazYSgYCtmxFZj4hYUiaJizWstBADfJv+1uFZoaxfN57BlG/WtCUwqvAgieFFzVeR 1nxcgme7gn3E/oWFqD+PJM/LzGjfYN6C2FRrqLTH+p8OTFnxStpmVgLnQ4Xrjw8er4BG zNsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="Cv+/OaF9"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=m1Vn8IN+; 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 r20si3265773jan.108.2021.07.29.06.23.50; Thu, 29 Jul 2021 06:24:01 -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="Cv+/OaF9"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=m1Vn8IN+; 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 S237665AbhG2NWp (ORCPT + 99 others); Thu, 29 Jul 2021 09:22:45 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:38396 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237499AbhG2NVr (ORCPT ); Thu, 29 Jul 2021 09:21:47 -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 66A38223D3; Thu, 29 Jul 2021 13:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1627564903; 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=nlAqPsEkB+TaxJN88gWtIIOVpIDjtByvKEzbcoIUzRs=; b=Cv+/OaF9dR4/NV8HJrxrG1gYGgghHJu8bTuNIiLrSaWW6SB0qf5fXEEAatCSEAcUj1gloM JuzhSVKDjy/DNFID3jnWi3/E8qSXPANvnnmuebGuM2cEMd07flwx2f8CXJulS+E6Vof6xj J2yRBU0TY9cuEQxAq3/KTxACHnfPJTk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1627564903; 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=nlAqPsEkB+TaxJN88gWtIIOVpIDjtByvKEzbcoIUzRs=; b=m1Vn8IN+W+qMCYG/E7jrNhB1+Fue6H+/BIw0Yk4nii6Gf8BmWzJMtMnP1qhHZHVH8n0NwV ijjyLN+kwNnOT9DQ== 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 3690313AE9; Thu, 29 Jul 2021 13:21:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aGXBDGerAmF9AwAAMHmgww (envelope-from ); Thu, 29 Jul 2021 13:21:43 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Mike Galbraith , Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Jann Horn , Vlastimil Babka Subject: [PATCH v3 16/35] mm, slub: validate slab from partial list or page allocator before making it cpu slab Date: Thu, 29 Jul 2021 15:21:13 +0200 Message-Id: <20210729132132.19691-17-vbabka@suse.cz> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210729132132.19691-1-vbabka@suse.cz> References: <20210729132132.19691-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we obtain a new slab page from node partial list or page allocator, we assign it to kmem_cache_cpu, perform some checks, and if they fail, we undo the assignment. In order to allow doing the checks without irq disabled, restructure the code so that the checks are done first, and kmem_cache_cpu.page assignment only after they pass. Signed-off-by: Vlastimil Babka --- mm/slub.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 43f38fd47062..c1a88ad4048b 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2772,10 +2772,8 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, lockdep_assert_irqs_disabled(); freelist = get_partial(s, gfpflags, node, &page); - if (freelist) { - c->page = page; + if (freelist) goto check_new_page; - } local_irq_restore(flags); put_cpu_ptr(s->cpu_slab); @@ -2788,9 +2786,6 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, } local_irq_save(flags); - if (c->page) - flush_slab(s, c); - /* * No other reference to the page yet so we can * muck around with it freely without cmpxchg @@ -2799,14 +2794,12 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, page->freelist = NULL; stat(s, ALLOC_SLAB); - c->page = page; check_new_page: if (kmem_cache_debug(s)) { if (!alloc_debug_processing(s, page, freelist, addr)) { /* Slab failed checks. Next slab needed */ - c->page = NULL; local_irq_restore(flags); goto new_slab; } else { @@ -2825,10 +2818,18 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, */ goto return_single; + if (unlikely(c->page)) + flush_slab(s, c); + c->page = page; + goto load_freelist; return_single: + if (unlikely(c->page)) + flush_slab(s, c); + c->page = page; + deactivate_slab(s, page, get_freepointer(s, freelist), c); local_irq_restore(flags); return freelist; -- 2.32.0