Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp652063pxt; Thu, 5 Aug 2021 08:27:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzse5/pgk5ZRmhgqdk+eucYCiupjaDLypwE9qMjGLVMt6hk5cgppYfc5YhRyRpFx81ZdZQ X-Received: by 2002:a05:6402:445:: with SMTP id p5mr7353364edw.208.1628177239567; Thu, 05 Aug 2021 08:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628177239; cv=none; d=google.com; s=arc-20160816; b=xg0mZHtOQV7BhgcRTaxNdeOxMCOIGkZYrz9HOGmdeSShzKO23p06YjzEDffcPypgiV BjQWNKIliw97juzvUPvNT583UjstfwVmReF9y32xjZ8/H6V3STqPUgg3GhQy7MAC/V6f YVCYoYWcV2AqqoVnM1MipQQHC11n6Jcc+m3xPMz6dmBXcgsBQW4tLo8IXb0wA9JeZ4RW 9njEqtSwieI/3IweEM+VxV5bVlRDt9qGrSnpeGSvC0ejIwV398dfQNfMr+/sWFfdUX0m sMt0ToCGK/8jgq7v96xsMLK4tIWquQc+RqPxfRU+EJfiAzDQf4kwNWJB78WWHW6aueK2 gySg== 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=n3QiNJ/QMAZN9ZYtp4tRW+NNF81Tr3DK/uTNAsiP8E8=; b=gYKcvc1jNQ41SPd0lZghc2s34WpIXOgsINYpAH3BEAMSBOg0jFNS7C1RRmgriofCJ7 QUfBclWdT6m7AKjraRSsaHI/OaCVxsbx011TWxxzZoVHA2VJfWJcKWHVRcseNnio9S7L UiQ7O8+StGxobGsez2m9fhZ8rUPsqla2dwUmtJmof1hCyUJIsugY3RvfjhUv8Xl/ZJ8c LipV4VBo7rwn1mKqdXxzZhl4iv0QLiR8ML5dqDYd58vI7nOn9fV5AiTppMhulECcLZg8 4jhPth3XT21XLVzGD/YMpxJ/ew3zkmTEIAHmlmYQJDdhAH372p0tN5YCTve/yP/IHdFD D39g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="b/u//VYA"; 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 zo9si6121218ejb.468.2021.08.05.08.26.56; Thu, 05 Aug 2021 08:27:19 -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="b/u//VYA"; 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 S242267AbhHEPZU (ORCPT + 99 others); Thu, 5 Aug 2021 11:25:20 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:59334 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241973AbhHEPUX (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 B88EB2024F; 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=n3QiNJ/QMAZN9ZYtp4tRW+NNF81Tr3DK/uTNAsiP8E8=; b=b/u//VYAAub56xeKb3c91CGDSp7yFEGChtdEJuBlY0OJjfbEuzDdHMb06PJgElTbBs8YcT eWpwRcJvCamYouo5nfJlX5jFNJnYQlmNs0YGCp7PJ2F104hjmDQasjAGoix9nF5JGqbZ8z QnrZjTHx/qntIURDi9UyTZ+4VTpY2os= 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=n3QiNJ/QMAZN9ZYtp4tRW+NNF81Tr3DK/uTNAsiP8E8=; b=txUtdFaIYt4XnTRpeYA+8rqQl9d74csHDG7LIB4d63vYLqd/3EMeSLZD9PHCXUY4IkNYe/ Ne0c3wgKB9OQn1Cg== 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 893FB13DAC; Thu, 5 Aug 2021 15:20:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0M/pIKcBDGFDdQAAMHmgww (envelope-from ); Thu, 05 Aug 2021 15:20:07 +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 19/35] mm, slub: move reset of c->page and freelist out of deactivate_slab() Date: Thu, 5 Aug 2021 17:19:44 +0200 Message-Id: <20210805152000.12817-20-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 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 assign kmem_cache_cpu.page before deactivation or care if somebody preempted us and assigned a different 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 b4a62aa00ae2..10fd2eaf8125 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2192,10 +2192,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)); @@ -2324,9 +2327,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; } /* @@ -2451,10 +2451,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); } /* @@ -2739,7 +2745,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: @@ -2818,11 +2827,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.32.0