qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: David Hildenbrand <david@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
	Eduardo Habkost <ehabkost@redhat.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	Xiao Guangrong <xiaoguangrong.eric@gmail.com>,
	David Gibson <david@gibson.dropbear.id.au>,
	Alexander Graf <agraf@suse.de>, Stefan Weil <sw@weilnetz.de>
Subject: Re: [Qemu-devel] [PATCH v3 2/4] util/oslib-win32: indicate alignment for qemu_anon_ram_alloc()
Date: Mon, 2 Jul 2018 12:16:11 +0200	[thread overview]
Message-ID: <20180702121611.0a3f3ed4@redhat.com> (raw)
In-Reply-To: <20180702093755.7384-3-david@redhat.com>

On Mon,  2 Jul 2018 11:37:53 +0200
David Hildenbrand <david@redhat.com> wrote:

> Let's set the alignment just like for the posix variant. This will
> implicitly set the alignment of the underlying memory region and
> therefore make memory_region_get_alignment(mr) return something > 0 for
> all memory backends applicable to PCDIMM/NVDIMM.
> 
> The allocation granularity is ususally 64k, while the page size is 4k.
> The documentation of VirtualAlloc is not really comprehensible in case
> only MEM_COMMIT is specified without an address. We'll detect the actual
> values and then go for the bigger one. The expection is, that it will
> always be 64k aligned. (The assumption is that MEM_COMMIT does an
> implicit MEM_RESERVE, so the address will always be aligned to the
> allocation granularity. And the allocation granularity is always bigger
> than the page size).
> 
> This will allow us to drop special handling in pc.c for
> memory_region_get_alignment(mr) == 0, as we can then assume that it is
> always set (and AFAICS >= getpagesize()).
> 
> For pc in pc_memory_plug(), under Windows TARGET_PAGE_SIZE == getpagesize(),
> therefore alignment of DIMMs will not change, and therefore also not the
> guest physical memory layout.
> 
> For spapr in spapr_memory_plug(), an alignment of 0 would have been used
> until now. As QEMU_ALIGN_UP will crash with the alignment being 0, this
> never worked, so we don't have to care about compatibility handling.
> 
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  util/oslib-win32.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index bb5ad28bd3..25dd1595ad 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -67,15 +67,24 @@ void *qemu_memalign(size_t alignment, size_t size)
>      return qemu_oom_check(qemu_try_memalign(alignment, size));
>  }
>  
> +static int get_allocation_granularity(void)
> +{
> +    SYSTEM_INFO system_info;
> +
> +    GetSystemInfo(&system_info);
> +    return system_info.dwAllocationGranularity;
> +}
> +
>  void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared)
>  {
>      void *ptr;
>  
> -    /* FIXME: this is not exactly optimal solution since VirtualAlloc
> -       has 64Kb granularity, but at least it guarantees us that the
> -       memory is page aligned. */
>      ptr = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
>      trace_qemu_anon_ram_alloc(size, ptr);
> +
> +    if (ptr && align) {
> +        *align = MAX(get_allocation_granularity(), getpagesize());
> +    }
>      return ptr;
>  }
>  
Not really tested, but patch looks correct to me, hence:

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

  reply	other threads:[~2018-07-02 10:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-02  9:37 [Qemu-devel] [PATCH v3 0/4] pc-dimm: pre_plug "slot" and "addr" assignment David Hildenbrand
2018-07-02  9:37 ` [Qemu-devel] [PATCH v3 1/4] pc-dimm: assign and verify the "slot" property during pre_plug David Hildenbrand
2018-07-03  8:10   ` Auger Eric
2018-07-02  9:37 ` [Qemu-devel] [PATCH v3 2/4] util/oslib-win32: indicate alignment for qemu_anon_ram_alloc() David Hildenbrand
2018-07-02 10:16   ` Igor Mammedov [this message]
2018-07-03  8:10   ` Auger Eric
2018-07-02  9:37 ` [Qemu-devel] [PATCH v3 3/4] pc: drop memory region alignment check for 0 David Hildenbrand
2018-07-03  8:10   ` Auger Eric
2018-07-02  9:37 ` [Qemu-devel] [PATCH v3 4/4] pc-dimm: assign and verify the "addr" property during pre_plug David Hildenbrand
2018-07-02 10:31   ` Igor Mammedov
2018-07-02 10:39     ` David Hildenbrand
2018-07-02 12:44       ` Igor Mammedov
2018-07-02 12:47         ` David Hildenbrand
2018-07-03  8:20           ` Auger Eric
2018-07-03  8:22           ` Auger Eric
2018-07-03  0:19   ` David Gibson

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=20180702121611.0a3f3ed4@redhat.com \
    --to=imammedo@redhat.com \
    --cc=agraf@suse.de \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=sw@weilnetz.de \
    --cc=xiaoguangrong.eric@gmail.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).