From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 8D57F2F4A14 for ; Wed, 11 Mar 2026 19:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773258022; cv=none; b=Q7zZ71jAe9zoLkH7SJfUA+Q/jivRSX77O2RxTmErCtuxHfrHW3wrx6/qTWjimyICP31YwXlThDhc7SKUHuGeoqK2J2Gf9A/07s7MkpV2omlugEaGGATVJCdTBvhq9gYHP5SpXFb/aMcGeI8tY+YQ2GNkQlbOp3aszbwZX29DAfQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773258022; c=relaxed/simple; bh=NPYEBbHT4HMWmpbX/kAfbJ2Y6rIfF5o1jHcQaGJDrYs=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=BXWaDsx4GnHkQ835cz4PEwMVXWR0DpcyzvPXi1fYqtvpBdZeMxY4DHefAa9StvoA+sjDh+wJR/6cEbuGktnYueUSxVRRZAvWkmyAxaUlmxZsaKSwl1H0ifZ+QmSlboWoy7slW7B0GFgG6IbxkFt9j1Wb48GeVkLZsbVXXWMGdH4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GZWeEQpA; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GZWeEQpA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773258020; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1I1AIx6CE4U2WG0g7ivhKq0hUuW9ZnU+bO39JSnN7tg=; b=GZWeEQpAXyglpDoiH8fzF/oXbdIQ6DLNOafTbLrQn862yyE2FUnHuN3vRTXtaBrjSi+gEU MFSkcoj+dlPke58DNLO291jQb8yV3NqmMjGrRnO2An+IpL1WO+e0D2z11n4I1Ida+XJvHf Z+C2KRsAhrjV8hbzy6WZ8KoQTx+Vhk0= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-aSd6piaxPASoBwYTacgUpA-1; Wed, 11 Mar 2026 15:40:15 -0400 X-MC-Unique: aSd6piaxPASoBwYTacgUpA-1 X-Mimecast-MFC-AGG-ID: aSd6piaxPASoBwYTacgUpA_1773258014 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ADA5A1956094; Wed, 11 Mar 2026 19:40:13 +0000 (UTC) Received: from [10.22.90.45] (unknown [10.22.90.45]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 50C9A18002A6; Wed, 11 Mar 2026 19:40:11 +0000 (UTC) Message-ID: <1dd9484c-8016-43a3-b16c-1ece95636aa2@redhat.com> Date: Wed, 11 Mar 2026 15:40:10 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 next 5/5] Avoid writing to node->next in the osq_lock() fast path From: Waiman Long To: david.laight.linux@gmail.com, Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , linux-kernel@vger.kernel.org, Linus Torvalds , Steven Rostedt , Yafang Shao References: <20260306225150.93178-1-david.laight.linux@gmail.com> <20260306225150.93178-6-david.laight.linux@gmail.com> <3afd7e58-8e31-4dba-860c-2055ba372423@redhat.com> Content-Language: en-US In-Reply-To: <3afd7e58-8e31-4dba-860c-2055ba372423@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 On 3/11/26 3:27 PM, Waiman Long wrote: > On 3/6/26 5:51 PM, david.laight.linux@gmail.com wrote: >> From: David Laight >> >> When osq_lock() returns false or osq_unlock() returns static >> analysis shows that node->next should always be NULL. >> This means that it isn't necessary to explicitly set it to NULL >> prior to atomic_xchg(&lock->tail, curr) on entry to osq_lock(). >> >> Defer determining the address of the CPU's 'node' until after the >> atomic_exchange() so that it isn't done in the uncontented path. >> >> Signed-off-by: David Laight >> --- >>   kernel/locking/osq_lock.c | 6 ++---- >>   1 file changed, 2 insertions(+), 4 deletions(-) >> >> diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c >> index 0619691e2756..3f0cfdf1cd0f 100644 >> --- a/kernel/locking/osq_lock.c >> +++ b/kernel/locking/osq_lock.c >> @@ -92,13 +92,10 @@ osq_wait_next(struct optimistic_spin_queue *lock, >>     bool osq_lock(struct optimistic_spin_queue *lock) >>   { >> -    struct optimistic_spin_node *node = this_cpu_ptr(&osq_node); >> -    struct optimistic_spin_node *prev, *next; >> +    struct optimistic_spin_node *node, *prev, *next; >>       unsigned int curr = encode_cpu(smp_processor_id()); >>       unsigned int prev_cpu; >>   -    node->next = NULL; > > Although it does look like node->next should always be NULL when > entering osq_lock(), any future change may invalidate this assumption. > I know you want to not touch the osq_node cacheline on fast path, but > we will need a big comment here to explicitly spell out this > assumption to make sure that we won't break it in the future. > > BTW, how much performance gain have you measured with this change? Can > we just leave it there to be safe. > Or you could have something like         if (IS_ENABLED(CONFIG_PROVE_LOCKING))                 WARN_ON_ONCE(node->next != NULL); Cheers, Longman