From nobody Mon Apr 6 19:59:14 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C3C83783A4; Wed, 18 Mar 2026 08:02:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773820975; cv=none; b=c8SKtavjHBE9xGyZflgTyKlw0lPWyY+ZyHWCPKQWUHaTf1AdT7v0zHV6/v/CAGFlDSDcQoPMtXCbR3bJ3o8igeoloZb3RZ0dFqkCW730BrXn/HLVSge42szP/nOVGDnj1WjY7jxoicTx9gjBaAbfRfVSlsOLrOd68OStQok6t84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773820975; c=relaxed/simple; bh=FrVmL747GRXMKm2+F6eX55Pa3nzRyG0IFOOAzFP9Knw=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=R4ucP6o8+RsB0yB6DFYU9ASpLJeymb8DdtzmA2ermgFL+9VjF4Z8+G8gNFUwfotzn8jNFNosHZF+PkiwqErPHQ6VJKsC7PK5mW/l3mFGm8kl+/1BF6+b6/lms5oy1OlVL2sZGj4ALHnGqDc+1tjrfXAeEOsJwGQFNGGO7Qa6v7c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=G5Lqehkm; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qTcWHHx3; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="G5Lqehkm"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qTcWHHx3" Date: Wed, 18 Mar 2026 08:02:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1773820972; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZQf8BhKkIykHfnmBAfsUdx0a8wkFAbcbz5SYphgJ9yg=; b=G5LqehkmAJh+Mnchit3HfE1S4UmG3XzXI2gVaAe1S6aWq5b9qjZO5xakYaLVAZndUDPne4 3VkpyxpJnIZUe8hYG2RhpBoTnPzU91acRoLA+ZL3D/0mVyla2/CI54v19S6958KJsLJYqC 61/s1R9NYuFymx8PTDVY6MknSrXHcLQokSUHriLqdaE0HN5slKnBPSu1zjs3AHl7M1PO15 kC1+yNhq+3kujBDlSViGMTeqtMzYgSswZ6EZ2d01yWQRp+2n07Rm2LfltBXr9m6L9otqCa Y06DbCV5KpZrreK4n683InHTNuqB1C1xQAjiPcAmmSxTTwVb2q6DK5fAX3/nyw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1773820972; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZQf8BhKkIykHfnmBAfsUdx0a8wkFAbcbz5SYphgJ9yg=; b=qTcWHHx32/cTXDi0xa80RQHjQbrZfx+QpqGYW0xBGLZTAfyDN9F8D37flUzP2+vK6g5X/W FpCpuSkwzWt6suCw== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] cleanup: Optimize guards Cc: Andrew Morton , "Peter Zijlstra (Intel)" , Dan Williams , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260309164516.GE606826@noisy.programming.kicks-ass.net> References: <20260309164516.GE606826@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177382097100.1647592.16531951136613750889.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the locking/core branch of tip: Commit-ID: 2deccd5c862a0337a691bcfaa87919b4216e6103 Gitweb: https://git.kernel.org/tip/2deccd5c862a0337a691bcfaa87919b42= 16e6103 Author: Peter Zijlstra AuthorDate: Mon, 09 Mar 2026 17:40:42 +01:00 Committer: Peter Zijlstra CommitterDate: Mon, 16 Mar 2026 13:16:49 +01:00 cleanup: Optimize guards Andrew reported that a guard() conversion of zone_lock increased the code size unnecessarily. It turns out the unconditional __GUARD_IS_ERR() is to blame. As explored earlier [1], __GUARD_IS_ERR(), similar to IS_ERR_OR_NULL(), generates somewhat sub-optimal code. However, looking at things again, it is possible to avoid doing the __GUARD_IS_ERR() unconditionally. Revert the normal destructors to a simple NULL test and only add the IS_ERR bit to COND guards. This cures the reported overhead; as compiled by GCC-16: page_alloc.o: pre: Total: Before=3D45299, After=3D45371, chg +0.16% post: Total: Before=3D45299, After=3D45026, chg -0.60% [1] https://lkml.kernel.org/r/20250513085001.GC25891@noisy.programming.kick= s-ass.net Reported-by: Andrew Morton Signed-off-by: Peter Zijlstra (Intel) Tested-by: Dan Williams Link: https://patch.msgid.link/20260309164516.GE606826@noisy.programming.ki= cks-ass.net --- include/linux/cleanup.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h index dbc4162..ea95ca4 100644 --- a/include/linux/cleanup.h +++ b/include/linux/cleanup.h @@ -286,15 +286,18 @@ static __always_inline _type class_##_name##_construc= tor(_init_args) \ __no_context_analysis \ { _type t =3D _init; return t; } =20 -#define EXTEND_CLASS(_name, ext, _init, _init_args...) \ -typedef lock_##_name##_t lock_##_name##ext##_t; \ +#define EXTEND_CLASS_COND(_name, ext, _cond, _init, _init_args...) \ +typedef lock_##_name##_t lock_##_name##ext##_t; \ typedef class_##_name##_t class_##_name##ext##_t; \ -static __always_inline void class_##_name##ext##_destructor(class_##_name#= #_t *p) \ -{ class_##_name##_destructor(p); } \ +static __always_inline void class_##_name##ext##_destructor(class_##_name#= #_t *_T) \ +{ if (_cond) return; class_##_name##_destructor(_T); } \ static __always_inline class_##_name##_t class_##_name##ext##_constructor(= _init_args) \ __no_context_analysis \ { class_##_name##_t t =3D _init; return t; } =20 +#define EXTEND_CLASS(_name, ext, _init, _init_args...) \ + EXTEND_CLASS_COND(_name, ext, 0, _init, _init_args) + #define CLASS(_name, var) \ class_##_name##_t var __cleanup(class_##_name##_destructor) =3D \ class_##_name##_constructor @@ -394,12 +397,12 @@ static __maybe_unused const bool class_##_name##_is_c= onditional =3D _is_cond __DEFINE_GUARD_LOCK_PTR(_name, _T) =20 #define DEFINE_GUARD(_name, _type, _lock, _unlock) \ - DEFINE_CLASS(_name, _type, if (!__GUARD_IS_ERR(_T)) { _unlock; }, ({ _loc= k; _T; }), _type _T); \ + DEFINE_CLASS(_name, _type, if (_T) { _unlock; }, ({ _lock; _T; }), _type = _T); \ DEFINE_CLASS_IS_GUARD(_name) =20 #define DEFINE_GUARD_COND_4(_name, _ext, _lock, _cond) \ __DEFINE_CLASS_IS_CONDITIONAL(_name##_ext, true); \ - EXTEND_CLASS(_name, _ext, \ + EXTEND_CLASS_COND(_name, _ext, __GUARD_IS_ERR(*_T), \ ({ void *_t =3D _T; int _RET =3D (_lock); if (_T && !(_cond)) _t = =3D ERR_PTR(_RET); _t; }), \ class_##_name##_t _T) \ static __always_inline void * class_##_name##_ext##_lock_ptr(class_##_nam= e##_t *_T) \ @@ -488,7 +491,7 @@ typedef struct { \ static __always_inline void class_##_name##_destructor(class_##_name##_t *= _T) \ __no_context_analysis \ { \ - if (!__GUARD_IS_ERR(_T->lock)) { _unlock; } \ + if (_T->lock) { _unlock; } \ } \ \ __DEFINE_GUARD_LOCK_PTR(_name, &_T->lock) @@ -565,7 +568,7 @@ __DEFINE_LOCK_GUARD_0(_name, _lock) =20 #define DEFINE_LOCK_GUARD_1_COND_4(_name, _ext, _lock, _cond) \ __DEFINE_CLASS_IS_CONDITIONAL(_name##_ext, true); \ - EXTEND_CLASS(_name, _ext, \ + EXTEND_CLASS_COND(_name, _ext, __GUARD_IS_ERR(_T->lock), \ ({ class_##_name##_t _t =3D { .lock =3D l }, *_T =3D &_t;\ int _RET =3D (_lock); \ if (_T->lock && !(_cond)) _T->lock =3D ERR_PTR(_RET);\