Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1292794rdb; Fri, 1 Dec 2023 11:59:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8DxuUMb6BY1IHa+fNnfIw3Nw2mLuibQq4O6dU6qlo8aSh/NY5/T0p/+/TcUmpHsnggucm X-Received: by 2002:a17:90b:388a:b0:285:8673:450d with SMTP id mu10-20020a17090b388a00b002858673450dmr47260pjb.40.1701460765481; Fri, 01 Dec 2023 11:59:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701460765; cv=none; d=google.com; s=arc-20160816; b=uaA3MEtaUOJDRu6l8uooEtdxFsBcJgSVbbelqfZP8Gl2LRvm6zqWa7QJvXZoQ5ywov EM4Bn8Pf2uGiKuMEvVruJrfzP249BH6WKvkTmLNwFcAW6FwuZIRuAe37nHMvDdwa2olE kmlY2FnZtvJNIzrMzHTDJoiX//nYnb7Kku83/KGcFu/YinLyhJnyUy/4wyucKd7YvHZs kYBq/3rvDbsasMBreYReLmjAaYo1DM+Amzy7oRApTwWuzraZmfGXKBHlsxmSNgyXYG6W SXAXVQgsuV/RBTT2nre5RmibUL4YMyLNfnSaZ2A/WIzNpNZusdsQIUDFnGJ3r2XMQBjQ b0lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date; bh=rwUpQFXbjYqRHwq4L4PRd+w0zOguEZrN+oy1TiU9DNo=; fh=yaqZu3JbG/uGA6V2iV56TbRNqA0l77H0ikG18l9uibM=; b=j1qnZJwcTZXSM17TnKWluHLWvlPaOkoSwXdfuLiBMvgVPCTiv63t45MxWyQUZI7OfQ ggMQkp+uA+91prUOiks84Y6a9ddXOvkP/ppRmrtS4xgHKYf/h50jX2AqDxYnMkPSksOh xT44eVTBq9Z+DpzfZjTcQl0whM9akgu9eFMuotDOrHpJ+cZ+ZsOa6ZP8D04V+9a/nxUQ F+Dslj84CCTSdguWbtmG/ThZei8YFaSEDqNHtJbZ49hLUCkdCQK8iGZ6NdFgrji1sCOj 4vUvu8Wfs8bxT/CYX9doMbF1878e6fukO5msZ/LqQutdcamJmNPDrdI5du24pBF22YU7 tGmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id x91-20020a17090a6c6400b0028656bf7196si1976435pjj.146.2023.12.01.11.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 11:59:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id BCA388297218; Fri, 1 Dec 2023 11:59:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379567AbjLAT7H (ORCPT + 99 others); Fri, 1 Dec 2023 14:59:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379559AbjLAT7G (ORCPT ); Fri, 1 Dec 2023 14:59:06 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEA6AFA for ; Fri, 1 Dec 2023 11:59:12 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AAEDC433C9; Fri, 1 Dec 2023 19:59:11 +0000 (UTC) Date: Fri, 1 Dec 2023 14:59:36 -0500 From: Steven Rostedt To: LKML , linux-mm@kvack.org Cc: David Hildenbrand , Vlastimil Babka , Andrew Morton Subject: [PATCH] mm/rmap: Fix misplaced parenthesis of a likely() Message-ID: <20231201145936.5ddfdb50@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 01 Dec 2023 11:59:22 -0800 (PST) From: Steven Rostedt (Google) Running my yearly branch profiler to see where likely/unlikely annotation may be added or removed, I discovered this: correct incorrect % Function File Line ------- --------- - -------- ---- ---- 0 457918 100 page_try_dup_anon_rmap rmap.h 264 [..] 458021 0 0 page_try_dup_anon_rmap rmap.h 265 I thought it was interesting that line 264 of rmap.h had a 100% incorrect annotation, but the line directly below it was 100% correct. Looking at the code: if (likely(!is_device_private_page(page) && unlikely(page_needs_cow_for_dma(vma, page)))) It didn't make sense. The "likely()" was around the entire if statement (not just the "!is_device_private_page(page)"), which also included the "unlikely()" portion of that if condition. If the unlikely portion is unlikely to be true, that would make the entire if condition unlikely to be true, so it made no sense at all to say the entire if condition is true. What is more likely to be likely is just the first part of the if statement before the && operation. It's likely to be a misplaced parenthesis. And after making the if condition broken into a likely() && unlikely(), both now appear to be correct! Cc: stable@vger.kernel.org Fixes:fb3d824d1a46c ("mm/rmap: split page_dup_rmap() into page_dup_file_rmap() and page_try_dup_anon_rmap()") Signed-off-by: Steven Rostedt (Google) --- diff --git a/include/linux/rmap.h b/include/linux/rmap.h index b26fe858fd44..3c2fc291b071 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -261,8 +261,8 @@ static inline int page_try_dup_anon_rmap(struct page *page, bool compound, * guarantee the pinned page won't be randomly replaced in the * future on write faults. */ - if (likely(!is_device_private_page(page) && - unlikely(page_needs_cow_for_dma(vma, page)))) + if (likely(!is_device_private_page(page)) && + unlikely(page_needs_cow_for_dma(vma, page))) return -EBUSY; ClearPageAnonExclusive(page);