Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3847756pxj; Mon, 24 May 2021 16:46:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyx6OYCjpJdV+d9ZhFgZF9YnED+6H8dhE+FKXN8iedtiNm6NN7rCXlQr9lH2xHasU4gtcBV X-Received: by 2002:a05:6402:50d1:: with SMTP id h17mr29450300edb.199.1621899968979; Mon, 24 May 2021 16:46:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621899968; cv=none; d=google.com; s=arc-20160816; b=zNSF44MVyTlvN8sj4sVzLGsGoKXshGI11ygg19Xa1HHu5tu9rBYFRTdhfEQcCfVwi8 SPyvX0ij3ie/Gt5DK/+YAea8J0koergBvrQd11y8zVpHmLVmYje0GbaelKyIlBaG/z0M RDvV8HO+xyJKKred6ahhSL1sxPHI76GR7WZtOI8PQtNX5yKOaq1sT2P7/f9XRe/QYNlb hqNjmQtUgPIa4AtXs9A+AYMntnCr7omm6CG0i+m3RuaITIvMTocjRVqu7L0EpwiIFIaX rtUixULfxiZCMNFHiLz8iq7b2X4bDgXZpFZYWyk131kXKZ3MiWcimCqM1LX2PouqcFBY r0Eg== 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=0tu41fI/tehEDdtk24Fc6V86f4NZ4fbmTVRxT+6xDtI=; b=RPXjP+lbimiC/VKz1XkR28aSMlcc0S/jrguE/aGEA+iqq3NDQatIjtB/Xnq2NYm+3Q yQUdEpO1TmKGdw8C0m2AO8yaVYFfIiws0Fj6zSvoVsqegk9OxFa0GrIaPMVGO+XGBWE2 ENMgSrzdxzLRV31uWXybh6WVmLP56UQ2pakdppxdprUu6YuXcf4fMWWDhYtMP6g8puEJ JdUvpxUYHlwx6v25rnYFXIEEH6zknWgzkzDW0/4myOLfKbrTIROyAcl6AK1BXPhguTW9 AXCN1THI0rrZTHnLVxou0Oq65ccNmPsfhwcDZOO4gY/aL8NIVLcLA5VR8aRLCIH44hql YMaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Q1Skr70S; 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 dn20si8777317ejc.125.2021.05.24.16.45.46; Mon, 24 May 2021 16:46:08 -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=Q1Skr70S; 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 S230114AbhEXXns (ORCPT + 99 others); Mon, 24 May 2021 19:43:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:50880 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229945AbhEXXmW (ORCPT ); Mon, 24 May 2021 19:42:22 -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=0tu41fI/tehEDdtk24Fc6V86f4NZ4fbmTVRxT+6xDtI=; b=Q1Skr70Skr7DkCUY/22aNjYfRK5j6dEk/M2CeFxGX/GcyUZUfYfO9SbmIeuQfsqXYx3Yvi Pr6mVr8Y6yRZBbT9aCLvCZj3h5M1ASQ7kM4t3823AfQCIZFjGz9eecjS3IrWfNcRifgmkm rYg+U1i04g/9svGprw6LzAJBcJGqZrY= 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=0tu41fI/tehEDdtk24Fc6V86f4NZ4fbmTVRxT+6xDtI=; b=gehOBtx2kTGbnW2lNeAX/zy5asReW9dnmEwJj9Ip4kKlrR9IwB1Cj7KZOt1x64G3Vn1RGI Bbve3XL4DpJRIXBw== Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9D871AF38; 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 16/26] mm, slub: move reset of c->page and freelist out of deactivate_slab() Date: Tue, 25 May 2021 01:39:36 +0200 Message-Id: <20210524233946.20352-17-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 deactivate_slab() removes the cpu slab by merging the cpu freelist with slab's freelist and putting the slab on the proper node's list. It also sets the respective kmem_cache_cpu pointers to NULL. By extracting the kmem_cache_cpu operations from the function, we can make it not dependent on disabled irqs. Also if we return a single free pointer from ___slab_alloc, we no longer have to load the slab page before deactivation or care if somebody preempted us and loaded a different slab page to our kmem_cache_cpu in the process. Signed-off-by: Vlastimil Babka --- mm/slub.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index bc7bee5d4bf2..cf855cd09802 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2163,10 +2163,13 @@ static void init_kmem_cache_cpus(struct kmem_cache *s) } /* - * Remove the cpu slab + * Finishes removing the cpu slab. Merges cpu's freelist with page's freelist, + * unfreezes the slabs and puts it on the proper list. + * Assumes the slab has been already safely taken away from kmem_cache_cpu + * by the caller. */ static void deactivate_slab(struct kmem_cache *s, struct page *page, - void *freelist, struct kmem_cache_cpu *c) + void *freelist) { enum slab_modes { M_NONE, M_PARTIAL, M_FULL, M_FREE }; struct kmem_cache_node *n = get_node(s, page_to_nid(page)); @@ -2295,9 +2298,6 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page, discard_slab(s, page); stat(s, FREE_SLAB); } - - c->page = NULL; - c->freelist = NULL; } /* @@ -2429,10 +2429,16 @@ static void put_cpu_partial(struct kmem_cache *s, struct page *page, int drain) static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c) { - stat(s, CPUSLAB_FLUSH); - deactivate_slab(s, c->page, c->freelist, c); + void *freelist = c->freelist; + struct page *page = c->page; + c->page = NULL; + c->freelist = NULL; c->tid = next_tid(c->tid); + + deactivate_slab(s, page, freelist); + + stat(s, CPUSLAB_FLUSH); } /* @@ -2712,7 +2718,10 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, local_irq_restore(flags); goto reread_page; } - deactivate_slab(s, page, c->freelist, c); + freelist = c->freelist; + c->page = NULL; + c->freelist = NULL; + deactivate_slab(s, page, freelist); local_irq_restore(flags); new_slab: @@ -2792,11 +2801,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, return_single: local_irq_save(flags); - if (unlikely(c->page)) - flush_slab(s, c); - c->page = page; - - deactivate_slab(s, page, get_freepointer(s, freelist), c); + deactivate_slab(s, page, get_freepointer(s, freelist)); local_irq_restore(flags); return freelist; } -- 2.31.1