From patchwork Thu Jan 16 02:30:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 13941166 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 77C50C02180 for ; Thu, 16 Jan 2025 02:35:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBB46280001; Wed, 15 Jan 2025 21:35:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E6C1F6B009F; Wed, 15 Jan 2025 21:35:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D598E280001; Wed, 15 Jan 2025 21:35:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B6F826B009E for ; Wed, 15 Jan 2025 21:35:41 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 550791C7110 for ; Thu, 16 Jan 2025 02:35:41 +0000 (UTC) X-FDA: 83011749282.16.12B06B8 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf18.hostedemail.com (Postfix) with ESMTP id D15FC1C0005 for ; Thu, 16 Jan 2025 02:35:39 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736994939; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=wP1MdTWFC6LTmxAPNPHUNCYzRt+jCTg3JWLRuiI26jk=; b=RD+gfGHkzDiwMjM10rc1Ko4qogEbu8wsHri1CtvJTxjVUYhGmUk7Wd0HblKqECIv7vk/kX is/y2zgamU7apNuVyk2Qnh9BWT2YkvHEp3HFepqqEpeYE08hqEirLANrhdhN4IGZEG/00w JY4bv8NF131ZZeUZB0d+izdCi0/l6g0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736994939; a=rsa-sha256; cv=none; b=AqQBfaKZHwyBoZOIeP8wOlZMYY+rT2U1XvpmyZBgGowUETMlb/wWfQv3GtGLPn4V7lF2F8 NxtrzYnk4D+4x+6Ep0TEi3Ejhp6HQFY9UIp/IqCF0RBTa6UfO2ZxCEEdNOkG2xF0FNYc4i gWfqcvAIxDfA1HGvFVTrg8eDnK1cV3s= Received: from fangorn.home.surriel.com ([10.0.13.7]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tYFfO-000000003nd-2t7B; Wed, 15 Jan 2025 21:31:30 -0500 From: Rik van Riel To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, bp@alien8.de, peterz@infradead.org, dave.hansen@linux.intel.com, zhengqi.arch@bytedance.com, nadav.amit@gmail.com, thomas.lendacky@amd.com, kernel-team@meta.com, linux-mm@kvack.org, akpm@linux-foundation.org, jannh@google.com, mhklinux@outlook.com, andrew.cooper3@citrix.com Subject: [PATCH v5 00/12] AMD broadcast TLB invalidation Date: Wed, 15 Jan 2025 21:30:23 -0500 Message-ID: <20250116023127.1531583-1-riel@surriel.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D15FC1C0005 X-Stat-Signature: bm3ejqqj44gdz7axik16idd13tbenfpw X-HE-Tag: 1736994939-583734 X-HE-Meta: U2FsdGVkX1/pdLcS8MkI2HazB2c0SSDViN8M9s8GYZqCHfxKKDdHMr3oCCYD5p82x6qdt9s+OMJRKaDXbNoLgpYpZhkWbtuC61AzJh4kLLQAQcaxnjTW5l902iHjWgA0k3GYpp4YK/2MGwbU8/zhEWeris8S+w00Bd9VCY+Lcg4yGzHBsRMzUX8BUKNeyjB4kiGiAxRgG82MNN85g4BG4Fk//K43FeMgpegO6VZKi/IZmrYm4nz8oZIn3bocl+atzAFt93b1l3GkDX9UsE65WLx5ppJLBEIlOckmh2ntbOuDcY0FtRhkQ1hIK20twbuRku4StHOdRBJcW2V5pishbVvtufXGfO51dnnNJyTyHqXkDTWQaH0mRo55rHThwj/sz5ZOgEnwSwHCrszaEQh0NE+6t+oNMkGRDlUtvpgoKVnGVkLKyd54so2IogpnxbKvHJMAfjoue1+gLx84Lq8oTfagVhMhtJQTEWTRT8v8nG+GPQDyQyjvt5cxYrtxLFW8BZR4najoZXGmpShPAUhHElUFQ6blzXBaosXwiEwmf2VYLjX9z+qwCTABTpSvi7hCCEz5lZNz2Al4zIwzBwHIOJz191+/sPXfMI6TVPAogJfR8e/lwCq4Q/tes/+2GxXZDPAryyrwvWmkLvHB49nHNq4PyPQdht11Ale317gBU9FmIy/WUKCElbRO2ZDcsFTV+WtXulqiDnznZGHqQ337TUWR7bKkQYhU7cf2yichfdvwKjF0vFai1zMbPCSBEK6j8YjE1U44D/2ogRHDqoolgKZ3YioaClu14uvwWOPNE76yuwcxQ/QDesVCYReP+56UljLeOD5YkvQaiABVYDs3gORgHGO/+phCYXYuELIqXGatN1DJdX2sgCdd6YQJBhofn5O0gF5yFm/6lIqrLgVzRVYtc9RkvoznhRDllf9/sQ11/B49LoFdppEyraYMpivZRb2YHtyCMHpM9T9IF5n t5LYAC5Q BrvLVL3ib6gE23+U76LqzsnOTgZSrNz7mwlW/M5mA8ZltJODqzzoDiaIGOcjpBbq5LxPnomcN/Od1gNl1l3FKhdo+aAjvOpRDNWxko2I0ALcxLcGVK3VrBXH2TBgK+t58U1PP1M7vXlyRg3sw5m6obXLOAzSu3YTc1sA2t4950S3ywBB5EnkMvs6ikVVNOJhmLubgHynN2vzz5ymOcKVlV2EmuR4zOyD/V4jlS1yEYQxyBHJrZtR0kt2zW8SvdvTfiFic7Kg4zNq2GntmpHFgyRiH8sSggSKYuY6LITQ7K7z79vCdl5hKMqMgiFCZcP6J2fK45yq2sJ5CuHaQoceCSXki1R8WKQXCbp3bniQtfHfQ4od1vVgofmNyAJ7d2BHKSOoyPzwi5zbK2vszaiCXUBi31u7/bMdkRB8pSbPy8XFQbZ5ndQfDB7UglXgthaJgEYiY 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: Add support for broadcast TLB invalidation using AMD's INVLPGB instruction. This allows the kernel to invalidate TLB entries on remote CPUs without needing to send IPIs, without having to wait for remote CPUs to handle those interrupts, and with less interruption to what was running on those CPUs. Because x86 PCID space is limited, and there are some very large systems out there, broadcast TLB invalidation is only used for processes that are active on 3 or more CPUs, with the threshold being gradually increased the more the PCID space gets exhausted. Combined with the removal of unnecessary lru_add_drain calls (see https://lkml.org/lkml/2024/12/19/1388) this results in a nice performance boost for the will-it-scale tlb_flush2_threads test on an AMD Milan system with 36 cores: - vanilla kernel: 527k loops/second - lru_add_drain removal: 731k loops/second - only INVLPGB: 527k loops/second - lru_add_drain + INVLPGB: 1157k loops/second Profiling with only the INVLPGB changes showed while TLB invalidation went down from 40% of the total CPU time to only around 4% of CPU time, the contention simply moved to the LRU lock. Fixing both at the same time about doubles the number of iterations per second from this case. Some numbers closer to real world performance can be found at Phoronix, thanks to Michael: https://www.phoronix.com/news/AMD-INVLPGB-Linux-Benefits The code is now in a state where I am not sure what else needs to be done before it can be merged. If you can think of something, please let me know ;) v5: - use byte assembly for compatibility with older toolchains (Borislav, Michael) - ensure a panic on an invalid number of extra pages (Dave, Tom) - add cant_migrate() assertion to tlbsync (Jann) - a bunch more cleanups (Nadav) - key TCE enabling off X86_FEATURE_TCE (Andrew) - fix a race between reclaim and ASID transition (Jann) v4: - Use only bitmaps to track free global ASIDs (Nadav) - Improved AMD initialization (Borislav & Tom) - Various naming and documentation improvements (Peter, Nadav, Tom, Dave) - Fixes for subtle race conditions (Jann) v3: - Remove paravirt tlb_remove_table call (thank you Qi Zheng) - More suggested cleanups and changelog fixes by Peter and Nadav v2: - Apply suggestions by Peter and Borislav (thank you!) - Fix bug in arch_tlbbatch_flush, where we need to do both the TLBSYNC, and flush the CPUs that are in the cpumask. - Some updates to comments and changelogs based on questions.