From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796113566; b=urr57E4Cj2t1iOYF71VIyRKgbyoyoevcFgYrswDUqZ5x0qukx3xpBYM/LaQ3PmPtPdTj qbm9ynSvQ9pj+Y+EQ/5d6b/cYsNEP9iN/Lavw2/0yuWyhNISd2X35bVzWAK7d9mssGZRO ov+CuqAyRtcEV+Xcohbwlax606jhRm5bpfW2Vd3rYWuWz7kHTvkBHKQL/T7PJYZm5QQmh 5QLeNSmJPbPJ9fT4o4Sesc4q0LPfEU3/44vpWlUW7vmYuvVn3EiIzmIigWFJs31w1uQFG GkHveVY7ppFNOL5OQkHaLlmkvp074MeMR+rZixl/wcZj8BZi/f+yGI1LmFSIePmyhAw== 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=XzIuf0KpYfwO7+kqrR7sowHUWqk5rvA/0D+28dM/97j6wQzpsd28f4SW5HjdWPZ6dEuU nIUHG01TvVzn82YBk1sVFFZiD5334JAv9HwrmgZJDUlrnziAniJWWUmABFwWD8G8/9tNS 0ekt0ftzhLrDjx8Ewip/VSWR8qihxft2ZDcEBSXiYYkz8l6MGeNKh2VjUX6IVFVadREM8 StPW0FYLidqc8MUi9NxaNNLyzPwa6flaDPUOnPE/5z+Ocmjn6JowsfCFjliRYbQBvuV+2 vDUP1ca+BLpCMFhPEICE4co/9cAzm6FOrg02PCA+Sl1iLH6Ue6ZTAw0tVW7Nh3MDe7w== 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.221.52 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 0A314606A33C for ; Tue, 1 Dec 2026 08:26:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0A314606A33C 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-wr1-f52.google.com with SMTP id ffacd0b85a97d-4a9be758734so7243868f8f.1 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=P+MXMEJt806dUS5i7JU7mTzqvpGUjTAlujRnhfNftrhA2w7LIbMFFb9EyBHJZ8aiZ4 Opt7rhJNo8gB1BKs42L24BjnLV9TGCsKtWuQ+C4xR0paHUkRcXHDP55cfTyZ1BK5lMLO TiLNg4l9yq6Wcly6lHjA/WW5H+krQfxl74yBcbVQjA4LtIWttiserkOjwNPwjWaXPM/0 9vJI8ztxObP2Hne3fseC01xtPqHiQ/z4a9y5BPqcQGFa3XfJVhsF5n9VGpH8LsQ9lgzQ qf/WeVAgJsmxZcI9Wbns+dox7yatOOudZJPJorwPu6D7entSxc+zJPIcImVfuqMsp+/n SQAQ== X-Forwarded-Encrypted: i=1; AL+hErHj1Dm8uwCNOGiVIJnnSAr+1PmAOGO6J/wKEMnmsTF7pa3yTrmYZ9UuFY+ZzYSUBjsG4ufHcnDUu/Cy4Lw=@vger.kernel.org X-Gm-Message-State: APuU4Z/vzPU7makhFhQb5r2qJcPcrLm+7Q1Pv5KDjVmftzlTSpwgbTcW UAL2twUc4EHQWhZHK7T2Ddh1ELneQ8Nv1djoPLsS/SV8f3nqFNxirr+i X-Gm-Gg: AZFdTZeLRkIgt1x+lEHyq6LFzblAOE5aCNLyJSN489wvjtZlEN09OnZVrMGkoOx5QU2 tGPQvRvPz4HvaYYYEO8OvwxCB379yZGDkQZEXrFXmegztS96b2fVJaUShtHeZGKAVn4ebmgOVwa jhqpzodJVb81Ziq/bF6dKh3hPMwPh8BHp3dQdtEI7833dymwr7jXfsZIOW32ThA/ISHlW4YzgV6 sfHq5qWb/d1DwJ/Xy6AimCr/OJpC4zS096CSQv4FiEHj8122y+w/DOxd6YW+GIyjlBp2t/rUBbJ wShxB4ncT2IY9tzXbqswCRoQl+rDStdDDUsDoLPHxUb48QgMXCnGGiOMJp9BJw4IpzldEo0sD9m 0LFZin8K8fe8s3zh4WyPbkx4EYvVG9A0/Xo/sVQzFigkg5cKAv/r3EJjrqjLQp5p7JGOqhSMQkb VaKLrMxP/QfTzLabTj+3Zxxzer1Gg29eTKnZqp+zDglMuOhYUGS9GeKxz9rXkpLjXR/dysrc/Yi 6pVkM+zu4f7tAwPp8SGQCDd2oiGC5FoUKDbrp9DRFhpal7POKlF23t0xUecm36u8GGZXMU9fPlf IIbfPJN+77BNqp5cJRQQeziuf/xGVTo8TZ4OCK7uCFcwP/6z6fkGnfceOuAf3FbKLJDWQpcl7l8 qK6uP03cO7ac= 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-bcache@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