diff mbox series

[11/15] KVM: selftests: Create VM with adjusted number of guest pages for perf tests

Message ID 20210210230625.550939-12-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series VM: selftests: Hugepage fixes and cleanups | expand

Commit Message

Sean Christopherson Feb. 10, 2021, 11:06 p.m. UTC
Use the already computed guest_num_pages when creating the so called
extra VM pages for a perf test, and add a comment explaining why the
pages are allocated as extra pages.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 tools/testing/selftests/kvm/lib/perf_test_util.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Ben Gardon Feb. 11, 2021, 1:32 a.m. UTC | #1
On Wed, Feb 10, 2021 at 3:06 PM Sean Christopherson <seanjc@google.com> wrote:
>
> Use the already computed guest_num_pages when creating the so called
> extra VM pages for a perf test, and add a comment explaining why the
> pages are allocated as extra pages.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>

Reviewed-by: Ben Gardon <bgardon@google.com>

> ---
>  tools/testing/selftests/kvm/lib/perf_test_util.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
> index 982a86c8eeaa..9b0cfdf10772 100644
> --- a/tools/testing/selftests/kvm/lib/perf_test_util.c
> +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
> @@ -71,9 +71,12 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
>         TEST_ASSERT(vcpu_memory_bytes % pta->guest_page_size == 0,
>                     "Guest memory size is not guest page size aligned.");
>
> -       vm = vm_create_with_vcpus(mode, vcpus,
> -                                 (vcpus * vcpu_memory_bytes) / pta->guest_page_size,
> -                                 0, guest_code, NULL);
> +       /*
> +        * Pass guest_num_pages to populate the page tables for test memory.
> +        * The memory is also added to memslot 0, but that's a benign side
> +        * effect as KVM allows aliasing HVAs in memslots.
> +        */
> +       vm = vm_create_with_vcpus(mode, vcpus, 0, guest_num_pages, guest_code, NULL);
>         pta->vm = vm;
>
>         /*
> --
> 2.30.0.478.g8a0d178c01-goog
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index 982a86c8eeaa..9b0cfdf10772 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -71,9 +71,12 @@  struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 	TEST_ASSERT(vcpu_memory_bytes % pta->guest_page_size == 0,
 		    "Guest memory size is not guest page size aligned.");
 
-	vm = vm_create_with_vcpus(mode, vcpus,
-				  (vcpus * vcpu_memory_bytes) / pta->guest_page_size,
-				  0, guest_code, NULL);
+	/*
+	 * Pass guest_num_pages to populate the page tables for test memory.
+	 * The memory is also added to memslot 0, but that's a benign side
+	 * effect as KVM allows aliasing HVAs in memslots.
+	 */
+	vm = vm_create_with_vcpus(mode, vcpus, 0, guest_num_pages, guest_code, NULL);
 	pta->vm = vm;
 
 	/*