Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp653352pxt; Thu, 5 Aug 2021 08:29:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdIgnv7PFM6vYuA9Cg7PSgNmlECYNtzX7SOJhT2rzV6YhW0ioW15y+Yq5gmMrd+SzpzDhf X-Received: by 2002:a05:6402:270f:: with SMTP id y15mr7334898edd.65.1628177346992; Thu, 05 Aug 2021 08:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628177346; cv=none; d=google.com; s=arc-20160816; b=XuE31lgCx9HJQgM/SqXdtqfYtZRW63yZveg6oN8+OPKS8LINJSQOSAz9M8D2La5UXn xhVYzqgX0teMK2Gn/ylsuMIhrQSA51hHsZbIytpj1GyQhLgeTUiMhFZ/CqgT8qtjobYz JTigztPTs0tq+aI4xKDys1BzFHopwO1xj0C9gcHbBJ+6J6TM3F9wl6dnH6pGh9DFxRRa D0YrOMLUSyu7AW2a4HOsTMewDN9EWCuR2ElbQuCPdJLQwgyyAPE429+I/1rnKAABpVW6 1CbWcH87udANM3auqbVk8v/UsExGqYUraFV6sVwJWfHYMB0NbY2JLDlTIDy8qOAO3ea+ r+pg== 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=T6BKY01S0uaxOaUT3bEXc17Onk2fr3qGNyeYkVq28EE=; b=nVcIQrD0q235Dyomc14+B9FclZH17t8CVp5z8gceqfNvYLFjcDkFo2NN2vK0DFDX9F HG8AUl0W7E1MhKxXn/d3M33/HMqw6k6nXMwuzXE1BClRokiRI8JqYz6hcNDSTdx8jeab mjSz986rscoJTTLJGMs3iGm2UoFApqcxu1xhEUu3GyyaAhtyBPZO1ArpT3dRV2wgIRS+ JOUqa5ywf3lvYuaGp7lCuBFL9moovHS6Qt2Joywn+5CBagqNyQH7RBy/DIVdr617QQVl aJTZ4vbMGOq8zu7H3JOUqm+Na07byii91V9EWc66P3Cvk0kF2jp8fiboBCzc6d2gI5UL RbEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="mqJI9m6/"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=m8nqoSDH; 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 u15si6365493edt.211.2021.08.05.08.28.43; Thu, 05 Aug 2021 08:29:06 -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="mqJI9m6/"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=m8nqoSDH; 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 S242245AbhHEPZP (ORCPT + 99 others); Thu, 5 Aug 2021 11:25:15 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:59306 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241971AbhHEPUX (ORCPT ); Thu, 5 Aug 2021 11:20:23 -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-out2.suse.de (Postfix) with ESMTPS id 2A9392024E; Thu, 5 Aug 2021 15:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1628176807; 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=T6BKY01S0uaxOaUT3bEXc17Onk2fr3qGNyeYkVq28EE=; b=mqJI9m6/Jjkv7uXKgHztSwoTiTXDGwyaBkZ/6K7VAlbeKpz7OGKGQ143QwIiBJeF2C0nmq keN8R29rVgbim2qywE+skjnJC/B4SKvPDinT7LyQWDBwSJBrqKzuIztc3DdIjKH4ou+30p QQT2HrXZZ1STmiDohAoiz6zwTijmT2A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1628176807; 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=T6BKY01S0uaxOaUT3bEXc17Onk2fr3qGNyeYkVq28EE=; b=m8nqoSDHaKzGH+T1b0EH+ANTMsvdj73urlJYapNoZJsNK8iDL0we2tHkKVBAx1Xg2RNpPW u9boAC6MRD+mHlCw== 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 F26E913DA8; 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 yMyoOqYBDGFDdQAAMHmgww (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 16/35] mm, slub: validate slab from partial list or page allocator before making it cpu slab Date: Thu, 5 Aug 2021 17:19:41 +0200 Message-Id: <20210805152000.12817-17-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 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 9350ff5110a0..5d58fde2bd70 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