Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp241756pxb; Wed, 18 Aug 2021 21:18:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoSdzros97uTQy9PyKhFXtf3tqDY78FY2HNvEmoRHqcNTkLjGqh9RH48vas4orRulkslYE X-Received: by 2002:a05:6638:168f:: with SMTP id f15mr11217247jat.85.1629346714098; Wed, 18 Aug 2021 21:18:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629346714; cv=none; d=google.com; s=arc-20160816; b=KXELNCTjuBGsnZbhU27UrhmPwv8CysunPTORGjI1SK9Q65W5rrfYYZBd6pZOo0/har ENcWoTPXbhKNroax2YPneizhSbJbHBsSSKh4nQI8ekldMrt+xbo1V7Ph7G4t5uKirBOM Tnnf0qDEfiKP+mxSU8IpE3Oj/fjcfOXMCOjG1bZZ54ilcJVdwUdtaTeh1jykbItSNDFt o6y92bSYzS7YfFEdb/yt0PEFySkZ5+9n/3YnRnRqiI+ponOaNuW47onhQ+85BXrMeEHt nKiQzLssxfzRfbQr9VBBpn3YfHP/KvgE9fpSiQxMs6jSzad1vl7oMS0szsUSYqJh0DC8 R7zA== 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 :message-id:subject:cc:to:from:date:dkim-signature; bh=w221Be1EofjnjmiRhYveteUIPXXfoWBMfLJIKwhzc6c=; b=e+RP6R8cYmc0HDRBBpLCO5EbvARAlghKpI0V/AJcWspg5vmbh5FRwUiTfZMmWcDcOE aGcFCZ7n83635/5bJOuiBZKrah6Q6UMdR6tuuFtsCsbfwW5etUDxGiL9GB73k6fE3LQv 0r86Rm1x7O3VjUkQKMy3pRKWu1pgXcf2HXxLDnQF2Yh8sWhPb//GHQt0jxl+J5M/MQr1 7QpoQSG/j6dCYw9XAFqPv3qQDtcNRG0BAq5NDHdOZOtxbOgHyz7o+g7nMkP7WIdx+74G 94gvmSm0HwG74ePTzZC+piLz/AZkVj5gnlpaJP8omjDJuBA4L/IJ6j6Ga4tcPz29WCjm xkxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fhEA6xLb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g7si1772751jar.3.2021.08.18.21.17.58; Wed, 18 Aug 2021 21:18:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fhEA6xLb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229596AbhHSEQF (ORCPT + 99 others); Thu, 19 Aug 2021 00:16:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbhHSEQE (ORCPT ); Thu, 19 Aug 2021 00:16:04 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 270CCC061764 for ; Wed, 18 Aug 2021 21:15:29 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id mq2-20020a17090b3802b0290178911d298bso3893509pjb.1 for ; Wed, 18 Aug 2021 21:15:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :in-reply-to; bh=w221Be1EofjnjmiRhYveteUIPXXfoWBMfLJIKwhzc6c=; b=fhEA6xLbFlhjCuprHe1t9zZjCHnVtAM2fFfth+B1eUBRu6EInah6dTHDMDKwsz0mV1 65BqyoyCpNPZLSPi8XCLuuOA1+WEfawyX/VoKt1E6KGHsSqmRqLH0CYhis0m0bEyFhm6 GxHz9MjLC+9q453UuBgVTOwQGhg8cEVz5iusw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:in-reply-to; bh=w221Be1EofjnjmiRhYveteUIPXXfoWBMfLJIKwhzc6c=; b=ZX5GmCFNSGPogclOzmwc/Utw4sgL2OfkSnrY+c9LXyNysDMVZ3KJIfP8SVLXrcYb8V t34KiUAEGlHGlZC4KFQLupUs9ssOR4W94VTo4+f4u716t6Ch4wllyDTzhiYJshqLx5Gc McGAyGsU3yv+gFWHmzsqVqauKMXXFQ/n8KmkkL5crwGWlqASJnKpgz6nbDIoAgjlPOqS Kc9IoNW0GfeZyoSl2eKbdCNCmommqBXhWBe9s9/BOjPDD/JWQoP44tblnaWUXG6N4Qnd OSRHsRkClhknXGLIuXPJAd5W1urFZ3pM7As+JRf7tJ9t3t0WMhfSWvOBvGrRtZ4w1Vbp wqFg== X-Gm-Message-State: AOAM533sEN8zyY1CxHA2cC5IBMv+3luMY5rcFMvRkup5DFUGHzfsQ+Ea I0GJ7yEjgDvdRdQu8/uQ4J5KaQ== X-Received: by 2002:a17:902:f703:b029:12c:982:c9ae with SMTP id h3-20020a170902f703b029012c0982c9aemr10078207plo.20.1629346528626; Wed, 18 Aug 2021 21:15:28 -0700 (PDT) Received: from google.com ([2409:10:2e40:5100:bc71:80fb:7292:eb8e]) by smtp.gmail.com with ESMTPSA id 141sm1421497pfv.15.2021.08.18.21.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 21:15:28 -0700 (PDT) Date: Thu, 19 Aug 2021 13:15:23 +0900 From: Sergey Senozhatsky To: Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Ben Gardon Subject: Re: [PATCH] KVM: x86/mmu: Complete prefetch for trailing SPTEs for direct, legacy MMU Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210818235615.2047588-1-seanjc@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [..] > Make a final call to direct_pte_prefetch_many() if there are "trailing" > SPTEs to prefetch, i.e. SPTEs for GFNs following the faulting GFN. The > call to direct_pte_prefetch_many() in the loop only handles the case > where there are !PRESENT SPTEs preceding a PRESENT SPTE. > > E.g. if the faulting GFN is a multiple of 8 (the prefetch size) and all > SPTEs for the following GFNs are !PRESENT, the loop will terminate with > "start = sptep+1" and not prefetch any SPTEs. > > Prefetching trailing SPTEs as intended can drastically reduce the number > of guest page faults, e.g. accessing the first byte of every 4kb page in > a 6gb chunk of virtual memory, in a VM with 8gb of preallocated memory, > the number of pf_fixed events observed in L0 drops from ~1.75M to <0.27M. > > Note, this only affects memory that is backed by 4kb pages as KVM doesn't > prefetch when installing hugepages. Shadow paging prefetching is not > affected as it does not batch the prefetches due to the need to process > the corresponding guest PTE. The TDP MMU is not affected because it > doesn't have prefetching, yet... Tested-by: Sergey Senozhatsky I ran some tests. - VM Boot up From EPT_VIOLATION 1192184 75.18% 4.40% 0.77us 18020.01us 4.32us ( +- 1.71% ) to EPT_VIOLATION 947460 69.92% 4.64% 0.69us 34902.15us 5.06us ( +- 1.64% ) - Running test app (in VM) From EPT_VIOLATION 6550167 71.05% 11.76% 0.77us 32562.18us 3.51us ( +- 0.36% ) to EPT_VIOLATION 5489904 68.32% 11.29% 0.71us 16564.19us 3.92us ( +- 0.29% )