From: Paolo Bonzini <pbonzini@redhat.com>
To: Dominik Dingel <dingel@linux.vnet.ibm.com>, qemu-devel@nongnu.org
Cc: Peter Crosthwaite <crosthwaite.peter@gmail.com>,
Richard Henderson <rth@twiddle.net>,
Halil Pasic <pasic@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v2] exec.c: Ensure right alignment also for file backed ram
Date: Tue, 12 Apr 2016 23:45:18 +0200 [thread overview]
Message-ID: <570D6C6E.5060600@redhat.com> (raw)
In-Reply-To: <1460064711-93294-1-git-send-email-dingel@linux.vnet.ibm.com>
On 07/04/2016 23:31, Dominik Dingel wrote:
> diff --git a/exec.c b/exec.c
> index c4f9036..1ae98e4 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1241,6 +1241,7 @@ static void *file_ram_alloc(RAMBlock *block,
> void *area;
> int fd = -1;
> int64_t page_size;
> + int64_t alignment;
>
> if (kvm_enabled() && !kvm_has_sync_mmu()) {
> error_setg(errp,
> @@ -1296,7 +1297,8 @@ static void *file_ram_alloc(RAMBlock *block,
> }
>
> page_size = qemu_fd_getpagesize(fd);
> - block->mr->align = page_size;
> + alignment = MAX(page_size, QEMU_VMALLOC_ALIGN);
> + block->mr->align = alignment;
>
> if (memory < page_size) {
> error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to "
> @@ -1305,7 +1307,7 @@ static void *file_ram_alloc(RAMBlock *block,
> goto error;
> }
>
> - memory = ROUND_UP(memory, page_size);
> + memory = ROUND_UP(memory, alignment);
I think this change is not necessary either; it is enough to change the
qemu_ram_mmap below.
Paolo
> /*
> * ftruncate is not supported by hugetlbfs in older
> @@ -1317,7 +1319,7 @@ static void *file_ram_alloc(RAMBlock *block,
> perror("ftruncate");
> }
>
> - area = qemu_ram_mmap(fd, memory, page_size, block->flags & RAM_SHARED);
> + area = qemu_ram_mmap(fd, memory, alignment, block->flags & RAM_SHARED);
> if (area == MAP_FAILED) {
> error_setg_errno(errp, errno,
> "unable to map backing store for guest RAM");
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index 408783f..a472372 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -247,6 +247,18 @@ void qemu_anon_ram_free(void *ptr, size_t size);
>
> #endif
>
> +#if defined(__linux__) && (defined(__x86_64__) || defined(__arm__))
> + /* Use 2 MiB alignment so transparent hugepages can be used by KVM.
> + Valgrind does not support alignments larger than 1 MiB,
> + therefore we need special code which handles running on Valgrind. */
> +# define QEMU_VMALLOC_ALIGN (512 * 4096)
> +#elif defined(__linux__) && defined(__s390x__)
> + /* Use 1 MiB (segment size) alignment so gmap can be used by KVM. */
> +# define QEMU_VMALLOC_ALIGN (256 * 4096)
> +#else
> +# define QEMU_VMALLOC_ALIGN getpagesize()
> +#endif
> +
> int qemu_madvise(void *addr, size_t len, int advice);
>
> int qemu_open(const char *name, int flags, ...);
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index 20ca141..4adde93 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -26,18 +26,6 @@
> * THE SOFTWARE.
> */
>
> -#if defined(__linux__) && (defined(__x86_64__) || defined(__arm__))
> - /* Use 2 MiB alignment so transparent hugepages can be used by KVM.
> - Valgrind does not support alignments larger than 1 MiB,
> - therefore we need special code which handles running on Valgrind. */
> -# define QEMU_VMALLOC_ALIGN (512 * 4096)
> -#elif defined(__linux__) && defined(__s390x__)
> - /* Use 1 MiB (segment size) alignment so gmap can be used by KVM. */
> -# define QEMU_VMALLOC_ALIGN (256 * 4096)
> -#else
> -# define QEMU_VMALLOC_ALIGN getpagesize()
> -#endif
> -
> #include "qemu/osdep.h"
> #include <termios.h>
> #include <termios.h>
>
next prev parent reply other threads:[~2016-04-12 21:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-07 21:31 [Qemu-devel] [PATCH v2] exec.c: Ensure right alignment also for file backed ram Dominik Dingel
2016-04-12 21:45 ` Paolo Bonzini [this message]
2016-04-13 7:19 ` Dominik Dingel
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=570D6C6E.5060600@redhat.com \
--to=pbonzini@redhat.com \
--cc=crosthwaite.peter@gmail.com \
--cc=dingel@linux.vnet.ibm.com \
--cc=pasic@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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).