From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796099042; b=nP95KRquq22HCqS64yB2owlKxmAsldwn76TYcOhQ3w0RdsndJHWVZiFdeI6vAOu0SqO/ nFfJEFtAAzOJ5IiR5qssrlugYhJMBVN97fCnvX8tvidxg9X7PMgGXSLagx30+9Rz/4xf8 MbG6aZIfF9jYOxyXuq5Lh4lVAvRvplbIycvgQBZ1sXKheT/TE0OOfFteGG30QsWwhxmVv 4Nn57R11zAESeAqNCN3LS4HXTtM3KL4A7AecboI4/9dp12wASeKbzUiISV8ma05axkiwf vl9cNDs75B+wE5JFt0yKMZHcF+8TJNJgHhu9Oknmo0kGJlU7fMO41oFe2KSA0+h+3Ww== 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=fpSOgi/SvWR8hYW7WhKf9cVirenrr1uyg4PqTpWBn19ToysWNtBw9+6oJew4bhGkl57Y 62Mjy5AT1+jVUeST1TQzPwZZJWDzIRq0Sj+7ZzOVHLTuQG9EBp+syRbZaxC7Yd8/5KO52 aYYtNoLuQ4C+qTfBOLMDJZ5d2TMPnxb+VEdS0bLSnhHyCBTTHphBI6WcLIGTiqVf348dA pSQXMn0KsBw6aEBfoPrXgbqs05n+hF3kzhMEoLzPR7jQ2Vkb17Ua8Ec8jv7Z3v0gbNrOn BRdLjQK9pCss+oXFbGw7UgI9wBTkGqIn4OPTZyrrwHOdvmxAkQ+z34dJtSHTXJNud+Q== 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.56 Received: from va-2-56.ptr.blmpb.com (va-2-56.ptr.blmpb.com [209.127.231.56]) (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 E435C606A32C for ; Tue, 1 Dec 2026 04:24:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E435C606A32C 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) 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: linux-kernel@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