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 CE96BC001DB for ; Thu, 10 Aug 2023 09:34:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A19E6B0075; Thu, 10 Aug 2023 05:34:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 651776B0078; Thu, 10 Aug 2023 05:34:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 519746B007B; Thu, 10 Aug 2023 05:34:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 437326B0075 for ; Thu, 10 Aug 2023 05:34:15 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DBC201607A8 for ; Thu, 10 Aug 2023 09:34:14 +0000 (UTC) X-FDA: 81107684028.01.8A656E7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id A3E81140007 for ; Thu, 10 Aug 2023 09:34:12 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="X/04LXZY"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691660052; 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:in-reply-to:references:references:dkim-signature; bh=eZQ1UrO3pXfioDS5G776rsMtsdXOwQUomsUH8c+ASvc=; b=4bak7MdJxA8OP5kujips/FS+4kOBPD5o29TFe4u+LyTJTZdDv6VPT4mMR0hu7naIjnBeWi kF/P+T38+5mk9AEmhp+1enYyJtKQyV6mQ4UKv0JvnHJl2ipadz/fVs4eXFi0pcB/TaMNAV kX/bHKncuoGDh1rAaGAFZvZqnYW607o= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="X/04LXZY"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691660052; a=rsa-sha256; cv=none; b=Qc2h3XSVSGmB/ELoeYjx7yyhMzF8sbtJjSAugWaEtDma2k/iuqT33rSYVZ+bEhOYb+ekII jSEt+a0Gg3COyuLWt/71zlwFVeLZp/wT3hRwRIjw2xLeS6JX/IumgHzNW7rDJRyrGjOm5S MlAfL2Q8iYgI/dvH9lb8hBcyemy63Fo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691660051; h=from:from: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:in-reply-to:references:references; bh=eZQ1UrO3pXfioDS5G776rsMtsdXOwQUomsUH8c+ASvc=; b=X/04LXZYdDoxNtYAPyDfeRVMSglmbA3c3IqmIvvCoaRN5DKUXs+dZaLhJEhsGniVbACGFf 7KDL+0/641gu5x27r3eItDMPbLmindJlxnX+lCGlLbo2XZazcd+ZerWCHO0hZvyeVcEhvJ 04DjeDCTcyqmLk7so/iRhAN6O1AwsKg= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-18-u3UxSXzrP_-zJsJW0H6S9w-1; Thu, 10 Aug 2023 05:34:10 -0400 X-MC-Unique: u3UxSXzrP_-zJsJW0H6S9w-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3172a94b274so498286f8f.0 for ; Thu, 10 Aug 2023 02:34:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691660049; x=1692264849; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eZQ1UrO3pXfioDS5G776rsMtsdXOwQUomsUH8c+ASvc=; b=GkAcbhi0jni2BPw9QIgEDQqI2ZLNnOYM3e9cmQjwK7Sx56H8bGfouVQMg8FYI+7ydl zd3To1NJJ5N0jxOBj+V9kQCLNYMra7v37n6aUMe1fj6cI+C5IFPd6f4J/UNTU8ExM15Q teJNOQvaja7WT1HOobYchEHUOmrBPFB4fWBRswV6gM5G5dG2OCkQM8HXmLCS106thED1 JcIKtJP91xbl77NF9+FcR0wEwIC721bVJptQP7Z0Rwz5HzXXrUri//qEZIhoM1ZpwIXY kk9MZImDRr1C1DPBIvAtPfijAd23o9m7cV/NqHsELCTV+81VoCdfgkYKk++yyH1ym835 lWrA== X-Gm-Message-State: AOJu0Yw452Sd6IFNv9YB370NcjrrMMDe9c6qVfua+0ocs3btk9rvuzqz 9UKMs4dx051tY/TaXLGeeWwf7Eu1HpquNvwqDULjeJQTbubPm0K/TF6s2jL7pHV91lVmkkAyp8L dCroYsy7P7Eg= X-Received: by 2002:a05:600c:254:b0:3fe:10d8:e7fa with SMTP id 20-20020a05600c025400b003fe10d8e7famr1422543wmj.41.1691660049436; Thu, 10 Aug 2023 02:34:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5yXe9vL7tImqVqRug64hJBNl2Wwl4As7KFn3mriGnFbR0uj4kA1OXmyoV172388L152+YOw== X-Received: by 2002:a05:600c:254:b0:3fe:10d8:e7fa with SMTP id 20-20020a05600c025400b003fe10d8e7famr1422528wmj.41.1691660049085; Thu, 10 Aug 2023 02:34:09 -0700 (PDT) Received: from ?IPV6:2a09:80c0:192:0:5dac:bf3d:c41:c3e7? ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with ESMTPSA id s13-20020a7bc38d000000b003fe2ebf479fsm1525174wmj.36.2023.08.10.02.34.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Aug 2023 02:34:08 -0700 (PDT) Message-ID: <41a893e1-f2e7-23f4-cad2-d5c353a336a3@redhat.com> Date: Thu, 10 Aug 2023 11:34:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [RFC PATCH v2 0/5] Reduce NUMA balance caused TLB-shootdowns in a VM To: Yan Zhao , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, mike.kravetz@oracle.com, apopple@nvidia.com, jgg@nvidia.com, rppt@kernel.org, akpm@linux-foundation.org, kevin.tian@intel.com References: <20230810085636.25914-1-yan.y.zhao@intel.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20230810085636.25914-1-yan.y.zhao@intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: A3E81140007 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: j15jtjo3ffhozrc31aqws7fgrsh9gwig X-HE-Tag: 1691660052-484805 X-HE-Meta: U2FsdGVkX18MEms0XVRkIGrAhkPayXk9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Evkxx4S/G3HbZv+o7IeMRYm5s+7G1NuVlHG8LwfldIfACjt6mrhyDzrQBAZGiIvW0xQ87DjRYIuVoXfBhLtW2MiYwm6FbRVIHeXOSZX92wO2SOav24BE73NWnOH8gE8l9MNMkhejYjZ7+ZowV14wmQEvyCFD86nZPmJWACWVYCt48L+L01gCMP20MUMeEKuc1RiWqgdP7vnFfTCJalPipNUPaF864gJkwmG3VkAchoOAAzTDRhUDLk5w2/cP7XAFwBp5ZAvui39awUP 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: On 10.08.23 10:56, Yan Zhao wrote: > This is an RFC series trying to fix the issue of unnecessary NUMA > protection and TLB-shootdowns found in VMs with assigned devices or VFIO > mediated devices during NUMA balance. > > For VMs with assigned devices or VFIO mediated devices, all or part of > guest memory are pinned for long-term. > > Auto NUMA balancing will periodically selects VMAs of a process and change > protections to PROT_NONE even though some or all pages in the selected > ranges are long-term pinned for DMAs, which is true for VMs with assigned > devices or VFIO mediated devices. > > Though this will not cause real problem because NUMA migration will > ultimately reject migration of those kind of pages and restore those > PROT_NONE PTEs, it causes KVM's secondary MMU to be zapped periodically > with equal SPTEs finally faulted back, wasting CPU cycles and generating > unnecessary TLB-shootdowns. > > This series first introduces a new flag MMU_NOTIFIER_RANGE_NUMA in patch 1 > to work with mmu notifier event type MMU_NOTIFY_PROTECTION_VMA, so that > the subscriber (e.g.KVM) of the mmu notifier can know that an invalidation > event is sent for NUMA migration purpose in specific. > > Patch 2 skips setting PROT_NONE to long-term pinned pages in the primary > MMU to avoid NUMA protection introduced page faults and restoration of old > huge PMDs/PTEs in primary MMU. > > Patch 3 introduces a new mmu notifier callback .numa_protect(), which > will be called in patch 4 when a page is ensured to be PROT_NONE protected. > > Then in patch 5, KVM can recognize a .invalidate_range_start() notification > is for NUMA balancing specific and do not do the page unmap in secondary > MMU until .numa_protect() comes. > Why do we need all that, when we should simply not be applying PROT_NONE to pinned pages? In change_pte_range() we already have: if (is_cow_mapping(vma->vm_flags) && page_count(page) != 1) Which includes both, shared and pinned pages. Staring at page #2, are we still missing something similar for THPs? Why is that MMU notifier thingy and touching KVM code required? -- Cheers, David / dhildenb