From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796099042; b=TRxbEcvHc9g13tJvdKR0Pgtq0VIcnRW2yOO0E7NMOCHxe+C5nsc8jBp7S7Z8GtmoLzPT RoX+5hSSj4W5tlEIqIL2F8cvz5QBjzw5zWld96I1EZGHAjGn1bXdlSXlDzSBDmRK3TqFN F8U4GIlPUzdrFMFrk8/rnPRTH3dlpfWisEEfEG0vbWCDjJJYoDJPSmhOJR/kxCef9UXwv KVsZMj28cVwUNhYq1Axh6YrPvCtX8Y3YyRkcn0/PBL7J2Eluxqn9e+6N2PcH8Jbvc7SKd FO/ZM/kgqrifpLyAI8Whx8fr26o2LN/ZxbCVb9ZmqpEvE+kpQYhFhljd5CBaMY7FRfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796099042; h=DMARC-Filter:DKIM-Signature:Cc:From:To:In-Reply-To:X-Lms-Return-Path: Date:Received:Content-Disposition:References:Subject:Message-Id: Mime-Version:Content-Type:X-Original-From:Content-Transfer-Encoding; bh=d+CFSCbSvMK4NdmzjQ1SZVyGxYLuxMNxCi0tlXLv65M=; b=Y7OSOcnhLrmuJdY99Bz/Ow1MHP2aC4129eRG//fo69llqTd/vdkoCIuXklq9B+txZvP5 RlfmwFwJybe3rIoQPsQj98E2tRzWYMb75eMYegMbWj414vwRA/vhEauXSnHY4oYFod/17 4LYWww3qapwFbaXM1JcfxErYXgrQAkQo57iY1ZW51nDVZgkZNg8MWRRQOVcyV/JD3lj7Y Z/o76Y5Rk0puzoI63NluOKM0PLSFqewv+MsyT5c6lCdjhJwtPX7U1jmJ2HfI13O9Wp/PE w+nOc84L/kuhFDuM+Sk2jUWaC0txENV77vwckS0u9+4DOCY63zY9SNOid1MpPdv4fRg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=fygo.io; spf=pass smtp.mailfrom=fygo.io; dkim=pass header.d=fygo-io.20200929.dkim.larksuite.com header.i=@fygo-io.20200929.dkim.larksuite.com header.a=rsa-sha256 header.s=s1 header.b=RMjqXCDN; arc=none smtp.remote-ip=209.127.231.44 Received: from va-2-44.ptr.blmpb.com (va-2-44.ptr.blmpb.com [209.127.231.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4920606A325 for ; Tue, 1 Dec 2026 04:24:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A4920606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fygo.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fygo.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=fygo-io.20200929.dkim.larksuite.com header.i=@fygo-io.20200929.dkim.larksuite.com header.a=rsa-sha256 header.s=s1 header.b=RMjqXCDN DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=s1; d=fygo-io.20200929.dkim.larksuite.com; t=1796099031; h=from:subject:mime-version:from:date:message-id:subject:to:cc: reply-to:content-type:mime-version:in-reply-to:message-id; bh=d+CFSCbSvMK4NdmzjQ1SZVyGxYLuxMNxCi0tlXLv65M=; b=RMjqXCDNAOowvNep+Lb+YmReFlkxoWewp/rvgcV+vm9oT4xAM34sCQ6mTFsC17/y4rQI+p sKm3vFHFBS3CNHSYlZHZRvJ0zCOuezAihw2kfxqi4dpqhuTrVqA8CsoN67bMCGAaEXehsW CRP1gCIsIKoHoQEK+uATzmyoMhE4JYm5h0b9hVc5LFMCe54Z9dxBvhKPAzeqv+TACj+sSd 3Q4cwfdr5+R2L2WuqWSWcxMgv6zZT1xahY1nTYHTr0l7G/IUzB8NsprTnMFA6ya51S/SNT LMhTJZzp/wvp90vORe2DAgP4vph6ix5gZBxDteK75VGPl1MVtN59J3QHDm1AvQ== Cc: "Wentao Liang" , "Kent Overstreet" , , , From: "Coly Li" To: "David Laight" In-Reply-To: <20261130182515.5a196fe3@pumpkin> X-Lms-Return-Path: Date: Tue, 1 Dec 2026 12:23:48 +0800 Received: from studio.local ([120.245.64.92]) by smtp.larksuite.com with ESMTPS; Tue, 01 Dec 2026 04:23:50 +0000 Content-Disposition: inline References: <20261103094627.1289665-1-vulab@iscas.ac.cn> <20261130182515.5a196fe3@pumpkin> Subject: Re: [PATCH 4/4] bcache: Release the cache kobject when cache_alloc() fails Message-Id: X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Original-From: Coly Li Content-Transfer-Encoding: 7bit On Mon, Nov 30, 2026 at 06:25:15PM +0800, David Laight wrote: > On Mon, 30 Nov 2026 23:08:20 +0800 > "Coly Li" wrote: > > > > kfree(ca->prio_buckets); > > > vfree(ca->buckets); > > > > For the above 2 lines, also kfree() and vfree() checks NULL inside, > > normally I would suggest to check the following checks, > > if (ca->prio_buckets) > > kfree(ca->prio_buckets); > > if (ca->buckets) > > vfree(ca->buckets); > > Then the extra function jumps to kfree() and vfree() can be avoided. > > I'd only do that if the common path has NULL pointers. This is not a common path, it is on failure handling or cache stop code path. So it should be executed once for days or months, even for frequent failures, it is once for several seconds. The code path is definitely cold, and branch prediction contributes little here. > Otherwise you are optimising for something that doesn't happen and > stand a moderate chance of a mispredicted branch (and likely() may not > help) - that might actually cost 40 clocks. Yes, I see the cost of mispredict. But I doubt it may happen here. This is a very cold code path, for this specific condition, considering kfree() and vfree() will be prefetched while the if-check, so extra cost of the extra if-check can be almostly ignorable (0~3 cpu cycles). > With luck (and a following wind) the test inside kfree() will be > predicted for 'not NULL' - so you only get the penalty in a (usually) > error path that passes NULL (you might get a mispredict on the next > non-NULL call, but that is really part of the penalty for the NULL). In such cold code path, if ca->prio_buckets is NULL, the cost of branch mispredict is just short jmp and prefetch kfree(). if (ca->prio_buckets) kfree(ca->prio_buckets); Without the above if-check, directly call kfree() for a NULL pointer ca->prio_buckets, will do a long jump into kfree() then a long jump back with a false if-check for the NULL pointer inside kfree(). This is more expensive IMHO. I guess x2 or x3 more. In common cases, your opinion works well. But this is very cold code path, the pipeline of speculated execution is quite short for branch prediction. False condition in if-check doesn't have so much penalty as hot code path does. Coly Li