From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796113566; b=viDMlELmyVdE/sPBZtWLi58fp+OIEFu7gK5UMVODZWoZionCssrkPclW9G6O+tJJjA9R rRxD7+X1c+hMrDhf7mS/IxxsHG+AsN9sPZJqRyzA82xC1aDJGb8J6M+Qtp2Knuxb2/23n mMn28pcGYGbIsS/OGnS/9rv6CYIoKsQ0oBtTkG0pHt1ymiL2cH3zn8ME+KHky0VSR5fgy Y6fo9DiIz7hHf6jgJ8yDv0Pnh4uEq5nHd2Kh1X/SQY1jXajRPixrmKIpaILEznEBxmJbU k8eA3Sg6xHX5WVaNWE4PHgUMw6qHq5bdCS7CsoMt4ATxF7kqGj2FL91a7CY257NiFrA== 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=RwAclOvlS6WVJkysSZx3IrlM2zusXRwrWym5KqJwnylvpv0opq2jCmJeo37TN12X0qeZ YWsi45fC8rzuRexNLhKjTNtQ5AfYWk3XEP/7U4kikABGCrC7U/Yk9rw5MsPyhU0/X+hlB oWEptZgt9euSF4B8hPT61e1TCaT3vCNIAXef/HneU63PQxkBIX4jWeEINTV1ugs6+wu7F gDeumkzmQAkAbUhL6/HBA/22wMv4QuP7N7ntEnXEyIrAPAt2R6ucy4v99rGSTzZ+cG9BY uz9N2WwJzVq+pPGepFm79dBU4xECnsIlW5mDqqjwJM8budIOgTxqXBFnSEq0MG5SDxA== 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.51 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 030A3606A334 for ; Tue, 1 Dec 2026 08:26:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 030A3606A334 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-f51.google.com with SMTP id ffacd0b85a97d-4a9be758734so7243867f8f.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=oaLo309MIfw5KhJnMDpXiRem7/Zr/KGWbJo+1kH8crSzrsWpmw2LQkW6t1jwfPaNsB vS8z9I3Rgnx6/IhyITwlqn0rxW/MrRSPWJ1KyYJopotWY3edGWxuxCm9ZxO/OoB/ZShs z8PJkXGofsYDYiAuYD3TmRXj1yKERhq5PpbqKKWyPLsLoYbnCiLXhrWE95myydvvDdGj tLhhsVCAnvYLaHBNN0BrKoMNr2HGNSBi/8D6r4xQw7+ls1yCCt8ufblAfuJbGvEMncUx VM2JGdKMU16TsNw4QPmY7YIbNIlaW0bHJUhEVeEeTrTwdS8Q1M/4L+awi86Db3fFDgkN iWmg== X-Forwarded-Encrypted: i=1; AL+hErH7rEFDBDUm/M1Y7SOe5KGuZGFXzIMnXUumWsb3NsUfAmZVMBmWAq+wPYKMtr/nXfVlb9zz+cc=@vger.kernel.org X-Gm-Message-State: APuU4Z/pfVQpLVg+QLpI1p16J9nmKCZh+JK/GRZGekN4i12OxqsM5uhB ykBjWi4xFucV7eZvAQMcaIT7BKOCY9EX76cacWu8706ASDL5FDLFgw3M X-Gm-Gg: AZFdTZdzqfhSqDHTohMfXuhwRQJ1jd2HZxNe5lZ6uioIyQS1JCJfEVJ04H3mEfjClT2 d5rMQ9rEwIUZUIMF0Y6o4V/CYwIisrKIlMRorpyHBi/uxzv282zPmI56vl6gpKYsA4T407h+NSR tohJ7D28Wvr67WYc98oNw8aGQvFpnoVNjd6nsaJtUc3cIcLgkrh7H9DrfroQnbpYQ4ygPwvfjLb hX470iJ71oPP9/9ikaI0Q1uZ2es4VMmSRpSe3KcXrnfmp1XX3+TAVW58NwEJwF8SLdECDqTgLoc s92Cm2t3OTokBmGc4Be3P5inB95s4h5lgyKo3ukIUdUawKi7IRhoueDiiuXg1cnqzi4HshQnZ7a bIYQ53c36atEPoG/DoHWaQRSPoX1Dhj8AF1H4YbijGAIJvauP+OERfrp2XQbFcUUwxU8jrr6krp myFEmUlqCDxGleypW+5sCA7z10qPVSsbHYQXeZ3w7o0Z+MaABzZ5+7wRN665CFjgXJUK72HQntk WioyPwt/qBggHJEOfqwNKf6T0+cxdXuaE9W+OdiE7DEbAecZ4AnyWACmue165hucIqqBXH3LMZT B/XohkoEBHXFmHx+wT7sn6Vhif/o485Rw/+heLoAMd73DjXQRsnFpLxlEp6RrSXbtnPyWQ1rnJg AmN+EabSksfY= 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: 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=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