diff mbox series

[PULL,04/47] util/oslib-win32: Use _aligned_malloc for qemu_try_memalign

Message ID 20210107201448.1152301-5-richard.henderson@linaro.org
State Accepted
Commit dfbd0b873a85021c083d9b4b84630c3732645963
Headers show
Series tcg patch queue | expand

Commit Message

Richard Henderson Jan. 7, 2021, 8:14 p.m. UTC
We do not need or want to be allocating page sized quanta.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Reviewed-by: Stefan Weil <sw@weilnetz.de>

Message-Id: <20201018164836.1149452-1-richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 util/oslib-win32.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

-- 
2.25.1

Comments

Volker Rümelin Jan. 10, 2021, 11:18 p.m. UTC | #1
> We do not need or want to be allocating page sized quanta.

>

> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> Reviewed-by: Stefan Weil <sw@weilnetz.de>

> Message-Id: <20201018164836.1149452-1-richard.henderson@linaro.org>

> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> ---

>  util/oslib-win32.c | 11 ++++-------

>  1 file changed, 4 insertions(+), 7 deletions(-)

>

> diff --git a/util/oslib-win32.c b/util/oslib-win32.c

> index 01787df74c..8adc651259 100644

> --- a/util/oslib-win32.c

> +++ b/util/oslib-win32.c

> @@ -39,6 +39,7 @@

>  #include "trace.h"

>  #include "qemu/sockets.h"

>  #include "qemu/cutils.h"

> +#include <malloc.h>

>  

>  /* this must come after including "trace.h" */

>  #include <shlobj.h>

> @@ -56,10 +57,8 @@ void *qemu_try_memalign(size_t alignment, size_t size)

>  {

>      void *ptr;

>  

> -    if (!size) {

> -        abort();

> -    }

> -    ptr = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);

> +    g_assert(size != 0);

> +    ptr = _aligned_malloc(alignment, size);


Hi Richard,

this doesn't work really well. The _aligned_malloc parameters are swapped. ptr = _aligned_malloc(size, alignment) is correct.

With best regards,
Volker

>      trace_qemu_memalign(alignment, size, ptr);

>      return ptr;

>  }

> @@ -93,9 +92,7 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared)

>  void qemu_vfree(void *ptr)

>  {

>      trace_qemu_vfree(ptr);

> -    if (ptr) {

> -        VirtualFree(ptr, 0, MEM_RELEASE);

> -    }

> +    _aligned_free(ptr);

>  }

>  

>  void qemu_anon_ram_free(void *ptr, size_t size)
罗勇刚(Yonggang Luo) Jan. 11, 2021, 3:10 a.m. UTC | #2
On Sun, Jan 10, 2021 at 3:19 PM Volker Rümelin <vr_qemu@t-online.de> wrote:
>

> > We do not need or want to be allocating page sized quanta.

> >

> > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> > Reviewed-by: Stefan Weil <sw@weilnetz.de>

> > Message-Id: <20201018164836.1149452-1-richard.henderson@linaro.org>

> > Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> > Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> > ---

> >  util/oslib-win32.c | 11 ++++-------

> >  1 file changed, 4 insertions(+), 7 deletions(-)

> >

> > diff --git a/util/oslib-win32.c b/util/oslib-win32.c

> > index 01787df74c..8adc651259 100644

> > --- a/util/oslib-win32.c

> > +++ b/util/oslib-win32.c

> > @@ -39,6 +39,7 @@

> >  #include "trace.h"

> >  #include "qemu/sockets.h"

> >  #include "qemu/cutils.h"

> > +#include <malloc.h>

> >

> >  /* this must come after including "trace.h" */

> >  #include <shlobj.h>

> > @@ -56,10 +57,8 @@ void *qemu_try_memalign(size_t alignment, size_t

size)
> >  {

> >      void *ptr;

> >

> > -    if (!size) {

> > -        abort();

> > -    }

> > -    ptr = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);

> > +    g_assert(size != 0);

> > +    ptr = _aligned_malloc(alignment, size);

>

> Hi Richard,

>

> this doesn't work really well. The _aligned_malloc parameters are

swapped. ptr = _aligned_malloc(size, alignment) is correct.
>

> With best regards,

> Volker

>

> >      trace_qemu_memalign(alignment, size, ptr);

> >      return ptr;

> >  }

> > @@ -93,9 +92,7 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t

*align, bool shared)
> >  void qemu_vfree(void *ptr)

> >  {

> >      trace_qemu_vfree(ptr);

> > -    if (ptr) {

> > -        VirtualFree(ptr, 0, MEM_RELEASE);

> > -    }

> > +    _aligned_free(ptr);

> >  }

> >

> >  void qemu_anon_ram_free(void *ptr, size_t size)

>

>


Dos this the cause of this failure?
https://cirrus-ci.com/task/6055645751279616?command=test#L593


MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}
G_TEST_SRCDIR=C:/Users/ContainerAdministrator/AppData/Local/Temp/cirrus-ci-build/tests
G_TEST_BUILDDIR=C:/Users/ContainerAdministrator/AppData/Local/Temp/cirrus-ci-build/build/tests
tests/test-qht.exe --tap -k
ERROR test-qht - too few tests run (expected 2, got 0)
make: *** [Makefile.mtest:256: run-test-30] Error 1
--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo


--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
<div dir="ltr"><br><br>On Sun, Jan 10, 2021 at 3:19 PM Volker Rümelin &lt;<a href="mailto:vr_qemu@t-online.de">vr_qemu@t-online.de</a>&gt; wrote:<br>&gt;<br>&gt; &gt; We do not need or want to be allocating page sized quanta.<br>&gt; &gt;<br>&gt; &gt; Reviewed-by: Philippe Mathieu-Daudé &lt;<a href="mailto:f4bug@amsat.org">f4bug@amsat.org</a>&gt;<br>&gt; &gt; Reviewed-by: Stefan Weil &lt;<a href="mailto:sw@weilnetz.de">sw@weilnetz.de</a>&gt;<br>&gt; &gt; Message-Id: &lt;<a href="mailto:20201018164836.1149452-1-richard.henderson@linaro.org">20201018164836.1149452-1-richard.henderson@linaro.org</a>&gt;<br>&gt; &gt; Signed-off-by: Philippe Mathieu-Daudé &lt;<a href="mailto:philmd@redhat.com">philmd@redhat.com</a>&gt;<br>&gt; &gt; Signed-off-by: Richard Henderson &lt;<a href="mailto:richard.henderson@linaro.org">richard.henderson@linaro.org</a>&gt;<br>&gt; &gt; ---<br>&gt; &gt;  util/oslib-win32.c | 11 ++++-------<br>&gt; &gt;  1 file changed, 4 insertions(+), 7 deletions(-)<br>&gt; &gt;<br>&gt; &gt; diff --git a/util/oslib-win32.c b/util/oslib-win32.c<br>&gt; &gt; index 01787df74c..8adc651259 100644<br>&gt; &gt; --- a/util/oslib-win32.c<br>&gt; &gt; +++ b/util/oslib-win32.c<br>&gt; &gt; @@ -39,6 +39,7 @@<br>&gt; &gt;  #include &quot;trace.h&quot;<br>&gt; &gt;  #include &quot;qemu/sockets.h&quot;<br>&gt; &gt;  #include &quot;qemu/cutils.h&quot;<br>&gt; &gt; +#include &lt;malloc.h&gt;<br>&gt; &gt; <br>&gt; &gt;  /* this must come after including &quot;trace.h&quot; */<br>&gt; &gt;  #include &lt;shlobj.h&gt;<br>&gt; &gt; @@ -56,10 +57,8 @@ void *qemu_try_memalign(size_t alignment, size_t size)<br>&gt; &gt;  {<br>&gt; &gt;      void *ptr;<br>&gt; &gt; <br>&gt; &gt; -    if (!size) {<br>&gt; &gt; -        abort();<br>&gt; &gt; -    }<br>&gt; &gt; -    ptr = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);<br>&gt; &gt; +    g_assert(size != 0);<br>&gt; &gt; +    ptr = _aligned_malloc(alignment, size);<br>&gt;<br>&gt; Hi Richard,<br>&gt;<br>&gt; this doesn&#39;t work really well. The _aligned_malloc parameters are swapped. ptr = _aligned_malloc(size, alignment) is correct.<br>&gt;<br>&gt; With best regards,<br>&gt; Volker<br>&gt;<br>&gt; &gt;      trace_qemu_memalign(alignment, size, ptr);<br>&gt; &gt;      return ptr;<br>&gt; &gt;  }<br>&gt; &gt; @@ -93,9 +92,7 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared)<br>&gt; &gt;  void qemu_vfree(void *ptr)<br>&gt; &gt;  {<br>&gt; &gt;      trace_qemu_vfree(ptr);<br>&gt; &gt; -    if (ptr) {<br>&gt; &gt; -        VirtualFree(ptr, 0, MEM_RELEASE);<br>&gt; &gt; -    }<br>&gt; &gt; +    _aligned_free(ptr);<br>&gt; &gt;  }<br>&gt; &gt; <br>&gt; &gt;  void qemu_anon_ram_free(void *ptr, size_t size)<br>&gt;<br>&gt;<br><br>Dos this the cause of this failure?<br><a href="https://cirrus-ci.com/task/6055645751279616?command=test#L593" target="_blank">https://cirrus-ci.com/task/6055645751279616?command=test#L593</a><br><br><br>MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))} G_TEST_SRCDIR=C:/Users/ContainerAdministrator/AppData/Local/Temp/cirrus-ci-build/tests G_TEST_BUILDDIR=C:/Users/ContainerAdministrator/AppData/Local/Temp/cirrus-ci-build/build/tests tests/test-qht.exe --tap -k<br>ERROR test-qht - too few tests run (expected 2, got 0)<br>make: *** [Makefile.mtest:256: run-test-30] Error 1<br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo<div class="gmail-yj6qo"></div><div class="gmail-adL"><br></div><br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo</div>
diff mbox series

Patch

diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 01787df74c..8adc651259 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -39,6 +39,7 @@ 
 #include "trace.h"
 #include "qemu/sockets.h"
 #include "qemu/cutils.h"
+#include <malloc.h>
 
 /* this must come after including "trace.h" */
 #include <shlobj.h>
@@ -56,10 +57,8 @@  void *qemu_try_memalign(size_t alignment, size_t size)
 {
     void *ptr;
 
-    if (!size) {
-        abort();
-    }
-    ptr = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
+    g_assert(size != 0);
+    ptr = _aligned_malloc(alignment, size);
     trace_qemu_memalign(alignment, size, ptr);
     return ptr;
 }
@@ -93,9 +92,7 @@  void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared)
 void qemu_vfree(void *ptr)
 {
     trace_qemu_vfree(ptr);
-    if (ptr) {
-        VirtualFree(ptr, 0, MEM_RELEASE);
-    }
+    _aligned_free(ptr);
 }
 
 void qemu_anon_ram_free(void *ptr, size_t size)