From: David Laight <david.laight.linux@gmail.com>
To: "Coly Li" <colyli@fygo.io>
Cc: "Wentao Liang" <vulab@iscas.ac.cn>,
"Kent Overstreet" <kent.overstreet@linux.dev>,
<linux-bcache@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<stable@vger.kernel.org>
Subject: Re: [PATCH 4/4] bcache: Release the cache kobject when cache_alloc() fails
Date: Mon, 30 Nov 2026 18:25:15 +0000 [thread overview]
Message-ID: <20261130182515.5a196fe3@pumpkin> (raw)
In-Reply-To: <aw1tfczkIurBvyEr@studio.local>
On Mon, 30 Nov 2026 23:08:20 +0800
"Coly Li" <colyli@fygo.io> 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.
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.
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).
David
prev parent reply other threads:[~2026-11-30 18:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 9:46 Wentao Liang
2026-11-30 15:08 ` Coly Li
2026-11-30 18:25 ` David Laight [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130182515.5a196fe3@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=colyli@fygo.io \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=vulab@iscas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®