Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5155245pxj; Wed, 9 Jun 2021 10:21:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzupcfis02mAVLKuaP9RuAJaXPLBUu0q9vFN5iwEJ7nHcb++2gBFQekIbdoODb+EEqcS72l X-Received: by 2002:a17:906:a017:: with SMTP id p23mr924935ejy.460.1623259309018; Wed, 09 Jun 2021 10:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623259309; cv=none; d=google.com; s=arc-20160816; b=Dh1HrzFOaYtOq5Th7atO5N2zT7ywUm3ot8OxCObHzVIG/804sEdSkmbCk3FRPQBnWU DCQ2iAckbJQLyEND7AjkPqXK8i+TavVWuNhd799HUUmiZXw5hjDZV1Y9jcvpxG/DBafs 9ocO34XkVxv7h5w0GiDrWPmOKHn4i9yFeuK1I4on+sqkeEVYgT4jgSt0jdv1eaNK0Qou p51B9tadGcghiIK6AUUgY9WeoGfEehM9+7Y3p+QERA23FNMsD3M+gs964fTj7hVN/IK8 aL0z2byN0Z+ccfYq+ojzgha1VFznx5X70/QBwvQtiE3iyIEcpXzaxYK3OFLE+GrBKodt e/3Q== 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=KdJtA4YoE6ORCzqq1AaRT5tX40ysKLrzxToE3yWrpNc=; b=ly/FH5KwkE9Cb6nkDSIHvqnxL8gUAO+8HRkORq7BVXeVExJyc5mNT3Njz0xB1VJfRi +X8QOVVHyZOKeG4ucpVbyaMWPJJmZmDBEqM+92V3UIdI25cSd5QjK8t9PffVtj9wb0LO jgTgWVLvNv3GKHd0KQmBWLOqrglHB/5sx5IZbkbn3uqcEWoS84kEfQro5rub9Yjw4Fp3 QDeywlnIwM69wY3jYvncQ/3Mh+4E4GVcDwUxwzNMEmCMDB1z7Ruj/dopXP/Axo8seWLo yKZOBQ7ZMXAZ1JOL8ntOAx5lupVHPgKvecbSOkxDdakgdEzX0iNEfu4o/vasa1QRWmK4 Sh5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=eBbXi4Ck; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=eBbXi4Ck; dkim=neutral (no key) header.i=@suse.cz header.b=9Bh+xb3b; 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 l20si270970ejn.131.2021.06.09.10.21.24; Wed, 09 Jun 2021 10:21:49 -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=eBbXi4Ck; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=eBbXi4Ck; dkim=neutral (no key) header.i=@suse.cz header.b=9Bh+xb3b; 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 S239430AbhFILnD (ORCPT + 99 others); Wed, 9 Jun 2021 07:43:03 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:46968 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239170AbhFILlb (ORCPT ); Wed, 9 Jun 2021 07:41:31 -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-out2.suse.de (Postfix) with ESMTPS id 817DC1FD6E; Wed, 9 Jun 2021 11:39:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623238776; 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=KdJtA4YoE6ORCzqq1AaRT5tX40ysKLrzxToE3yWrpNc=; b=eBbXi4CkX7EMTUHOJqT8xqoB7XkTXBITgC8amj4Ft5A/zuTI+epj2MA2uNs/7r7BWwbr8Z SlS9+EJ0riQXBr0gUf6QENf1TU0lv2w/UQc1fihTkGXAlQWqtpLPz9kUTGZeS96IQNstRK TjPilB4ucJlLxv+7y6oDtv+Y4skJtXM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623238776; 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=KdJtA4YoE6ORCzqq1AaRT5tX40ysKLrzxToE3yWrpNc=; b=9Bh+xb3bwIRXHzIn2wniiILwcrIoB8irmjGvkKTb7yikdN5thh/m6p+drBo7EMwbtJWjHG p5UrXNRUSFAvq8Bw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 4D20311A98; Wed, 9 Jun 2021 11:39:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623238776; 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=KdJtA4YoE6ORCzqq1AaRT5tX40ysKLrzxToE3yWrpNc=; b=eBbXi4CkX7EMTUHOJqT8xqoB7XkTXBITgC8amj4Ft5A/zuTI+epj2MA2uNs/7r7BWwbr8Z SlS9+EJ0riQXBr0gUf6QENf1TU0lv2w/UQc1fihTkGXAlQWqtpLPz9kUTGZeS96IQNstRK TjPilB4ucJlLxv+7y6oDtv+Y4skJtXM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623238776; 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=KdJtA4YoE6ORCzqq1AaRT5tX40ysKLrzxToE3yWrpNc=; b=9Bh+xb3bwIRXHzIn2wniiILwcrIoB8irmjGvkKTb7yikdN5thh/m6p+drBo7EMwbtJWjHG p5UrXNRUSFAvq8Bw== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id 6EFaEniowGD6XgAALh3uQQ (envelope-from ); Wed, 09 Jun 2021 11:39:36 +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 25/34] mm, slub: detach percpu partial list in unfreeze_partials() using this_cpu_cmpxchg() Date: Wed, 9 Jun 2021 13:38:54 +0200 Message-Id: <20210609113903.1421-26-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 Instead of relying on disabled irqs for atomicity when detaching the percpu partial list, we can use this_cpu_cmpxchg() and detach without irqs disabled. However, unfreeze_partials() can be also called from another cpu on behalf of a cpu that is being offlined, so we need to restructure the code accordingly: - __unfreeze_partials() is the bulk of unfreeze_partials() that processes the detached percpu partial list - unfreeze_partials() uses this_cpu_cmpxchg() to detach list from current cpu - unfreeze_partials_cpu() is to be called for the offlined cpu so it needs no protection, 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 it Signed-off-by: Vlastimil Babka --- mm/slub.c | 77 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 22 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 3e0ec7211d55..0867801e3086 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2287,25 +2287,15 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page, } } -/* - * 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 *partial_page) +{ struct kmem_cache_node *n = NULL, *n2 = NULL; - struct page *page, *partial_page, *discard_page = NULL; + struct page *page, *discard_page = NULL; unsigned long flags; local_irq_save(flags); - partial_page = slub_percpu_partial(c); - c->partial = NULL; - while (partial_page) { struct page new; struct page old; @@ -2360,10 +2350,49 @@ static void unfreeze_partials(struct kmem_cache *s, discard_slab(s, page); stat(s, FREE_SLAB); } +} -#endif /* CONFIG_SLUB_CPU_PARTIAL */ +/* + * Unfreeze all the cpu partial slabs. + * + * This function must be called with preemption or migration + * disabled. + */ +static void unfreeze_partials(struct kmem_cache *s) +{ + struct page *partial_page; + + do { + partial_page = this_cpu_read(s->cpu_slab->partial); + + } while (partial_page && + this_cpu_cmpxchg(s->cpu_slab->partial, partial_page, NULL) + != partial_page); + + if (partial_page) + __unfreeze_partials(s, partial_page); } +static void unfreeze_partials_cpu(struct kmem_cache *s, + struct kmem_cache_cpu *c) +{ + struct page *partial_page; + + partial_page = slub_percpu_partial(c); + c->partial = NULL; + + if (partial_page) + __unfreeze_partials(s, partial_page); +} + +#else /* CONFIG_SLUB_CPU_PARTIAL */ + +static void unfreeze_partials(struct kmem_cache *s) { } +static 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) into a * partial page slot if available. @@ -2392,7 +2421,7 @@ static void put_cpu_partial(struct kmem_cache *s, struct 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 = NULL; pobjects = 0; pages = 0; @@ -2427,11 +2456,6 @@ static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c) stat(s, CPUSLAB_FLUSH); } -/* - * 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 = per_cpu_ptr(s->cpu_slab, cpu); @@ -2439,14 +2463,23 @@ static inline void __flush_cpu_slab(struct kmem_cache *s, int cpu) if (c->page) flush_slab(s, c); - unfreeze_partials(s, c); + unfreeze_partials_cpu(s, c); } +/* + * Flush cpu slab. + * + * Called from IPI handler with interrupts disabled. + */ static void flush_cpu_slab(void *d) { struct kmem_cache *s = d; + struct kmem_cache_cpu *c = this_cpu_ptr(s->cpu_slab); - __flush_cpu_slab(s, smp_processor_id()); + if (c->page) + flush_slab(s, c); + + unfreeze_partials(s); } static bool has_cpu_slab(int cpu, void *info) -- 2.31.1