Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp5259093rwb; Tue, 17 Jan 2023 11:08:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXs3jx0podBDZlM3Bm1rAVdNITMnAUGsCciTGgViT7VqSgFDXL02+zw/C/tbJ3FG4c7NeIoE X-Received: by 2002:a17:906:781:b0:871:8297:7576 with SMTP id l1-20020a170906078100b0087182977576mr3692421ejc.26.1673982526065; Tue, 17 Jan 2023 11:08:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673982526; cv=none; d=google.com; s=arc-20160816; b=kfhztfl3I0IUG3J7ZO+C2XM/3DrP9kWEHtpL+z7M1vD49LuXsDM9GtgEW1VwpoqAAm 6WfpcnzOSWci9SPZCwSheJiXB8l+QOKeOaPk3UdPDix/HF63ixp2FK7BwM6XWB/MNrFs //0f12i2PwucKbuAD+bYGbQVvjUBs+72QVrRbBUrBP+jpLjNERXbE5bhUmjkjxG2+Yg7 t9HNGUo3vMgUtSlBfMYZb+f2Cko8uuKZWEQrqvpAKTNb5p2r0rkWBsGAnjyJMfglOAue nsam6h1bpXNCj4+Tbv2NXeEkSdRcVHAOgJ8iorktQmvmA0t3Uc4//swybaNn4euuU8eF 0C6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kjzPtu3zrCJ7LGN8rTmaJPE6Mz4bv33wdR1lSV8x46Y=; b=xVuUHX+n7Qw1+hp4rWXz5KwW8ZTVBzJ1JkAwgBVP5jvAO7veX3cY+efOgayNTjERre +HO2ai5zH9Kfs4kHzEim/BuBZt4X+4nC68hUJTtQGtG5hihZy/43pIdDOuQfw8H+ihtS FAiEpvoLEsnjBfFkncaQAXEpBRJvl36xneOJzqmX6JwZ9I97Z+UxyywaXOEy/9wQJXQC u7EInzTkv2BXjtiXIdQMGNFEYQ/mtPvm2V72jXRZptj7Q1Wv38gXlem9SljKnrFZltDh nD7VumH4bPTVawBBObqsYDd8WIF90Q1ta4akGPKXtAaI5unSU0/p2pddqUShHN8AFr9c l8MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=FpCwn17I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht8-20020a170907608800b0086f510007e6si10352936ejc.908.2023.01.17.11.08.34; Tue, 17 Jan 2023 11:08:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=FpCwn17I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229577AbjAQSuj (ORCPT + 47 others); Tue, 17 Jan 2023 13:50:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235157AbjAQSsj (ORCPT ); Tue, 17 Jan 2023 13:48:39 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E8FE4DCC6 for ; Tue, 17 Jan 2023 10:15:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=kjzPtu3zrCJ7LGN8rTmaJPE6Mz4bv33wdR1lSV8x46Y=; b=FpCwn17IJKT76tn1oBj68F9qvT OjxGi/x1in4z37b9B+lVy0CNficyOfMmlE9g1rYdRRG1lTlmSEguXX5yxat4nL9STqETp6AJ6F69/ a/6HCtP2NNfgcV86cPQ4fijJtySW/24ehKr9nhK4DHtOFKw4+utyw5DWfkUvhNUUVENjufX119qHC JsHbdataE92XKLCPH2/FlxWYMURhOVS8ZzUb98kN+5H+P1z2JVNl5YTUwWKaZ02HJsZFkq9XvQMG0 kMDkLFN3j1excScPTSTM603ZRkLG3wZ7n/XRPRhWAiRkfsm0L1AMi3lrAHYzqnfV0DEmv6YEXwWdE FaB4n93w==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pHqU0-0060fj-1T; Tue, 17 Jan 2023 18:14:53 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id AEFD93002BF; Tue, 17 Jan 2023 19:14:59 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9A12D202203E9; Tue, 17 Jan 2023 19:14:59 +0100 (CET) Date: Tue, 17 Jan 2023 19:14:59 +0100 From: Peter Zijlstra To: Linus Torvalds Cc: "Kirill A. Shutemov" , Dave Hansen , Andy Lutomirski , x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Taras Madan , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , Bharata B Rao , Jacob Pan , Ashok Raj , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sami Tolvanen , ndesaulniers@google.com, joao@overdrivepizza.com Subject: Re: [PATCHv14 08/17] x86/mm: Reduce untagged_addr() overhead until the first LAM user Message-ID: References: <20230111123736.20025-1-kirill.shutemov@linux.intel.com> <20230111123736.20025-9-kirill.shutemov@linux.intel.com> <20230117135703.voaumisreld7crfb@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 17, 2023 at 09:18:01AM -0800, Linus Torvalds wrote: > The reason clang seems to generate saner code is that clang seems to > largely ignore the whole "__builtin_expect()", at least not to the > point where it tries to make the unlikely case be out-of-line. So in this case there is only a 'likely' hint, we're explicitly trying to keep the thing in-line so we can jump over it. It is GCC that generated an implicit else (and marked it 'unlikely' -- which we didn't ask for), but worse, it failed to spot the else case is in fact shared with the normal case and it could've simply lifted that mov instruction. That is, instead of this: 0003 23b3: eb 76 jmp 242b 0005 23b5: 65 48 8b 0d 00 00 00 00 mov %gs:0x0(%rip),%rcx # 23bd 23b9: R_X86_64_PC32 tlbstate_untag_mask-0x4 000d 23bd: 48 89 f8 mov %rdi,%rax 0010 23c0: 48 c1 f8 3f sar $0x3f,%rax 0014 23c4: 48 09 c8 or %rcx,%rax 0017 23c7: 48 21 f8 and %rdi,%rax 001a 23ca: 48 b9 00 f0 ff ff ff 7f 00 00 movabs $0x7ffffffff000,%rcx 007b 242b: 48 89 f8 mov %rdi,%rax 007e 242e: eb 9a jmp 23ca It could've just done: 0003 48 89 f8 mov %rdi,%rax 0006 eb 76 jmp +18 0008 65 48 8b 0d 00 00 00 00 mov %gs:0x0(%rip),%rcx # 23bd 23b9: R_X86_64_PC32 tlbstate_untag_mask-0x4 0010 48 c1 f8 3f sar $0x3f,%rax 0014 48 09 c8 or %rcx,%rax 0017 48 21 f8 and %rdi,%rax 001a 48 b9 00 f0 ff ff ff 7f 00 00 movabs $0x7ffffffff000,%rcx and everything would've been good. In all the cases I've seen it do this, it was the same, it has this silly move out of line that's also part of the regular branch. That is, I like __builtin_expect() to be a strong hint. If I don't want things out of line, I shouldn't have put unlikely on it. What I don't like is that implicit else branches get the opposite strong hint. What I like even less is that it found it needed that else branch at all.