Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1086695lql; Tue, 12 Mar 2024 07:05:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVQ1sxob6v+fGF84QzS9hbQWwooKEwLZDGhvZSsd3UGWqQiLWVlBVkVUYE9W3HFTlXn4+SFsZVMRDjHHEupGIpNggOOqrUzyBbMAGckqA== X-Google-Smtp-Source: AGHT+IH95iYXhGO33tMAWfIneHNjR1krkHhEGwPj4HPe7pYSwTHjPBatjh4gQsenY7SBaJiV9I8l X-Received: by 2002:a17:90b:3143:b0:29b:c306:11bc with SMTP id ip3-20020a17090b314300b0029bc30611bcmr1198250pjb.5.1710252358702; Tue, 12 Mar 2024 07:05:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710252358; cv=pass; d=google.com; s=arc-20160816; b=rrgZLCQB/lcb8YouYf+eq7lf2c8bc4dvoqUhnkmIq5aRZWqcyRoF3XsYL3/41UVwyN GDuqhURQgydEDMPTWBXq1PPujjMqxuaF1rs6SLJVJr4H4U9ct2i0nrLEtHvOXWP69JtL W3/c2WltWrGYHHcIzBjEaKV9KVaG2P90YQv0PZIBKtDs92vDMJVXMp/Si/A7qYp4lBrf gIiYHCzdtLznFToKNRUsemHSJiV2UdgznnCcnx82DmBYXiBM7U+h0gUzJVwn3oeM2vRP I5oM/dVToXGxcWo6ByP8guRkgWHDfLH07tEmstTQBaWSYQMv6YERv/OGuwHHrfMqqVF5 ZWrg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=BbMF8m5gDueYZRCHMsIy/5bezoPRbX1YTQWlc+gdLlw=; fh=ZNUvxdr8PpDGQLKvzzRxrEfJsNX4wGKczM4Uy+pqom0=; b=UOpbKEL+Wx4juA5UNxkD7gIyuVtLexavVgmdmijzSewAQZnypXedHw+MDBhvs0TUmI DHxeGxFsHP0b58frzuYhUarFhj9367e8AszDaHgwMxMehdc8PgYmFYP+n3KAo0TNvgPl 6wC0AeiCc5zK12OlWGmrQ5OQI1dAl36mfkIk9jOAyetEu4wfwwZZyyKz4TF8EEKVTYXU ZZQD4U+t6FDFt9doJ1i+hh3Kz+sfeRYNwTDRTpo8T15MGi1hZcg3puQ9cWy/zmK9hrRL K3qdlgcZ7MswdsDZBZ6yqdRU8V5sB8TKQJvmNhpcsTqDnvy7/jjXAXrJQ4j/uyypzeBf Bh4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@me.com header.s=1a1hai header.b=Ptf12zcd; arc=pass (i=1 spf=pass spfdomain=me.com dkim=pass dkdomain=me.com dmarc=pass fromdomain=me.com); spf=pass (google.com: domain of linux-kernel+bounces-100316-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100316-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=me.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 12-20020a17090a098c00b0029bb27f3510si7140862pjo.115.2024.03.12.07.05.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 07:05:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100316-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@me.com header.s=1a1hai header.b=Ptf12zcd; arc=pass (i=1 spf=pass spfdomain=me.com dkim=pass dkdomain=me.com dmarc=pass fromdomain=me.com); spf=pass (google.com: domain of linux-kernel+bounces-100316-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100316-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=me.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5D63A28279C for ; Tue, 12 Mar 2024 14:05:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D5DD7A72C; Tue, 12 Mar 2024 14:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=me.com header.i=@me.com header.b="Ptf12zcd" Received: from pv50p00im-ztdg10021201.me.com (pv50p00im-ztdg10021201.me.com [17.58.6.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F9CE78298 for ; Tue, 12 Mar 2024 14:05:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710252352; cv=none; b=a60/mFKZ+rSLz0vId6IWCRo0F3VG0F51XYsnA6oduVzN2bjS2uwLzC8gYsCF0tCa+HEkS1tapRYTttqksJ4JAK7ecGFYmtdCo+0Q4JFfZfQs4rh3o/N+gZkHvzuVGUe+owWtC/79jvp1+nbKRLYKBn6bkiEpV94BRu0WJzb2DO4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710252352; c=relaxed/simple; bh=hNF2+RXl//4KAAi3too/Os0YMBFOsoQcXZrz7NrJcss=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Yu9JsLWfQzI0Z9dFDDRamDlYLfnyc1xt+S7GCfZg7tWhzIi7m781m19triDZF5kI2+s1FNCsU9Un4NHnNZaEDEgqUyZ/XMIpRauc5MJ2DmOs1hKptzmD+QE7D5LJJM3HMBQWimvkETDOX4P0c7osADIdcPYhQS/IFhnlvrSVc+0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=me.com; spf=pass smtp.mailfrom=me.com; dkim=pass (2048-bit key) header.d=me.com header.i=@me.com header.b=Ptf12zcd; arc=none smtp.client-ip=17.58.6.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=me.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=me.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1710252350; bh=BbMF8m5gDueYZRCHMsIy/5bezoPRbX1YTQWlc+gdLlw=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Ptf12zcd9lFsEaaDF/p/Gggh1EhsjloxWw6oFekA8cURMFejeQ+dSoz08KdnHnJJn W1Ct1bd1k+raEfxyO/rDOMIAw1JFFkJTVy3Ip5zxgpaYqb4Ky5pkMnuI7A380O1cBi ezAVztXyogKKqRvoFS5a7S66SoVyhEvDm99mbjYtUN5JY4akWbr0C2Wyobzu5q+b9G rddlf8/8f6IrNppV75lKNP9UiVWl6XLeetDnjQrJO8iBe0vd93/gey3Ah6V5hjgV4b eUlfW/LKNySQ3X2z97IfIgZ5chfpNRHf7b+lZyoKTEC4ZJtqQMoC3iM9QdLadbQrvB 7gMmr+zseC1Xw== Received: from xiongwei.. (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021201.me.com (Postfix) with ESMTPSA id A13F0681BA5; Tue, 12 Mar 2024 14:05:45 +0000 (UTC) From: sxwjean@me.com To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Chengming Zhou Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xiongwei Song Subject: [PATCH v2] mm/slub: Simplify get_partial_node() Date: Tue, 12 Mar 2024 22:05:32 +0800 Message-Id: <20240312140532.64124-1-sxwjean@me.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: Yn2ommIikT1KPMGk-GpetYDo4xMKhwyq X-Proofpoint-ORIG-GUID: Yn2ommIikT1KPMGk-GpetYDo4xMKhwyq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-12_09,2024-03-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1011 mlxlogscore=999 phishscore=0 suspectscore=0 bulkscore=0 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2403120108 From: Xiongwei Song Remove the check of !kmem_cache_has_cpu_partial() because it is always false, we've known this by calling kmem_cache_debug() before calling remove_partial(), so we can remove the check. Meanwhile, redo filling cpu partial and add comment to improve the readability. Signed-off-by: Xiongwei Song --- Changes in v2: - Use "#if IS_ENABLED(CONFIG_SLUB_CPU_PARTIAL)" to instead "if (IS_ENABLED(CONFIG_SLUB_CPU_PARTIAL))" to fix build error. (Thanks Chengming Zhou) - Add __maybe_unused for partial_slabs to prevent compiler warning. v1: https://lore.kernel.org/linux-kernel/20240311132720.37741-1-sxwjean@me.com/T/ --- mm/slub.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index a3ab096c38c0..ab526960ee5b 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2588,7 +2588,7 @@ static struct slab *get_partial_node(struct kmem_cache *s, { struct slab *slab, *slab2, *partial = NULL; unsigned long flags; - unsigned int partial_slabs = 0; + unsigned int __maybe_unused partial_slabs = 0; /* * Racy check. If we mistakenly see no partial slabs then we @@ -2620,19 +2620,21 @@ static struct slab *get_partial_node(struct kmem_cache *s, if (!partial) { partial = slab; stat(s, ALLOC_FROM_PARTIAL); - } else { - put_cpu_partial(s, slab, 0); - stat(s, CPU_PARTIAL_NODE); - partial_slabs++; + + /* Fill cpu partial if needed from next iteration, or break */ + if (IS_ENABLED(CONFIG_SLUB_CPU_PARTIAL)) + continue; + else + break; } -#ifdef CONFIG_SLUB_CPU_PARTIAL - if (!kmem_cache_has_cpu_partial(s) - || partial_slabs > s->cpu_partial_slabs / 2) + +#if IS_ENABLED(CONFIG_SLUB_CPU_PARTIAL) + put_cpu_partial(s, slab, 0); + stat(s, CPU_PARTIAL_NODE); + + if (++partial_slabs > s->cpu_partial_slabs/2) break; -#else - break; #endif - } spin_unlock_irqrestore(&n->list_lock, flags); return partial; -- 2.34.1