From mboxrd@z Thu Jan 1 00:00:00 1970 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 979FA199949; Wed, 29 Jul 2026 11:22:22 +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=1785324144; cv=none; b=fk65BVDpyukRZZ5Fp/bd3Hjzy4AMBULxYehfmdbZHMT3XHyTSNt+2xUH6+0W+oiyxA5C8jTuwoxA2NILrXSlNpKHPWsykSPNzYwP+ieGq/QH4yWcjqrwAG3A1AzOLajcIu0v3V7cxe3bxGwkiHVs4J8/Dj/faZ2KQcl4Gohs458= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785324144; c=relaxed/simple; bh=OgBwRfXIVyz77PHvZ36UcZL8MLB1M+7FodKryZeijb4=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=So2AmrEmB9BLdfTEq2km0MZAmR6MCGpHHW5kIZKsk8Zi/7byOOtxyCzpDTGIGVZK/rdLVc8+ZrAZrLuv7d6X4mg7dZ2apaIvgFDZlKrWaFb6o//1Odg/i+7LDVeDI3hZ8ZbZTqW/xbluSMKjfbHacs72iwyAP4LrubqAOkGqQpE= 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=zeApk1no; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=TeCTiuu1; 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="zeApk1no"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="TeCTiuu1" Date: Wed, 29 Jul 2026 11:22:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1785324140; 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=xGsOSoZ/OcJ08D7pcqBPVKmfNSPnMHSNIW/fzhpXLKQ=; b=zeApk1nogy/iKzrkluOCTKaIP3YqJkqZ0F07bFGseMfaHvEc/Mt5c7XK6gllLAqkEWwwi9 C7d7LUu8ErBlVnz+hulqsj9WVLL8zmca3EaHreEiu8Z1p6hzkPq39fQws5XXfzLTEDuT76 4VjQxy709zGEwI9gEpkG6POwY+HDy9LOvsZ0fbkg9flWwwMNvPuep+iWtTlL/WdZJYUhEA GZpv0syPgql6sRtSsgZPinoo+mD3150VmXqq3RrMkzymRpMd3WwxA0CsQoDrjbW3qUceLO /m76/VC+zxnFzEnDnEFUBj8nsqnnsWla/xesoHUPxZheDBB/D81z7n4CmeHEYw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1785324140; 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=xGsOSoZ/OcJ08D7pcqBPVKmfNSPnMHSNIW/fzhpXLKQ=; b=TeCTiuu1iCfefdbnSWytsRfb6m0xny0EDrvh4i+Tt4B84Qtvx4tHu6+tBt3meYMkDSwt0Z WlTfkcv0dVqDcaAg== From: "tip-bot2 for Sebastian Andrzej Siewior" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] futex: Optimise the size check get_futex_key() Cc: Sebastian Andrzej Siewior , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260701161736.xYYizA0e@linutronix.de> References: <20260701161736.xYYizA0e@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178532413842.112641.6566766965612364337.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: 5e601ab3615c86be7c4068ce992f94654693a032 Gitweb: https://git.kernel.org/tip/5e601ab3615c86be7c4068ce992f9465469= 3a032 Author: Sebastian Andrzej Siewior AuthorDate: Wed, 01 Jul 2026 18:17:36 +02:00 Committer: Peter Zijlstra CommitterDate: Wed, 29 Jul 2026 13:17:52 +02:00 futex: Optimise the size check get_futex_key() The futex address must be naturally aligned and this is checked via "address % size" where `address' is the supplied address and `size' is the expected size of futex. It is guaranteed that `size' is power of two but the compiler does not see it and creates here a `div' operation (x86, arm, gcc-15). We can take advantage of the pow2 property and rewrite it as "address & (size-1)". As per testing, the command |perf bench futex hash -f 1 -b 16384 -t 1 -r 30 improved from | [thread 0] futex: 0x5619f931f740 [ 7001583 ops/sec ] to | [thread 0] futex: 0x55da173e5740 [ 7376137 ops/sec ] or by 5.3% Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/20260701161736.xYYizA0e@linutronix.de --- kernel/futex/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/futex/core.c b/kernel/futex/core.c index 3bf6cb7..0864c6e 100644 --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -516,7 +516,7 @@ int get_futex_key(u32 __user *uaddr, unsigned int flags, = union futex_key *key, * The futex address must be "naturally" aligned. */ key->both.offset =3D address % PAGE_SIZE; - if (unlikely((address % size) !=3D 0)) + if (unlikely((address & (size-1)) !=3D 0)) return -EINVAL; address -=3D key->both.offset; =20