From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aq67m-00059C-MT for qemu-devel@nongnu.org; Tue, 12 Apr 2016 17:45:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aq67j-0007qd-5p for qemu-devel@nongnu.org; Tue, 12 Apr 2016 17:45:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59098) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aq67i-0007qZ-UY for qemu-devel@nongnu.org; Tue, 12 Apr 2016 17:45:27 -0400 References: <1460064711-93294-1-git-send-email-dingel@linux.vnet.ibm.com> From: Paolo Bonzini Message-ID: <570D6C6E.5060600@redhat.com> Date: Tue, 12 Apr 2016 23:45:18 +0200 MIME-Version: 1.0 In-Reply-To: <1460064711-93294-1-git-send-email-dingel@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2] exec.c: Ensure right alignment also for file backed ram List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Dominik Dingel , qemu-devel@nongnu.org Cc: Peter Crosthwaite , Richard Henderson , Halil Pasic 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 =3D -1; > int64_t page_size; > + int64_t alignment; > =20 > if (kvm_enabled() && !kvm_has_sync_mmu()) { > error_setg(errp, > @@ -1296,7 +1297,8 @@ static void *file_ram_alloc(RAMBlock *block, > } > =20 > page_size =3D qemu_fd_getpagesize(fd); > - block->mr->align =3D page_size; > + alignment =3D MAX(page_size, QEMU_VMALLOC_ALIGN); > + block->mr->align =3D alignment; > =20 > 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; > } > =20 > - memory =3D ROUND_UP(memory, page_size); > + memory =3D 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"); > } > =20 > - area =3D qemu_ram_mmap(fd, memory, page_size, block->flags & RAM_S= HARED); > + area =3D qemu_ram_mmap(fd, memory, alignment, block->flags & RAM_S= HARED); > if (area =3D=3D 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); > =20 > #endif > =20 > +#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); > =20 > 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. > */ > =20 > -#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 > #include >=20