Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5038027pxj; Wed, 9 Jun 2021 07:49:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhWQELIk9sFJeqaxCH3DRxmp2q09Kkzkew9nNSFO/tXOUpWm/HIVGsIOK843hvCPppCUl9 X-Received: by 2002:a17:906:b0cb:: with SMTP id bk11mr269528ejb.310.1623250141027; Wed, 09 Jun 2021 07:49:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623250141; cv=none; d=google.com; s=arc-20160816; b=Q2hEJSKu95LGyFev8+xBCexrsfUbf2Ks2DxheWxQaQbXCUu7E6dQctgeEhGYzsER26 8BuD78o9tu0QzK8ttb5lM6yVD5dFn3Ss3fuWDmvLQ79VJhlA0uExFdtr68XGfdx0P1gT PUNF+o+26kgUPrWsRxkjOfxrJyMy2zUGPI7RNd8hPEJWPlukWODKbGJjq6SMwAhiqPa5 aEmO+NP3xU1A4MFRI9/yrrB+2OE/kWMf32tRbR4r9xDdQLBmIUYFPKV6EaAdFV5S24Vy dVnxfh0XAFzzS92gmCHKQ1o5tRIaVRAt4zBbIc4Z4RxnK7QfnUCRp01A+cmJrRhzXm/r Lwkw== 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=tMRaEZFMqbqCquk4QWerCUuNLFI/dmGIIEo12matNCQ=; b=AAucBEi40tF/Y23YaTjBf4/Fut6s5NQn4nFU66AB+WDOByB6QKqe48c0q0pBhq1XMg Ok+cJBYktjGFBCmenw9k0sae8Rinj1BdvBUTrCLnLbZhTwaOByG7pp88ODlDtGGCNbEv FFUspeltKEVoxJmwcSv72c5Vt0RRPMLRY5t/TiE3s5e4GWe/FZ9N5f0MaiE9NxmGdS3t GzNhzK4REas2AxqSrqTrRsK3T+GlDAxYEGV86IQsLQpLmlVHEYUy1jGZWgz2HWNsyJ9+ 19wqb80+Csy+IqJqU+IvHASnlVlFIkcfVAoNW5DwynjfoLZMOR6WNtED8jB2CXJ5eAcc qLog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="JixlPVZ/"; dkim=neutral (no key) header.i=@suse.cz; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="JixlPVZ/"; 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 i8si2512724edr.440.2021.06.09.07.48.37; Wed, 09 Jun 2021 07:49: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="JixlPVZ/"; dkim=neutral (no key) header.i=@suse.cz; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="JixlPVZ/"; 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 S239300AbhFILmJ (ORCPT + 99 others); Wed, 9 Jun 2021 07:42:09 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:54644 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239150AbhFILl3 (ORCPT ); Wed, 9 Jun 2021 07:41:29 -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 B2A47219A0; 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=tMRaEZFMqbqCquk4QWerCUuNLFI/dmGIIEo12matNCQ=; b=JixlPVZ/dhqgk2DKFXTb9/92CPbymu2U2qdnX76atqNlB3g4f5zRYLrlagVZykKDgTLiih vdtQ2g8HU6gvUexrcHtoj++v92tsyscySr+X6yT768ECqYJ9UoxdH2tvJvzE81A8ZjkZJl DiBFYN5o+iGwciHTh9oG8bqhimuctos= 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=tMRaEZFMqbqCquk4QWerCUuNLFI/dmGIIEo12matNCQ=; b=zfxQHLpAV+0vuOAM4N2A1QLCJuhr4WM5p+V9/v0tkidBV+a2F3kGHCnPj1z3qv/ypM1tUg uCtQ1DyLEASbacBw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 85851118DD; 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=tMRaEZFMqbqCquk4QWerCUuNLFI/dmGIIEo12matNCQ=; b=JixlPVZ/dhqgk2DKFXTb9/92CPbymu2U2qdnX76atqNlB3g4f5zRYLrlagVZykKDgTLiih vdtQ2g8HU6gvUexrcHtoj++v92tsyscySr+X6yT768ECqYJ9UoxdH2tvJvzE81A8ZjkZJl DiBFYN5o+iGwciHTh9oG8bqhimuctos= 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=tMRaEZFMqbqCquk4QWerCUuNLFI/dmGIIEo12matNCQ=; b=zfxQHLpAV+0vuOAM4N2A1QLCJuhr4WM5p+V9/v0tkidBV+a2F3kGHCnPj1z3qv/ypM1tUg uCtQ1DyLEASbacBw== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id gI0YIHaowGD6XgAALh3uQQ (envelope-from ); Wed, 09 Jun 2021 11:39:34 +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 16/34] mm, slub: validate slab from partial list or page allocator before making it cpu slab Date: Wed, 9 Jun 2021 13:38:45 +0200 Message-Id: <20210609113903.1421-17-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 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 f4ce372e3dd3..378f1cb040b3 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2729,10 +2729,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); @@ -2745,9 +2743,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 @@ -2756,14 +2751,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 { @@ -2782,10 +2775,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.31.1