All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] some fix in tests/migration
@ 2019-10-04  3:43 Mao Zhongyi
  2019-10-04  3:43 ` [PATCH v3 1/3] tests/migration: mem leak fix Mao Zhongyi
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Mao Zhongyi @ 2019-10-04  3:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: tony.nguyen, alex.bennee, armbru, Mao Zhongyi, laurent

This patchset mainly fixes memory leak, typo and return
value of stress function in stress test.

v3->v2:
p1: 
- replace malloc with g_malloc   [Laurent Vivier]
p3:
- change stressone type to void and stree return value
  to -1 to make the path of 'if (stress(ramsizeGB, ncpus) < 0)'
  can be reached.                [Laurent Vivier]
- update the commit message.

v2->v1:
- use g_autofree to release memory automatically instead
  of free().                     [Alex Bennée]
                      
Cc: armbru@redhat.com 
Cc: laurent@vivier.eu 
Cc: tony.nguyen@bt.com
Cc: alex.bennee@linaro.org

Mao Zhongyi (3):
  tests/migration: mem leak fix
  tests/migration: fix a typo in comment
  tests/migration:fix unreachable path in stress test

 tests/migration/stress.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

-- 
2.17.1





^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 1/3] tests/migration: mem leak fix
  2019-10-04  3:43 [PATCH v3 0/3] some fix in tests/migration Mao Zhongyi
@ 2019-10-04  3:43 ` Mao Zhongyi
  2019-10-04  7:17   ` Laurent Vivier
  2019-10-04  3:43 ` [PATCH v3 2/3] tests/migration: fix a typo in comment Mao Zhongyi
  2019-10-04  3:43 ` [PATCH v3 3/3] tests/migration:fix unreachable path in stress test Mao Zhongyi
  2 siblings, 1 reply; 7+ messages in thread
From: Mao Zhongyi @ 2019-10-04  3:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: tony.nguyen, alex.bennee, armbru, Mao Zhongyi, laurent

‘data’ has the possibility of memory leaks, so use the
glib macros g_autofree recommended by CODING_STYLE.rst
to automatically release the memory that returned from
g_malloc().

Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
---
 tests/migration/stress.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index d9aa4afe92..9e128eef50 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -170,10 +170,10 @@ static unsigned long long now(void)
 static int stressone(unsigned long long ramsizeMB)
 {
     size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
-    char *ram = malloc(ramsizeMB * 1024 * 1024);
+    g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
     char *ramptr;
     size_t i, j, k;
-    char *data = malloc(PAGE_SIZE);
+    g_autofree char *data = g_malloc(PAGE_SIZE);
     char *dataptr;
     size_t nMB = 0;
     unsigned long long before, after;
@@ -186,7 +186,6 @@ static int stressone(unsigned long long ramsizeMB)
     if (!data) {
         fprintf(stderr, "%s (%d): ERROR: cannot allocate %d bytes of RAM: %s\n",
                 argv0, gettid(), PAGE_SIZE, strerror(errno));
-        free(ram);
         return -1;
     }
 
@@ -198,8 +197,6 @@ static int stressone(unsigned long long ramsizeMB)
     memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
 
     if (random_bytes(data, PAGE_SIZE) < 0) {
-        free(ram);
-        free(data);
         return -1;
     }
 
@@ -227,9 +224,6 @@ static int stressone(unsigned long long ramsizeMB)
             }
         }
     }
-
-    free(data);
-    free(ram);
 }
 
 
-- 
2.17.1





^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 2/3] tests/migration: fix a typo in comment
  2019-10-04  3:43 [PATCH v3 0/3] some fix in tests/migration Mao Zhongyi
  2019-10-04  3:43 ` [PATCH v3 1/3] tests/migration: mem leak fix Mao Zhongyi
@ 2019-10-04  3:43 ` Mao Zhongyi
  2019-10-07 15:09   ` Thomas Huth
  2019-10-04  3:43 ` [PATCH v3 3/3] tests/migration:fix unreachable path in stress test Mao Zhongyi
  2 siblings, 1 reply; 7+ messages in thread
From: Mao Zhongyi @ 2019-10-04  3:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: tony.nguyen, alex.bennee, armbru, Mao Zhongyi, laurent

Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
---
 tests/migration/stress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index 9e128eef50..debf34359f 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -191,7 +191,7 @@ static int stressone(unsigned long long ramsizeMB)
 
     /* We don't care about initial state, but we do want
      * to fault it all into RAM, otherwise the first iter
-     * of the loop below will be quite slow. We cna't use
+     * of the loop below will be quite slow. We can't use
      * 0x0 as the byte as gcc optimizes that away into a
      * calloc instead :-) */
     memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
-- 
2.17.1





^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 3/3] tests/migration:fix unreachable path in stress test
  2019-10-04  3:43 [PATCH v3 0/3] some fix in tests/migration Mao Zhongyi
  2019-10-04  3:43 ` [PATCH v3 1/3] tests/migration: mem leak fix Mao Zhongyi
  2019-10-04  3:43 ` [PATCH v3 2/3] tests/migration: fix a typo in comment Mao Zhongyi
@ 2019-10-04  3:43 ` Mao Zhongyi
  2019-10-04  7:20   ` Laurent Vivier
  2 siblings, 1 reply; 7+ messages in thread
From: Mao Zhongyi @ 2019-10-04  3:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: tony.nguyen, alex.bennee, armbru, Mao Zhongyi, laurent

If stressone() or stress() exits it's because of a failure
because the test runs forever otherwise, so change stressone
type to void and stress should always return -1 to make the
path of 'if (stress(ramsizeGB, ncpus) < 0)' can be reached.

Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
---
 tests/migration/stress.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index debf34359f..b0df1323bb 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -167,7 +167,7 @@ static unsigned long long now(void)
     return (tv.tv_sec * 1000ull) + (tv.tv_usec / 1000ull);
 }
 
-static int stressone(unsigned long long ramsizeMB)
+static void stressone(unsigned long long ramsizeMB)
 {
     size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
     g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
@@ -181,12 +181,12 @@ static int stressone(unsigned long long ramsizeMB)
     if (!ram) {
         fprintf(stderr, "%s (%05d): ERROR: cannot allocate %llu MB of RAM: %s\n",
                 argv0, gettid(), ramsizeMB, strerror(errno));
-        return -1;
+        return;
     }
     if (!data) {
         fprintf(stderr, "%s (%d): ERROR: cannot allocate %d bytes of RAM: %s\n",
                 argv0, gettid(), PAGE_SIZE, strerror(errno));
-        return -1;
+        return;
     }
 
     /* We don't care about initial state, but we do want
@@ -197,7 +197,7 @@ static int stressone(unsigned long long ramsizeMB)
     memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
 
     if (random_bytes(data, PAGE_SIZE) < 0) {
-        return -1;
+        return;
     }
 
     before = now();
@@ -250,7 +250,7 @@ static int stress(unsigned long long ramsizeGB, int ncpus)
 
     stressone(ramsizeMB);
 
-    return 0;
+    return -1;
 }
 
 
@@ -348,6 +348,4 @@ int main(int argc, char **argv)
 
     if (stress(ramsizeGB, ncpus) < 0)
         exit_failure();
-
-    exit_success();
 }
-- 
2.17.1





^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 1/3] tests/migration: mem leak fix
  2019-10-04  3:43 ` [PATCH v3 1/3] tests/migration: mem leak fix Mao Zhongyi
@ 2019-10-04  7:17   ` Laurent Vivier
  0 siblings, 0 replies; 7+ messages in thread
From: Laurent Vivier @ 2019-10-04  7:17 UTC (permalink / raw)
  To: Mao Zhongyi, qemu-devel; +Cc: tony.nguyen, alex.bennee, armbru

Le 04/10/2019 à 05:43, Mao Zhongyi a écrit :
> ‘data’ has the possibility of memory leaks, so use the
> glib macros g_autofree recommended by CODING_STYLE.rst
> to automatically release the memory that returned from
> g_malloc().
> 
> Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  tests/migration/stress.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/tests/migration/stress.c b/tests/migration/stress.c
> index d9aa4afe92..9e128eef50 100644
> --- a/tests/migration/stress.c
> +++ b/tests/migration/stress.c
> @@ -170,10 +170,10 @@ static unsigned long long now(void)
>  static int stressone(unsigned long long ramsizeMB)
>  {
>      size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
> -    char *ram = malloc(ramsizeMB * 1024 * 1024);
> +    g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
>      char *ramptr;
>      size_t i, j, k;
> -    char *data = malloc(PAGE_SIZE);
> +    g_autofree char *data = g_malloc(PAGE_SIZE);
>      char *dataptr;
>      size_t nMB = 0;
>      unsigned long long before, after;
> @@ -186,7 +186,6 @@ static int stressone(unsigned long long ramsizeMB)
>      if (!data) {

As g_malloc() aborts on error, data is never NULL.
There is the same thing for ram.

Thanks,
Laurent


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 3/3] tests/migration:fix unreachable path in stress test
  2019-10-04  3:43 ` [PATCH v3 3/3] tests/migration:fix unreachable path in stress test Mao Zhongyi
@ 2019-10-04  7:20   ` Laurent Vivier
  0 siblings, 0 replies; 7+ messages in thread
From: Laurent Vivier @ 2019-10-04  7:20 UTC (permalink / raw)
  To: Mao Zhongyi, qemu-devel; +Cc: tony.nguyen, alex.bennee, armbru

Le 04/10/2019 à 05:43, Mao Zhongyi a écrit :
> If stressone() or stress() exits it's because of a failure
> because the test runs forever otherwise, so change stressone
> type to void and stress should always return -1 to make the
> path of 'if (stress(ramsizeGB, ncpus) < 0)' can be reached.
> 
> Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
> ---
>  tests/migration/stress.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/tests/migration/stress.c b/tests/migration/stress.c
> index debf34359f..b0df1323bb 100644
> --- a/tests/migration/stress.c
> +++ b/tests/migration/stress.c
> @@ -167,7 +167,7 @@ static unsigned long long now(void)
>      return (tv.tv_sec * 1000ull) + (tv.tv_usec / 1000ull);
>  }
>  
> -static int stressone(unsigned long long ramsizeMB)
> +static void stressone(unsigned long long ramsizeMB)
>  {
>      size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
>      g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
> @@ -181,12 +181,12 @@ static int stressone(unsigned long long ramsizeMB)
>      if (!ram) {
>          fprintf(stderr, "%s (%05d): ERROR: cannot allocate %llu MB of RAM: %s\n",
>                  argv0, gettid(), ramsizeMB, strerror(errno));
> -        return -1;
> +        return;
>      }
>      if (!data) {
>          fprintf(stderr, "%s (%d): ERROR: cannot allocate %d bytes of RAM: %s\n",
>                  argv0, gettid(), PAGE_SIZE, strerror(errno));
> -        return -1;
> +        return;
>      }

Thanks to the g_malloc() you can remove this two "if () { }" blocks.

>  
>      /* We don't care about initial state, but we do want
> @@ -197,7 +197,7 @@ static int stressone(unsigned long long ramsizeMB)
>      memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
>  
>      if (random_bytes(data, PAGE_SIZE) < 0) {
> -        return -1;
> +        return;
>      }
>  
>      before = now();
> @@ -250,7 +250,7 @@ static int stress(unsigned long long ramsizeGB, int ncpus)

you can change it to "void" too
>  
>      stressone(ramsizeMB);
>  
> -    return 0;
> +    return -1;
>  }
>  
>  
> @@ -348,6 +348,4 @@ int main(int argc, char **argv)
>  
>      if (stress(ramsizeGB, ncpus) < 0)

As it exits only on failure, you can remove the "if"

>          exit_failure();
> -
> -    exit_success();

and always use exit_failure().

>  }
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 2/3] tests/migration: fix a typo in comment
  2019-10-04  3:43 ` [PATCH v3 2/3] tests/migration: fix a typo in comment Mao Zhongyi
@ 2019-10-07 15:09   ` Thomas Huth
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Huth @ 2019-10-07 15:09 UTC (permalink / raw)
  To: Mao Zhongyi, qemu-devel
  Cc: QEMU Trivial, tony.nguyen, alex.bennee, armbru, laurent

On 04/10/2019 05.43, Mao Zhongyi wrote:
> Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
> ---
>  tests/migration/stress.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/migration/stress.c b/tests/migration/stress.c
> index 9e128eef50..debf34359f 100644
> --- a/tests/migration/stress.c
> +++ b/tests/migration/stress.c
> @@ -191,7 +191,7 @@ static int stressone(unsigned long long ramsizeMB)
>  
>      /* We don't care about initial state, but we do want
>       * to fault it all into RAM, otherwise the first iter
> -     * of the loop below will be quite slow. We cna't use
> +     * of the loop below will be quite slow. We can't use
>       * 0x0 as the byte as gcc optimizes that away into a
>       * calloc instead :-) */
>      memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-10-07 15:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-04  3:43 [PATCH v3 0/3] some fix in tests/migration Mao Zhongyi
2019-10-04  3:43 ` [PATCH v3 1/3] tests/migration: mem leak fix Mao Zhongyi
2019-10-04  7:17   ` Laurent Vivier
2019-10-04  3:43 ` [PATCH v3 2/3] tests/migration: fix a typo in comment Mao Zhongyi
2019-10-07 15:09   ` Thomas Huth
2019-10-04  3:43 ` [PATCH v3 3/3] tests/migration:fix unreachable path in stress test Mao Zhongyi
2019-10-04  7:20   ` Laurent Vivier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.