From mboxrd@z Thu Jan 1 00:00:00 1970 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 4FB80C3DA4A for ; Thu, 15 Aug 2024 00:23:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC08C6B0088; Wed, 14 Aug 2024 20:23:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D70DD6B0089; Wed, 14 Aug 2024 20:23:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5F726B008A; Wed, 14 Aug 2024 20:23:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A7C086B0088 for ; Wed, 14 Aug 2024 20:23:41 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 67AE412127F for ; Thu, 15 Aug 2024 00:23:41 +0000 (UTC) X-FDA: 82452581442.10.5CF74EB Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf15.hostedemail.com (Postfix) with ESMTP id 8167DA000B for ; Thu, 15 Aug 2024 00:23:39 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=T03ngLuc; spf=pass (imf15.hostedemail.com: domain of 3iUq9ZgYKCFAAws51uy66y3w.u64305CF-442Dsu2.69y@flex--seanjc.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3iUq9ZgYKCFAAws51uy66y3w.u64305CF-442Dsu2.69y@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723681383; a=rsa-sha256; cv=none; b=gw/PCMP6hg2JTGTWMCQGDE4dWyu1B6zkRTJe1hGrPJrF9M/buDqwTaeV9q9Lt34siarAUv OosTArdRhxFWMEuO8QgoFiVLrRahBSpMtgv3Szk8/3K1LA21suQoNChwlHXtXQI4kca7hf jrr0iL9sL5rFnSFBgu9wj0zMPBEZWNE= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=T03ngLuc; spf=pass (imf15.hostedemail.com: domain of 3iUq9ZgYKCFAAws51uy66y3w.u64305CF-442Dsu2.69y@flex--seanjc.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3iUq9ZgYKCFAAws51uy66y3w.u64305CF-442Dsu2.69y@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723681383; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=na+DQAropa9HhQkX0n6COE58Sm+QVzbS54Fw3LBcwkg=; b=s51zq8tBI3M2vNEMD+JXQemBHaMs8xASZSSkdAZQNZBRWWlLxwjq6I60lzcyG+HhFRCBBd HlDnBxuZJ2LVTlsYG1hp182gDwPsD7ML6wkhu/NPjMK93qRMScP5MeJwrJgkDTg4hUVKa8 5C//YT00KP4Qif3hOn0fUIKGGdpw44M= Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-71065f49abeso350579b3a.3 for ; Wed, 14 Aug 2024 17:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723681418; x=1724286218; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=na+DQAropa9HhQkX0n6COE58Sm+QVzbS54Fw3LBcwkg=; b=T03ngLuc+HrjZJEkXHX6GSwaVGVPo1KCWYbC4ayBDBtf/TNDKvbTXd9ewC4YZO84mK nYKuguyMJ+ULNH217d0XvnKfM/rv3Nl64zNalBrirEZP7PQP5OPufKcpwZ07MNHA8LZ2 HAVuqFKKyQ4EC42lhUqO3xWQ07ZvUahvn7iUdZbaE26T20b5UJ1Fo/hXFU8xAHowCNZn 71+g9hNAZ6iJTJ1vNh2GSoanP9tlYJC/fLk56WXP9yxx5c1Rt9x5KhXaHMz4l+3R6MkH KotOuh8YvsKfvyQ5IwdlUGHC26k2PPK8m7cBC0TH1kZ3qcTNLUYUfYdDvemKLRtXvtG8 Hv9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723681418; x=1724286218; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=na+DQAropa9HhQkX0n6COE58Sm+QVzbS54Fw3LBcwkg=; b=D9d8hg5/lJsX0mgwkIcfo+YNN9Hr1L1u5t8M8x0yuSgAKcYauZ+TbNYqlhvXr9Dn5I bzuxLGSCwVwCsrwReiUxkoKQLRiEOIheStR2aD8MmVC1NV7A+5aNe8GHDDX+wFpgg32W ABMCliMtq4fnyh/aOMV0tKRsHcSZEobOx/pqUQuia4RM5Xaup6CvhWW0btYxYOGuJrIn /YWEGdKhKZVX68B3HQuYfyKcbUs472NIrQC1FOAUv4rk2eVa9+oJqRfLoCZKqIIS2eNS SFtfDHI68wui/4j2kKGbei+Ow/gagZAEYLTi/iwCmZU6ltvDWgMYZ3RcULhipO3ObPAQ wq2A== X-Forwarded-Encrypted: i=1; AJvYcCWWee2YqEgTqolHtWsJHzu6WFB5tR4IEHOA8/q7U8w0PJeiUFjV85C9thaETkMG4nc0TUk6icEUy4WeZf2E/T16NhI= X-Gm-Message-State: AOJu0YxfoJVZe4PM9l106FRG83ODtqBJvmY3AqiuZLPA82G7gP+6A11K Tnt34ZrjNxr5DjOCEKV6o3OjIXzqriGA9MRcBLQiU3pTTh5U7DDPMGn+CgBC5Aixrb78Uz85gvL +jg== X-Google-Smtp-Source: AGHT+IGoZtQk6EhIPI9XMZuU6TS6huGs8UeaDStKkTJudv5DvPbQJzN1W9iOqNUU9Nrexb3O6V5rC1Lbce8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:aa7:91c9:0:b0:710:4d06:93b3 with SMTP id d2e1a72fcca58-712673e5d8bmr25637b3a.3.1723681417634; Wed, 14 Aug 2024 17:23:37 -0700 (PDT) Date: Wed, 14 Aug 2024 17:23:36 -0700 In-Reply-To: Mime-Version: 1.0 References: <20240809160909.1023470-1-peterx@redhat.com> <20240814123715.GB2032816@nvidia.com> <20240814144307.GP2032816@nvidia.com> Message-ID: Subject: Re: [PATCH 00/19] mm: Support huge pfnmaps From: Sean Christopherson To: Oliver Upton Cc: Jason Gunthorpe , Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador , Axel Rasmussen , linux-arm-kernel@lists.infradead.org, x86@kernel.org, Will Deacon , Gavin Shan , Paolo Bonzini , Zi Yan , Andrew Morton , Catalin Marinas , Ingo Molnar , Alistair Popple , Borislav Petkov , David Hildenbrand , Thomas Gleixner , kvm@vger.kernel.org, Dave Hansen , Alex Williamson , Yan Zhao , Marc Zyngier Content-Type: text/plain; charset="us-ascii" X-Stat-Signature: k6oaqpyiwcuwx1xdabh7g6pridrx6j6c X-Rspamd-Queue-Id: 8167DA000B X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1723681419-877729 X-HE-Meta: U2FsdGVkX1/asgNRfC+LUUEYC7RsPxsrv7uNgPS2cDarQbyOhS6chaaCRVVu9DlbmtNlqLzMPiz7zGzuBD0DUhnIY/tfqXn31vffB9cLxZcBnB5Ay6fB/lBPZbq8F4ZRV6bo6tnzbPkd1DxpDWet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diRcHXgANnBD6RB+E/gVVN3e0cnM1TfeYs/pTvE2uORxuGrKPGaNTlIOGfAUjRyprJwDrI+m06VHXHzGanPi9N7CduZgPn+N8sVK7hC0iFAJu6uKRz0WBB55wxoWSb9RZFJTmy9DCCMMXX+dh1in/g6VEdYuoM+AmP0CKuKf0Z8S7+WNHN8R/lHmGmHOM4r44O7CzM6rpMonnuzdLa4ReJxLehdkRobrWCIy/2udvdTsVsJilZrYKeqX2uM5K4Esgif8J9UCZFBpv1PaRL7UGOuklJ6hDSZDts4e6jLU2c9DNWRbtoReXRtadBQM9pTadn5LrmBIZW4OeY/W96VBXAQaLOnqd8HI14+OheT/wi/axvraRjFmUyqX3hfdQ34h66yDDUy7aCfDjC3bk3h/owwrgHmbt7pBcbDBU0uCHUHQ0VI4TbH2o6XpeCaE= 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: On Wed, Aug 14, 2024, Oliver Upton wrote: > On Wed, Aug 14, 2024 at 04:28:00PM -0700, Oliver Upton wrote: > > On Wed, Aug 14, 2024 at 01:54:04PM -0700, Sean Christopherson wrote: > > > TL;DR: it's probably worth looking at mmu_stress_test (was: max_guest_memory_test) > > > on arm64, specifically the mprotect() testcase[1], as performance is significantly > > > worse compared to x86, > > > > Sharing what we discussed offline: > > > > Sean was using a machine w/o FEAT_FWB for this test, so the increased > > runtime on arm64 is likely explained by the CMOs we're doing when > > creating or invalidating a stage-2 PTE. > > > > Using a machine w/ FEAT_FWB would be better for making these sort of > > cross-architecture comparisons. Beyond CMOs, we do have some > > ... some heavy barriers (e.g. DSB(ishst)) we use to ensure page table > updates are visible to the system. So there could still be some > arch-specific quirks that'll show up in the test. Nope, 'twas FWB. On a system with FWB, ARM nicely outperforms x86 on mprotect() when vCPUs stop on the first -EFAULT. I suspect because ARM can do broadcast TLB invalidations and doesn't need to interrupt and wait for every vCPU to respond. run1 = 10.723194154s, reset = 0.000014732s, run2 = 0.013790876s, ro = 2.151261587s, rw = 10.624272116s However, having vCPUs continue faulting while mprotect() is running turns the tables, I suspect due to mmap_lock run1 = 10.768003815s, reset = 0.000012051s, run2 = 0.013781921s, ro = 23.277624455s, rw = 10.649136889s The x86 numbers since they're out of sight now: -EFAULT once run1 = 6.873408794s, reset = 0.000165898s, run2 = 0.035537803s, ro = 6.149083106s, rw = 7.713627355s -EFAULT forever run1 = 6.923218747s, reset = 0.000167050s, run2 = 0.034676225s, ro = 14.599445790s, rw = 7.763152792s > > > and there might be bugs lurking the mmu_notifier flows. > > > > Impossible! :) > > > > > Jumping back to mmap_lock, adding a lock, vma_lookup(), and unlock in x86's page > > > fault path for valid VMAs does introduce a performance regression, but only ~30%, > > > not the ~6x jump from x86 to arm64. So that too makes it unlikely taking mmap_lock > > > is the main problem, though it's still good justification for avoid mmap_lock in > > > the page fault path. > > > > I'm curious how much of that 30% in a microbenchmark would translate to > > real world performance, since it isn't *that* egregious. vCPU jitter is the big problem, especially if userspace is doing something odd, and/or if the kernel is preemptible (which also triggers yeild-on-contention logic for spinlocks, ew). E.g. the range-based retry to avoid spinning and waiting on an unrelated MM operation was added by the ChromeOS folks[1] to resolve issues where an MM operation got preempted and so blocked vCPU faults. But even for cloud setups with a non-preemptible kernel, contending with unrelated userspace VMM modification can be problematic, e.g. it turns out even the gfn_to_pfn_cache logic needs range-based retry[2] (though that's a rather pathological case where userspace is spamming madvise() to the point where vCPUs can't even make forward progress). > > We also have other uses for getting at the VMA beyond mapping granularity > > (MTE and the VFIO Normal-NC hint) that'd require some attention too. Yeah, though it seems like it'd be easy enough to take mmap_lock if and only if it's necessary, e.g. similar to how common KVM takes it only if it encounters VM_PFNMAP'd memory. E.g. take mmap_lock if and only if MTE is active (I assume that's uncommon?), or if the fault is to device memory. [1] https://lore.kernel.org/all/20210222024522.1751719-1-stevensd@google.com [2] https://lore.kernel.org/all/f862cefff2ed3f4211b69d785670f41667703cf3.camel@infradead.org