From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29DA52FDC3C for ; Tue, 10 Mar 2026 14:52:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773154356; cv=none; b=hw151sb3UD/oOVggr8o05oYWLr6xcEpABoOPGH2cvs1HGRjzslsS3RHFMIiDp/MEIDP4f3ZYFXYv7TtouM5CxOMfF4oU8px2dNeCnxdpccJmtJM1GE+32o86tLB3dZq3I6+VdikiK5ySjDCmnAgI5jqB7kPlom0bqf8hd0CxZgk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773154356; c=relaxed/simple; bh=nNT08OXZ+foj3c8qL6cEktLfXz4SEfmFoLf3u4thxeQ=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NBgUo23sOt8Vde/40Mchp+CqJcFV+TxUA8DI6jVYcJXfhAHKVwWYr66BRXjGazNUXIglDaabk9sCRMcSTN8FFpP1D7uQF38sNnddbcSjqDydCN6uyQFO4aGm5FYOgBntcSGkgvqryxKTO9Nvhb7TRmhM4sXOuoOHd66HtZyUJ7k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S7lvDdsy; arc=none smtp.client-ip=209.85.128.53 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.b="S7lvDdsy" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-485392de558so14001305e9.1 for ; Tue, 10 Mar 2026 07:52:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773154353; x=1773759153; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=ml1c+QBVKH1G4D7WQDxLbH41bxeuoQxcf06ZreXxasU=; b=S7lvDdsyOqtNA1HzlQXkDrchQLdvFrI8vJdcZf/q3YFnqFgcC+JkDCtumQ3s54zi0b bWqIWy9iPCK5XFYobQopOjtFVmf2Ax4X1+gYevsKagBkMhNCVGHskrsO75DxDEjyMJqR 4wIyiTw3RQwAVg1xduhkaIwrGLXNKIZWXb+UHDNH8pePLFqyQrpX3+4yn/IUmCX8hoAx NWj1veS3nfmdcSq2g0i7bYr8OD+WoaRWa0BTnUcPCRjgnaDeGuTxXIvST4cZkX4BJga2 rcjYspoaF0I8G9oieyRU1gOov3WCypYHVSpu2wXHWXZTrnnNFEvvONEIU2Y2roN09qhf W96Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773154353; x=1773759153; h=content-transfer-encoding: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; bh=ml1c+QBVKH1G4D7WQDxLbH41bxeuoQxcf06ZreXxasU=; b=h5/TWym5CiB3LMJIY1jMOXGhEZzP3ztW4Zu6KfVtg96bdAY60O4tXftVWW9bmuU1NJ 6AaVp17Spg7ZWR4asGs30hLjVfZVnCIjFLcXRJIJO9OLg1rAy6Mum7RJU3xaW3l8R1G7 dMG0gGVd5QNrnrIWoF7zdI9mDYRrGc5ds+nA0LwP/v823yNNdriWuRjl2WnBB8oK7qs8 mycGS12hlBxxx9SZP9EOc046zxplY+wOP5f+nIr+mv1IbNu6A7QU+AAdpN0sfisreNaP RlKxA5uHiWiJaiIgIevXc9GRY80J9vOrdkGMBA6n00zopfDmjJllookVuPu7eJqQXO8a qqpQ== X-Forwarded-Encrypted: i=1; AJvYcCUKiMsmcASvHo/smBDT3eCNx1BRzcr3f06eCo+Kd6hSnnOqdRiBxR/UFHgNjgxUXIOCyn/FoRICJh94spg=@vger.kernel.org X-Gm-Message-State: AOJu0Ywl/WsCxCpyoV837d+NDACygtg6Z9zBg/Y4Qju3Kov0XbLMhjYP v0VTm02g6O79e0nkfQeYW1W3+i61rmZAeGJT48nBQ9MKh+iWT0xJ8QmD X-Gm-Gg: ATEYQzzTji8kX29jZl/2c+yLJ5w2EyFRRDOEVKrg7VHoiP0JKsvAQYxs8yT9MlwZGHG Gt1lJpoZxPyRG6dIHUeNs111dmoTx9nQX6/kOle30BixB0ZAASfeS0WwDgj2E4p5xufjb5IAAEj 0fz2YC1tF3IakG33xYZLDnXihOZ0LJHXje+I8oH66RfS3UAuQPShohOp+7r0gVIBYU60BlnZx+r aSPFdMcs40RlM8hVZqaEhrf2RPNCpQjM7RVp+2gAGIW/+4x3M+IUUgEY36o8ElkzNanTsSXIwGr WPLvACVuJe6+ki6R4JHkaNDkBpHQT86kmfJVuvjFyXqR1FU6mhDLBsry7XXdwYJLoajEyob0NC6 1UawhuB0+byDdWA7QKvOIn/T6FWWEwo++lNBeqcgt4FT1ntfDlzyaOf0dgCOhYkYsZL06lXTvss OAkA0dzMjty9cewUNPEM7SCzg2TMrcINHWA2MwmYBDdMCmreeL5yFYHMcDoz2mCJ/C X-Received: by 2002:a05:600c:8b5b:b0:480:4ae2:def1 with SMTP id 5b1f17b1804b1-485269305e5mr250455895e9.13.1773154353218; Tue, 10 Mar 2026 07:52:33 -0700 (PDT) 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-439dada3b43sm37635135f8f.13.2026.03.10.07.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2026 07:52:32 -0700 (PDT) Date: Tue, 10 Mar 2026 14:52:31 +0000 From: David Laight To: "Vlastimil Babka (SUSE)" Cc: Xie Yuanbin , willy@infradead.org, Liam.Howlett@oracle.com, akpm@linux-foundation.org, david@kernel.org, justinstitt@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ljs@kernel.org, llvm@lists.linux.dev, mhocko@suse.com, morbo@google.com, nathan@kernel.org, nick.desaulniers+lkml@gmail.com, rppt@kernel.org, surenb@google.com Subject: Re: [PATCH] mm: optimize the implementation of WARN_ON_ONCE_GFP() Message-ID: <20260310145231.1680db9b@pumpkin> In-Reply-To: References: <20260309155933.41179-1-qq570070308@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 10 Mar 2026 11:55:55 +0100 "Vlastimil Babka (SUSE)" wrote: > On 3/9/26 16:59, Xie Yuanbin wrote: > > On Mon, 9 Mar 2026 15:40:13 +0000, Matthew Wilcox wrote: > >>On Mon, Mar 09, 2026 at 11:38:11PM +0800, Xie Yuanbin wrote: > >>> As shown in the commit message of commit 242b872239f6a7deacbc > >>> ("include/linux/once_lite.h: fix judgment in WARN_ONCE with clang"), > >>> the code "unlikely(a && b)" may generate poor assembly code if it is > >>> actually "unlikely(a) && unlikely(b)" or "unlikely(a) && b". > >> > >> Why fix this in multiple places in the kernel instead of once in clang? > > > > If a and b is both unlikely, then "unlikely(a) && unlikely(b)" will > > generate better code than "unlikely(a && b)". This is also true for gcc. > > What are the details of how it's better for gcc? I'm not sure about that specific case, but I've definitely seen gcc generate sub-optimal code for some un/likely() of compound expressions. The underlying cause is that the code is (probably) first transformed to: bool tmp = expression; if (unlikely(tmp)) ... this means that you lose some of the short-circuiting that happens early in the code generation of 'if (expression)'. It is also not at all clear what you want the compiler to generate. For 'unlikely(a || b)' you want 'if (a) goto x; if (b) goto x' so that the 'likely' path is the no-branch one. But for 'unlikely(a && b)' you still want 'if (a) goto x; y:' which means that the 'b' test is out-of-line and has to be 'x: if (!b) goto y' to avoid a branch when a is false - but that means you have a 'normally taken' branch after the test of b. That pretty much means the compiler has to decide which unlikely() to ignore. So it only makes sense to do 'if (unlikely(a) && b)'. Indeed even 'if (unlikely(a) && likely(b))' may be better! David > > > As for the issue of clang judging twice, I have already submitted it to > > clang: > > Link: https://github.com/llvm/llvm-project/issues/167117 > > However, even if clang fixes it, this optimization will not be merged > > back to the old version of clang. > > That's life and not worth complicating the kernel code for. This is not > about making it functional, only about perf. >