From: Andrew Jones <drjones@redhat.com>
To: Ben Gardon <bgardon@google.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Paolo Bonzini <pbonzini@redhat.com>,
Cannon Matthews <cannonmatthews@google.com>,
Peter Xu <peterx@redhat.com>
Subject: Re: [PATCH v3 4/8] KVM: selftests: Add memory size parameter to the demand paging test
Date: Tue, 7 Jan 2020 16:02:45 +0100 [thread overview]
Message-ID: <20200107150245.cblsqirr5mu4fqoo@kamzik.brq.redhat.com> (raw)
In-Reply-To: <20191216213901.106941-5-bgardon@google.com>
On Mon, Dec 16, 2019 at 01:38:57PM -0800, Ben Gardon wrote:
> Add an argument to allow the demand paging test to work on larger and
> smaller guest sizes.
>
> Signed-off-by: Ben Gardon <bgardon@google.com>
> ---
> .../selftests/kvm/demand_paging_test.c | 56 ++++++++++++-------
> 1 file changed, 35 insertions(+), 21 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
> index 11de5b58995fb..4aa90a3fce99c 100644
> --- a/tools/testing/selftests/kvm/demand_paging_test.c
> +++ b/tools/testing/selftests/kvm/demand_paging_test.c
> @@ -32,6 +32,8 @@
> /* Default guest test virtual memory offset */
> #define DEFAULT_GUEST_TEST_MEM 0xc0000000
>
> +#define DEFAULT_GUEST_TEST_MEM_SIZE (1 << 30) /* 1G */
> +
> /*
> * Guest/Host shared variables. Ensure addr_gva2hva() and/or
> * sync_global_to/from_guest() are used when accessing from
> @@ -264,11 +266,10 @@ static int setup_demand_paging(struct kvm_vm *vm,
> return 0;
> }
>
> -#define GUEST_MEM_SHIFT 30 /* 1G */
> #define PAGE_SHIFT_4K 12
>
> static void run_test(enum vm_guest_mode mode, bool use_uffd,
> - useconds_t uffd_delay)
> + useconds_t uffd_delay, uint64_t guest_memory_bytes)
> {
> pthread_t vcpu_thread;
> pthread_t uffd_handler_thread;
> @@ -276,33 +277,40 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
> int r;
>
> /*
> - * We reserve page table for 2 times of extra dirty mem which
> - * will definitely cover the original (1G+) test range. Here
> - * we do the calculation with 4K page size which is the
> - * smallest so the page number will be enough for all archs
> - * (e.g., 64K page size guest will need even less memory for
> - * page tables).
> + * We reserve page table for twice the ammount of memory we intend
> + * to use in the test region for demand paging. Here we do the
> + * calculation with 4K page size which is the smallest so the page
> + * number will be enough for all archs. (e.g., 64K page size guest
> + * will need even less memory for page tables).
> */
> vm = create_vm(mode, VCPU_ID,
> - 2ul << (GUEST_MEM_SHIFT - PAGE_SHIFT_4K),
> + (2 * guest_memory_bytes) >> PAGE_SHIFT_4K,
> guest_code);
>
> guest_page_size = vm_get_page_size(vm);
> - /*
> - * A little more than 1G of guest page sized pages. Cover the
> - * case where the size is not aligned to 64 pages.
> - */
> - guest_num_pages = (1ul << (GUEST_MEM_SHIFT -
> - vm_get_page_shift(vm))) + 16;
> +
> + TEST_ASSERT(guest_memory_bytes % guest_page_size == 0,
> + "Guest memory size is not guest page size aligned.");
> +
> + guest_num_pages = guest_memory_bytes / guest_page_size;
> +
> #ifdef __s390x__
> /* Round up to multiple of 1M (segment size) */
> guest_num_pages = (guest_num_pages + 0xff) & ~0xffUL;
> #endif
> + /*
> + * If there should be more memory in the guest test region than there
> + * can be pages in the guest, it will definitely cause problems.
> + */
> + TEST_ASSERT(guest_num_pages < vm_get_max_gfn(vm),
> + "Requested more guest memory than address space allows.\n"
> + " guest pages: %lx max gfn: %lx\n",
> + guest_num_pages, vm_get_max_gfn(vm));
>
> host_page_size = getpagesize();
> - host_num_pages = (guest_num_pages * guest_page_size) / host_page_size +
> - !!((guest_num_pages * guest_page_size) %
> - host_page_size);
> + TEST_ASSERT(guest_memory_bytes % host_page_size == 0,
> + "Guest memory size is not host page size aligned.");
> + host_num_pages = guest_memory_bytes / host_page_size;
>
> guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
> guest_page_size;
> @@ -381,7 +389,8 @@ static void help(char *name)
> int i;
>
> puts("");
> - printf("usage: %s [-h] [-m mode] [-u] [-d uffd_delay_usec]\n", name);
> + printf("usage: %s [-h] [-m mode] [-u] [-d uffd_delay_usec]\n"
> + " [-b bytes test memory]\n", name);
> printf(" -m: specify the guest mode ID to test\n"
> " (default: test all supported modes)\n"
> " This option may be used multiple times.\n"
> @@ -395,6 +404,8 @@ static void help(char *name)
> printf(" -d: add a delay in usec to the User Fault\n"
> " FD handler to simulate demand paging\n"
> " overheads. Ignored without -u.\n");
> + printf(" -b: specify the number of bytes of memory which should be\n"
> + " allocated to the guest.\n");
Can we input in megabytes instead? And also it might be nice to output the
default size here.
> puts("");
> exit(0);
> }
> @@ -402,6 +413,7 @@ static void help(char *name)
> int main(int argc, char *argv[])
> {
> bool mode_selected = false;
> + uint64_t guest_memory_bytes = DEFAULT_GUEST_TEST_MEM_SIZE;
> unsigned int mode;
> int opt, i;
> bool use_uffd = false;
> @@ -414,7 +426,7 @@ int main(int argc, char *argv[])
> vm_guest_mode_params_init(VM_MODE_P40V48_4K, true, true);
> #endif
>
> - while ((opt = getopt(argc, argv, "hm:ud:")) != -1) {
> + while ((opt = getopt(argc, argv, "hm:ud:b:")) != -1) {
> switch (opt) {
> case 'm':
> if (!mode_selected) {
> @@ -435,6 +447,8 @@ int main(int argc, char *argv[])
> TEST_ASSERT(uffd_delay >= 0,
> "A negative UFFD delay is not supported.");
> break;
> + case 'b':
> + guest_memory_bytes = strtoull(optarg, NULL, 0);
Missing break. So it doesn't look like this was tested.
> case 'h':
> default:
> help(argv[0]);
> @@ -448,7 +462,7 @@ int main(int argc, char *argv[])
> TEST_ASSERT(vm_guest_mode_params[i].supported,
> "Guest mode ID %d (%s) not supported.",
> i, vm_guest_mode_string(i));
> - run_test(i, use_uffd, uffd_delay);
> + run_test(i, use_uffd, uffd_delay, guest_memory_bytes);
> }
>
> return 0;
> --
> 2.24.1.735.g03f4e72817-goog
>
Thanks,
drew
next prev parent reply other threads:[~2020-01-07 15:02 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-16 21:38 [PATCH v3 0/8] Create a userfaultfd demand paging test Ben Gardon
2019-12-16 21:38 ` [PATCH v3 1/8] KVM: selftests: Create a " Ben Gardon
2020-01-07 14:33 ` Peter Xu
2020-01-07 14:56 ` Andrew Jones
2020-01-07 18:41 ` Ben Gardon
2020-01-08 13:45 ` Andrew Jones
2019-12-16 21:38 ` [PATCH v3 2/8] KVM: selftests: Add demand paging content to the " Ben Gardon
2020-01-07 16:00 ` Peter Xu
2020-01-07 21:13 ` Ben Gardon
2019-12-16 21:38 ` [PATCH v3 3/8] KVM: selftests: Add configurable demand paging delay Ben Gardon
2020-01-07 16:04 ` Peter Xu
2019-12-16 21:38 ` [PATCH v3 4/8] KVM: selftests: Add memory size parameter to the demand paging test Ben Gardon
2020-01-07 15:02 ` Andrew Jones [this message]
2020-01-07 21:18 ` Ben Gardon
2019-12-16 21:38 ` [PATCH v3 5/8] KVM: selftests: Pass args to vCPU instead of using globals Ben Gardon
2020-01-07 15:23 ` Andrew Jones
2020-01-07 18:26 ` Ben Gardon
2020-01-08 13:59 ` Andrew Jones
2019-12-16 21:38 ` [PATCH v3 6/8] KVM: selftests: Support multiple vCPUs in demand paging test Ben Gardon
2020-01-07 15:27 ` Andrew Jones
2019-12-16 21:39 ` [PATCH v3 7/8] KVM: selftests: Time guest demand paging Ben Gardon
2019-12-16 21:39 ` [PATCH v3 8/8] KVM: selftests: Move large memslots above KVM internal memslots in _vm_create Ben Gardon
2020-01-07 15:42 ` Andrew Jones
2020-01-07 21:20 ` Ben Gardon
2020-01-08 14:07 ` Andrew Jones
2020-01-06 22:46 ` [PATCH v3 0/8] Create a userfaultfd demand paging test Ben Gardon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200107150245.cblsqirr5mu4fqoo@kamzik.brq.redhat.com \
--to=drjones@redhat.com \
--cc=bgardon@google.com \
--cc=cannonmatthews@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).