From: David Gibson <david@gibson.dropbear.id.au>
To: Greg Kurz <groug@kaod.org>
Cc: ehabkost@redhat.com, imammedo@redhat.com, pbonzini@redhat.com,
qemu-ppc@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCHv2 for-2.13 1/2] Make qemu_mempath_getpagesize() accept NULL
Date: Fri, 6 Apr 2018 15:01:58 +1000 [thread overview]
Message-ID: <20180406050158.GD3212@umbus.fritz.box> (raw)
In-Reply-To: <20180405155636.288f9672@bahia.lan>
[-- Attachment #1: Type: text/plain, Size: 4860 bytes --]
On Thu, Apr 05, 2018 at 03:56:36PM +0200, Greg Kurz wrote:
> On Thu, 5 Apr 2018 12:20:01 +1000
> David Gibson <david@gibson.dropbear.id.au> wrote:
>
> > qemu_mempath_getpagesize() gets the effective (host side) page size for
> > a block of memory backed by an mmap()ed file on the host. It requires
> > the mem_path parameter to be non-NULL.
> >
> > This ends up meaning all the callers need a different case for handling
> > anonymous memory (for memory-backend-ram or default memory with -mem-path
> > is not specified).
> >
> > We can make all those callers a little simpler by
>
> by "having" ?
Yes, oops.
> > qemu_mempath_getpagesize() accept NULL, and treat that as the anonymous
> > memory case.
> >
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
>
> Reviewed-by: Greg Kurz <groug@kaod.org>
>
> > exec.c | 21 ++++++---------------
> > target/ppc/kvm.c | 8 ++------
> > util/mmap-alloc.c | 26 ++++++++++++++------------
> > 3 files changed, 22 insertions(+), 33 deletions(-)
> >
> > diff --git a/exec.c b/exec.c
> > index 02b1efebb7..b38b004563 100644
> > --- a/exec.c
> > +++ b/exec.c
> > @@ -1488,19 +1488,14 @@ void ram_block_dump(Monitor *mon)
> > */
> > static int find_max_supported_pagesize(Object *obj, void *opaque)
> > {
> > - char *mem_path;
> > long *hpsize_min = opaque;
> >
> > if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
> > - mem_path = object_property_get_str(obj, "mem-path", NULL);
> > - if (mem_path) {
> > - long hpsize = qemu_mempath_getpagesize(mem_path);
> > - g_free(mem_path);
> > - if (hpsize < *hpsize_min) {
> > - *hpsize_min = hpsize;
> > - }
> > - } else {
> > - *hpsize_min = getpagesize();
> > + char *mem_path = object_property_get_str(obj, "mem-path", NULL);
> > + long hpsize = qemu_mempath_getpagesize(mem_path);
> > + g_free(mem_path);
> > + if (hpsize < *hpsize_min) {
> > + *hpsize_min = hpsize;
> > }
> > }
> >
> > @@ -1513,11 +1508,7 @@ long qemu_getrampagesize(void)
> > long mainrampagesize;
> > Object *memdev_root;
> >
> > - if (mem_path) {
> > - mainrampagesize = qemu_mempath_getpagesize(mem_path);
> > - } else {
> > - mainrampagesize = getpagesize();
> > - }
> > + mainrampagesize = qemu_mempath_getpagesize(mem_path);
> >
> > /* it's possible we have memory-backend objects with
> > * hugepage-backed RAM. these may get mapped into system
> > diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> > index 1bd38c6a90..f393eae127 100644
> > --- a/target/ppc/kvm.c
> > +++ b/target/ppc/kvm.c
> > @@ -496,12 +496,8 @@ bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path)
> > char *mempath = object_property_get_str(mem_obj, "mem-path", NULL);
> > long pagesize;
> >
> > - if (mempath) {
> > - pagesize = qemu_mempath_getpagesize(mempath);
> > - g_free(mempath);
> > - } else {
> > - pagesize = getpagesize();
> > - }
> > + pagesize = qemu_mempath_getpagesize(mempath);
> > + g_free(mempath);
> >
> > return pagesize >= max_cpu_page_size;
> > }
> > diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
> > index 2fd8cbcc6f..fd329eccd8 100644
> > --- a/util/mmap-alloc.c
> > +++ b/util/mmap-alloc.c
> > @@ -50,19 +50,21 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
> > struct statfs fs;
> > int ret;
> >
> > - do {
> > - ret = statfs(mem_path, &fs);
> > - } while (ret != 0 && errno == EINTR);
> > -
> > - if (ret != 0) {
> > - fprintf(stderr, "Couldn't statfs() memory path: %s\n",
> > - strerror(errno));
> > - exit(1);
> > - }
> > + if (mem_path) {
> > + do {
> > + ret = statfs(mem_path, &fs);
> > + } while (ret != 0 && errno == EINTR);
> >
> > - if (fs.f_type == HUGETLBFS_MAGIC) {
> > - /* It's hugepage, return the huge page size */
> > - return fs.f_bsize;
> > + if (ret != 0) {
> > + fprintf(stderr, "Couldn't statfs() memory path: %s\n",
> > + strerror(errno));
> > + exit(1);
> > + }
> > +
> > + if (fs.f_type == HUGETLBFS_MAGIC) {
> > + /* It's hugepage, return the huge page size */
> > + return fs.f_bsize;
> > + }
> > }
> > #ifdef __sparc__
> > /* SPARC Linux needs greater alignment than the pagesize */
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2018-04-06 7:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-05 2:20 [Qemu-devel] [PATCHv2 for-2.13 0/2] Helpers to obtain host page sizes for guest RAM David Gibson
2018-04-05 2:20 ` [Qemu-devel] [PATCHv2 for-2.13 1/2] Make qemu_mempath_getpagesize() accept NULL David Gibson
2018-04-05 13:56 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2018-04-06 5:01 ` David Gibson [this message]
2018-04-05 2:20 ` [Qemu-devel] [PATCHv2 for-2.13 2/2] Add host_memory_backend_pagesize() helper David Gibson
2018-04-05 14:04 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2018-04-05 2:35 ` [Qemu-devel] [PATCHv2 for-2.13 0/2] Helpers to obtain host page sizes for guest RAM no-reply
2018-04-05 3:00 ` David Gibson
2018-04-05 2:38 ` no-reply
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=20180406050158.GD3212@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=ehabkost@redhat.com \
--cc=groug@kaod.org \
--cc=imammedo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/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).