Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5154968pxj; Wed, 9 Jun 2021 10:21:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzH1I4XprnLGvf2q9RMwjjN7OgWS8kQDilrL3EH3vF2rA6VVqkFKCjQJkCxPhdrzgWv5ucs X-Received: by 2002:a17:906:988a:: with SMTP id zc10mr908167ejb.62.1623259288675; Wed, 09 Jun 2021 10:21:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623259288; cv=none; d=google.com; s=arc-20160816; b=ahrNWuFCQvz3zXsNPI0cIzq0JnuO6sgfvB/3Jgcu8Jz3lPxb4THcJAzA9akGQBMmz9 eXgDQ3DCyYlF6M7XlWfE4zsepckMOfkFLG8sGo1u1l2de9X9rS+S90KcWNVZCasx1/r0 Vfy8ISsevLH76z9h/P3FCL9F7jQal+7rLD0SBlxdj+868yM793A9PscFJ9P/PNQSynBv GHGbYvIh4EvjuddPNOTMJTrn4XpClFS5IsXWprLgi0Pz7cGSY7+JDvOF8acAeevupSGZ 5c8hPtO5y7Ex3FR9d9VNXv/S9FMl/WVbriHY7eZ3f0BIqcitbvvgKArLruBSx8bkPtoB sbjg== 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=Cqt0VXEchackCh9ETD6KPbwS56wP8+xgoNpRJiEk95Q=; b=mfHY/Sm0VoXaWM1mqUirKzYNJZHteUYt4a9ZB3jkllXq9OVVUibl2/TP21jIvFwKeH 2wCfODBcpfuFyNiW+HRh6A0M8Bf6Z3CqmeAscLG11wEfJ7qKanQLXyD3fhkkURPk4zVo 8v8xwfvOogIhFlqU+wjbj7/vDOa9BtbQIUzF2B1U8q2+QzHi5sRtw1kXAxmlneMgQMxb sTWFweiWq2gjxBBdH82rKpKHI94FVgZVZITCUzCdgJcbahiKcoaKnZ28jjDKAkwG8FLI oHRRNFsPjCo7rOPo9Ywrr+vEV4qPJyXSp8KDKkpQ9Fv9GpuzkqGUTTUvgHlQR/d+kEkD 69Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=gpYYQAKt; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=okCO1DzM; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=gpYYQAKt; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 14si280832eji.468.2021.06.09.10.21.04; Wed, 09 Jun 2021 10:21:28 -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=gpYYQAKt; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=okCO1DzM; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=gpYYQAKt; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 S239316AbhFILmt (ORCPT + 99 others); Wed, 9 Jun 2021 07:42:49 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:47100 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239163AbhFILlb (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 4C0CC1FD6B; Wed, 9 Jun 2021 11:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623238775; 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=Cqt0VXEchackCh9ETD6KPbwS56wP8+xgoNpRJiEk95Q=; b=gpYYQAKtd2Lwif+d4UZBHLgSL8vuuV+4zM4kQ1Ln6B6RZo4EnFEmpmcKrw2lXGLdfKpb+c SMseFmoRl3zVfWtFjvyKxgofvLyau2t+voqxPqCHPcoq+ZnWfH2T2fq6eGqW393QZmaov2 1zwd7rQt7dwHJtDDfd34O/+c0FrWpXo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623238775; 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=Cqt0VXEchackCh9ETD6KPbwS56wP8+xgoNpRJiEk95Q=; b=okCO1DzMKaLPjSNK2ZYSOvomn80slibDBV2mV+Y/ePmltdzlc1O1KSDFI5Ln4UV+YEhYzz EgVrDFJlomag1GBw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 1E02811A98; Wed, 9 Jun 2021 11:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623238775; 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=Cqt0VXEchackCh9ETD6KPbwS56wP8+xgoNpRJiEk95Q=; b=gpYYQAKtd2Lwif+d4UZBHLgSL8vuuV+4zM4kQ1Ln6B6RZo4EnFEmpmcKrw2lXGLdfKpb+c SMseFmoRl3zVfWtFjvyKxgofvLyau2t+voqxPqCHPcoq+ZnWfH2T2fq6eGqW393QZmaov2 1zwd7rQt7dwHJtDDfd34O/+c0FrWpXo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623238775; 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=Cqt0VXEchackCh9ETD6KPbwS56wP8+xgoNpRJiEk95Q=; b=okCO1DzMKaLPjSNK2ZYSOvomn80slibDBV2mV+Y/ePmltdzlc1O1KSDFI5Ln4UV+YEhYzz EgVrDFJlomag1GBw== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id MMjdBneowGD6XgAALh3uQQ (envelope-from ); Wed, 09 Jun 2021 11:39:35 +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 19/34] mm, slub: move reset of c->page and freelist out of deactivate_slab() Date: Wed, 9 Jun 2021 13:38:48 +0200 Message-Id: <20210609113903.1421-20-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 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 6f894d1e84d6..8b0b975bfa36 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2149,10 +2149,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)); @@ -2281,9 +2284,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; } /* @@ -2408,10 +2408,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); } /* @@ -2696,7 +2702,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: @@ -2775,11 +2784,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