linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Gardon <bgardon@google.com>
To: Yanan Wang <wangyanan55@huawei.com>
Cc: kvm <kvm@vger.kernel.org>,
	linux-kselftest@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Ingo Molnar <mingo@kernel.org>, Andrew Jones <drjones@redhat.com>,
	Peter Xu <peterx@redhat.com>, Marc Zyngier <maz@kernel.org>,
	wanghaibin.wang@huawei.com, yuzenghui@huawei.com
Subject: Re: [RFC PATCH v2 4/7] KVM: selftests: Add a helper to get system configured THP page size
Date: Thu, 25 Feb 2021 15:27:00 -0800	[thread overview]
Message-ID: <CANgfPd8rSmKr_G9HFqt30hFGJ9jW387yUODYH+f+BUJPv7-sCA@mail.gmail.com> (raw)
In-Reply-To: <20210225055940.18748-5-wangyanan55@huawei.com>

On Wed, Feb 24, 2021 at 10:00 PM Yanan Wang <wangyanan55@huawei.com> wrote:
>
> If we want to have some tests about transparent hugepages, the system
> configured THP hugepage size should better be known by the tests, which
> can be used for kinds of alignment or guest memory accessing of vcpus...
> So it makes sense to add a helper to get the transparent hugepage size.
>
> With VM_MEM_SRC_ANONYMOUS_THP specified in vm_userspace_mem_region_add(),
> we now stat /sys/kernel/mm/transparent_hugepage to check whether THP is
> configured in the host kernel before madvise(). Based on this, we can also
> read file /sys/kernel/mm/transparent_hugepage/hpage_pmd_size to get THP
> hugepage size.
>
> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>

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

> ---
>  .../testing/selftests/kvm/include/test_util.h |  2 ++
>  tools/testing/selftests/kvm/lib/test_util.c   | 36 +++++++++++++++++++
>  2 files changed, 38 insertions(+)
>
> diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
> index b7f41399f22c..ef24c76ba89a 100644
> --- a/tools/testing/selftests/kvm/include/test_util.h
> +++ b/tools/testing/selftests/kvm/include/test_util.h
> @@ -78,6 +78,8 @@ struct vm_mem_backing_src_alias {
>         enum vm_mem_backing_src_type type;
>  };
>
> +bool thp_configured(void);
> +size_t get_trans_hugepagesz(void);
>  void backing_src_help(void);
>  enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name);
>
> diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
> index c7c0627c6842..f2d133f76c67 100644
> --- a/tools/testing/selftests/kvm/lib/test_util.c
> +++ b/tools/testing/selftests/kvm/lib/test_util.c
> @@ -10,6 +10,7 @@
>  #include <limits.h>
>  #include <stdlib.h>
>  #include <time.h>
> +#include <sys/stat.h>
>  #include "linux/kernel.h"
>
>  #include "test_util.h"
> @@ -117,6 +118,41 @@ const struct vm_mem_backing_src_alias backing_src_aliases[] = {
>         {"anonymous_hugetlb", VM_MEM_SRC_ANONYMOUS_HUGETLB,},
>  };
>
> +bool thp_configured(void)
> +{
> +       int ret;
> +       struct stat statbuf;
> +
> +       ret = stat("/sys/kernel/mm/transparent_hugepage", &statbuf);
> +       TEST_ASSERT(ret == 0 || (ret == -1 && errno == ENOENT),
> +                   "Error in stating /sys/kernel/mm/transparent_hugepage: %d",
> +                   errno);
> +
> +       return ret == 0;
> +}
> +
> +size_t get_trans_hugepagesz(void)
> +{
> +       size_t size;
> +       char buf[16];
> +       FILE *f;
> +
> +       TEST_ASSERT(thp_configured(), "THP is not configured in host kernel");
> +
> +       f = fopen("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", "r");
> +       TEST_ASSERT(f != NULL,
> +                   "Error in opening transparent_hugepage/hpage_pmd_size: %d",
> +                   errno);
> +
> +       if (fread(buf, sizeof(char), sizeof(buf), f) == 0) {
> +               fclose(f);
> +               TEST_FAIL("Unable to read transparent_hugepage/hpage_pmd_size");
> +       }
> +
> +       size = strtoull(buf, NULL, 10);
> +       return size;
> +}
> +
>  void backing_src_help(void)
>  {
>         int i;
> --
> 2.19.1
>

  reply	other threads:[~2021-02-25 23:28 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-25  5:59 [RFC PATCH v2 0/7] Some improvement and a new test for kvm page table Yanan Wang
2021-02-25  5:59 ` [RFC PATCH v2 1/7] tools include: sync head files of mmap flag encodings about hugetlb Yanan Wang
2021-02-25  5:59 ` [RFC PATCH v2 2/7] KVM: selftests: Use flag CLOCK_MONOTONIC_RAW for timing Yanan Wang
2021-02-25 18:54   ` Andrew Jones
2021-02-26  2:49     ` wangyanan (Y)
2021-02-25  5:59 ` [RFC PATCH v2 3/7] KVM: selftests: Make a generic helper to get vm guest mode strings Yanan Wang
2021-02-25 18:55   ` Andrew Jones
2021-02-26  5:56   ` wangyanan (Y)
2021-02-25  5:59 ` [RFC PATCH v2 4/7] KVM: selftests: Add a helper to get system configured THP page size Yanan Wang
2021-02-25 23:27   ` Ben Gardon [this message]
2021-02-25  5:59 ` [RFC PATCH v2 5/7] KVM: selftests: List all hugetlb src types specified with page sizes Yanan Wang
2021-02-25 23:42   ` Ben Gardon
2021-02-26  5:45     ` wangyanan (Y)
2021-02-25  5:59 ` [RFC PATCH v2 6/7] KVM: selftests: Adapt vm_userspace_mem_region_add to new helpers Yanan Wang
2021-02-25 23:44   ` Ben Gardon
2021-02-26  5:48     ` wangyanan (Y)
2021-02-25  5:59 ` [RFC PATCH v2 7/7] KVM: selftests: Add a test for kvm page table code Yanan Wang
2021-02-25 23:45 ` [RFC PATCH v2 0/7] Some improvement and a new test for kvm page table 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=CANgfPd8rSmKr_G9HFqt30hFGJ9jW387yUODYH+f+BUJPv7-sCA@mail.gmail.com \
    --to=bgardon@google.com \
    --cc=acme@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=mingo@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanghaibin.wang@huawei.com \
    --cc=wangyanan55@huawei.com \
    --cc=yuzenghui@huawei.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).