From patchwork Tue Oct 31 14:07:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13441575 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DE1DC4167D for ; Tue, 31 Oct 2023 14:09:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1AAE6B0301; Tue, 31 Oct 2023 10:09:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC9DB6B0300; Tue, 31 Oct 2023 10:09:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96A9B6B0301; Tue, 31 Oct 2023 10:09:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 883F26B02FE for ; Tue, 31 Oct 2023 10:09:05 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D56AF1A070D for ; Tue, 31 Oct 2023 14:09:04 +0000 (UTC) X-FDA: 81405938208.26.92A9464 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) by imf22.hostedemail.com (Postfix) with ESMTP id C35C3C000C for ; Tue, 31 Oct 2023 14:09:02 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=fWm3Ia9W; spf=pass (imf22.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.186 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698761342; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=V/1IQ8DC4Ww2WANT0Yk1WGGMP6T1XolwvFVe/nWWtdo=; b=N60ZHEKevHrWvbq+lRHU3Wp3YoVlWb1QkQwRhOIoC0XZ+9MuyYjM/8IZXdr4sQa2AZueCT gsjFjx9ivWC8wEnwK8T1mAsm4kl15/kg1H9wi73U88uOT2rI5rWOQwSkp4aEFCuV6LbvPE CzQDzuMSg3aL9Zn4BStGEoEnrJ13pwE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698761343; a=rsa-sha256; cv=none; b=QkXwCIbV11zApFdhXra522+Eq7pBQfqZiaNMpp1ABNKLmQG4+DKwfUZluUL9yr6gWn7SRL UWIuOt6xML/6ozUHl1UdiHCX6DfqXglBABdLyCsoTx2VG/kX8Rt0irJqbNCmr38wGQ+oaI J1euPjFflgpf4hTXBVp223BCAxcRoCc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=fWm3Ia9W; spf=pass (imf22.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.186 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698761341; h=from:from:reply-to:subject:subject: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=V/1IQ8DC4Ww2WANT0Yk1WGGMP6T1XolwvFVe/nWWtdo=; b=fWm3Ia9WLFuFmGWFVj3nkTO3KKIcArYI3sKwoNpxt4Vp+VSnp85jAdULf4fwS1xOUGBFRy qaL4xq+9jHvu/YO3QBypb2sb88cVvTthrSNRtZkaROqU8A7pGtYB9RLWsXKVwXBPAiXyCD wIoAlyBL54p89iiOAU9sfE8NjzIGnzM= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.org, willy@infradead.org Cc: rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou Subject: [RFC PATCH v4 1/9] slub: Reflow ___slab_alloc() Date: Tue, 31 Oct 2023 14:07:33 +0000 Message-Id: <20231031140741.79387-2-chengming.zhou@linux.dev> In-Reply-To: <20231031140741.79387-1-chengming.zhou@linux.dev> References: <20231031140741.79387-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: C35C3C000C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ef6a9watcm7zcgcxec19j9da8setied9 X-HE-Tag: 1698761342-93511 X-HE-Meta: U2FsdGVkX19uI8C8/qoaLSElIaZdPJnJD6QzX3GqIGhNNCGEKXPQXFu2Zm8aC29VVa9G6OZhqu99ygvTzeaisDdo2eFsxzVq5FQeByF1aG3Z6DQcFsy3Khs8dG5ITl8bFR9PNlcAYKQ0FFZMv5w5sKHQEvQNdK5WiOzljHWgLK/21msRKJJ7JWcZzTF6apkmj//pY3k9WREUfS4mpH4c67AwAw9HKLblcRaso8CMq2r9d8qL9AqXZylGyQku30bygtCrBUONpLK3IehTGdDwBmWWsau/A+6srSGo3/H3kEsthCb/0yqlQaH7blKSu58VasiRe1WiJeI8q/G2gACnod0t8KL916qIuhTSEMLxZxu3uOfpMGiDSeo4w8ahbmSXTJrdIUOQVut9z4aPKla/LjTTvIvrWy4gicyY8hRYkiZRqjA11OEx9lFUtywxIzV9bslp5XxHgIc867KSfxYt5+e0SrYk6bF7q0WFi4ezdE+B/uSk6NGkGqHlzOgah1pgBI/VR9EP9RwADIBf2JPROOGg+C7qLT+YOMzPKalSluqc1F7AQyTEBPC/VOuMNP0pZ6WZ5ZyHSK+wAeiWHFQLfn3Dya/62a3kG3jjYYy1zWLBuPD0Dlo3QcmdPvFudKALYVYVRsG73wMYfIJLeVj2FOx4xtPQF2XnPMYXqY4OfHWpKLv9c8hRvx1DiZTEFdo51njUtyVEr8dKUlvs/x96e2uyviYmgtJjKmk9dr0Ej6yHDVteB6faGZYbuCfSBWmm0Nx5bEQb+8eeMRxfmYVYxgoVB81boa9UNLocxi5Fu6iRyIn8BMkxwxPU7SwQrJgdmcVxUTq0ugOG+Yjgm7yjaDXIQragN6l4wskqFQcdSZcP7Lmpe4f/W1VLciH6pkSuJ2rbmOEMVEnYZuAPxlALwACnSRla1Cojcy0AChP39jMbFzr12FBePhA1TPyRV1ayJ4IsgEJIrz1uFPAkrL+ MFls9MRF wFpt/PhRjb+uNG6E0q8IB8jH5k1epkdtq0rsLbkJmeM/4JkIfsuFq6AAqXOyb/c91ctWuFpdQNIlzNIzi5YGX42jEtsuOD27fcbz4mLZT7HOnTLiSvjSRH4BiN5Tlq/zlRZd5cWEDVCxz5zEwE+O2Ph5W8Nh3GypYNRhJ8+sEO5T7fUsJ053+Yzvh1d4ChzxD4/esfdMU8OnrEnJFHHbcaK4sXRqv9KYpK05qwX2qPrKQ9Oll1A9ldu44Dnp8etLizYx7Y/7K3bnoTgUatwrs975qWw== 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: List-Subscribe: List-Unsubscribe: From: Chengming Zhou The get_partial() interface used in ___slab_alloc() may return a single object in the "kmem_cache_debug(s)" case, in which we will just return the "freelist" object. Move this handling up to prepare for later changes. And the "pfmemalloc_match()" part is not needed for node partial slab, since we already check this in the get_partial_node(). Signed-off-by: Chengming Zhou Reviewed-by: Vlastimil Babka --- mm/slub.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 63d281dfacdb..0b0fdc8c189f 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3216,8 +3216,21 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, pc.slab = &slab; pc.orig_size = orig_size; freelist = get_partial(s, node, &pc); - if (freelist) - goto check_new_slab; + if (freelist) { + if (kmem_cache_debug(s)) { + /* + * For debug caches here we had to go through + * alloc_single_from_partial() so just store the + * tracking info and return the object. + */ + if (s->flags & SLAB_STORE_USER) + set_track(s, freelist, TRACK_ALLOC, addr); + + return freelist; + } + + goto retry_load_slab; + } slub_put_cpu_ptr(s->cpu_slab); slab = new_slab(s, gfpflags, node); @@ -3253,20 +3266,6 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, inc_slabs_node(s, slab_nid(slab), slab->objects); -check_new_slab: - - if (kmem_cache_debug(s)) { - /* - * For debug caches here we had to go through - * alloc_single_from_partial() so just store the tracking info - * and return the object - */ - if (s->flags & SLAB_STORE_USER) - set_track(s, freelist, TRACK_ALLOC, addr); - - return freelist; - } - if (unlikely(!pfmemalloc_match(slab, gfpflags))) { /* * For !pfmemalloc_match() case we don't load freelist so that From patchwork Tue Oct 31 14:07:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13441576 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2472CC4332F for ; Tue, 31 Oct 2023 14:09:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACD3A6B0300; Tue, 31 Oct 2023 10:09:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7CE26B0302; Tue, 31 Oct 2023 10:09:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91C916B0303; Tue, 31 Oct 2023 10:09:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7F2206B0300 for ; Tue, 31 Oct 2023 10:09:07 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 59318B5C51 for ; Tue, 31 Oct 2023 14:09:07 +0000 (UTC) X-FDA: 81405938334.11.02F9EA8 Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf09.hostedemail.com (Postfix) with ESMTP id 56179140012 for ; Tue, 31 Oct 2023 14:09:05 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=TXFp5ZrS; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf09.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698761345; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GvFpTjudBUawLgUZhfA4XumfhFt8DHF3SUizR1gsSN0=; b=Y+8dJWvmn/03HpLme0xKiKlJL+tMa0RbbYu8M8x/obwfcVKgBztLt0RavyYEMGTJebpVoX TQJORKz8Cwq3ae+V7imfnr85+m1t0O5QZASb4nuhR80+faYbrwq9i+pFrocV8oglszIFsq lNxlTWtFiP3ImKOarxbY39YZlkIeTIc= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=TXFp5ZrS; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf09.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698761345; a=rsa-sha256; cv=none; b=3pgo7PkdcEfeyblr5T+OB7WpdC3kGP4TmmWBZb6XXHBxmy1/T8L0eBtU03yx2OriFZ7CW6 KEIwfp6h/Su/AfcHqykRnQDgKZuTwpyD8sgVFBtz56ugjXZdy5vgkRY2uVkyoUy/FQ/0w2 VmdiFv4pKOnRA/E1s0c3ZENEB+yWhNw= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698761343; h=from:from:reply-to:subject:subject: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=GvFpTjudBUawLgUZhfA4XumfhFt8DHF3SUizR1gsSN0=; b=TXFp5ZrS2RLrdK40RbVab8YMC1O20QrLDJHbtWDv0h7N6MLbta00vjmZGm7DnKTG5RBgxq h6YdjNWfhUe2h4dCRzYErdTwo+9MGcYO5LIMetNw+He4mdD9iExl/e/+7gz+qY3n+fIq95 TDslQnTghxmWva6tPEM6zC6/ZgI5/0A= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.org, willy@infradead.org Cc: rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou Subject: [RFC PATCH v4 2/9] slub: Change get_partial() interfaces to return slab Date: Tue, 31 Oct 2023 14:07:34 +0000 Message-Id: <20231031140741.79387-3-chengming.zhou@linux.dev> In-Reply-To: <20231031140741.79387-1-chengming.zhou@linux.dev> References: <20231031140741.79387-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 56179140012 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 31h1tcwb589zfs69sc6uhe6ma4rt67rp X-HE-Tag: 1698761345-805416 X-HE-Meta: U2FsdGVkX18nqRPN1gInOiMWpBeuvckDrM4Y2j1IaQoputiu82+ig4XAMxkAhwmyThOTOq2N6QwLSPF3f3PsW4CymDy6SqLCmRtTv9URcMlDYeiI0GCHtzCLKRngOdTF9zhhY+hvaUVlw59Lnce5xQtXEZdIefBbN5YeNaS/VhntZLirEZEIdAgse3f6JSbczKsQ1Z4i+JUxv9qnVlR42y6DVGbpmU+bI8lWJ8GBMVwEMO23LpTX5+tfIoqKv5jrKz4P+WHzYJcSjtyE/F2lnSbxdDjwl0g7W8sS+1PzdcPz1hpBdsp7A2LN4icNQgonELGXrIns+T4ZpuZMNUr7Ag3DalxdTsphjmlEp9kPhouuO4FNoGor3+7/5ZIcmajjb1Ibpy6qIlGvWiyP9z5/bUpUUGMkB5QVJiCVzTzIMxfAgsw7MGJcpUJTQTNO/bKnmTuN0+OdA/s3oUsOVACpr2VNt41vMh1EW1wDtNb9bMw1JG61TzuRT4plKWfW5KYrZrMyHgcmNt+A2orToqtSBcTMRF5C+vtwz3cDHv6hIKsqHbl2jv/jaNlF1RdNqPYrJ2oLw6nkcoDgsuRcFhXK4oOzgdumYEH4U1KT8/Jq0i1VsxU1D6FZR4CaBAjIwoZG8K+fQlci9ME75MQRCrgWKIBEs3klj0d9ukjXvlF74dvSdn0+g873wmmUHjPMZtLJWPKLIHrvBIJqtJ9ZKepTl4ykn5DYlMdHKJRIQTWueXZ9MiK45MwS3FA5yXGIEkAC3IBD8/7kXbNmUzhOcxXvzMalbNb2IZbY0SIGTQk8mL4udDpn7D9CzA6QxWOejcnoVgrFYsqIlq6UYCaA1RpLmH2+bE/Yt+/jWNRe1ARNSwcFDLMXzPLz7nvJ7f8VO3XVH+XZHRoD2GqPy8WDE78tsJFK2WR0yf5iwI2NWYipjt86WTMKO+ggUOMwp7Dc/DedPQVLaWG+IOVPmBqQin+ ye0UZeV5 LbeHAe5U5suanZoX8pSeOy9dH9fDAa+Bgp2UZAPmUR2VvWUehrATLyh9syHBA1hwKfi16pqWNfKHcUQPNBWdmVDgK9hMnVDtY4rjmehJOgpWDduPRbRqVpy7NG3Ky/Vt481VTPaPxi2tluzNtan3O04DXEi1w81GeNoZJSgzcutG558wx4ld7XvZZ5Php0RQKPn+UQlA2GYqfySTNlJp2P3iDTuP0pPI8U8STpcdTHTGW0vVVLsh1j0wfNUpi0C1Lfofn 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: List-Subscribe: List-Unsubscribe: From: Chengming Zhou We need all get_partial() related interfaces to return a slab, instead of returning the freelist (or object). Use the partial_context.object to return back freelist or object for now. This patch shouldn't have any functional changes. Suggested-by: Vlastimil Babka Signed-off-by: Chengming Zhou Reviewed-by: Vlastimil Babka --- mm/slub.c | 63 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 0b0fdc8c189f..03384cd965c5 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -204,9 +204,9 @@ DEFINE_STATIC_KEY_FALSE(slub_debug_enabled); /* Structure holding parameters for get_partial() call chain */ struct partial_context { - struct slab **slab; gfp_t flags; unsigned int orig_size; + void *object; }; static inline bool kmem_cache_debug(struct kmem_cache *s) @@ -2269,10 +2269,11 @@ static inline bool pfmemalloc_match(struct slab *slab, gfp_t gfpflags); /* * Try to allocate a partial slab from a specific node. */ -static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n, - struct partial_context *pc) +static struct slab *get_partial_node(struct kmem_cache *s, + struct kmem_cache_node *n, + struct partial_context *pc) { - struct slab *slab, *slab2; + struct slab *slab, *slab2, *partial = NULL; void *object = NULL; unsigned long flags; unsigned int partial_slabs = 0; @@ -2288,27 +2289,28 @@ static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n, spin_lock_irqsave(&n->list_lock, flags); list_for_each_entry_safe(slab, slab2, &n->partial, slab_list) { - void *t; - if (!pfmemalloc_match(slab, pc->flags)) continue; if (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) { object = alloc_single_from_partial(s, n, slab, pc->orig_size); - if (object) + if (object) { + partial = slab; + pc->object = object; break; + } continue; } - t = acquire_slab(s, n, slab, object == NULL); - if (!t) + object = acquire_slab(s, n, slab, object == NULL); + if (!object) break; - if (!object) { - *pc->slab = slab; + if (!partial) { + partial = slab; + pc->object = object; stat(s, ALLOC_FROM_PARTIAL); - object = t; } else { put_cpu_partial(s, slab, 0); stat(s, CPU_PARTIAL_NODE); @@ -2324,20 +2326,21 @@ static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n, } spin_unlock_irqrestore(&n->list_lock, flags); - return object; + return partial; } /* * Get a slab from somewhere. Search in increasing NUMA distances. */ -static void *get_any_partial(struct kmem_cache *s, struct partial_context *pc) +static struct slab *get_any_partial(struct kmem_cache *s, + struct partial_context *pc) { #ifdef CONFIG_NUMA struct zonelist *zonelist; struct zoneref *z; struct zone *zone; enum zone_type highest_zoneidx = gfp_zone(pc->flags); - void *object; + struct slab *slab; unsigned int cpuset_mems_cookie; /* @@ -2372,8 +2375,8 @@ static void *get_any_partial(struct kmem_cache *s, struct partial_context *pc) if (n && cpuset_zone_allowed(zone, pc->flags) && n->nr_partial > s->min_partial) { - object = get_partial_node(s, n, pc); - if (object) { + slab = get_partial_node(s, n, pc); + if (slab) { /* * Don't check read_mems_allowed_retry() * here - if mems_allowed was updated in @@ -2381,7 +2384,7 @@ static void *get_any_partial(struct kmem_cache *s, struct partial_context *pc) * between allocation and the cpuset * update */ - return object; + return slab; } } } @@ -2393,17 +2396,18 @@ static void *get_any_partial(struct kmem_cache *s, struct partial_context *pc) /* * Get a partial slab, lock it and return it. */ -static void *get_partial(struct kmem_cache *s, int node, struct partial_context *pc) +static struct slab *get_partial(struct kmem_cache *s, int node, + struct partial_context *pc) { - void *object; + struct slab *slab; int searchnode = node; if (node == NUMA_NO_NODE) searchnode = numa_mem_id(); - object = get_partial_node(s, get_node(s, searchnode), pc); - if (object || node != NUMA_NO_NODE) - return object; + slab = get_partial_node(s, get_node(s, searchnode), pc); + if (slab || node != NUMA_NO_NODE) + return slab; return get_any_partial(s, pc); } @@ -3213,10 +3217,10 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, new_objects: pc.flags = gfpflags; - pc.slab = &slab; pc.orig_size = orig_size; - freelist = get_partial(s, node, &pc); - if (freelist) { + slab = get_partial(s, node, &pc); + if (slab) { + freelist = pc.object; if (kmem_cache_debug(s)) { /* * For debug caches here we had to go through @@ -3408,12 +3412,11 @@ static void *__slab_alloc_node(struct kmem_cache *s, void *object; pc.flags = gfpflags; - pc.slab = &slab; pc.orig_size = orig_size; - object = get_partial(s, node, &pc); + slab = get_partial(s, node, &pc); - if (object) - return object; + if (slab) + return pc.object; slab = new_slab(s, gfpflags, node); if (unlikely(!slab)) { From patchwork Tue Oct 31 14:07:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13441577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29ADAC4332F for ; Tue, 31 Oct 2023 14:09:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B68A86B0303; Tue, 31 Oct 2023 10:09:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF0176B0304; Tue, 31 Oct 2023 10:09:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 991736B0305; Tue, 31 Oct 2023 10:09:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7DF316B0303 for ; Tue, 31 Oct 2023 10:09:10 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 54BDD140328 for ; Tue, 31 Oct 2023 14:09:10 +0000 (UTC) X-FDA: 81405938460.29.499CE55 Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) by imf21.hostedemail.com (Postfix) with ESMTP id 25CAB1C002E for ; Tue, 31 Oct 2023 14:09:07 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=e0oJj347; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf21.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698761348; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=A++jOVGS7LIP72VwRB52HksoP76pYwnYqPVPh8XlVaY=; b=o+KuPsWDf8rssweeZa7mdzU1RK1+aENRmGTwcHtOWJs+RHqz5TB4Ep+hMHQLdrzULqQXQG IozOwpSa//m/Ny0o4z8mt/w3z8c5BxtU5JEyd5RNlvAjcMz1TV0zVe3yafMojPRpGZv8ne tUGf7sLCbRwGoRL2r9j9+46lZ/wv4hs= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=e0oJj347; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf21.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698761348; a=rsa-sha256; cv=none; b=HWZlxor2hRQW/i3S8nX9tJtoC7YB6xt0lmMaZ/HMj4OscYdLJwWXhDvPUJzvcZEWrZZlKa a7l8lA0cH/GX/tXWyNMcEu9JEEQKgF7fms5/cXxjkFmD1O8NWSmlgLAwsgLCBDDVmHRxFj eFSO4spFdEmhyZFYTEbEnBTNxLJkoLk= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698761346; h=from:from:reply-to:subject:subject: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=A++jOVGS7LIP72VwRB52HksoP76pYwnYqPVPh8XlVaY=; b=e0oJj347aPZSwbHKIh3vXLsSkKARGwrOKNnsPyGmHd3T7kZSTXQX3ogXWfbcaQarI3N9T+ K6a8+/g2w/Lvo1/fNOwaYaNltKZM0McSUApZ+72CI1R6rJaPoGntDGGb/xG8G5fgvNBo8e 6XB8zAf1SLuL1e087s8VurnX6PJPY5s= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.org, willy@infradead.org Cc: rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou Subject: [RFC PATCH v4 3/9] slub: Keep track of whether slub is on the per-node partial list Date: Tue, 31 Oct 2023 14:07:35 +0000 Message-Id: <20231031140741.79387-4-chengming.zhou@linux.dev> In-Reply-To: <20231031140741.79387-1-chengming.zhou@linux.dev> References: <20231031140741.79387-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 25CAB1C002E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: xcxdphdui7p64yueegg41kudq4ts1f3t X-HE-Tag: 1698761347-225172 X-HE-Meta: U2FsdGVkX19gTvKlasa6WEsLJGEctEtCdiENveTi5mdy7aPs30R77e94CJ7CxjtJrYdmz93nD2+RF4PAYgM/QHrgtpqJCBTASGHI05ac9FLdO0Idl0YI4OWwhZQ5/Zh7EbCaXVrvhcmX8vSvgLW2OwFfzrXjQ757qY5ydiSzIsvHAaXwi9TTiek1QiXwhwzmBeDCUZOVEgmlbLthxgP8rr9Hh/Y+kNXwHEnv2jprOsrWcoV/RgnHg3u7hZNi88Rh3Hy1gSaz25igJAup49nNdKxrSNTRonRkiXic5Bqg/BdzTn/s2yYtmK/rckPnlpQ9EMGBZdGNbc3wzag8UEqOOd58aO+BRQvh/PX+kqlWQMzIAkNfdz5t6CXxFOAORbzU7ewH+XVBItf1BjL6rLdEz5zlRWIa/0ILWEQjGVGP08Yey9hOu54bcKoK0GEf4SKL6ZX9hHd8HrIOi0/f+fLRtXlZVrQgLAnE/sTL8lA21wGIiZj//fn4VX5NkyNondd+pbHeLcT4FQa4yA6KEA2qOYAoOrXcnNBGw+s+xeZsUVWYJAQRZ8G4byBTqGL5FzG22Z2ilpyLep6ASfj0hU9QX/xs+5ZK51+p6JCKYPxtKdE7TV0DOeDQWEC/yNJ5uWnDcfJwRCQoYcWVkp3dmnbZKJQmcSPCUe/FnD8DMlHugnlR/Li9G98KIOTFExuVDEQS4B1TnwDEUbvk9d/klNheiiU2tYqFUUfJkbMGcJSCxxeKDyFqz3Ym3G0pXBLBLrw4VCP3IY1ucQg7giyPor1+Wtw3aQf7fBcAfqsGdTYBm3OgwBER55R6lHIU/sGS7IsHiC3noG+TVli2RVk8YMkdCvggaqPwwgKpLsC9YNQlWlSNduMbHyNJNlPon5dV30+j7ydtaa2GSQF5UuP7zjtoPpkB+5U0dmqGLcTi1HFvDIeiJ6Jk5DOmkEFmQVToTeZW0/47rohLwZ/dCyfKf7D MeGl2F1W tj6dnJ4mkNnQqZNnsit/5swgXtzxhg3G318rBg8W3ENnfw+3FOVUegOcnvQG/Ob8iaytnG8Oa2sE0Q2G4ynwwmy34ofN2RDXGr/9ryLXGH0af1wJ2qbfHVT9JqUJ4HizGrvY/IhzuHk68lqthpVEYvPNrqTzKtiepuAYMwzAicJyfjirB+4mJjuKgUf6aA/8Sh8bVS5Va5jMWkL4K48Ko0z6XLi53Smp9leLwLR7/Km7fARWj0Kfjb/Wo87Tm4N5SD9MWfM52mMViWE4= 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: List-Subscribe: List-Unsubscribe: From: Chengming Zhou Now we rely on the "frozen" bit to see if we should manipulate the slab->slab_list, which will be changed in the following patch. Instead we introduce another way to keep track of whether slub is on the per-node partial list, here we reuse the PG_workingset bit. We use __set_bit and __clear_bit directly instead of the atomic version for better performance and it's safe since it's protected by the slub node list_lock. Suggested-by: Matthew Wilcox Signed-off-by: Chengming Zhou Reviewed-by: Vlastimil Babka --- mm/slub.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 03384cd965c5..eed8ae0dbaf9 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2116,6 +2116,25 @@ static void discard_slab(struct kmem_cache *s, struct slab *slab) free_slab(s, slab); } +/* + * SLUB reuses PG_workingset bit to keep track of whether it's on + * the per-node partial list. + */ +static inline bool slab_test_node_partial(const struct slab *slab) +{ + return folio_test_workingset((struct folio *)slab_folio(slab)); +} + +static inline void slab_set_node_partial(struct slab *slab) +{ + __set_bit(PG_workingset, folio_flags(slab_folio(slab), 0)); +} + +static inline void slab_clear_node_partial(struct slab *slab) +{ + __clear_bit(PG_workingset, folio_flags(slab_folio(slab), 0)); +} + /* * Management of partially allocated slabs. */ @@ -2127,6 +2146,7 @@ __add_partial(struct kmem_cache_node *n, struct slab *slab, int tail) list_add_tail(&slab->slab_list, &n->partial); else list_add(&slab->slab_list, &n->partial); + slab_set_node_partial(slab); } static inline void add_partial(struct kmem_cache_node *n, @@ -2141,6 +2161,7 @@ static inline void remove_partial(struct kmem_cache_node *n, { lockdep_assert_held(&n->list_lock); list_del(&slab->slab_list); + slab_clear_node_partial(slab); n->nr_partial--; } @@ -4833,6 +4854,7 @@ static int __kmem_cache_do_shrink(struct kmem_cache *s) if (free == slab->objects) { list_move(&slab->slab_list, &discard); + slab_clear_node_partial(slab); n->nr_partial--; dec_slabs_node(s, node, slab->objects); } else if (free <= SHRINK_PROMOTE_MAX) From patchwork Tue Oct 31 14:07:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13441578 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAFBFC4167B for ; Tue, 31 Oct 2023 14:09:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B2A46B0305; Tue, 31 Oct 2023 10:09:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 43B376B0306; Tue, 31 Oct 2023 10:09:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DB8B6B0307; Tue, 31 Oct 2023 10:09:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1A3CE6B0305 for ; Tue, 31 Oct 2023 10:09:13 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DD2FE1CAD17 for ; Tue, 31 Oct 2023 14:09:12 +0000 (UTC) X-FDA: 81405938544.21.66D6547 Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) by imf03.hostedemail.com (Postfix) with ESMTP id F315220008 for ; Tue, 31 Oct 2023 14:09:10 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=wNIpzakv; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf03.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.171 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698761351; a=rsa-sha256; cv=none; b=ekrfja1F3HlVFtsnPW4eYECJ4ZM9icR4ubINhFsP0Y3m+6VygpPGmqufaDJzZqfLkJ+es7 bzAJcLVRCc3KzRGCkY63R0JrffVgMB6BDJ8YR0AZdEB9BaNBlwe7EVAVPNA5uoO5fWOlJ7 Q1NZra+HvOWYNhT9sICTE0CPn+tzv/g= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=wNIpzakv; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf03.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.171 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698761351; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=v/W13f1yvwrCHZgH+TSl+cdWReIuGoRVTB5psVe8An4=; b=q/P/Ruziz+6Ot9QebNsZ3UG3ySsiLARDBqmoS2GKiTDdIGDqFGMZxVY+M2VdhfLq+NTpG0 PYJkzqPfjCyWWjcb+94Uwqk85cvZ42YEsjy4gDLsUYcuMwqii3RGlp732vguqTz3Nq7qNz ZCdcgWU6MjA5VrXn5Cnw83JFap+7iA8= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698761349; h=from:from:reply-to:subject:subject: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=v/W13f1yvwrCHZgH+TSl+cdWReIuGoRVTB5psVe8An4=; b=wNIpzakvsd93W80vtkHwQf555uZ1X7UCHSu5UZdhAwR+WInzzIHY0wg3MqdVqIXyuFrveg zfUzHrnr02/YVCm2lpOuVKjDOu31IpZFnrJaagZexEAqG5577/evBuPT6k6264Mc9xVBB2 K4yu/KTcypElGi304xzyFujmguhhPdg= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.org, willy@infradead.org Cc: rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou Subject: [RFC PATCH v4 4/9] slub: Prepare __slab_free() for unfrozen partial slab out of node partial list Date: Tue, 31 Oct 2023 14:07:36 +0000 Message-Id: <20231031140741.79387-5-chengming.zhou@linux.dev> In-Reply-To: <20231031140741.79387-1-chengming.zhou@linux.dev> References: <20231031140741.79387-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: F315220008 X-Stat-Signature: edtzqmj4fcfa6ygg4fqdzfitotha9hbm X-HE-Tag: 1698761350-506226 X-HE-Meta: U2FsdGVkX19EBe4tDRw7e3jEuEMzZKLBwTBRioMqoQey4ml+BO4RWueXDbAC0c/cOgMlNAJ/qp3e+MTeJWQyafK2M/4O4xECxamlQu6SxMLV4thDF5Yml0UqZabwNzl1ecy0jslC4cJ2ikRPn/EJfiG7/BcF6RuDkoQGhdGa2Qkmat1mBbGMVauc1tvn1Rg301Er9zXR85Jk4w8QJUif03UgsiY9LobMjLeJH5ZyNqua1ElXaEDaLN+KKEbH86/TYo4N8WyiWi2BGVd2HkG/wkzkOAm6bVWFKui3rkS2E+Wl/1oW9lBhJxBSyJbddZRzDnEZb1z7NEIzFfH7bvdNsEjSmbsIs1xqcb77eM477aWY0nFZW241SJLm6p1bt1uJn5X4H/R9KBMJ90Yw0zwHhttX4Kwv07PsnnGhOASWWRSzEeDiI/yq2+MTBdeSdDfZzsnB13kbdUSJP2ubgz9Cl8WEltnNmuVd8mjnx/ua73b8Grco0/O5xnZsg7Xt4+jGlsr931Jjn/uKA1fNtMXhmTLgAOksnionUqF1tUSMt3Y1ZW5yxq/gzJtu6md6Y0eOfkKXXEVYFUB09mlm1ash78RdFikszIrgbzbCMl2xQgHENysb42sFRmoJ5pIEA5bpgz+lOjF8qoFqHTJUHPHD1xuWhJRO/22kxiPoTha5fTdLmhBTCVMnGXthUnBiccY4woei0PVyf7EiCc0Bpre0aDYwNeXyDOW5STKpQ13lLqVTk9ZQm5E3poRbra5bRHKcahjDiN4xlWxbu7QkhSDhxwtP00yVZq5u1cMQUK8YWB5ODHuDJdD12/2ebvROY3JDSxKl1FyNwIl24vET8tZ8Yl0R9GYPgcjioKL/DQPeWthq7WrZueY2qxE27RxTWnoH23ySSiV/GWyLe9zBetkjjCoKd+mTJkT90AmySBy51yGJKjFDXOgdw0wv+mlVYwJPXXPvexGNH/8YRjSlU3S tCqovKh1 DtzcWmEClg56snuaviD/96Q45pKs0NLOwiLm2/bHAcCE4eCisKJD/u4MPAzPpJ6KVht8MwwmWR8BBiSE04M4eP9MUrLn4QlXk5S0/8Hc/qaKoCPe15sCWiT6+KbyFdIxJaRiXOHJwEoTtu9p0KTHn9P6gEDAOsumQH6Uz2Vipyinrv/2dbBQ8rUrKIHib1dY54WRjfaOLSXV1oWkmShsVCprUrke5+CTakMw6hYtIQ2GCz4F20ymR20i6YQ0Y79sOqCEZ 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: List-Subscribe: List-Unsubscribe: From: Chengming Zhou Now the partially empty slub will be frozen when taken out of node partial list, so the __slab_free() will know from "was_frozen" that the partially empty slab is not on node partial list and is a cpu or cpu partial slab of some cpu. But we will change this, make partial slabs leave the node partial list with unfrozen state, so we need to change __slab_free() to use the new slab_test_node_partial() we just introduced. Signed-off-by: Chengming Zhou Reviewed-by: Vlastimil Babka --- mm/slub.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index eed8ae0dbaf9..1880b483350e 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3631,6 +3631,7 @@ static void __slab_free(struct kmem_cache *s, struct slab *slab, unsigned long counters; struct kmem_cache_node *n = NULL; unsigned long flags; + bool on_node_partial; stat(s, FREE_SLOWPATH); @@ -3678,6 +3679,7 @@ static void __slab_free(struct kmem_cache *s, struct slab *slab, */ spin_lock_irqsave(&n->list_lock, flags); + on_node_partial = slab_test_node_partial(slab); } } @@ -3706,6 +3708,15 @@ static void __slab_free(struct kmem_cache *s, struct slab *slab, return; } + /* + * This slab was partially empty but not on the per-node partial list, + * in which case we shouldn't manipulate its list, just return. + */ + if (prior && !on_node_partial) { + spin_unlock_irqrestore(&n->list_lock, flags); + return; + } + if (unlikely(!new.inuse && n->nr_partial >= s->min_partial)) goto slab_empty; From patchwork Tue Oct 31 14:07:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13441579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0014C4167D for ; Tue, 31 Oct 2023 14:09:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B0A06B0307; Tue, 31 Oct 2023 10:09:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 460FF6B0308; Tue, 31 Oct 2023 10:09:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 350BD6B0309; Tue, 31 Oct 2023 10:09:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 25AD86B0307 for ; Tue, 31 Oct 2023 10:09:17 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EE5801CA82E for ; Tue, 31 Oct 2023 14:09:16 +0000 (UTC) X-FDA: 81405938712.23.3124BCB Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) by imf22.hostedemail.com (Postfix) with ESMTP id B1BD3C0007 for ; Tue, 31 Oct 2023 14:09:13 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=WHMjfXAw; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698761353; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DSV2hJzhN1EMBaKNKe5GTqHBigf8Oik9SH9kDO4tfhs=; b=0I4AJ5YKG1m0YmRguKq6qF5vbHEu1YQA9FvcLZIRKd9M5vK9zn/R3+n2k3lfM/98TgDFmr 51/TAU1XfQyBvZikVK/1Q5MPY3VQLxoIQ4+AZdP3Lca5dhnhStR5c9NSGmxsSRb5Jalmel wLBZ4QWvNC0LdsTyf9i3MXI6iX4fY4Y= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=WHMjfXAw; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698761353; a=rsa-sha256; cv=none; b=nG6dV04ZxwLj8qxBW1cVdrtEGnt9LiQJ0LGx7G5fgjy26OJMTcK9Yrw9YxBr6lGC7qn03i qPnLnG3g/X+Y2qLUcJbsr1tjuKxmaiNPWIKcCKIyDSyHt1gh71pBEIWP7mQRsmenTyBXna ZgnrMmsIDDDKbQXFY1LNAaxlVb0SzuQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698761352; h=from:from:reply-to:subject:subject: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=DSV2hJzhN1EMBaKNKe5GTqHBigf8Oik9SH9kDO4tfhs=; b=WHMjfXAw75r95lcc5nFUiMN89Tof/YlZMyVPqZKNOdvO1yteE6uHCrbGBMOqY7xCBTII+D bv4O0JIZHkzqYTy9jSpAEEAubWuuo1+LX71TrqtSTlbNRuljW0aerBJZZx3KeiAGfHntFE 9WQV2XL6SGskdWaTT/AwR5nu7UHQO8I= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.org, willy@infradead.org Cc: rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou Subject: [RFC PATCH v4 5/9] slub: Introduce freeze_slab() Date: Tue, 31 Oct 2023 14:07:37 +0000 Message-Id: <20231031140741.79387-6-chengming.zhou@linux.dev> In-Reply-To: <20231031140741.79387-1-chengming.zhou@linux.dev> References: <20231031140741.79387-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B1BD3C0007 X-Stat-Signature: cw48hyg148g9ebwa8zyor4heqnz4e81i X-Rspam-User: X-HE-Tag: 1698761353-66328 X-HE-Meta: U2FsdGVkX18hjXfIGAe8N+CgClYN90+4hYzmI3l0IWuyBlDKd8AA4bO9YJy/hDod/G7hQLa9f2f+fh2zzL6iv9dQ1fP9sntJljfUIykj+PuMtWV0rbqeh57QpEq4Z9M7UF+QlOvZkEH4LSt+OGyhI1DgmbW96GLMuxjIjdK/em3xjfjlL+JvcL6UVCk6UJ9nSQbFZX36tKrFZb8tnun/Aa2j+vwOuqxtNc/Dx8kWk97ds+2VD6KDr3KGNsml3UETkMNzwNxyV4d78Q4u+GKO1Jg8DsXVA2PFCuSaNRVTcnVuPZFlPAMVWbvZfTFbMVFSVZZ/9JQLjLkoeBIxZ+V307jJ2L6Pn42y87pf+HjOtd/SpgEMJ3h9RFNfd59OFfVWk1DxjJL+4kmoNvbnCMByZPPo9o3Dxb5gF9GvLtO+jslwblcw9uv5IEN+7g8d8frFUnp0zTsgp97DxSgwdfTV5aMnu+w2ZygwNzrucd3caZw7sQDvorz9Ii3h5pqdTE+qLFkJ9I1gCOCfP7vkVdXlBaic+KVmh09nuPjQMnrwuvU1CDMS0MuNYRvMbwM77VQfz1E739wropO+c4RLOJUhW/KeTabwDkvqkp5UH8EQ2tiUuY6jTelI/UHh1aFeW4Cp/iUvH0O/JQywzQwqb+dZyMUuL1hPKjMjZuFN1cA4XDUJ451hor4iCiM1+YtOdRbWmg38qfrUbz5nTi6eY990N8vS0lTHL1OhHF3hTDr1DZneQrFGtamYe+fo2Lw+jBoD8BVzeyqRm+HwqX2TZ4maBMDElxIgH7ZF2mbLLKlbiq5tCLhGqGN5Y0eILAekPuqC5fpJRcz9yYsVBuZXWEhYDSU8zuj8pfXT3e5T0xc9FKnqnKz1pZzyZ8/kMJtQHiosHG8HOjx4NogPRoruDTzYiaNGFVKtI4TfOky1KTtEwSDKOSJp+SYboNiCVjJMZjnlQJ2a8WbdtkazX2YOy79 jMFCF06h TVeOCeKHWBUxFx6pisNB4q4o1ddriIPYpASgn0VAmygXRzZLeJYveN+fae9Ge3RpNbUs/BvLU1RfI/MVI7gMRJ4HdQI9j6dKLQXHb1hJVCPdQP4M3ulfabBnmIM1TwPRYt/BGAD5/Fw3h279trkj0RiUPHcZU1bOF6azGSX/QMG1/uiPsf5CQUmtDfPh1Jsv1XSKHV4rIk6FL0w5huCEfSpjsErDHfmtcPkv+bI9FxEd+p3i5cLHFuRSmW/7OPeSE3W+6fvpLqjbXY8TNp2HvXh+Dz28yUWtAcqCt 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: List-Subscribe: List-Unsubscribe: From: Chengming Zhou We will have unfrozen slabs out of the node partial list later, so we need a freeze_slab() function to freeze the partial slab and get its freelist. Signed-off-by: Chengming Zhou Reviewed-by: Vlastimil Babka Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/slub.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 1880b483350e..edf567971679 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3098,6 +3098,33 @@ static inline void *get_freelist(struct kmem_cache *s, struct slab *slab) return freelist; } +/* + * Freeze the partial slab and return the pointer to the freelist. + */ +static inline void *freeze_slab(struct kmem_cache *s, struct slab *slab) +{ + struct slab new; + unsigned long counters; + void *freelist; + + do { + freelist = slab->freelist; + counters = slab->counters; + + new.counters = counters; + VM_BUG_ON(new.frozen); + + new.inuse = slab->objects; + new.frozen = 1; + + } while (!slab_update_freelist(s, slab, + freelist, counters, + NULL, new.counters, + "freeze_slab")); + + return freelist; +} + /* * Slow path. The lockless freelist is empty or we need to perform * debugging duties. From patchwork Tue Oct 31 14:07:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13441580 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E554EC4332F for ; Tue, 31 Oct 2023 14:09:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80EF76B0309; Tue, 31 Oct 2023 10:09:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BDE46B030A; Tue, 31 Oct 2023 10:09:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65D746B030B; Tue, 31 Oct 2023 10:09:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4F2076B0309 for ; Tue, 31 Oct 2023 10:09:19 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8FBAFB5C56 for ; Tue, 31 Oct 2023 14:09:18 +0000 (UTC) X-FDA: 81405938796.30.C9E1095 Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) by imf23.hostedemail.com (Postfix) with ESMTP id 97A2C14000B for ; Tue, 31 Oct 2023 14:09:16 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=T7PF2RDx; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.176 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698761356; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WFFMQyhLZJnEzwgDfbrlXS+sPYcJwR5pdI64P4BtRGU=; b=rGgDQP4WiEB1f7RqFqm1SK0qyuwEILGv3h8eXQus1yzmqjeCUCvs2/BiBiAxQQbPEcSKz9 coodQRSqXHBYdfCC3Iv9jGFK4sqL2U8jm/Y6gzqKnSb8u7sWvzQX8bVTOpgU/w2D2NZOEh 1inryW1RS1PhXKn6+sH725CroSKiDkk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=T7PF2RDx; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.176 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698761356; a=rsa-sha256; cv=none; b=NCnn2MSMuzs3ZAw0Ds9ZjFo/YrGU225fzwNgfVJcQDw6HSQ3j4k9ZudsXa5Xk0Omh/SsBm hzzFoyGM9ciF2N6C4Bz8lHwWR50WFJUVnT5WTCzNN8tplm2gK5mUyjgkfA95sZqU/EYjrz sUNMfX+O8wjY21KOfU9wOKwbaP9apwk= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698761355; h=from:from:reply-to:subject:subject: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=WFFMQyhLZJnEzwgDfbrlXS+sPYcJwR5pdI64P4BtRGU=; b=T7PF2RDxrnhml9AGrzBwH7Qb6gebmTAsuAiIOValuuZMya2Gd9T1jQvXTSlgNdQynWleC7 BIbYj4Hhvn5EHHFj1uNZNgRFHhPDpDZmezPhOhX5zL2VsVdotFZfFjnqhG8XarSBkxuXgN ddq0HXNsmojE5zrxEzjWz16CJWMGtZU= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.org, willy@infradead.org Cc: rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou Subject: [RFC PATCH v4 6/9] slub: Delay freezing of partial slabs Date: Tue, 31 Oct 2023 14:07:38 +0000 Message-Id: <20231031140741.79387-7-chengming.zhou@linux.dev> In-Reply-To: <20231031140741.79387-1-chengming.zhou@linux.dev> References: <20231031140741.79387-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: d1uxrgptjmyr3hmkdceyaghnzbsjir3d X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 97A2C14000B X-HE-Tag: 1698761356-966153 X-HE-Meta: U2FsdGVkX19Hk9TJqIBqwoLju0ywc0wf2v6/Y7+diVn6nvS+qdaMqerx93oIF8oCabBKUhiJn953bIi9wmrvy0IZr4rcWBAy0NepM2AVCCRy+f9e3S2OsIMbkxNRZE9bLEXZQs3f7Ic5wQn0D8JcLbhAfgIR1F8xhl8RjkhxjFNyhff7Py7YjxDKP5a3/G6VlksmVMe1y5bwvYKePtSjitV378UIVjCp4XqFYgz85sqoiipIXfMfCwu0nDOeIww6TVYflwrbs3V6h3ASwJ8+4w8MofOgEoep5tiGpJ2wut1Sp3zMBYXtIDzf3lXCLBlWg247T/vv1AWZ85zw24H+bomwcAnDtq6LVpVzkS4lQYPn7yX1sUIxNcZGsYVlcHkMr8pRVecc0JtQDytZrtmkFEpxYu5mAF3BcekQAib+7yEu/RMEvXBpHaKeSN5RRU9bmiXMhcR+BM/BSmkrS4buAjUvlY+qEm29bbolSfSE1wgyYl57Wza3GvrOMVjnrHsiOgMOJYOktBngROv7faEAnG1tOs6U1jdD48169wBfLkCvnJK7iJ4EuTsWWH+RJ56pCBocxQEbLnFFTQNvMH/fP2exk+XG6OMLBVHTym63GBfdjcOz/9hWBBQP19NTDxqDZd1NbyP9mmI917ePnzNiGkEUotzWFt6EYjEXjZisNOAAyPO7UF5XEfNjpXWaWX2A6Ck8GtpyQwVL6h6EszB6BFsHrrsmzSGbHUyjP8do4xn+XmL97m8ve/naydXCWqSui6XW8QZyoM8XkVx1Ueg0VZbckaMN+uyqwibBjQ+fECJXwM5ztt0IphJCqwmgY4idvpjYfcdJqaHBKEJxQOVIRoBuA3uNDBlm2FgzYZPjBXl/PCdeFiRR4HBj09JpndBrfIaTfobARsKKY7xL45v9k1HQNGq74QwgufcAIFRAjDa0VhUx4ajPusUo6cHikgwyfVsgG36QWJ9R2Jm7LT2 5RO05oLO h9QOjaUi+Ax/AtdSuWIwOa14IVJtlLHXTHdfOWWhnJxA/e7PmqSlcfX7RZwrn726xT/QdPP2bKYd34HWvXy86LkL5R8SynLz48q8muAUJdQDKy0MGmTmu2uAg2BP7X+qighVDFLV4Z1ZHWP06CL+w8nNJX8kP9a5OCqJHE+vHgsHbDtMYe/TzDBeqG0G84+Q6BRN0iR0SHVqGWiU= 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: List-Subscribe: List-Unsubscribe: From: Chengming Zhou Now we will freeze slabs when moving them out of node partial list to cpu partial list, this method needs two cmpxchg_double operations: 1. freeze slab (acquire_slab()) under the node list_lock 2. get_freelist() when pick used in ___slab_alloc() Actually we don't need to freeze when moving slabs out of node partial list, we can delay freezing to when use slab freelist in ___slab_alloc(), so we can save one cmpxchg_double(). And there are other good points: - The moving of slabs between node partial list and cpu partial list becomes simpler, since we don't need to freeze or unfreeze at all. - The node list_lock contention would be less, since we don't need to freeze any slab under the node list_lock. We can achieve this because there is no concurrent path would manipulate the partial slab list except the __slab_free() path, which is now serialized by slab_test_node_partial() under the list_lock. Since the slab returned by get_partial() interfaces is not frozen anymore and no freelist is returned in the partial_context, so we need to use the introduced freeze_slab() to freeze it and get its freelist. Similarly, the slabs on the CPU partial list are not frozen anymore, we need to freeze_slab() on it before use. We can now delete acquire_slab() as it became unused. Signed-off-by: Chengming Zhou Reviewed-by: Vlastimil Babka --- mm/slub.c | 113 +++++++++++------------------------------------------- 1 file changed, 23 insertions(+), 90 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index edf567971679..bcb5b2c4e213 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2234,51 +2234,6 @@ static void *alloc_single_from_new_slab(struct kmem_cache *s, return object; } -/* - * Remove slab from the partial list, freeze it and - * return the pointer to the freelist. - * - * Returns a list of objects or NULL if it fails. - */ -static inline void *acquire_slab(struct kmem_cache *s, - struct kmem_cache_node *n, struct slab *slab, - int mode) -{ - void *freelist; - unsigned long counters; - struct slab new; - - lockdep_assert_held(&n->list_lock); - - /* - * Zap the freelist and set the frozen bit. - * The old freelist is the list of objects for the - * per cpu allocation list. - */ - freelist = slab->freelist; - counters = slab->counters; - new.counters = counters; - if (mode) { - new.inuse = slab->objects; - new.freelist = NULL; - } else { - new.freelist = freelist; - } - - VM_BUG_ON(new.frozen); - new.frozen = 1; - - if (!__slab_update_freelist(s, slab, - freelist, counters, - new.freelist, new.counters, - "acquire_slab")) - return NULL; - - remove_partial(n, slab); - WARN_ON(!freelist); - return freelist; -} - #ifdef CONFIG_SLUB_CPU_PARTIAL static void put_cpu_partial(struct kmem_cache *s, struct slab *slab, int drain); #else @@ -2295,7 +2250,6 @@ static struct slab *get_partial_node(struct kmem_cache *s, struct partial_context *pc) { struct slab *slab, *slab2, *partial = NULL; - void *object = NULL; unsigned long flags; unsigned int partial_slabs = 0; @@ -2314,7 +2268,7 @@ static struct slab *get_partial_node(struct kmem_cache *s, continue; if (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) { - object = alloc_single_from_partial(s, n, slab, + void *object = alloc_single_from_partial(s, n, slab, pc->orig_size); if (object) { partial = slab; @@ -2324,13 +2278,10 @@ static struct slab *get_partial_node(struct kmem_cache *s, continue; } - object = acquire_slab(s, n, slab, object == NULL); - if (!object) - break; + remove_partial(n, slab); if (!partial) { partial = slab; - pc->object = object; stat(s, ALLOC_FROM_PARTIAL); } else { put_cpu_partial(s, slab, 0); @@ -2629,9 +2580,6 @@ static void __unfreeze_partials(struct kmem_cache *s, struct slab *partial_slab) unsigned long flags = 0; while (partial_slab) { - struct slab new; - struct slab old; - slab = partial_slab; partial_slab = slab->next; @@ -2644,23 +2592,7 @@ static void __unfreeze_partials(struct kmem_cache *s, struct slab *partial_slab) spin_lock_irqsave(&n->list_lock, flags); } - do { - - old.freelist = slab->freelist; - old.counters = slab->counters; - VM_BUG_ON(!old.frozen); - - new.counters = old.counters; - new.freelist = old.freelist; - - new.frozen = 0; - - } while (!__slab_update_freelist(s, slab, - old.freelist, old.counters, - new.freelist, new.counters, - "unfreezing slab")); - - if (unlikely(!new.inuse && n->nr_partial >= s->min_partial)) { + if (unlikely(!slab->inuse && n->nr_partial >= s->min_partial)) { slab->next = slab_to_discard; slab_to_discard = slab; } else { @@ -3167,7 +3099,6 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, node = NUMA_NO_NODE; goto new_slab; } -redo: if (unlikely(!node_match(slab, node))) { /* @@ -3243,7 +3174,8 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, new_slab: - if (slub_percpu_partial(c)) { +#ifdef CONFIG_SLUB_CPU_PARTIAL + while (slub_percpu_partial(c)) { local_lock_irqsave(&s->cpu_slab->lock, flags); if (unlikely(c->slab)) { local_unlock_irqrestore(&s->cpu_slab->lock, flags); @@ -3255,12 +3187,22 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, goto new_objects; } - slab = c->slab = slub_percpu_partial(c); + slab = slub_percpu_partial(c); slub_set_percpu_partial(c, slab); local_unlock_irqrestore(&s->cpu_slab->lock, flags); stat(s, CPU_PARTIAL_ALLOC); - goto redo; + + if (unlikely(!node_match(slab, node) || + !pfmemalloc_match(slab, gfpflags))) { + slab->next = NULL; + __unfreeze_partials(s, slab); + continue; + } + + freelist = freeze_slab(s, slab); + goto retry_load_slab; } +#endif new_objects: @@ -3268,8 +3210,8 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, pc.orig_size = orig_size; slab = get_partial(s, node, &pc); if (slab) { - freelist = pc.object; if (kmem_cache_debug(s)) { + freelist = pc.object; /* * For debug caches here we had to go through * alloc_single_from_partial() so just store the @@ -3281,6 +3223,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, return freelist; } + freelist = freeze_slab(s, slab); goto retry_load_slab; } @@ -3682,18 +3625,8 @@ static void __slab_free(struct kmem_cache *s, struct slab *slab, was_frozen = new.frozen; new.inuse -= cnt; if ((!new.inuse || !prior) && !was_frozen) { - - if (kmem_cache_has_cpu_partial(s) && !prior) { - - /* - * Slab was on no list before and will be - * partially empty - * We can defer the list move and instead - * freeze it. - */ - new.frozen = 1; - - } else { /* Needs to be taken off a list */ + /* Needs to be taken off a list */ + if (!kmem_cache_has_cpu_partial(s) || prior) { n = get_node(s, slab_nid(slab)); /* @@ -3723,9 +3656,9 @@ static void __slab_free(struct kmem_cache *s, struct slab *slab, * activity can be necessary. */ stat(s, FREE_FROZEN); - } else if (new.frozen) { + } else if (kmem_cache_has_cpu_partial(s) && !prior) { /* - * If we just froze the slab then put it onto the + * If we started with a full slab then put it onto the * per cpu partial list. */ put_cpu_partial(s, slab, 1); From patchwork Tue Oct 31 14:07:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13441581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6235EC4167B for ; Tue, 31 Oct 2023 14:09:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACC156B030A; Tue, 31 Oct 2023 10:09:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A54856B030B; Tue, 31 Oct 2023 10:09:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 944396B030C; Tue, 31 Oct 2023 10:09:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7DCCE6B030A for ; Tue, 31 Oct 2023 10:09:21 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 52CDA1A087A for ; Tue, 31 Oct 2023 14:09:21 +0000 (UTC) X-FDA: 81405938922.19.B7D4A3E Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf26.hostedemail.com (Postfix) with ESMTP id 7656314001D for ; Tue, 31 Oct 2023 14:09:19 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=EgWg7Jyu; spf=pass (imf26.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698761359; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=71jccDuvmHUN0B2hAN0chVUZ3a/I3ZWuScusSDMRbZM=; b=74sk8ZDaI5P/pOzYzNw1dG0E7fkwuvOBg7M3dX6GRuOZqquQKUqe2hgjioo8Xluwamb1us QjCXJlBVAQVAeUNuNVTLao02Zhi+BP6JQrNvcYKTTsUkm7SVj2WSQI/GJ4VLNFaM4KGESI 3xvWELNZW7AWFCKDnjTBi7PIWzhtBkc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698761359; a=rsa-sha256; cv=none; b=2gAgmH2KsLuHCTKdVvyBdfS6RH1q7dEL5jZNiwUPYRnGdhVnX50TskyBDMkdDEoknIS1NZ 64GAlncScMz7SSGkT172ITb0maqPZIT14XIUIo9Wo4wpUERu9G/4IgILyfNaUzZKyv4w4P D1+xytd4GLdCSKhmFZpFOegO7pBDznk= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=EgWg7Jyu; spf=pass (imf26.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698761358; h=from:from:reply-to:subject:subject: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=71jccDuvmHUN0B2hAN0chVUZ3a/I3ZWuScusSDMRbZM=; b=EgWg7JyuljiAgmtHeNxZPVDCEzu19y0onJXhXs8aae8cO3ZMQHroKY26QyUFiFaebUhzCc RGV6bWjUO05MthcYp2hTuKmvk++h80PzPUQqKT6vJe0w3lTBc8M2DdpDA2JE+ug45MtF26 X/0C77Wy9EZYl/zFaNFqEn7aLM2cGT8= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.org, willy@infradead.org Cc: rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou Subject: [RFC PATCH v4 7/9] slub: Optimize deactivate_slab() Date: Tue, 31 Oct 2023 14:07:39 +0000 Message-Id: <20231031140741.79387-8-chengming.zhou@linux.dev> In-Reply-To: <20231031140741.79387-1-chengming.zhou@linux.dev> References: <20231031140741.79387-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 7656314001D X-Rspam-User: X-Stat-Signature: xx847z8h47t4bnfxd5p7izniabfcezx1 X-Rspamd-Server: rspam03 X-HE-Tag: 1698761359-308847 X-HE-Meta: U2FsdGVkX1+alMJiBELCDUY0fHokRB8I51fYBgICY64+NB2bKVebTkC0idDz6l+IW5uTEJDr4I42jIos9L8ucldq3LHRfDk6tRQUpTpbF9yeLVj9dEfaE+LuUbTTPj4TgvmRyc6y1atS+FRZjTl0eJZVru4i/kgc8N+zaBtXJ79bFHw9ce2tOCKHYTSn6+F2y9ApKDugj1uAOi0eszrUvhXVShCbjBzmRD4i6MPH/02kxoGOeND+58+uU2CllBYS/8QIb5fC5AiyaoFb1e6JehRfTpun+w7K86h5vFnBqGQScBX+qT0U8nLgrTNOBbA/wIVymeU9wMRXctb1N3MsG5lZwvfE7/8SsrZTkf7jGwmWytX29CIbS5jeXYJPfcB20Lstk4QCCiXlCvUkpLy8e//DGZpz/iGC5eXNxWUuzazswpgoKpkFlP7w6T0ajNJdnutsOtpCuNVBHfyy/2tI/D32z9fiysl9azEVZEPVEVhyZhWa3vsyQJf2Yd6m8x8Kax4kQaW7/h3XzOjlzg/+gpmMjl81x0Uv4Ta27HGcvQghVa1IUorMiMz22woxIhoADCPcyh54c32FcG/3NnvyzVv7Gztk0OaIYZpzgAj3FllzjKOa69CXHO8labnHqunFLvIp9DKRUOw1keZemHEbja4p/19F8kg5KLsoQ+o6cIxcvGW+dnKl9Bar2D6jg3NQxSrhk+XwxuauSIlXT9MaNjD+yFRj5Yi0UqM6jQY1MgRqYXtoNhVc2u45kBSATTi0qLwqEGHgUVEIa0ruxGh/Qvy4WMDSvkA7X5floaLChUfrQxba4dLKHf4AXeoT0bCbTBhUHAqUsbt+3sB1Clm84dqV9mBfDDMTEYfVlRsXOTIyJeosZuSPCrLUlRr0HB1ueFuAztXjKuFUXeymcfEjuc8KxOqTpavofXSm07YMot1/djLhYIc7N1FfYIrgHxy1rUeVa1m0xH98BLPBoGp Salcq23C oRdvcQi92qBW7vOCldQtAxAQBaaSxwDlvgegjQNlVvh2TRahP+kC0qRBZroebq8TB1JKQK3Nlz1tKHMFijpsJ+PrigyRzxws578z9HMDdDGq2VlKX9unoAqxxCruFhTYE5mpougaxFqIrrfIhwDFRMUcwcWJGGhRQhA/rJqia+2Z7aLQuXDwGpNTBGYJbtTJsYxTFIUNy7fheOU1d49LZDd5WxcsSVFXNRU8GLZMtCyv81NcBknI4qkjxyS1YhC+eMw4Y 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: List-Subscribe: List-Unsubscribe: From: Chengming Zhou Since the introduce of unfrozen slabs on cpu partial list, we don't need to synchronize the slab frozen state under the node list_lock. The caller of deactivate_slab() and the caller of __slab_free() won't manipulate the slab list concurrently. So we can get node list_lock in the last stage if we really need to manipulate the slab list in this path. Signed-off-by: Chengming Zhou Reviewed-by: Vlastimil Babka --- mm/slub.c | 76 +++++++++++++++++++------------------------------------ 1 file changed, 26 insertions(+), 50 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index bcb5b2c4e213..c429f8baba5f 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2468,10 +2468,8 @@ static void init_kmem_cache_cpus(struct kmem_cache *s) static void deactivate_slab(struct kmem_cache *s, struct slab *slab, void *freelist) { - enum slab_modes { M_NONE, M_PARTIAL, M_FREE, M_FULL_NOLIST }; struct kmem_cache_node *n = get_node(s, slab_nid(slab)); int free_delta = 0; - enum slab_modes mode = M_NONE; void *nextfree, *freelist_iter, *freelist_tail; int tail = DEACTIVATE_TO_HEAD; unsigned long flags = 0; @@ -2512,62 +2510,40 @@ static void deactivate_slab(struct kmem_cache *s, struct slab *slab, * * Ensure that the slab is unfrozen while the list presence * reflects the actual number of objects during unfreeze. - * - * We first perform cmpxchg holding lock and insert to list - * when it succeed. If there is mismatch then the slab is not - * unfrozen and number of objects in the slab may have changed. - * Then release lock and retry cmpxchg again. */ -redo: - - old.freelist = READ_ONCE(slab->freelist); - old.counters = READ_ONCE(slab->counters); - VM_BUG_ON(!old.frozen); - - /* Determine target state of the slab */ - new.counters = old.counters; - if (freelist_tail) { - new.inuse -= free_delta; - set_freepointer(s, freelist_tail, old.freelist); - new.freelist = freelist; - } else - new.freelist = old.freelist; - - new.frozen = 0; + do { + old.freelist = READ_ONCE(slab->freelist); + old.counters = READ_ONCE(slab->counters); + VM_BUG_ON(!old.frozen); + + /* Determine target state of the slab */ + new.counters = old.counters; + new.frozen = 0; + if (freelist_tail) { + new.inuse -= free_delta; + set_freepointer(s, freelist_tail, old.freelist); + new.freelist = freelist; + } else { + new.freelist = old.freelist; + } + } while (!slab_update_freelist(s, slab, + old.freelist, old.counters, + new.freelist, new.counters, + "unfreezing slab")); + /* + * Stage three: Manipulate the slab list based on the updated state. + */ if (!new.inuse && n->nr_partial >= s->min_partial) { - mode = M_FREE; + stat(s, DEACTIVATE_EMPTY); + discard_slab(s, slab); + stat(s, FREE_SLAB); } else if (new.freelist) { - mode = M_PARTIAL; - /* - * Taking the spinlock removes the possibility that - * acquire_slab() will see a slab that is frozen - */ spin_lock_irqsave(&n->list_lock, flags); - } else { - mode = M_FULL_NOLIST; - } - - - if (!slab_update_freelist(s, slab, - old.freelist, old.counters, - new.freelist, new.counters, - "unfreezing slab")) { - if (mode == M_PARTIAL) - spin_unlock_irqrestore(&n->list_lock, flags); - goto redo; - } - - - if (mode == M_PARTIAL) { add_partial(n, slab, tail); spin_unlock_irqrestore(&n->list_lock, flags); stat(s, tail); - } else if (mode == M_FREE) { - stat(s, DEACTIVATE_EMPTY); - discard_slab(s, slab); - stat(s, FREE_SLAB); - } else if (mode == M_FULL_NOLIST) { + } else { stat(s, DEACTIVATE_FULL); } } From patchwork Tue Oct 31 14:07:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13441582 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77AB7C4332F for ; Tue, 31 Oct 2023 14:09:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17FE66B030E; Tue, 31 Oct 2023 10:09:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12E936B030F; Tue, 31 Oct 2023 10:09:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F11656B0310; Tue, 31 Oct 2023 10:09:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DC80C6B030E for ; Tue, 31 Oct 2023 10:09:25 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 87165B5CAF for ; Tue, 31 Oct 2023 14:09:24 +0000 (UTC) X-FDA: 81405939048.30.9B58059 Received: from out-184.mta1.migadu.com (out-184.mta1.migadu.com [95.215.58.184]) by imf13.hostedemail.com (Postfix) with ESMTP id 8D36220027 for ; Tue, 31 Oct 2023 14:09:22 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=r1MiH4vM; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.184 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698761362; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WNirFUhouaQ2FdRmy2RjQgkCONe7ugTNtD0fPI9SkvQ=; b=iznIbvBOFckbaGSWQ4gHd/XwvwvmtWFKh747Ca9fVo38QIh4dbasDsPHKmkrXsXOsoRJ0M Eb6tXPGwTYcsrrBUNbSTk8etkgOokjjftNBlFCR1aL5Qjo8SOvGHtrjWvnIhAWeVs83bvX LHooFavsN6Qv0b8a2jhsfvjrlVjGdbI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=r1MiH4vM; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.184 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698761362; a=rsa-sha256; cv=none; b=rQtHaTqQp7RN514tEqG1k+ODRKoGggKsZt4T49M0ubCLrjp5YDzHxMUvPe3z3BQrOrzI2u +f/nIfYqO8onm5d/Ud0ej+xUwP6GNHguXKzq/BGkDl3NvuzBVlO+nKOcuFkPHtDHi+0snq uxBYnXLaK9Q+8Vlt2T7rYAZfBQOLtiU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698761361; h=from:from:reply-to:subject:subject: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=WNirFUhouaQ2FdRmy2RjQgkCONe7ugTNtD0fPI9SkvQ=; b=r1MiH4vM84Jj3nwHog6emae9i1zx3YqzKMYp0IBEloU7g/8tB45Y1H9zMFiMKQbkD/H0Qe VuvBkAF8ea4irChfcbAhAq0tXL092g71ipfL7eKZwrga14ekhl47LZcRSrMGn4jQOfzSeP bhCSvGRNAWF820iIR0MuX+4oZgKIP/E= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.org, willy@infradead.org Cc: rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou Subject: [RFC PATCH v4 8/9] slub: Rename all *unfreeze_partials* functions to *put_partials* Date: Tue, 31 Oct 2023 14:07:40 +0000 Message-Id: <20231031140741.79387-9-chengming.zhou@linux.dev> In-Reply-To: <20231031140741.79387-1-chengming.zhou@linux.dev> References: <20231031140741.79387-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: ag6fjuy1nbnnfyziaewramsas1qu148t X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8D36220027 X-HE-Tag: 1698761362-656888 X-HE-Meta: U2FsdGVkX1/kyEUmhQbkwLh8L2jPVfygnDwbenlHwJwGfdx2ikm2/RM5+3kPHGHybFg70dM4f0BQTG4vF1Sp2/c0epeZhtFFWgt7ksICTGBK54D25MWu9zN9+YVzABB5/C6QqE/R/RnlBdYX/8gfOIHMNVThIQ9HgjlxxlxFQVPFvfHzgcrhCLvKgjFoyutO1a5SspxYBR1bJIo1cG59kTLRdu2h/lAanzkTLahf/G+GGPDdEg3ZKWsQlaXpMlkG23Xnw61yYRFbiJwdsvZkIVMnCTqUdYlmHHhc27fWvXloO41o2uoRrQYGq07cHOK5+pP2ICGwIaoVNhCXuScwrZQzv97M0UpHzkq/9eSDXq87p8dz39FDZsaAofKiaoqKum83pqsWlo2xqujrlaTgl25KZzOsIoIINQeDCfXbW5u4r6qHFGQ7KAJq9AoR/V1lvGZdQ2l5GXT/G0Ia0PgAytya1TzZEDLCTVzyDdT//qij5lVOh9tPLIUwbHjivDqAi9mtIyxcYjRa/qwAAozY7jILt/W5sYY8xcFJ+B4MhIcc4F7tq8J6NSjLJnsRs8IbMsXskHvZrn8yLIESP9otJ5JhmCEGbNg4KT58ohmwXMqoJlq3yCewQhtNdPWDazxzt1UcQycTlA/t8u7rCUVVhdspY0b1DxxsUa+zsP+lCgIK4DG7uBEUTe7iAUEuYdNa3p2oq/t/vLi+IHGaUmBU2Z3F0M21mnV9/PszTXVYkc6Kec/d07uePSLvGjS6CtkmPprQ4rfLmfQpaV3cKFPMFBlV8S1P5GdC2viqszZ9fKEVp2FvVsIX0mtfVudHP66xb334XUPYr2I3rN0ZVEwurYqWyhinHVRtkGyCJ8Uxtgx0cxX0epvKULLG/QOrYmcmkAzwTDdF0ck8HpPuyTW24y6xQ36Z60DdfvnuHMyOOXpiM4Z2ejbPSmMVEAZkrKDYZ8PciIKwbG57ZQSzgAf w0kQTIvM LqAs9S+oeSNWXUQ+zW8+Uq0XhTqHbcdZ3foE8JlsJpGKDr+lV0lelhw4vs6Gjw7aHt7svLCx88uglY2LHPV+ztZ34cNnbdrVNbIuVJXFqBIIAlyL6VkIcrphj0jsaMVadiKyq2maTfzwT3XSEDKam0vS8ARMIYXSd+6KIFGiNLbfOKBLp8qhmeWxA+AZbphhvjliIOVPNTY9MuvgXuYo3SPDioATkOQRxAnlB5RRFfvvA5uJ6XE3iQI6MtY2ZAoXX1xJg 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: List-Subscribe: List-Unsubscribe: From: Chengming Zhou Since all partial slabs on the CPU partial list are not frozen anymore, we don't unfreeze when moving cpu partial slabs to node partial list, it's better to rename these functions. Signed-off-by: Chengming Zhou Reviewed-by: Vlastimil Babka --- mm/slub.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index c429f8baba5f..bb7368047103 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2549,7 +2549,7 @@ static void deactivate_slab(struct kmem_cache *s, struct slab *slab, } #ifdef CONFIG_SLUB_CPU_PARTIAL -static void __unfreeze_partials(struct kmem_cache *s, struct slab *partial_slab) +static void put_partials_node(struct kmem_cache *s, struct slab *partial_slab) { struct kmem_cache_node *n = NULL, *n2 = NULL; struct slab *slab, *slab_to_discard = NULL; @@ -2591,9 +2591,9 @@ static void __unfreeze_partials(struct kmem_cache *s, struct slab *partial_slab) } /* - * Unfreeze all the cpu partial slabs. + * Put all the cpu partial slabs to the node partial list. */ -static void unfreeze_partials(struct kmem_cache *s) +static void put_partials(struct kmem_cache *s) { struct slab *partial_slab; unsigned long flags; @@ -2604,11 +2604,11 @@ static void unfreeze_partials(struct kmem_cache *s) local_unlock_irqrestore(&s->cpu_slab->lock, flags); if (partial_slab) - __unfreeze_partials(s, partial_slab); + put_partials_node(s, partial_slab); } -static void unfreeze_partials_cpu(struct kmem_cache *s, - struct kmem_cache_cpu *c) +static void put_partials_cpu(struct kmem_cache *s, + struct kmem_cache_cpu *c) { struct slab *partial_slab; @@ -2616,7 +2616,7 @@ static void unfreeze_partials_cpu(struct kmem_cache *s, c->partial = NULL; if (partial_slab) - __unfreeze_partials(s, partial_slab); + put_partials_node(s, partial_slab); } /* @@ -2629,7 +2629,7 @@ static void unfreeze_partials_cpu(struct kmem_cache *s, static void put_cpu_partial(struct kmem_cache *s, struct slab *slab, int drain) { struct slab *oldslab; - struct slab *slab_to_unfreeze = NULL; + struct slab *slab_to_put = NULL; unsigned long flags; int slabs = 0; @@ -2644,7 +2644,7 @@ static void put_cpu_partial(struct kmem_cache *s, struct slab *slab, int drain) * per node partial list. Postpone the actual unfreezing * outside of the critical section. */ - slab_to_unfreeze = oldslab; + slab_to_put = oldslab; oldslab = NULL; } else { slabs = oldslab->slabs; @@ -2660,17 +2660,17 @@ static void put_cpu_partial(struct kmem_cache *s, struct slab *slab, int drain) local_unlock_irqrestore(&s->cpu_slab->lock, flags); - if (slab_to_unfreeze) { - __unfreeze_partials(s, slab_to_unfreeze); + if (slab_to_put) { + put_partials_node(s, slab_to_put); stat(s, CPU_PARTIAL_DRAIN); } } #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) { } +static inline void put_partials(struct kmem_cache *s) { } +static inline void put_partials_cpu(struct kmem_cache *s, + struct kmem_cache_cpu *c) { } #endif /* CONFIG_SLUB_CPU_PARTIAL */ @@ -2712,7 +2712,7 @@ static inline void __flush_cpu_slab(struct kmem_cache *s, int cpu) stat(s, CPUSLAB_FLUSH); } - unfreeze_partials_cpu(s, c); + put_partials_cpu(s, c); } struct slub_flush_work { @@ -2740,7 +2740,7 @@ static void flush_cpu_slab(struct work_struct *w) if (c->slab) flush_slab(s, c); - unfreeze_partials(s); + put_partials(s); } static bool has_cpu_slab(int cpu, struct kmem_cache *s) @@ -3171,7 +3171,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, if (unlikely(!node_match(slab, node) || !pfmemalloc_match(slab, gfpflags))) { slab->next = NULL; - __unfreeze_partials(s, slab); + put_partials_node(s, slab); continue; } From patchwork Tue Oct 31 14:07:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13441583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8F6FC4167B for ; Tue, 31 Oct 2023 14:09:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96E256B0310; Tue, 31 Oct 2023 10:09:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F45B6B0312; Tue, 31 Oct 2023 10:09:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A48F6B0314; Tue, 31 Oct 2023 10:09:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 634896B0310 for ; Tue, 31 Oct 2023 10:09:27 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1E569C07F5 for ; Tue, 31 Oct 2023 14:09:27 +0000 (UTC) X-FDA: 81405939174.18.5E8AD8F Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 413E418002A for ; Tue, 31 Oct 2023 14:09:24 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Y0fRMVJb; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.172 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698761365; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1rWlR4h5g4eDWf2XTzUlOrJLNxfEOq6mT+00ilTz0G0=; b=FoEJQCbi42k909KZaK35H2VInIZxVl6CYMA5WJKkdFF9bOyRqcP19lQkMN+Nu7VGfNA5vw DdOPUuElepPiTS9b50Z99N0LbeUAXZdH1GTyjvTDWNp8pIFoTF5sHuWmrMMl61Et3IolYY 7U+ZVe21lTyRv2f9HrQLsRHfQ8ms6fk= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Y0fRMVJb; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.172 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698761365; a=rsa-sha256; cv=none; b=Xx31Bh9d45IUEF/YpugW/aZzBjE0uIJUQUmdts3qTL4X6FEMgs0DkpR+1ZOyi85t9+zqL/ 4wN68A5JBhTX0HthcuMYNHChIZq5WGMJK5D4b1zFeTXUKIAPq56fsldgundhqFJAmJ4IqK CRdaaI1F/TFOkWw1LSGB1+eP3DNA1r4= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698761363; h=from:from:reply-to:subject:subject: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=1rWlR4h5g4eDWf2XTzUlOrJLNxfEOq6mT+00ilTz0G0=; b=Y0fRMVJblxItnO7fa29gryhY0OuDSuYpX3u9Ss3dhqwRf1OZ/GJBzbFxGqASfXa3ZkcDEd llhl/Boestl6/Pzbcckw30/f5cm8ZIVtqAPveVEahzHWy0Mm0D45/0Br2r/TLM+w+opTst LbLFwmWZyebAWLmuYs8XzdN4+enFRJY= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.org, willy@infradead.org Cc: rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou Subject: [RFC PATCH v4 9/9] slub: Update frozen slabs documentations in the source Date: Tue, 31 Oct 2023 14:07:41 +0000 Message-Id: <20231031140741.79387-10-chengming.zhou@linux.dev> In-Reply-To: <20231031140741.79387-1-chengming.zhou@linux.dev> References: <20231031140741.79387-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: 55pzqq3gb61ckzoba7ymq8stfxpn39py X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 413E418002A X-HE-Tag: 1698761364-539673 X-HE-Meta: U2FsdGVkX1/EMnZcjQdjuAxMLz7q22EtvmcH524J2fFmxnZDResnAAbOx9BOIYB+Jzc6r1liCaiTBN3pYf1AkPAK+UtGQDIAnU2dBgMiQFbD7AaVTw3c7/hQKVOFDhr890qumRrmbSV7Re9hGnkx7vcwH/IHh6fQkDdMhUYm7adKXC+zlx7wUpcED1LS5GBwxlp/lDIiR1sNADWmEXc6gHFBPDLBDgCgRMkjHkZN0Ca3cWxvCzMJ+p5vbylIhPE4z605O7HI0Q5hdNhmpvTIvzVTFxyOnvSsnRQTLaF7mXG/stSuig1XBH9nMlv+1qbWbcRqFd/IJquAMk4WbJ937eaqFZPyh4NsyzdOkScnLFjFTAEe0A0kJGtsY46jQDpTvXRJVvBkJ2BUlL2W8JLRBZeTpOtOdEJvgCteSQlHg3e/zZT32WKn0lm//yjVduqNRZKBNSteUi4pMBnIOH/kHL4tmM2IgO6iuwcFERXYcjd8FJNOLEycHcmDU9iau1ETC0K0fGivqckLss3VaGypVZxLbYwfCO1TBPqzlbaBgeclUqoo47E6FO6r3VS2bWB0xaAOP6zN7hmVnkoPtpKXFt17Zl7jFnbqPM5IVQjufp8N6e68AXfdrYzN++QrKAbx9TgL6zu107NZ1tu14joB1NUWjYOzguNYFL9ISmA6nSl5ZqKmEvvJEdJVFZaiChZLGT2nX54NVh7Ad+OUOTYKZ5nymXRVfqNONyoZfvHi8y3T9lCKDw48KBMvCaIhhiour2+NzI7sYQ+PRsYZCR3uNdf30ztBKoiB8pFdLcZfPv/ciRIoeDIbzs+0FnqI6ChDp81Z/j+mnLVxylNRYyhmZuvw7e3OVf2Dt24zgY0STnWrz6R2mEbdeaUk0bA7F6AmkhtyL2pnnJ0RJSDR9hNK/1tT1x1rlgNPvEakog2DkcW7U/bIkhpyoMKAtNsyywZWzIrGEkagqXt7T+8CAZc 2IlK1vqT In9jGWmnk0tooV2Ue4xfqOM6cLUYxzUjX4Co8HSk+UKlwrQshC63Rc/y1IPcWXMrxP3yuuwcMSNxfWN4Cc7FpDT8CePKztw9f9KhPKQDptpCzfMSLIcY2SnOZIqIYGO6Oa8YReHJMzn85vBLcUqaXuXNyhYHh+2ct4ybINbEgLBRINKHNi0xXBMaODNGLppGLRexLvzJOIyNhE9o= 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: List-Subscribe: List-Unsubscribe: From: Chengming Zhou The current updated scheme (which this series implemented) is: - node partial slabs: PG_Workingset && !frozen - cpu partial slabs: !PG_Workingset && !frozen - cpu slabs: !PG_Workingset && frozen - full slabs: !PG_Workingset && !frozen The most important change is that "frozen" bit is not set for the cpu partial slabs anymore, __slab_free() will grab node list_lock then check by !PG_Workingset that it's not on a node partial list. And the "frozen" bit is still kept for the cpu slabs for performance, since we don't need to grab node list_lock to check whether the PG_Workingset is set or not if the "frozen" bit is set in __slab_free(). Update related documentations and comments in the source. Signed-off-by: Chengming Zhou --- mm/slub.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index bb7368047103..89d3f7a18a73 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -76,13 +76,22 @@ * * Frozen slabs * - * If a slab is frozen then it is exempt from list management. It is not - * on any list except per cpu partial list. The processor that froze the + * If a slab is frozen then it is exempt from list management. It is + * the cpu slab which is actively allocated from by the processor that + * froze it and it is not on any list. The processor that froze the * slab is the one who can perform list operations on the slab. Other * processors may put objects onto the freelist but the processor that * froze the slab is the only one that can retrieve the objects from the * slab's freelist. * + * CPU partial slabs + * + * The partially empty slabs cached on the CPU partial list are used + * for performance reasons, which speeds up the allocation process. + * These slabs are not frozen, but also exempt from list management, + * by clearing the PG_workingset flag when moving out of the node + * partial list. Please see __slab_free() for more details. + * * list_lock * * The list_lock protects the partial and full list on each node and @@ -2620,8 +2629,7 @@ static void put_partials_cpu(struct kmem_cache *s, } /* - * Put a slab that was just frozen (in __slab_free|get_partial_node) into a - * partial slab slot if available. + * Put a slab into a partial slab slot if available. * * If we did not find a slot then simply move all the partials to the * per node partial list.