From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B122AC4338F for ; Thu, 5 Aug 2021 15:21:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 59C3160E53 for ; Thu, 5 Aug 2021 15:21:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 59C3160E53 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 986566B0085; Thu, 5 Aug 2021 11:20:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8733D8D0006; Thu, 5 Aug 2021 11:20:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 565846B0085; Thu, 5 Aug 2021 11:20:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id C89076B0099 for ; Thu, 5 Aug 2021 11:20:10 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8C9AA1F042 for ; Thu, 5 Aug 2021 15:20:10 +0000 (UTC) X-FDA: 78441387780.35.745716A Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf05.hostedemail.com (Postfix) with ESMTP id 0AB0F502FE5D for ; Thu, 5 Aug 2021 15:20:09 +0000 (UTC) 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 DB10420254; Thu, 5 Aug 2021 15:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1628176808; 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=0tHKVexUODlCjCDTjxePVAtF0VzjMMYB15eSPQdP/ms=; b=F0BXkna1+rv/gCKbvbzswSMMWr3LY8vqv/XDO23+e8nRS7wkUB0jmez+sa/GfAQc43ew8m itVofpbBA5TsztNBjc1DT2jV4UxSut8I4lSD3Oaoi4UFpe/hWUrVd2mjTmUYbq6QHZFBFm 7VG1Kzt9QhSdzXDSoQpJQczOcASrRfk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1628176808; 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=0tHKVexUODlCjCDTjxePVAtF0VzjMMYB15eSPQdP/ms=; b=IiHdMSXDN/TnwmCg1vUS1OtVOw7Ao4E3/246RyjmMbBNTpyQpoBAeEWSkmnOex2Q8c3ZKp TV+FO2zfQYMtFHCg== 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 A593013DAC; Thu, 5 Aug 2021 15:20:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GATfJ6gBDGFDdQAAMHmgww (envelope-from ); Thu, 05 Aug 2021 15:20:08 +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 25/35] mm, slub: separate detaching of partial list in unfreeze_partials() from unfreezing Date: Thu, 5 Aug 2021 17:19:50 +0200 Message-Id: <20210805152000.12817-26-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 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0AB0F502FE5D Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=F0BXkna1; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=IiHdMSXD; dmarc=none; spf=pass (imf05.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Stat-Signature: crjr36qjq79u1uamj4pkrdtdcdrbg4w9 X-HE-Tag: 1628176809-672803 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Unfreezing partial list can be split to two phases - detaching the list f= rom struct kmem_cache_cpu, and processing the list. The whole operation does = not need to be protected by disabled irqs. Restructure the code to separate t= he detaching (with disabled irqs) and unfreezing (with irq disabling to be r= educed in the next patch). Also, unfreeze_partials() can be called from another cpu on behalf of a c= pu that is being offlined, where disabling irqs on the local cpu has no sens= e, so restructure the code as follows: - __unfreeze_partials() is the bulk of unfreeze_partials() that processes= the detached percpu partial list - unfreeze_partials() detaches list from current cpu with irqs disabled a= nd calls __unfreeze_partials() - unfreeze_partials_cpu() is to be called for the offlined cpu so it need= s no irq disabling, and is called from __flush_cpu_slab() - flush_cpu_slab() is for the local cpu thus it needs to call unfreeze_partials(). So it can't simply call __flush_cpu_slab(smp_processor_id()) anymore and we have to open-code t= he proper calls. Signed-off-by: Vlastimil Babka --- mm/slub.c | 73 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 984173ce8465..c8637150bf28 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2330,25 +2330,15 @@ static void deactivate_slab(struct kmem_cache *s,= struct page *page, } } =20 -/* - * Unfreeze all the cpu partial slabs. - * - * This function must be called with preemption or migration - * disabled with c local to the cpu. - */ -static void unfreeze_partials(struct kmem_cache *s, - struct kmem_cache_cpu *c) -{ #ifdef CONFIG_SLUB_CPU_PARTIAL +static void __unfreeze_partials(struct kmem_cache *s, struct page *parti= al_page) +{ struct kmem_cache_node *n =3D NULL, *n2 =3D NULL; - struct page *page, *partial_page, *discard_page =3D NULL; + struct page *page, *discard_page =3D NULL; unsigned long flags; =20 local_irq_save(flags); =20 - partial_page =3D slub_percpu_partial(c); - c->partial =3D NULL; - while (partial_page) { struct page new; struct page old; @@ -2403,10 +2393,45 @@ static void unfreeze_partials(struct kmem_cache *= s, discard_slab(s, page); stat(s, FREE_SLAB); } +} =20 -#endif /* CONFIG_SLUB_CPU_PARTIAL */ +/* + * Unfreeze all the cpu partial slabs. + */ +static void unfreeze_partials(struct kmem_cache *s) +{ + struct page *partial_page; + unsigned long flags; + + local_irq_save(flags); + partial_page =3D this_cpu_read(s->cpu_slab->partial); + this_cpu_write(s->cpu_slab->partial, NULL); + local_irq_restore(flags); + + if (partial_page) + __unfreeze_partials(s, partial_page); } =20 +static void unfreeze_partials_cpu(struct kmem_cache *s, + struct kmem_cache_cpu *c) +{ + struct page *partial_page; + + partial_page =3D slub_percpu_partial(c); + c->partial =3D NULL; + + if (partial_page) + __unfreeze_partials(s, partial_page); +} + +#else /* CONFIG_SLUB_CPU_PARTIAL */ + +static inline void unfreeze_partials(struct kmem_cache *s) { } +static inline void unfreeze_partials_cpu(struct kmem_cache *s, + struct kmem_cache_cpu *c) { } + +#endif /* CONFIG_SLUB_CPU_PARTIAL */ + /* * Put a page that was just frozen (in __slab_free|get_partial_node) int= o a * partial page slot if available. @@ -2435,7 +2460,7 @@ static void put_cpu_partial(struct kmem_cache *s, s= truct page *page, int drain) * partial array is full. Move the existing * set to the per node partial list. */ - unfreeze_partials(s, this_cpu_ptr(s->cpu_slab)); + unfreeze_partials(s); oldpage =3D NULL; pobjects =3D 0; pages =3D 0; @@ -2470,11 +2495,6 @@ static inline void flush_slab(struct kmem_cache *s= , struct kmem_cache_cpu *c) stat(s, CPUSLAB_FLUSH); } =20 -/* - * Flush cpu slab. - * - * Called from IPI handler with interrupts disabled. - */ static inline void __flush_cpu_slab(struct kmem_cache *s, int cpu) { struct kmem_cache_cpu *c =3D per_cpu_ptr(s->cpu_slab, cpu); @@ -2482,14 +2502,23 @@ static inline void __flush_cpu_slab(struct kmem_c= ache *s, int cpu) if (c->page) flush_slab(s, c); =20 - unfreeze_partials(s, c); + unfreeze_partials_cpu(s, c); } =20 +/* + * Flush cpu slab. + * + * Called from IPI handler with interrupts disabled. + */ static void flush_cpu_slab(void *d) { struct kmem_cache *s =3D d; + struct kmem_cache_cpu *c =3D this_cpu_ptr(s->cpu_slab); =20 - __flush_cpu_slab(s, smp_processor_id()); + if (c->page) + flush_slab(s, c); + + unfreeze_partials(s); } =20 static bool has_cpu_slab(int cpu, void *info) --=20 2.32.0