From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796113566; b=a28QZ3+AbyFpcaaubaonYJQDUjBu/pkpb0LxZSpKCoGVQxVCUkYlydj2+L3G85VRLfXx MdkXhLI3FNqrjyEladJIekVgfp8OiEztQMLekR5/SPBwMwHBBkBYKRmAvzm6BWvdawzj/ EsVGxkk3PoPkToLrolYum9OZt+NiZqw05ctwGs1vdLijSGYiHi6BISRpAa0i9uE7urEaw tXiN/SOsh7RewMZvwH9CXOAeWwddGTh4rlm+oyWQhgqw4NVnDcBqimjinUNtmqvGznmc0 uvhLeW4Dp1G3cJ9oWZaiC361n0R2RA6zt76+8robzpYogy7ZXQzekEtGLYEDkvjZgjw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796113566; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=Yq5jvqt6oCIvJtzkzG5wgG4SgUynLkMAlVOGL3qorBI=; b=I3AqYv9z4K1S+xhFNX0YRUiABHz40m5s2bO4af2koPzVDwjznWD0WrUGB579ghhCF0yq TkP2a1bYrZ7QLkOKUxWLAcQDxiEdGqdmWg2QCrOBaoKUyPVstHswSP8bVTyIBp93t2X21 a9sYO9gu8PjuLah0cD82My+C3OW5M7wQ6Dpl5a9wYWUZFSU990y01Zn1NO0bODqjua/R0 iDeuOTUu7w/W2eAbrnyyTi/tfaguH37PQEF3NmIcVut/2Q/OzRvKqB9vfMwDJIdwNowZc MhgEyC937zT8AjLBFxsxrWFe5hTNDNODE/P07i051G2QTYKZGoYwV8Ya7qrAH6Jcsvw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Et998ekY; arc=none smtp.remote-ip=209.85.128.44 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.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 EEBEC606A33B for ; Tue, 1 Dec 2026 08:26:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EEBEC606A33B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Et998ekY Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4a35ac4475dso81193025e9.2 for ; Tue, 01 Dec 2026 00:26:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796113564; x=1796718364; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Yq5jvqt6oCIvJtzkzG5wgG4SgUynLkMAlVOGL3qorBI=; b=Et998ekYGdmDILY0fkmVeQV/ZtCRNniMcOoE3x4DAR6waDgZBs8fcUIsZaq+a3jLw+ hTiA0tyyEGkDXNnAGsTxJ+9RS1izsjLh7adVO0LQgUDr4qmobN8T9s+ixBgrWKCTzYK+ zI/cBr51TCCIq9IxBPsvOms8Qf3HKLuN8WDXe0UPD0MSzzp46u6f1RO3kYm59+Beg5i2 fBK/e/m7ynUQtiWYr7IMlE92tp9QVwqI8IwUm10+HvGprnN72trH/IFEbL1fe/gk5cXz x4FWsrLf9JbivnYPqQKceLmEGveEUZ5OTrdUuBzadL59h074Mcnm/ILDFH2VsBjy113p i0QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796113564; x=1796718364; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Yq5jvqt6oCIvJtzkzG5wgG4SgUynLkMAlVOGL3qorBI=; b=U/GwSv/CcCIXoltuT21SumVbNvShzZREVPNtrf+H5qbJU7OKkgbZTudub7pxzjgfjp qyemT1/254JBL5JSfvN2FI9w/RQBCoruM8Wrw+XZqkAVJc1XR7RVqlBo1oHf9l1pjXhW 19L6Q2C2onJ6KNeXuqh3rnyao38wXkNJDUQj11HMl6hFVgdC8hY6uuhtGfIon0KH0oAP aoAqh9aAneM3EJePVN7jr2Nwy2NGlrgbkmk4+wjtQsG1tFza8jZRyFKOJZ35jF7Bd1nY tvQF4iJJUOw9WhxObComQ5JfbRDNe/3X+HV9dB3Mq4vzOjDmzzHw/RVncCDO7xrU1ZWw IDVg== X-Forwarded-Encrypted: i=1; AL+hErGtyDN8eqtugNz+3H71vw5Wu1k/D8aif7N1EVMbrJ43jESajw1DtRprxsV6/OVFxSzx6Qw9I/fOkze6eZs=@vger.kernel.org X-Gm-Message-State: APuU4Z94K98NvOoptB0D8BEGSX6CBVMlPnUgd6agdyFL2HTwIDMOAcfl W42PTWNJ6O4w5yW+f0IO3rQwyM+tQpfkIv9sEBx5Mj9dnA51I427Mzc8Qi7LG7nu X-Gm-Gg: AZFdTZcubbIOokqaRoWz2rf+9MFxPkG7byxUdaDwcwl/YTks4DR2Uw/ov4gwszsBAJT a/th+KmH7I3qd9pIeoBWEf8z9OBlC3EJKDU3IehAoVdcLJJtaBaiTuWufs6Vs6FY8Y3pasT8UJR eSaFZkBSb/5x97uSQgsqf5xDRMbpoLwgv5xAdkwEikvwefV12m0qSDQLf7J/VgeHeYwJRDtzE4j 3ZPW3BzxhdUKHIT/edSKlF/tCF5uetcgR19XsZBKWYn/ZQLb1dY6SA9blxwBB/K0kA3gfVyIr6t g1HH/qspmoDk1loBxgw6eG1fySvUQy+OAGAUO0QKGflhyaH50enjtjwPvsVC4q8P8AiE4hgblAE hhrRPhY9hseFz7XNxjYzdlWs4w/lqJmuZwUmoqrAuIIgZqzIYsrkR4OJtsB/yRWl4Rh1j/dy8ml QBgleXDVuz5eLKo6E+HzWrCFhJpBE5gB3qLMdCesf3ScJvyyabP4uj+m5iWi9xzZDAb+tHFkOgb 8byiwn4ATmESNMQj6niGPD5NFGwQAqj2QzDl6vlm4s6gpUJU2JLOeQox/0mCHppKFDomqzaP7bo oX4pURCL7vJCsI9aqCMfoCaUw4OXuhBnytkwBB2viAJqUJRJFJ31xdExXyAMmbGEZFnBNF3UZKK Hbk54V85EYRM= X-Received: by 2002:a05:6000:299c:10b0:4ab:7c3:105 with SMTP id ffacd0b85a97d-4abb00d6ed6mr49666942f8f.22.1796113564216; Tue, 01 Dec 2026 00:26:04 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6a67fec7sm66220514f8f.26.2026.12.01.00.26.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 00:26:03 -0800 (PST) Date: Tue, 1 Dec 2026 08:26:02 +0000 From: David Laight To: "Coly Li" Cc: "Wentao Liang" , "Kent Overstreet" , , , Subject: Re: [PATCH 4/4] bcache: Release the cache kobject when cache_alloc() fails Message-ID: <20261201082602.1fcb676d@pumpkin> In-Reply-To: References: <20261103094627.1289665-1-vulab@iscas.ac.cn> <20261130182515.5a196fe3@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 1 Dec 2026 12:23:48 +0800 "Coly Li" wrote: > 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. Right, so code size wins and you don't have the extra conditional. David > > Coly Li