From nobody Fri Dec 19 15:19:35 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 C47441CF7C4 for ; Wed, 4 Sep 2024 13:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725457297; cv=none; b=T3J4ui0oE1c1MNZJ9NNTCsvxBASAiFTC7zjHVkalwO7LmipOFMRxuvelmEUMawlxH1aOR7ynUm1X6CVSiFYYYOlI0IMC7GHVtJzuqSvfULwOEQ+Qd3c7J5GTpniP2bnS2CPtVEl7+MpF5joNtvSxswbnRqrfDQ9aNxxLxzLhOWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725457297; c=relaxed/simple; bh=1AbWWeZEOpWtGlqls25ky1dwlnbdmQsHIPVJg7ZCeVs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VnuoFZTeSTgmPRu6Rh0+Nnc1r5/uJG5SWx/fkudUMXgYiWPjVI3pBrT3Nf1uOP9uefp6qQgT19BCycqBjpV9plzRJHTLYLt4VQd2MpRxBRdTMjVFNRtL3Lro2S48lYKL7iOiz5/JHfg3bt5fr+Y1WmuHDfZ5UAAX5c8hCB2xsI0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WzNtZ4wzLz1j82j; Wed, 4 Sep 2024 21:41:10 +0800 (CST) Received: from dggpemf100006.china.huawei.com (unknown [7.185.36.228]) by mail.maildlp.com (Postfix) with ESMTPS id 0632C1A016C; Wed, 4 Sep 2024 21:41:31 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemf100006.china.huawei.com (7.185.36.228) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 4 Sep 2024 21:41:30 +0800 From: Zhen Lei To: Andrew Morton , Thomas Gleixner , CC: Zhen Lei Subject: [PATCH v2 1/6] debugobjects: Fix the compilation attributes of some global variables Date: Wed, 4 Sep 2024 21:39:39 +0800 Message-ID: <20240904133944.2124-2-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20240904133944.2124-1-thunder.leizhen@huawei.com> References: <20240904133944.2124-1-thunder.leizhen@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100006.china.huawei.com (7.185.36.228) Content-Type: text/plain; charset="utf-8" 1. Both debug_objects_pool_min_level and debug_objects_pool_size are read-only after initialization, change attribute '__read_mostly' to '__ro_after_init', and remove '__data_racy'. 2. Many global variables are read in the debug_stats_show() function, but didn't mask KCSAN's detection. Add '__data_racy' for them. Suggested-by: Thomas Gleixner Signed-off-by: Zhen Lei --- lib/debugobjects.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/debugobjects.c b/lib/debugobjects.c index 7cea91e193a8f04..7226fdb5e129a79 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c @@ -70,10 +70,10 @@ static HLIST_HEAD(obj_to_free); * made at debug_stats_show(). Both obj_pool_min_free and obj_pool_max_used * can be off. */ -static int obj_pool_min_free =3D ODEBUG_POOL_SIZE; -static int obj_pool_free =3D ODEBUG_POOL_SIZE; +static int __data_racy obj_pool_min_free =3D ODEBUG_POOL_SIZE; +static int __data_racy obj_pool_free =3D ODEBUG_POOL_SIZE; static int obj_pool_used; -static int obj_pool_max_used; +static int __data_racy obj_pool_max_used; static bool obj_freeing; /* The number of objs on the global free list */ static int obj_nr_tofree; @@ -84,9 +84,9 @@ static int __data_racy debug_objects_fixups __read_most= ly; static int __data_racy debug_objects_warnings __read_mostly; static int __data_racy debug_objects_enabled __read_mostly =3D CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT; -static int __data_racy debug_objects_pool_size __read_mostly +static int debug_objects_pool_size __ro_after_init =3D ODEBUG_POOL_SIZE; -static int __data_racy debug_objects_pool_min_level __read_mostly +static int debug_objects_pool_min_level __ro_after_init =3D ODEBUG_POOL_MIN_LEVEL; =20 static const struct debug_obj_descr *descr_test __read_mostly; @@ -95,8 +95,8 @@ static struct kmem_cache *obj_cache __ro_after_init; /* * Track numbers of kmem_cache_alloc()/free() calls done. */ -static int debug_objects_allocated; -static int debug_objects_freed; +static int __data_racy debug_objects_allocated; +static int __data_racy debug_objects_freed; =20 static void free_obj_work(struct work_struct *work); static DECLARE_DELAYED_WORK(debug_obj_work, free_obj_work); --=20 2.34.1 From nobody Fri Dec 19 15:19:35 2025 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (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 99C0B26AED for ; Wed, 4 Sep 2024 13:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725457297; cv=none; b=tAvpoIglYYc0N5cP+z40RkDCj9N+MqRzgMi2GUvDH6dUeQ11eJQODwwjZlFHHu1k13Z31OokLt1+8DQqZAc5VERnWmcJmFcbfEBAMtnC5F8+BRrLCOGN2uG1mjqnnHoDE5UxTboR3v6lZsTz8Sz2HmI8i1XBr63mb/k++6h4aoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725457297; c=relaxed/simple; bh=0fCzj+OIc4N4SMC1QMIo3kEc+Ed0A0yHD28WRtrN4o0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l2HaNSmvMkGGwscJCVxi2PtnS5UckRdNaEgAKRSzE4ctT2G88ltRKFfFsYkZk41fpGW6ccR1FFm0ExtejkONu7/XTrrOFqHSrk3FEwKRETGkuQt6xg7sQgYEhwvYP1m7EYQpqOu1hLNfUo+c+se15nx1l6EgVflA8ayijGxxzgA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4WzNtZ2LfZz1S9fT; Wed, 4 Sep 2024 21:41:10 +0800 (CST) Received: from dggpemf100006.china.huawei.com (unknown [7.185.36.228]) by mail.maildlp.com (Postfix) with ESMTPS id 691F11400DB; Wed, 4 Sep 2024 21:41:31 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemf100006.china.huawei.com (7.185.36.228) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 4 Sep 2024 21:41:31 +0800 From: Zhen Lei To: Andrew Morton , Thomas Gleixner , CC: Zhen Lei Subject: [PATCH v2 2/6] debugobjects: Fix the misuse of global variables in fill_pool() Date: Wed, 4 Sep 2024 21:39:40 +0800 Message-ID: <20240904133944.2124-3-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20240904133944.2124-1-thunder.leizhen@huawei.com> References: <20240904133944.2124-1-thunder.leizhen@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100006.china.huawei.com (7.185.36.228) Content-Type: text/plain; charset="utf-8" The global variable 'obj_pool_min_free' records the lowest historical value of the number of nodes in the global list 'obj_pool', instead of being used as the minimum level to keep around. It has to be replaced with variable 'debug_objects_pool_min_level'. Fixes: d26bf5056fc0 ("debugobjects: Reduce number of pool_lock acquisitions= in fill_pool()") Fixes: 36c4ead6f6df ("debugobjects: Add global free list and the counter") Signed-off-by: Zhen Lei --- lib/debugobjects.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/debugobjects.c b/lib/debugobjects.c index 7226fdb5e129a79..6329a86edcf12ac 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c @@ -142,13 +142,14 @@ static void fill_pool(void) * READ_ONCE()s pair with the WRITE_ONCE()s in pool_lock critical * sections. */ - while (READ_ONCE(obj_nr_tofree) && (READ_ONCE(obj_pool_free) < obj_pool_m= in_free)) { + while (READ_ONCE(obj_nr_tofree) && + READ_ONCE(obj_pool_free) < debug_objects_pool_min_level) { raw_spin_lock_irqsave(&pool_lock, flags); /* * Recheck with the lock held as the worker thread might have * won the race and freed the global free list already. */ - while (obj_nr_tofree && (obj_pool_free < obj_pool_min_free)) { + while (obj_nr_tofree && (obj_pool_free < debug_objects_pool_min_level)) { obj =3D hlist_entry(obj_to_free.first, typeof(*obj), node); hlist_del(&obj->node); WRITE_ONCE(obj_nr_tofree, obj_nr_tofree - 1); --=20 2.34.1 From nobody Fri Dec 19 15:19:35 2025 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 C45BD1DA10D for ; Wed, 4 Sep 2024 13:41:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725457296; cv=none; b=hlGnaVQXbZclLkhik3zanw7twEzSTBUFmcDdD6fj6l709utRTlZ01W+JdAj5tSv5+V0GRQ5kFe94mQbN8AI2KyauI/wha3bpyoeTDMIiAHC2ZcUGQM7wsfwlAyTk23yyyXcCNJuXtrusoH2kmlWscD9XEnCVLTOoqkb/pUDNgt8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725457296; c=relaxed/simple; bh=sB78dWO5QeNHu/5FpHflaziWOlOYJ6eILUJmj7kKJDA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P0SgCdKK78zxRf7Ai4N0Hr0esHg0N6eDtqyVg1yhPwagOnoT+oTmpV9aHG+6fwIzlgbNnrjJdQbgXvS8dWKylH2Bi0vJ41WKKj+NGZjUr0V4ymAn28IdwBPyYRTmpwARG5COnuxOjJgvyEgL2AaT6nCK7R9hmnH68P7XfsJWRLk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WzNnG4vfGz20n6Q; Wed, 4 Sep 2024 21:36:34 +0800 (CST) Received: from dggpemf100006.china.huawei.com (unknown [7.185.36.228]) by mail.maildlp.com (Postfix) with ESMTPS id DF2D51400DB; Wed, 4 Sep 2024 21:41:31 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemf100006.china.huawei.com (7.185.36.228) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 4 Sep 2024 21:41:31 +0800 From: Zhen Lei To: Andrew Morton , Thomas Gleixner , CC: Zhen Lei Subject: [PATCH v2 3/6] debugobjects: Remove redundant checks in fill_pool() Date: Wed, 4 Sep 2024 21:39:41 +0800 Message-ID: <20240904133944.2124-4-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20240904133944.2124-1-thunder.leizhen@huawei.com> References: <20240904133944.2124-1-thunder.leizhen@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100006.china.huawei.com (7.185.36.228) Content-Type: text/plain; charset="utf-8" (1) if (READ_ONCE(obj_pool_free) >=3D debug_objects_pool_min_level) return; (2) while (READ_ONCE(obj_nr_tofree) && READ_ONCE(obj_pool_free) < debug_objects_pool_min_level) { raw_spin_lock_irqsave(&pool_lock, flags); (3) while (obj_nr_tofree && (3) (obj_pool_free < debug_objects_pool_min_level)) { ... ... } raw_spin_unlock_irqrestore(&pool_lock, flags); } The conditions for the outer loop (2) and inner loop (3) are exactly the same. The inner loop is completed under the protection of the spinlock. When the inner loop ends, at least one of the two loop conditions must be met. The time from the end of the inner loop to the restart of the outer loop is extremely short, and the probability of other cores modifying 'obj_nr_tofree' and 'obj_pool_free' is almost zero during this time. In fact, after the outer loop ends, it is still possible for other cores to modify the values of these two variables. Therefore, restarting the outer loop has no practical effect except for an additional check. So the outer 'while' should be changed to 'if'. Then we'll see that the second condition of the new 'if' is already guaranteed above (1) and can be removed. Signed-off-by: Zhen Lei --- lib/debugobjects.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/debugobjects.c b/lib/debugobjects.c index 6329a86edcf12ac..7a8ccc94cb037ba 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c @@ -135,15 +135,13 @@ static void fill_pool(void) return; =20 /* - * Reuse objs from the global free list; they will be reinitialized + * Reuse objs from the global tofree list; they will be reinitialized * when allocating. * - * Both obj_nr_tofree and obj_pool_free are checked locklessly; the - * READ_ONCE()s pair with the WRITE_ONCE()s in pool_lock critical - * sections. + * The obj_nr_tofree is checked locklessly; the READ_ONCE() pair with + * the WRITE_ONCE() in pool_lock critical sections. */ - while (READ_ONCE(obj_nr_tofree) && - READ_ONCE(obj_pool_free) < debug_objects_pool_min_level) { + if (READ_ONCE(obj_nr_tofree)) { raw_spin_lock_irqsave(&pool_lock, flags); /* * Recheck with the lock held as the worker thread might have --=20 2.34.1 From nobody Fri Dec 19 15:19:35 2025 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (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 AF4BB185948 for ; Wed, 4 Sep 2024 13:41:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725457298; cv=none; b=jwKoyQsrqlOwqLZl2cOJ0102y59U99d4sFmMV9eSFE5B/THJWkAMOw3FF/J3L1Mvr+E0JnPJ8x+vq8RcRLV5iLiAQTPgO2B/tGa9ggMwPJl5ATSG83AR8NRpSFcZKbX/3AlTGX/25o2t+J+u7CDz8Rs8NxvDxsCHQN+V2kaoTtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725457298; c=relaxed/simple; bh=LMnM+5IgCL22RvYQlX96uBFPVCZCm7KQizyhj1G3SoY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cU7U89dvH3X4PiY1hrqHVg1arr6anHPsTzaeo2mwtat3w+hTOhrSTDlKao3OGE7rOp8xObm6lBQ59FR1Uu4LQHShbUzw4ydEESxGPJkoheUFnblBaraT6Dj9dF68PBWEN1zhy7GB1xWdvXdQ9vJRltFMQ0U0H4KkVUaf2JJKF9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WzNnG4Z1nz69Mk; Wed, 4 Sep 2024 21:36:34 +0800 (CST) Received: from dggpemf100006.china.huawei.com (unknown [7.185.36.228]) by mail.maildlp.com (Postfix) with ESMTPS id 48B1418024B; Wed, 4 Sep 2024 21:41:32 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemf100006.china.huawei.com (7.185.36.228) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 4 Sep 2024 21:41:31 +0800 From: Zhen Lei To: Andrew Morton , Thomas Gleixner , CC: Zhen Lei Subject: [PATCH v2 4/6] debugobjects: Don't start fill if there are remaining nodes locally Date: Wed, 4 Sep 2024 21:39:42 +0800 Message-ID: <20240904133944.2124-5-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20240904133944.2124-1-thunder.leizhen@huawei.com> References: <20240904133944.2124-1-thunder.leizhen@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100006.china.huawei.com (7.185.36.228) Content-Type: text/plain; charset="utf-8" If the conditions for starting fill are met, it means that all cores that call fill() later are blocked until the first core completes the fill operation. But obviously, for a core that has free nodes locally, it does not need to be blocked(see below for why). This is good in stress situations. 1. In the case of no nesting, a core uses only one node at a time. As long as there is a local node, there is no need to use the free node in obj_pool. 2. In the case of nesting depth is one, nodes in obj_pool need to be used only when there is only one local node. #define ODEBUG_POOL_PERCPU_SIZE 64 #define ODEBUG_BATCH_SIZE 16 Assume that when nested, the probability of percpu_obj_pool having each number of nodes is the same. The probability of only one node is less than 1/17=3D6%. Assuming the probability of nesting is 5%, that's a pretty high estimate. Then the probability of using obj_pool is 6% * 5% =3D 0.3%. In other words, a 333-core environment produces only one core to compete for obj_pool. #define ODEBUG_POOL_MIN_LEVEL 256 #define ODEBUG_BATCH_SIZE 16 But we can tolerate "256 / (16 + 1)" =3D 15 cores competing at the same time. 3. In the case of nesting depth more than one, the probability is lower and negligible. Nesting Depth=3D2: "2/17 * 5% * 5%" =3D 0.03% Nesting Depth=3D3: "3/17 * 5% * 5% * 5%" =3D 0.002% However, to ensure sufficient reliability, obj_pool is not filled only when there are more than two local nodes, reduce the probability of problems to the impossible. Signed-off-by: Zhen Lei --- lib/debugobjects.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/debugobjects.c b/lib/debugobjects.c index 7a8ccc94cb037ba..4f64b5d4329c27d 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c @@ -131,6 +131,16 @@ static void fill_pool(void) struct debug_obj *obj; unsigned long flags; =20 + /* + * The upper-layer function uses only one node at a time. If there are + * more than two local nodes, it means that even if nesting occurs, it + * doesn't matter. The probability of nesting depth >=3D 2 is extremely + * low, and the number of global free nodes guarded by + * debug_objects_pool_min_level is adequate. + */ + if (likely(obj_cache) && this_cpu_read(percpu_obj_pool.obj_free) >=3D 2) + return; + if (likely(READ_ONCE(obj_pool_free) >=3D debug_objects_pool_min_level)) return; =20 --=20 2.34.1 From nobody Fri Dec 19 15:19:35 2025 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 C45621D9D97 for ; Wed, 4 Sep 2024 13:41:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725457296; cv=none; b=FtkPbH0GgEzANZ+b+en+PAr5I1wtUWZzid7SYm1erY3RZUTlieZOH6W3P1e/J0FWj1PpsVw/dF69Fg1d5i5GlRzxc9ZGL0gH8059U5+CJ6wlsYFEnDgiWYOuZzDTeiLCZXxtmbF3nSa/PIToAWxqLd6myHYsXgbD5SBkVn/LIRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725457296; c=relaxed/simple; bh=Hqux90Rf0JdCR6jWI+BtwgNNcGnqTvrBr9spid367Ac=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YYGgvTX2zCA/RTzqTkKo6oIVmUI7UmWKq+FibRnAtX+Od6PFfZtyax5B6R9/B6xnq88seBYve/Z0jeBK09nOtwlM6BhHKaowFgXJ9MWoD0jgGPNe5T+K3ZD9ztYEHYEXQMUgc4js/2cMDJFogkxTRyw8LCcIOYJVJpAkcyb02Yo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WzNtc1ZXGz2DbdH; Wed, 4 Sep 2024 21:41:12 +0800 (CST) Received: from dggpemf100006.china.huawei.com (unknown [7.185.36.228]) by mail.maildlp.com (Postfix) with ESMTPS id B4F3918002B; Wed, 4 Sep 2024 21:41:32 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemf100006.china.huawei.com (7.185.36.228) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 4 Sep 2024 21:41:32 +0800 From: Zhen Lei To: Andrew Morton , Thomas Gleixner , CC: Zhen Lei Subject: [PATCH v2 5/6] debugobjects: Use hlist_splice_init() to reduce lock conflicts Date: Wed, 4 Sep 2024 21:39:43 +0800 Message-ID: <20240904133944.2124-6-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20240904133944.2124-1-thunder.leizhen@huawei.com> References: <20240904133944.2124-1-thunder.leizhen@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100006.china.huawei.com (7.185.36.228) Content-Type: text/plain; charset="utf-8" The sub list can be prepared in advance outside the lock, so that the operation time inside the lock can be reduced and the possibility of lock conflict can be reduced. Signed-off-by: Zhen Lei --- lib/debugobjects.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/debugobjects.c b/lib/debugobjects.c index 4f64b5d4329c27d..9876e7ad5291492 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c @@ -171,23 +171,25 @@ static void fill_pool(void) return; =20 while (READ_ONCE(obj_pool_free) < debug_objects_pool_min_level) { - struct debug_obj *new[ODEBUG_BATCH_SIZE]; + struct debug_obj *new, *last =3D NULL; + HLIST_HEAD(freelist); int cnt; =20 for (cnt =3D 0; cnt < ODEBUG_BATCH_SIZE; cnt++) { - new[cnt] =3D kmem_cache_zalloc(obj_cache, gfp); - if (!new[cnt]) + new =3D kmem_cache_zalloc(obj_cache, gfp); + if (!new) break; + hlist_add_head(&new->node, &freelist); + if (!last) + last =3D new; } if (!cnt) return; =20 raw_spin_lock_irqsave(&pool_lock, flags); - while (cnt) { - hlist_add_head(&new[--cnt]->node, &obj_pool); - debug_objects_allocated++; - WRITE_ONCE(obj_pool_free, obj_pool_free + 1); - } + hlist_splice_init(&freelist, &last->node, &obj_pool); + debug_objects_allocated +=3D cnt; + WRITE_ONCE(obj_pool_free, obj_pool_free + cnt); raw_spin_unlock_irqrestore(&pool_lock, flags); } } --=20 2.34.1 From nobody Fri Dec 19 15:19:35 2025 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (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 663411D9D96 for ; Wed, 4 Sep 2024 13:41:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725457297; cv=none; b=aZHsJyb13TjLdjWtRTQzt04jeOSHCqSyH0y2w5czaDbLx1yP8fSBCG9Lcqr0MxoFUikfamOk27IKR1vc52Bc23YEVAPurgUAWTPsYrVa/cdNQ+0qgzQqMk+zu1rltauaNZ+nbGbrOBn87A4pwQCnFprOk5ajIHEV9vlERV9Uiug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725457297; c=relaxed/simple; bh=4of56Nx30EiO+1gvFAy8PDdS0NIkA3vPkyzmyPdX9uU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LEZ2fpdtSNNM1x43s70xs/JtoEBZMnf/cpQPHFK9sbez38f2+HGyD2jWea3uBvjUR8BC8gTdSkutSOrnWUN2rzu9VGzLtJQeJc/hmv3mGhy+dlpejW/Y8dnV7bjejytpC70tyK6xGQ1j5XrOZKJZwPUVvFYz/rSgH4i2U+1CVsU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4WzNsv48JSz13vb2; Wed, 4 Sep 2024 21:40:35 +0800 (CST) Received: from dggpemf100006.china.huawei.com (unknown [7.185.36.228]) by mail.maildlp.com (Postfix) with ESMTPS id 2599018005F; Wed, 4 Sep 2024 21:41:33 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemf100006.china.huawei.com (7.185.36.228) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 4 Sep 2024 21:41:32 +0800 From: Zhen Lei To: Andrew Morton , Thomas Gleixner , CC: Zhen Lei Subject: [PATCH v2 6/6] debugobjects: Delete a piece of redundant code Date: Wed, 4 Sep 2024 21:39:44 +0800 Message-ID: <20240904133944.2124-7-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20240904133944.2124-1-thunder.leizhen@huawei.com> References: <20240904133944.2124-1-thunder.leizhen@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100006.china.huawei.com (7.185.36.228) Content-Type: text/plain; charset="utf-8" The statically allocated objects are all located in obj_static_pool[], the whole memory of obj_static_pool[] will be reclaimed later. Therefore, there is no need to split the remaining statically nodes in list obj_pool into isolated ones, no one will use them anymore. Just write INIT_HLIST_HEAD(&obj_pool) is enough. Since hlist_move_list() directly discards the old list, even this can be omitted. Signed-off-by: Zhen Lei --- lib/debugobjects.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/debugobjects.c b/lib/debugobjects.c index 9876e7ad5291492..65ecc611ac24720 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c @@ -1337,10 +1337,7 @@ static int __init debug_objects_replace_static_objec= ts(void) * active object references. */ =20 - /* Remove the statically allocated objects from the pool */ - hlist_for_each_entry_safe(obj, tmp, &obj_pool, node) - hlist_del(&obj->node); - /* Move the allocated objects to the pool */ + /* Replace the statically allocated objects list with the allocated objec= ts list */ hlist_move_list(&objects, &obj_pool); =20 /* Replace the active object references */ --=20 2.34.1