From patchwork Thu Nov 2 03:23:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13443349 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 12134C4167D for ; Thu, 2 Nov 2023 03:24:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7C8F8E0016; Wed, 1 Nov 2023 23:24:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A078F8E0009; Wed, 1 Nov 2023 23:24:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87FA58E0016; Wed, 1 Nov 2023 23:24:43 -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 785F28E0009 for ; Wed, 1 Nov 2023 23:24:43 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5646880E6F for ; Thu, 2 Nov 2023 03:24:43 +0000 (UTC) X-FDA: 81411572046.29.6198220 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) by imf25.hostedemail.com (Postfix) with ESMTP id A10C0A0004 for ; Thu, 2 Nov 2023 03:24:41 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=KQjfhe1X; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf25.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.186 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698895481; a=rsa-sha256; cv=none; b=K3jAasAlAXWGEul/9UWB5NdtMKiivYP69OmU1FxmNh+bRJewG4rVGn5yZUB0gwDtvA4C3k 0CSItSQ9tzs0wFMoCdsReo6unr+oluPG2W1lAgGxUc0lyKsHxB8lKpXoed1trTV9lY7mRT J4cEZiLm3/D3q4fkt2y5VjoZN79XvWU= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=KQjfhe1X; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf25.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.186 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=1698895481; 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=SxN7Gc7oPUWEeX+rwHiBiXl514BfxOyW9F4Ey0p4ljE=; b=lTLF7BAiN7Snnq5i6XnF1zctuXqHQ40NmA8EV/717hV2NqzmrP/+kq1spjGDmnHVCmyr1M uCUSGpeSL7ZrrmPWQ9FLAbFgeKW0BPn3EhN2hQqapWMReXNed1ngABI68xKDcKlZV4GUq1 jFQyuCUZ82M2D8Z4w28sSUgXnzEVPwk= 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=1698895480; 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=SxN7Gc7oPUWEeX+rwHiBiXl514BfxOyW9F4Ey0p4ljE=; b=KQjfhe1X0vzh80JaLfhIpxkVvacWOXmJrdGiki+nTBnVHkJnDiiAVRsK2kELO7fDNxvQI6 G6ybzeZ5YjP1xah95OqvCvgzwmI2JTnc6KOhO8JBYI5WOuwCfe9ULPpNMpW0LdOZ/2n96O //Wvc+JEmR8lCOYJBPeBl/5I81NJdYw= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.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: [PATCH v5 1/9] slub: Reflow ___slab_alloc() Date: Thu, 2 Nov 2023 03:23:22 +0000 Message-Id: <20231102032330.1036151-2-chengming.zhou@linux.dev> In-Reply-To: <20231102032330.1036151-1-chengming.zhou@linux.dev> References: <20231102032330.1036151-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: A10C0A0004 X-Stat-Signature: f8kdp1bjfdg1shuuumc415rnabpapqzy X-HE-Tag: 1698895481-53424 X-HE-Meta: U2FsdGVkX182y7oRFjUKNu/vOAPJ5Dy4FDTRursOYxzRgjJzlQiqWSYF3LrFVFlwhWR0JZR/zPoPHJEC78m0WIG1K+LQE2EaBf5YcAVOQ1SQWAZS7lxePVE2pp8f0EjjV6V5LiHcoChskPvAOftoPuNnePfrY7/9wI4U2O+xBNEvt+nHpZFsRCh2XErGSaHTFR54PPyHfzvvjBUR1FmAmMUAbUk/IRYKbmL8ZfCgPdcIGEtDDbbVO1qgvTY6kDIJkb54ZbYow7RxhMuM28bXTAZMjMyaR4Qi9BzyqIb525kmEDa6ax2l0+dp/vKQRLaX3WVPxGKO3kIok6Ea6AsDLovURXiGge+PebP3R1dWi9+aXBbrMJtWFWS1mqiKV0iQMtSWt7SmYzMUD++XEwrk3Q04IorXDcrktYtQ5OpUi/qF75QjnJgchs7iC6og8N13dMwJyH3wpGRXdo6N3z/mOnZlOH3IMVZ0uxhc5jZH1kKXNuSSppDyHm0Z0FYRd+1yjLyJKJHwRI24MjZOxoVuB0l3NbVhfVxfQkawmVah1NB9Vne4v+bNlNVxUDQIPncq6aHy6vl8W/Xe8rEKz3jMPTVu7aYTjuyw8V/76Ff8wkPmSxQa+VFdpzJvZITajPIUx3gzntVaAS0RYckcVcKarnZpRCIqWML5M0UjIAG6BIaDQsybMbBeiSJjEFiGn6jdocjuC4c2Zvh8XTV7v844Cg/6bL5C6W6B6JFIZ7HKwXjOQwfs/NUKaDWTDHcmWhLFjwcioG3jl6L53+UI1o1th7PtbURgNSGFVJIpUhR/9V3NN6zohz2d/uiSI02M/QJnacd5rb8Atm2xwiBFRM3trMHMjHbHpFp3t0AGILTfdn6sMAYJdmCPfQAHvLRITdfUwupr4KqgH3hykj2E8GxTkwKqG9h0rRQPKWgPCm4lmIq8H3s3ot6t4knRyiJ+v9YV/H7/jPsL24V5xSdGvWH v0sTrsfk Q5C4F6Ijgi/rOqyJ1T0wtn1/tl3RO1Tt+2ZR/FhSIx9OVfvFft3BPABMnw+s8BVZ7wT77dNO7v7XYZYV3Ngy8zh4m8vt0QEMGl062cLQIMSmwyVl9bcIkXUGu9fwpquhBLUtncqJ5Mla/cB8AQPeX9yck2txPkSsdL5KnV21u/QHjDLph56w2/aeoDA79JKyhnEXOBRJ9Ua2VwXb0/OY85kae6zG/zUwzMpF2DFz43FQ8wt4U0fHqjvT+rde+U0N91oxS/eN7Yfm1+n6V6pG1ccm3gg== 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 Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- 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 Thu Nov 2 03:23:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13443350 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 248BDC4167B for ; Thu, 2 Nov 2023 03:24:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF2EA8E0017; Wed, 1 Nov 2023 23:24:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7B068E0009; Wed, 1 Nov 2023 23:24:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CE0C8E0017; Wed, 1 Nov 2023 23:24:46 -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 73DFA8E0009 for ; Wed, 1 Nov 2023 23:24:46 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 46FEA120E03 for ; Thu, 2 Nov 2023 03:24:46 +0000 (UTC) X-FDA: 81411572172.07.0BAECA6 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by imf20.hostedemail.com (Postfix) with ESMTP id 72FC31C000F for ; Thu, 2 Nov 2023 03:24:44 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="Hb4c5/5c"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf20.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.177 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=1698895484; 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=rXE5qC66xflKju/b5K0r0xT61UeednKHJ/BZyj3zT9w=; b=aeeYG9i/v+120qC6g1Qks0g+1Y26Ml5l9x/mrMJHmvOALbwkbuBp6AxSZTM99lXpPyAl1W Ebf0RtVGztlKjKJTG1P4p4lOsS7LcZpt5+9qJXW/EMt88mSYnhdntXChAkR0oOFzZHelNd 9AxJGOljgucPUEjuBN5XVoP033c/WQ0= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="Hb4c5/5c"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf20.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698895484; a=rsa-sha256; cv=none; b=bwksTKhypGJ5OudPm6l+EYAthN8z+6EMtzaS5UspkbP00eVVr7iMoJK2KdzBcOgh6r8dzt gyy3UTQmcO5ikSq4sq11erct3nEIFYfY5ow0NCuQV0C1AW+EnY3bM0T4xv1aih8zyksjIB G8mOn9/759Y4bMQpIm/kkXV6GSLQGM4= 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=1698895483; 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=rXE5qC66xflKju/b5K0r0xT61UeednKHJ/BZyj3zT9w=; b=Hb4c5/5cMu557sfyb4Qm+N+E2afW9N5tC2dmGC7W2tqshdmHyIQi0ignzc96Sfv3lH/6v4 /pMsyHBXFmwbe/kt7UshRgo+l+u5TurmWX3zHZI3IJ9XGdtBS8AY4ZNbtEcl52hm/S2deO rdYAz7rU1LmdQ25nUsrxBo6s5PDHjlI= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.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: [PATCH v5 2/9] slub: Change get_partial() interfaces to return slab Date: Thu, 2 Nov 2023 03:23:23 +0000 Message-Id: <20231102032330.1036151-3-chengming.zhou@linux.dev> In-Reply-To: <20231102032330.1036151-1-chengming.zhou@linux.dev> References: <20231102032330.1036151-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: 9wcyz5wg45ne1xz4jrfzip745dnqjcie X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 72FC31C000F X-HE-Tag: 1698895484-215925 X-HE-Meta: U2FsdGVkX1+d7jMI4wLqS3fxQKV5Mi7Dz1WTGIX2ovztFHZ1YYV4CXJ7NogwfmIMFfCAcs13cAz1Nolru4vSTKnI8VyNUQ64HSXBeJZjkBAqWPvXhq9sJUvNyD74EWeIITRsG7HAR32nJItRy9XtpsbXVJQjM1uCI1x5G3DLHOFnRvvgRRYwxLolW06hg+ZWnZRMz7gMO+46oFpwkqPDtv/We6eQqWNkaWt975C5I7QBIwOHKgUIuKkkC7ZBfm6S54adOjk9EzH+M30EvQ/giZZRLl5T27qcYZrVAQ4Qc7a4ivgfZc8NYPcBWPQJibZFNLrN/aejyLpG+qnJwz4KBC3jDO3XqY4eU4uGtuImJhUMYn//6WrsjFY3KDDJS9+4yut41qfnmIbiPmGp3znOA4b+d9WJHzdh+gmZo9UK5hObiOafyLYJxqukQ57OdqygGnKK2KTOjFU0Aa88ZtThwYmkjcGp2eDfmYyKu6UTSCQ1nI87HFi9ezCHw2Du2kiax3tpMYQrKB/SzPiZeRDCdyEHx0IqUg/NL4B0i3v8AJ7jZxpZuORQQXwXhm5hlOXDEYo7q5G09C/RIFjtKJ4yZ7b1CVG4+odxCGxt/KFQaSFu6s+eDPRU//0MIFSI55R9DUebW6AJQwRwMtkY7DFwbCS828Efee1DPGovE5G8aNJtpJBx5ecxTtHM1mBo3N8KGy06GNHWVWLDPKl+TNy1Xua6BBLUDCEbKE9U0KGnl+MtVBYemsepSIK6UDzkUx1z6ei6QPqgMIWQUkhz8S+84EVKjkfRwgBWemSURDkBaymq8xIQDGPBEdnLKfXb57/m4Rri+a4o+xt88l2fMWqfSzA2N+eXoS4PeRZ+CTEtuEyLyxDIzCq+aujIR8POlGxT0c4AOdBl1peMwjIc9WYcAVSotxRjvGQtEEwlMJuMvfVBDllqW3C100cH+BoKDDKQpVi1/9ZYf2gk0K42nbd O2P/XoYZ rFXqCJ0zUiOt4ojQDOpEPhrx03u3CaKSkOa/Bwdku86+YxC3gdMng4xKzYMmkyPz52kQkmjsCR5WE4ovPfzFKIIylqxy+zJuW7titzTl4EzfZIgSiDnRpc9cXgZKC7v2D8fvrUSKtxtmuGuRSwdhX6hfjoOuzj5Y7UX2HyywRV1mKsK6zFMv2GbD2ITvX5OPtHlOvWd9QVPuKIUa3VTgCG4cA5MuCqRDPcp7uLZ9hBfaz3f6D6RN5+DKTMrGChFU8V6iab16Elx5PedAtnKNmxMVITg== 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 Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- 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 Thu Nov 2 03:23:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13443351 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 053BDC4167B for ; Thu, 2 Nov 2023 03:24:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 798A68E0018; Wed, 1 Nov 2023 23:24:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7223F8E0009; Wed, 1 Nov 2023 23:24:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 599CB8E0018; Wed, 1 Nov 2023 23:24:51 -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 417638E0009 for ; Wed, 1 Nov 2023 23:24:51 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F27B31CB59F for ; Thu, 2 Nov 2023 03:24:50 +0000 (UTC) X-FDA: 81411572340.15.E249B8A Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) by imf10.hostedemail.com (Postfix) with ESMTP id 40118C0004 for ; Thu, 2 Nov 2023 03:24:49 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="v1GKoBc/"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.186 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=1698895489; 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=IPS3iWC0ordY9Z/gFrasLVfoOU0ee6NMzPFkJtmjEdA=; b=y0FSEBn4zmEm+t9ZLRqPbSnajqqH1ocfqhccFNY/uKvOndBRIktv0sEbCr+o+TN0NR0DxU N+8IRJVCKjHvPuE5RS4Iyv8YmgBrpBADAFvkTiPsTuqaa6D+tlJgUjeOnc2ysS9Uv2AXMZ gLTjdPNf0As67x3Wly00nuO0P3PwxZE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="v1GKoBc/"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.186 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698895489; a=rsa-sha256; cv=none; b=GBQmvEnQLS855tIVI6k4lT2KbBssgQKAgeYSCKNdWPyHKaGxHMW6w2naB8jTikEy/QP3bQ xnlRjBt/pA2l5uDrQp9AYH0JF+s+wMSbfprLZHyp+a9cNOO+NS+KOvNVCneS8YFiLwl6nf vUgaeZh9ZX4LJdLpqx+tZCRrlK62TIU= 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=1698895487; 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=IPS3iWC0ordY9Z/gFrasLVfoOU0ee6NMzPFkJtmjEdA=; b=v1GKoBc/GWi/6wA+3MMyQ6L15tftj7e2VTfNMKRmvlXo85TA0YUcUSnVVJ8Kga11asCboO btJ3b5nOE+cya1I08GWukxT+lICauUTNrau2aealf4F9CdmRScWkmlPsoHeV6UcabxAXZx LYjHaUg928T27sxO5LCHMigYm2gu+Xw= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.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 , Matthew Wilcox Subject: [PATCH v5 3/9] slub: Keep track of whether slub is on the per-node partial list Date: Thu, 2 Nov 2023 03:23:24 +0000 Message-Id: <20231102032330.1036151-4-chengming.zhou@linux.dev> In-Reply-To: <20231102032330.1036151-1-chengming.zhou@linux.dev> References: <20231102032330.1036151-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 40118C0004 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: cn8zwqgx98buif8nomugsg3z1fhwkzsf X-HE-Tag: 1698895489-574151 X-HE-Meta: U2FsdGVkX19PJBZNEXIlYfAT8injr3nxCEwyiloXNdc5I2/1kZwa3zHicBokbyixgvYysTPfVxIC8qTbSZ0XGH7HcJ8l7wVAfqukHw22vATUFPIXHanm3UoAJSXES1XS9yvc5oPhmYj/AuTrvZotJu0oYGoILuGkEopHtI3N92yE1Rj7wKAIdeZ0tgWPoJCcv4NaYuTuZ8lvZfB4tK7mmIpRxuo1F/dVrGF2tJ+4djmaOBSr9AgyVRRF+QAnLkuQVx2BuN91X/RnRs8pJMxGzEsxVOOep4sSSnBdhPUT/7ajCdmCe743CRf15kAkk944rP1pb6srkyI9w5DkrrAv3c+ULNgWN0Fr+vB/yScoOqItctm93uAwp4QXheu0U5Q7J+FyDtr+B1efw7+/F9htpLzkcHi1weZ01W3zxVlw5SIG9kITYnJQ584Ii8N/wTgxmTYm0nc20ivcMJm2tC/jh8kQQZwrsEK3Ur7WwwVXnxpckrpmYludMHFXreu38g6RWJ4t0icqdLYBfduq5Netyaj+D9M5MBev1hmdl57SsxmSYzIbrjB3lcqLRH3qxBPxVcW7esX+d9PgmVoBPki3MSbphxyHZflG7xE+VOeycI60IcCfC0iffFEdbYUatj8E6PTS+Ecr8ev2UqV3HrUEx4qyeosqbdmEQGVsMTwfmKciCZWBE3IMWFuczu2EYpk8p1pzjSKAyjzaVHr2yntXJefiBeVWLyvuhq1mac/RCx/bfyTTH/9FVBAlZMXXRTn2NEois76W8u6KK2GFKO2WuwikdnhCQLIlSOQwM5idT4SK2SJ4tS+j5S9W/pgvzjo4k0khD91b+vJy2H3Z+Hvgvx+SqnzyfM2Ehuc8DcqAW+2ooltZPTG9LHbKFPgmUFsvCaZBIECjjUziuP6HHhqNXK9BVvKVV+mwgyguptkbzkZi89/qZ+pkmJZEGCQlb1mVxrClOi8IvzNM8U/wkcL 2JwzGSKm RpdUT/mJPfIjwfjqotvTv/FydGQIemXo+3NU3xurJhT6pOhpZCOpC3/KgijWKzA8we7bQyLCXuXztTNlzlPtE90QFwpAk7p/wOBSLJ0nzvtVY+fUpi0pf708ZIozvj0phUDZBRlW567+quGDG+fQMIlSHoHDncNtG0xEC8pjSe2NYLYydNUXwND74osGdHliLJH+gZTY4+5n6SbHKNylziJYOWLyfbPe1KrFHjvbK1zn82Xa9D8ztCeakfaTEt/jb0e+eF0mrYBE+skz9CuQ08GGPrcsx8WCw7CEt 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 Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- 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 Thu Nov 2 03:23:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13443352 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 E36A7C4332F for ; Thu, 2 Nov 2023 03:24:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 772188E0019; Wed, 1 Nov 2023 23:24:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F98D8E0009; Wed, 1 Nov 2023 23:24:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 573D08E0019; Wed, 1 Nov 2023 23:24:56 -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 41A468E0009 for ; Wed, 1 Nov 2023 23:24:56 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1F73840DEA for ; Thu, 2 Nov 2023 03:24:56 +0000 (UTC) X-FDA: 81411572592.10.ED14053 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) by imf10.hostedemail.com (Postfix) with ESMTP id 625F3C0005 for ; Thu, 2 Nov 2023 03:24:54 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BPwts8cC; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.181 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698895494; a=rsa-sha256; cv=none; b=Ab9Y4A0mrRhJxzNx4JmEhDB1qn2+/gAgpxHk+z9X6XXWcVJbx7ETkjdhyXvAvIizcwJ/SF PhUXTo4vw17z7JEyvoFGa7xN2v4bkxSM9aKBn/DYRxwaFo2CvxfztyyksI7IlRgDPKVaXQ 1/s0C158C/zOpLOA67ri43Qd3cbzsyE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BPwts8cC; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.181 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=1698895494; 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=f6Me2hDPNAg0QwflvoQbBjNc8QPP2obW8dtDV2OvsdM=; b=e120VBwrKy/QiFhe7Lzvp0J5wHnB14Yni7fR3fX/NebjQoZzpVVxYsNA+8lQ0zr6MpNgDE HrmoNG0mtX+L80PZjvA1ItsEZmcl0TO8IwiWusV9/rqw6hxY6MeVZVqZCDm1AXtDTd2YV4 JsZFnXuToOIIfAa/epnNuwPVcAaigKc= 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=1698895493; 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=f6Me2hDPNAg0QwflvoQbBjNc8QPP2obW8dtDV2OvsdM=; b=BPwts8cCYtipUTdyFWricBp8OGyxnWzOEVZlgGagJ9J46S70yP6mdX0Zikc3F0F2DBJvXT /yMeu2ntPNaXcbiqN3TobVLGvOh9MDaYMJyNpEP8dSexDMJlp27RoUaeceT+iumgN10Z/7 Sn3Ry4EaMJKSfkAaTC3ksH7jqeLcYEc= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.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: [PATCH v5 4/9] slub: Prepare __slab_free() for unfrozen partial slab out of node partial list Date: Thu, 2 Nov 2023 03:23:25 +0000 Message-Id: <20231102032330.1036151-5-chengming.zhou@linux.dev> In-Reply-To: <20231102032330.1036151-1-chengming.zhou@linux.dev> References: <20231102032330.1036151-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: 625F3C0005 X-Stat-Signature: 9f5idmmih4q6cawyzexujopmnxjtabsz X-HE-Tag: 1698895494-616696 X-HE-Meta: U2FsdGVkX183eXK0HCLJpJ+9iiWG20eqGchN88U/Du40688IAmX3Z7yKeQirKxJPqR6qRxQVliEfIWtEZQCqYwC/VQT6shfO9Qg7fMQmlPsBtrZ3p/NMZnd60JViCqr4Jyi6pReoqMPbhFXFsFXGm+p6Zbqvm+/+kp4XHrahc0aNf7A87aSX206O6SFIR+SYvij0bNkE2Q5msvOX9HhRDuWrwosx8vrzkLqN0R6U1eQudUz2QoBvZxpfRrsiiFCvKEPPjVUon7zN9E/MvzlzEF+fwDnKBflDfv6UvKn2ZpXjSDHq6QEzXgTq34Bzn8x1Hs9S82JoY94sS3zSthAJ0ey8EJ3v91X39qLsBibp2GruLNZ7F0V5knOj5iU4T3VEFQczr5D8+ucxoRkbYVrJoB7CAxYon3KufMGS6fSd14TxhoiCOprS+q/mkHC+bgOF9qs4sSPzIVSB5Cex2AQPtvpy4MHdOpnP0nMHI8axBKhMcMmfBadQruqx5edPT34DkcXP3GrHkS+N4tPQe7EWbNwEhy7Aqc2KG6SsmUXqZUfCrA6LADm4cleifZEldu8GcqWAVdYVVrYyc0AY5E6aNwlpCetHicG9j/lZa67M0R/0fZdyYGolRMrsdJSwpEFBFRNPkjXWErWugup2bNav0tsagsBDe7dwWp+8S5BTfWzICnVEzmn6jrdeVe/S+GIlCsoxAWDcDgZTa8sUr8KSCh3HRm3HNUPLx97w8gTiieLwz6vvWjsHVbSIIqS+rTAIX77KS2/XYrdJ/xetdz0RGpg3gKY1PlGWBy7c9Q97hrSzLH/eNoxspVfMBOL69bdb2CDFmcmdtfpJ5hWCnNJ3ucEBGQXaS/r60sfhbI/JqiMxmfmGCb2pfCjDYsBqmaoYZKiXWVMiC6CM4P2sueF1KKYkfiRpRlwY9WmgoTQy6AsQuEhiZWlmyWA+gjqnraIfRWbgNj45peKNq2cEgBR n3IgkzuM ztEWQtejJZpg7OAx5HmwdSiYlc5CiMrS3EZUvHd6e4vUcewZpESPkI8so2GQOOwFXHBpSUGpRo33ThcqVGmpcG8XFJ4WAsMIxxP/t3Y06qCsFaz7RpnK0RQqMwVp1d+4K+iQ0mn2O/r30dQNYUwz3dgNtqTKsYxNZ0w+qKqS/kG4BQv94E1OVp6PmTfWIc42MxOPxFWtCSKkvWFIMGhS5szVFOFpQEw2YYlwEZfyua0EN+3DLNwzLbFL6e8biJZki6fKHVk50bLUZhQldUCuIV826CA== 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 Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- 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 Thu Nov 2 03:23:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13443353 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 D3B73C4332F for ; Thu, 2 Nov 2023 03:25:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AD968E001A; Wed, 1 Nov 2023 23:25:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 636108E0009; Wed, 1 Nov 2023 23:25:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B0CC8E001A; Wed, 1 Nov 2023 23:25:02 -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 3613B8E0009 for ; Wed, 1 Nov 2023 23:25:02 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 133721CBB82 for ; Thu, 2 Nov 2023 03:25:02 +0000 (UTC) X-FDA: 81411572844.10.6DC286C Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) by imf15.hostedemail.com (Postfix) with ESMTP id 3EEB0A000F for ; Thu, 2 Nov 2023 03:24:59 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=lFfmSKyh; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf15.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=1698895500; 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=Y0gxyVelJQEnoALRuyqBzkeEChILTc95BveKj67/aCg=; b=Gh85aiDB6Jzd/9Eedb6B9lBg4J5zcN56bVOtCP/KVg4hY+DoTvIOUw/O3yP4bSKEqLyQoP o59Tgk2REspJ9DANYCiHo62k+Ng+KPbawf7hzQTSDj75H9cEIuclgiqNm2E7sRnuEQowvw M1MgPwnv6bYf/H+Kj0L5qkgbQRnI6ys= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=lFfmSKyh; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf15.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=1698895500; a=rsa-sha256; cv=none; b=PrRw5N4A/qd9b6+Yk7PfiTMNwFXH7z7hytp93bw9dZRhwIg9lAzACv37U6/Rrp3OCQtqYi FJBd7nlyqys+5Rncl+hCj9qPcq6rBMvPys+ifUsrkda2LjYCZpbEl32VZd9nth4ttdRIqB uufApakDtVY/1BvhDBQP//fMByCU2eM= 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=1698895498; 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=Y0gxyVelJQEnoALRuyqBzkeEChILTc95BveKj67/aCg=; b=lFfmSKyhGA3gVCpgOxB6Id7LBL0rMpEGl5gAgGZuLLsAnnTy6no1BEn+SeD5u7+7EuXT02 tiwcrE0IU15hQr17N0/O6wDqFW8ovwBIDEs0JU6KOd0J6sBKfSBYsgMLgyQ2qyobNj/QlF NFtNE/LIi0zdnMrItnwzeHEGbAdss+8= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.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: [PATCH v5 5/9] slub: Introduce freeze_slab() Date: Thu, 2 Nov 2023 03:23:26 +0000 Message-Id: <20231102032330.1036151-6-chengming.zhou@linux.dev> In-Reply-To: <20231102032330.1036151-1-chengming.zhou@linux.dev> References: <20231102032330.1036151-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: upish1qdy6wz3cpdioefoo3tkoqbpkkb X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3EEB0A000F X-HE-Tag: 1698895499-9114 X-HE-Meta: U2FsdGVkX1/MSrUq1ekep23lNnZFdBUSpgGqrolELKkIJ9nVyJIEDOFAzQXl9W5dOXTOj7Pyjtng/J9Krz9pJANbUK1raHIyQsUy5lHFVu09V0SrCA43BH8DQdxejGqB7NTQKYSGGNBuPaxFUIyhxG9+FlH7idjha3hkMM0WhKT2EIperqJS+hm1iN82QCfEdxRFgoaKVJgIE1o/iMAq4BKVgQTqS0/XTV1YVlXY49XNdbz9W/iL5b8ogMhk8rl9QVBVJl0jaXULYxbDteFulVZHh1wCDMYh2OpbmGvRv9lb+BdE40ee9m8EZR+xAyxGgMzDd9Ku1NMhDkjULEIUdeGYaRXqk1u3QPULneeR2oUpjiT7/RnTy0JX59aRIy6N2OPzYyxwCesj95/oK5MnfgbSY0IwqUxS75Nkt9W77JsdY7oo4S/FXp8x4hC12ATg/CEBwOHGuabyKym1f6VepJQPrea/cZqLcczCQBY909erDHWFj1gx4UReQjILWQU8gULSAIaJwM5676c2RKtugkC9iDnqOH92FW6ZZCo/uZ+RGmDx38fDt2SuTP4UOUSq1ckd2vFvK4C5uRvQ82WAROU5YTB0MnbqaIFlONSIV38tbw/kvG7NFOEjeGeCsgskD+M42Mfw1K6CyeCK4Z3Z4ZR+6ECo7sSvoaiRso423hNyJsksZCf2UJFZF88g+w3TW4QdqjKokijyCiGbbPLJwWisXuF6Rpb4CMccXrt3nt7Co+7xGp5gFYOH1GPmBEItrri4jtG1W/XDWSlc0zVrJWC51qEfsRq7MMNvokq5h4oMqCuoqfiPZqpnVhgB45+RksAjydNy4jXR/sFVDxX5ZrpxGOTu0qYKMqouFLPG+ro8xvN1r34qI0mp6jvjKL0gGygrCWFcoV3jxzPZhYdJYF+7bAhBfqEx1yR6ogXs9EdFLS9a8cOJorxgVBREnTKtfABIkE4yqS7YgfmwtXc PotDxwN8 XvCYBb4Wqcxl159eQF1ji6fuy+Zjgw5oU9+AJ2+pcxAFjY48DaFmjOSF32IlRvYyvbFdf1xm2QLNzGC4UZbpzVQ6iib/GOXVuAw/MADeGcjb1NrsfGr3IwMqICIm2EP3miRM6XbbuKm76f4xR5i6yQKdsH0DjQAEdugX7l0ZQG9PReU4T3+KeyPJ1+J/835QE7wNA1C/7khB1HCf8hgeOK5dypA0J3mVfxTCaSjHI6+xmWRgc6/sYgSGwGdVrBuwWzVyWyuiqHYaaWF4ojJt28dHqrw== 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 Tested-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 Thu Nov 2 03:23:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13443354 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 7A497C4332F for ; Thu, 2 Nov 2023 03:25:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 109B58E001B; Wed, 1 Nov 2023 23:25:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 091AF8E0009; Wed, 1 Nov 2023 23:25:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4C158E001B; Wed, 1 Nov 2023 23:25:06 -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 CECC78E0009 for ; Wed, 1 Nov 2023 23:25:06 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AF9C440DED for ; Thu, 2 Nov 2023 03:25:06 +0000 (UTC) X-FDA: 81411573012.14.CD8AC4F Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) by imf22.hostedemail.com (Postfix) with ESMTP id EE491C0012 for ; Thu, 2 Nov 2023 03:25:04 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="d9B/WWGs"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.170 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=1698895505; 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=eS7MrX3LWikN1DLYb4lOax9/7h+5CRyI/1/wKTB6RQU=; b=hy8demntoRx8AdC7XGSPH/ONNvqnqNusOZYwT/ugd7nWyG8WGGvaKVDq7bh59SCNirwVFh GXFV10QoyvcDN3WMowtcN0VVdxOHVmvfLPWF4VaZw+Z7R0pHhnpMukz8HTdQYl/7kIrBmj XIkv7NKxXnuAbuBPOmPCRmwe09krI88= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="d9B/WWGs"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.170 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698895505; a=rsa-sha256; cv=none; b=p+fhd/BQeWaz2Eh73IUH3y4heonIzf7xdmhaNQQerglSC9iLok7h4sqFJAeUR/6W0dIhfM ZjLStgpCMmKuVz7kZntFHlD3JrL76vRhaS7ktuGlrY2A/1nPkurSdJycpxdz3piiToh0ZL MUtdpFNKOXtO1mfWzGS7IGEuVCiNiOw= 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=1698895503; 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=eS7MrX3LWikN1DLYb4lOax9/7h+5CRyI/1/wKTB6RQU=; b=d9B/WWGsa8AoP9ussGNC0kPusAYCFPBeAQmfPhKZ7WEK7TjlN5ddZZc39LBarNoAdB8jIQ DDraEREuZQYSs4zN95VOQr3psrEiMT5K6FXATomckUDVHfNmgi+DDJbjmbTyYpRL/M4j0p 9h17G+GlKq2BMQwQZj0ZOUhtnjzLGpI= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.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: [PATCH v5 6/9] slub: Delay freezing of partial slabs Date: Thu, 2 Nov 2023 03:23:27 +0000 Message-Id: <20231102032330.1036151-7-chengming.zhou@linux.dev> In-Reply-To: <20231102032330.1036151-1-chengming.zhou@linux.dev> References: <20231102032330.1036151-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: EE491C0012 X-Stat-Signature: td1uzgu53jp3cri911771jimyw4fxdnt X-HE-Tag: 1698895504-953416 X-HE-Meta: U2FsdGVkX19fpNEPUF2hlo8QoiDflNknwWVdZywIcu8/n3UFU063YMRmQimW/6urjN+TECL5n1ktaNG6qzjeCqQSDuT/0UJj0LlCuABEAzraJP35YOOa9BCwXh0rJFLs5RofrexACGQFHGwILn7SZB/FUJ9aPa83YHNmpLjeguCUCSnS/iW4FzAD6iPBFiIekZbmq5+/Xzzp5Re5o7BcvnMFLlmitsmXsMbUFqDfXdXr+AuWF6NWfnhTNpM/YZOE/pdmGTQXO7Xn4ki5NDF3ZyOORk7tXYrpxZfBpNNIXZhlpnfngVR8S9D+av08fAkP127YBWrWjH0etSPNuzVK9Ww/u7K0Q/pYOROpwZWmnHPQakVs4cuEpJQ71OFlPwRsipwz7Ch8238wxEfmZKs72uqD3xeAOuH7DW2642bUm+ZjfEamxendJF5aFvS8CmjBDGtjEyXkknOWoH+o6ggTDn3nDox7V0vz/f6i4aoszQlkm32f6rQuxjA4F/+GWxyO8yrwdxK5IK2MNonswMq/2C/DZaXvxk7ez/0uJW0NzURwzCQ2Lh7YKiOBV/5MTxHY8OoCOQm6osr2cIBh7OjgWjQnMAO5LYvSecGKmDbD4kPFNlW8Gftw7BG8EIvHfbkoRB5V8BKNQHxNhlDByCX9/yRxTPLU8FQxXUaLGRBKg5b31iYFqh1GNDI5qLS12rANrit1R0p3Oxl1QOMzTP17uoUu+hHh1HEj3Pmf8IyD67p0TkbQ6YzPXidNFJNRjV6FnpdYfJz4LIctEfI5KEko8Me3wKu/6Thq/nLjjbRsVDhoxNiOFal7ffV1eCdExt5tC559czcQ87Z0snVPynnvkqIVtrnkvaTA4D4kmXs45k/zL6U7dfOlwxgO34rlo2S1M5rUJX4rHl6PCbTfpGiREG8JERJ7iX91zBs0rDui/s5M/qhkYACIKO+DIGHVP2DUDSYIcqf5d5v7maWH9G+ /j81CsQ9 v7MjOhDMbM2gUKSt8FasfEOFM7gqeYXHUMG36uO6vbjCwK/In/fZQVAliMsQrg+UiE2PzmzsUJsBzVYPbiG3HVdT8aZarBT44xvvYc/wvZAcDaqYTDSuuJcrXoW7RVIyMt34ImZqclC6Zs5vJL/D0U45cef2g9PcbF/iweOaWajbpdeEp5FYNOh6JeIpYH+BYn8BuYw45PIqRxDkTRdF3wxKl76PxwNXNcckXhiM3Gl6anC8= 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 Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Signed-off-by: Vlastimil Babka Tested-by: Mark Brown Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- 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 Thu Nov 2 03:23:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13443355 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 A5A48C4332F for ; Thu, 2 Nov 2023 03:25:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3EEE58E001C; Wed, 1 Nov 2023 23:25:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39D4E8E0009; Wed, 1 Nov 2023 23:25:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 217DB8E001C; Wed, 1 Nov 2023 23:25:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 097FB8E0009 for ; Wed, 1 Nov 2023 23:25:13 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C6E68140E21 for ; Thu, 2 Nov 2023 03:25:12 +0000 (UTC) X-FDA: 81411573264.15.6B88144 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) by imf27.hostedemail.com (Postfix) with ESMTP id 2007440009 for ; Thu, 2 Nov 2023 03:25:10 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=gHbx+Mfk; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf27.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.170 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698895511; a=rsa-sha256; cv=none; b=0Y4oQAQR6t2Rp5Wk+lE8cubM6fpi1UJH+GEX+C3MjniH3tBQ39H4m9E5+lCE+aDF2kYMlq sze2J2S1E8uLm3uWgvudtAwB2+Fg19PsL27WCGOuzAjipjJ2yjJpF09isOqxYhx551Bsya gUHacYMiBNr1NoRgWTnJ0aWPMOOoRaQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=gHbx+Mfk; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf27.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.170 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=1698895511; 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=bbgfkr34Ut5bOat3PkSebFKZ4A5Cv7UHaj4yNDSPhuU=; b=rjsi81zf+gZAmQWL7MG2erabCBTSkGoK1OoRMHvCc8PCk6CwgivXYcOdEZEUWq8BFl73O3 fVZFz215HjwFk9xRhoeE0N7S0bqK2GkUWZ9asDiCxo0Z4ZmFdqtPeEms67QKbERIgv4BH0 e0Q4wKGwY6IULGXCfSWSXWBrq3Qxt4M= 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=1698895509; 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=bbgfkr34Ut5bOat3PkSebFKZ4A5Cv7UHaj4yNDSPhuU=; b=gHbx+MfkKMaXjWLoeHR6R2/oAAyFc9gfvo3ohtd4K4S4h0A6KE0hMrTwtFkBS0N7jtWhrk xt6ezAgfua8IzYH47q+ur2/jbneBGFE275j69jA9HgOkeQ4CEUTLkH6FIThRIPBcrygeuj fPAujlzG9ChYjmdwj+8gHQRxUvZnQVo= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.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: [PATCH v5 7/9] slub: Optimize deactivate_slab() Date: Thu, 2 Nov 2023 03:23:28 +0000 Message-Id: <20231102032330.1036151-8-chengming.zhou@linux.dev> In-Reply-To: <20231102032330.1036151-1-chengming.zhou@linux.dev> References: <20231102032330.1036151-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: 2007440009 X-Stat-Signature: 6ip7gy7simk5wtzgrqe54ixx54znp598 X-HE-Tag: 1698895510-600265 X-HE-Meta: U2FsdGVkX1858zjIWRy7MagTzht5Du6r8OylJ0S5e6+zmrFo5gT0uiaEUKff4kgqwx9InrVn/lj/MhTb5mqKUJxQN/k2GcLBUD0aJRNYnAkSD8Cwe1W49pLQP6P2eS3so82LiwdzVI1qMNWGdTuC8t1oebdRiNU+MxyKFX8sPZo0iYqZKL+p28SsuRDAodODFDQdfhGrkWsS7ieFiXkVBkN6LUijTZYR2cK7PZ+F45noz2zQpfFsSb0IiDJCOwPNgeGM+pfhZhMLXe0c30PhmbDdbWZJ6kzdrx2Aufih4VY34zs3hzdaYpBHq9RilIR+j1KHjqXCMb/AUGnp15+DLrrPCFaMma4POk420zqj4VGHfW3YZo6oX7pcMCq6V0QUmzxi9to+LuJU3HW/pRB+/wmErb04pLoylYIAEZBl2d2n3bx78yRAobJZPBobuyDqjKwFw6W/vakcsjU+l81WmMBPkE+nttmHGUAlxn5Fcf3z+KBFu7tsaJf6fgijwsdIYzaxi9igycp4Nt/SbJw6gnRzEe5pnfM+f1ZuofQtEBuuj0uvE8G8YK4K574zDjOx3kUu1/jnuWZsq+5EpI12vISG7OMHxqBsmXaRj8nQcMyznEmAvEVmxQ43sKE/dxXiR/n4/EgGHkclGeqKb7QkbWHJTWyup50kPfD6XL8js5lPPE88nU7GZujuZqzla34ykQ8VQkNUu+BFdTh/aFTxnaG3YIyF8xKjD7UydvIXsCp27wzv7fYMwyXQFSW6n4aRNht5SBjmF7Lcui67RxHJU3J/pKUWgoSiW1Q3mj/TiqljyIbAxxd+geLSTpoxw90CzZkMIvBDUP0DeeLR7IMVgKKmzzemHfOzlAQxOd1mz4kvBJl2weFoz7NVJ5LZdMWz8hZFtsNTTB35MwD+C1drJZGvyeI7j+Lq1vV5NCY+ic0GWooMeqAXkvYJaFrmErrdY/eua3A3wD869O2zmc1 lkIaI1e3 hL3Tb0n+DHy0TSkn9FTx+T3dDt8YbcP+qhZ7jsKvwlIQpVZ5Mlc4FfvITSaf3cxZXak1ci4bHA2eQEJPiS/7BGZFwlaXe56MWLYxh7homZiQQWE8Al29j+cQx8mQo5e6BU5xgNkp4o2WWfLcpYIV0P8sq4J0AGqREs6zEXbNhaOtmorS2WGxYeOXsqMQQj+wEzbSF2YYa35RVDrKsJUFletO7GfHwxfMNNR2yRED09vPvY8Cktyne7B5UJG9tPTEGjP9yQsbKFaHhEdMx3sS4RpSQAg== 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 Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/slub.c | 79 ++++++++++++++++++------------------------------------- 1 file changed, 26 insertions(+), 53 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index bcb5b2c4e213..d137468fe4b9 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; @@ -2509,65 +2507,40 @@ static void deactivate_slab(struct kmem_cache *s, struct slab *slab, /* * Stage two: Unfreeze the slab while splicing the per-cpu * freelist to the head of slab's freelist. - * - * 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 Thu Nov 2 03:23:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13443356 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 E3B0BC4167D for ; Thu, 2 Nov 2023 03:25:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 833128E001D; Wed, 1 Nov 2023 23:25:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E36A8E0009; Wed, 1 Nov 2023 23:25:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 683D78E001D; Wed, 1 Nov 2023 23:25:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 549A58E0009 for ; Wed, 1 Nov 2023 23:25:26 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1652FA0E92 for ; Thu, 2 Nov 2023 03:25:26 +0000 (UTC) X-FDA: 81411573852.10.56A2D7D Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf26.hostedemail.com (Postfix) with ESMTP id 5F609140006 for ; Thu, 2 Nov 2023 03:25:24 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=k4QQibDC; dmarc=pass (policy=none) header.from=linux.dev; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698895524; a=rsa-sha256; cv=none; b=DlT2662wQE5dS40A0i/eSB4g6WJdW3ne4dPc4f+GcuDu80u3sUQEEdsPTOeQLUvXUhsY2K wyp+k2pF0iaiM48ESNGoK7MEC5d63030MvxSO1qbAuQF8RlkSXjeTZV9jDGqkraNoMbijF uhcPqZLv+x/up1AIDwjpcbuExUSRCH8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=k4QQibDC; dmarc=pass (policy=none) header.from=linux.dev; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698895524; 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=N3Xfo0y6jZ0YfVFtmWrT6BPsa9Nsm+KQGum2QWoNV0I=; b=AQMYum94SF1awUNBDi5t6xBD+6WFaFdb6sZe3E9Uh16nYBQ7346eESAb4sldaMEBqtMZuq OGmCVSwo8c1o860LugMvigL4aQLnBomhPPxoMtxla2A6XspWJalzNjHasbIHaJJ6MvFmSf 120otrt9HkzmgRkgBjpWVKiOYiqaGyQ= 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=1698895522; 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=N3Xfo0y6jZ0YfVFtmWrT6BPsa9Nsm+KQGum2QWoNV0I=; b=k4QQibDC1ld0UrW3iBDGGZ48phYAHJ1+HACNNhCO/C89ykyWOPzBIhsNfTvaTJprJCvNXn xOQ7UO16oxS2c3AfRJJiFnt6rOq3FciJQ8ilKoxXDPfHcQOyfEz6OK1DOpVwj61rke/jDb 3Vlw5deJI3Z6PFrtYghaLkTN4KlSeUA= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.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: [PATCH v5 8/9] slub: Rename all *unfreeze_partials* functions to *put_partials* Date: Thu, 2 Nov 2023 03:23:29 +0000 Message-Id: <20231102032330.1036151-9-chengming.zhou@linux.dev> In-Reply-To: <20231102032330.1036151-1-chengming.zhou@linux.dev> References: <20231102032330.1036151-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: 5F609140006 X-Stat-Signature: mkjfkrhmutjrqkcsnznxuhhgcwakxkty X-HE-Tag: 1698895524-439575 X-HE-Meta: U2FsdGVkX1/phueQpF5Lfs00Q4pHsxhJZalGe5lg+hags/8kPaQRchlFt3WnP/z6XJaOOyHEv7PV46zrQtU4zWS1yc3Hoq9Pv60Eys6Ao6G/4SFhq29rYgaBSG+nTfiJRjvFhCEdUWv73e7CH/H5rQi0GHX1r5iThsHsGrKpvss4yUz8I+2tn1uwg5vbCGCDZ/Yz/y/CeAMlo1xrFQIb3Yn1BY/ROwmatjn4SIoHYWsoyAc/5DAbUNte/K5f3on5CZaRGOflXZa7ihzFUsgSEPa8uteko/ok3yxyadEYs5FoQ4nPTCup4U886PkyKGOW/CfbwuFQXTu/5N+9cSMmmyyUEzCvjoPa7xsbWZqbQQqcL0k+axriEe2uywWH7nUuQALPg1V9NpkgTxJ2SSUC7+Ybjk3g1+cqXVOPBTAZIAyCHoD8P2YfDYUpehXIsRVJKY9+oEQdWYUH0OpTGUel7CsraOdKnDd5EyGUc3v3BQfcfggPDdMHumN85IFnbNj4MiWn5/tx30KOpYjzTluFIOmz09UnzsbOXFQgZ8lAfCMKheK13/1PGLqN9hm/ZHACentdXWt9keEVZs4E678YAmRIST1vlMv2GUfrfDoXhQaQvyHgMw1GAtEUa3dZwnkFENq6KawxNXIE+FIlbReAe24LYsup/MuskOUJfBenqUqWJMnnkX64YnhhHt0d7ECjbf3D+pwtJuyI8uwIqgveZMTVNzeFXwzDLAgVIgE2G/Ptb0Gq0aG8I35Pp0FchtAt6SNTKRWzstuMvTEwdjQG0nESEfqG6HFfTUYDVNZX61aGoiQBCt5Cec3tPU2IbfTsn1FxyOu/F/mMTzfvSD7IXprzD6IZwvVCIScqR4/zmUw9MIU9vCxZWq9eZIA2bRv9x8I6zILHf6fGOKm402HJiG21mEvTlWdKVVH4OvyO6R8mtlHRf8N6uMazrVI0JZ1PNUPUlpgMKREaB0foIwQ P+npumae kZqrTjvYIpBWiXzwZR6FYGMNmnjnzZHEYys1nnUp9TpM7x1nwCOs02ALcM+Ko7HOXKSBuWFoLd6G0DgnpHwLnXXzDSOx+Jq8Tc6MnlhqtYGKTbe/D7qRvU4o+H1BKjI3CvKu2teesYK0pxEyvWg1ElaqEF7VbMowJTnOlpWjcf6zZdRbvyodshEIsbhYvcy0RHWry/nqiGlpJA4Z4ckTu2831qs6U0BROK5zO/jumBivHX5De1t9iIHbLdiuf9UdMOFhvW3DLl3c4F1M= 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 Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/slub.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index d137468fe4b9..c20bdf5dab0f 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2546,7 +2546,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(struct kmem_cache *s, struct slab *partial_slab) { struct kmem_cache_node *n = NULL, *n2 = NULL; struct slab *slab, *slab_to_discard = NULL; @@ -2588,9 +2588,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; @@ -2601,11 +2601,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(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; @@ -2613,7 +2613,7 @@ static void unfreeze_partials_cpu(struct kmem_cache *s, c->partial = NULL; if (partial_slab) - __unfreeze_partials(s, partial_slab); + __put_partials(s, partial_slab); } /* @@ -2626,7 +2626,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; @@ -2641,7 +2641,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; @@ -2657,17 +2657,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(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 */ @@ -2709,7 +2709,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 { @@ -2737,7 +2737,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) @@ -3168,7 +3168,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(s, slab); continue; } From patchwork Thu Nov 2 03:23:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13443357 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 0845FC4332F for ; Thu, 2 Nov 2023 03:25:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9BA298E001E; Wed, 1 Nov 2023 23:25:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 942F08E0009; Wed, 1 Nov 2023 23:25:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E3EF8E001E; Wed, 1 Nov 2023 23:25:35 -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 6D9BC8E0009 for ; Wed, 1 Nov 2023 23:25:35 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4F90DA0E93 for ; Thu, 2 Nov 2023 03:25:35 +0000 (UTC) X-FDA: 81411574230.07.57D8C58 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) by imf08.hostedemail.com (Postfix) with ESMTP id 8D7BC160021 for ; Thu, 2 Nov 2023 03:25:33 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=nDjeGraa; spf=pass (imf08.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.173 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=1698895533; 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=gJd616cEH+YooKkPi26MjXWgnIGEXuyIPk1hxd0FhTk=; b=FmV0w4MigEBUPOglogwafec2StwpTH3Xl+Q5X+0xkE6wKpQpxP1KWtUfVSuv0dewn0xmyC mX475fJ5/Gg4yxuGxVspkf+tl6x1L2uCtbtZwjmUhU88avG4cvWZfINUPZWGUp5ZiU/kKC YmBVjlUGIls9gZodfG5CPhb9lRhiYNs= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=nDjeGraa; spf=pass (imf08.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.173 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698895533; a=rsa-sha256; cv=none; b=rZPzYPNeFutNdn5V4Nb540ii2Ls9v/T5fNU0dqWFujOagUaxLliX6Q+Dpqfi/SdIpyoKKc TDF8IFRU91d6ziTIru9gE7uYhOTYACMWSly6/8/VArfA4t29bXfPh8fvHbNY5aBw1ti5A6 huyY8Tr4+EnEoP4jtezzCTsvSikjq8w= 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=1698895532; 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=gJd616cEH+YooKkPi26MjXWgnIGEXuyIPk1hxd0FhTk=; b=nDjeGraaC0yMn15FP6J1O98CFrfWFi/efFlDQyWlgTKRBWcIkb3Bueh3V63chVaCnBjh/z aT+DJ4liAnoOXN6AjPz5ujQz9YSWQl2pq1MhhIZ8NmN0T3o3AMQcWG/ZORLSwwjhMGbr7d UKvLJzRg/tomBOgosqWMv4T+MnQQ2Cg= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.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: [PATCH v5 9/9] slub: Update frozen slabs documentations in the source Date: Thu, 2 Nov 2023 03:23:30 +0000 Message-Id: <20231102032330.1036151-10-chengming.zhou@linux.dev> In-Reply-To: <20231102032330.1036151-1-chengming.zhou@linux.dev> References: <20231102032330.1036151-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 8D7BC160021 X-Rspam-User: X-Stat-Signature: nky4asfdbyq7ppzc8f1ficobhs4qys7e X-Rspamd-Server: rspam01 X-HE-Tag: 1698895533-867760 X-HE-Meta: U2FsdGVkX1+VdKpadSlWGpNqeB4NVFxQB0NHYv9w4aCapQXuZ24pv/JaTVCrjisUAwZCGGAsPuiPcXjLCLpZAaB6bOHN23wRYCoaPar8Xn4Ex0zqDWdqw7zHN2FQv9ZxY7W6Gg0xDfA878YgnjZfWSDMvn5P/epT9tkGTKh47qGd4DFRZKODGskM6Ncds75JSyegIgDcv1AK/5T8RjDoTp4MmGv9Ir7XE1G7d/aYx1BY0v5N/hvUqLfyvrVNkMLs9Vjs8g8UzkRTKCbusTKBMmHXLKZfF0LIKzXofQqWoFrAYYuMhc0rktuBetXj/8rJbB6njI8eaTL4D5krH3rYpRbRPPrcAX2LcXqbbXrXn+EFN5ju2ak9JF6J07g4ued+So+kiy/coSnXujb/1gCBBSxaU18NTHMn0T6kWUmQcLC+xOli5pKgZ4H2ccufVopZSHmNkOhddy1Fj7GggpByWFMjXwjGJFXD/fXvdp8AWFaMlwob8QbUsOqzjihuzoOVHCjdPZTwPq0TuEhanETjyhXeQT7FKijvcX1hf+SKt8jl7T1ni8ObbwvA8xQtseuHjcc3PICbWNVCuE3JEaQh2ooeax7A+KsCgTm06Ld64DRW/PsH1Xz4MDwwfQkW4U7hub3kbUpqhzKSNXEn/ODGI3gdm09n8GFZ0BqIC0MvAWtTeyZJ7dSIJVERU5Nh0AZnowwxBxTWn7LmAZycY73WrQArHrnRLFcyypWSxeOBr4kuMI+EasEfR97wzf/Va3+1N4CdV5WcdP3eZXBsMY4Kr96BiVFFWbXSMcJnOBP/zyNc1FT5g/80SFRFKTwqwPliSdGS5CMDPy2vq2N35zZ3hFd/i1WFj/aTSrBWFcuDCxXcvYlB7M+q6jsnkT5wMIAbqL9NmLwOrs0Dz5UYMdXWm1e1GPtirc345gARrMo+AV0+pAR7apSuyIs+nnJ700xTCYcIfhgxv5iINRKlgYg 6zMmWRB3 Ira4WdTPHhJXGZgB2Yzog0mSDGZkOpvVNt1omTVDMG5Of5NfKx+wdieRu762MSfHehkcpA4XcoTQNj/gykJ+Pl6xJCObDrv1kIt4F5+3KxO24r197NIxmWrVAbm2TGTzxAPE/btvm5XpCrXFx0zaCEMwQEJBA6NqwKHC2G8KguOKcja/Rah8bif7uDV1Q+Qy9/QFLpeMBANe64+C0JcJgPKVhsbf0byq5/kXNdkoO07F796k= 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 Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Acked-by: Christoph Lameter (Ampere) --- mm/slub.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index c20bdf5dab0f..a307d319e82c 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 are 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 @@ -2617,8 +2626,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.