From patchwork Fri Dec 1 19:59:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13476321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B93EC10F04 for ; Fri, 1 Dec 2023 19:59:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9C466B03AA; Fri, 1 Dec 2023 14:59:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A4C836B03AB; Fri, 1 Dec 2023 14:59:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93A066B03AE; Fri, 1 Dec 2023 14:59:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7FF836B03AA for ; Fri, 1 Dec 2023 14:59:18 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4F6B880348 for ; Fri, 1 Dec 2023 19:59:18 +0000 (UTC) X-FDA: 81519313596.02.6549F00 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf10.hostedemail.com (Postfix) with ESMTP id 23B1EC0003 for ; Fri, 1 Dec 2023 19:59:14 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of "SRS0=XJYy=HM=goodmis.org=rostedt@kernel.org" designates 145.40.68.75 as permitted sender) smtp.mailfrom="SRS0=XJYy=HM=goodmis.org=rostedt@kernel.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701460755; h=from:from:sender: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: references; bh=rwUpQFXbjYqRHwq4L4PRd+w0zOguEZrN+oy1TiU9DNo=; b=D/WglyEZln2RQfkruoCgrxsrGgtyVfxvyXRQ5Z/6xCPY4UIReh/a3N7p/gid2W7XdoBoWe WSkH8RDzjgVyQad5iuolHLMVz0+x924gXr3J0YYCHrW/G4AK6AAQ6Br+l9R4KhlnYZgqyu 3K0b5HBpMZf+bRprID2lb65kqsvi1R8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of "SRS0=XJYy=HM=goodmis.org=rostedt@kernel.org" designates 145.40.68.75 as permitted sender) smtp.mailfrom="SRS0=XJYy=HM=goodmis.org=rostedt@kernel.org" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701460755; a=rsa-sha256; cv=none; b=yx/klOH+uV8XoOUeosq3PelOP9w+J1DocrzfD5INHd04k3s2PRjh1Oj+9ikureYJ0h7VOH XvjB7vqXIj8/E9ou30Qc9gmxgPJLy9hiXh6iWN2cHP0hqQJvgopBWISHP1zuBmMWLH3W16 s4QNCdtvKeP6j+nW5aEK7mbWTAGCWMM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 3C8F1B84916; Fri, 1 Dec 2023 19:59:13 +0000 (UTC) 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.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pm9+gJg6QCaEzAoQGJLC9CfM9SRBKFCvEIzL5GorLCkGlfnWhrVM/3h7vLxfEFukGcn47lg5N GHrAkRoc 7Zs9p3TuHFzWLAMYGwQTtSLJomq6b8FJw7U8UiZVTfyzAjAAfTRa35BgO8rgJb92HSb3zbj4mVvFoM4XuR1KfWgPsRxs3AuPAyjzXXeNMfxbuUzQl+59PkYLX+lAz0WyZErVsvRX2bUgXaaGrb+Q1HS0nAtm+PDvJYOg6eQvZOtE2nzhb9tAd9aO61uCf2/kHfWpAUe9pq1MVS+YMt8PcqYWn3Tns8m0EGqDMMdtG8809aH44iaSiEl2H6IN6O+0PAiLWwlf3QbUwNqcpF2SaIaYMx4NsA0mAf1vqDXfrQXqYOQYNhDQ7JRqa2NA63e/EqPg0y0J0yk1rKg5einBhl5UxLWnaly2EgE/clXRolc1fsIQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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) Reviewed-by: David Hildenbrand Acked-by: Vlastimil Babka 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);