* [PATCH v4 0/3] some fix in tests/migration
@ 2019-10-04 17:32 Mao Zhongyi
2019-10-04 17:32 ` [PATCH v4 1/3] tests/migration: mem leak fix Mao Zhongyi
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Mao Zhongyi @ 2019-10-04 17:32 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.
v4-v3:
p1:
- remove redundant g_malloc return value judgment.
[Laurent Vivier]
p3:
- always use exit_failure() as the exit function of main().
[Laurent Vivier]
- update the commit message.
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 | 36 ++++++++----------------------------
1 file changed, 8 insertions(+), 28 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v4 1/3] tests/migration: mem leak fix
2019-10-04 17:32 [PATCH v4 0/3] some fix in tests/migration Mao Zhongyi
@ 2019-10-04 17:32 ` Mao Zhongyi
2019-10-23 9:45 ` Laurent Vivier
2019-10-04 17:32 ` [PATCH v4 2/3] tests/migration: fix a typo in comment Mao Zhongyi
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Mao Zhongyi @ 2019-10-04 17:32 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 | 21 ++-------------------
1 file changed, 2 insertions(+), 19 deletions(-)
diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index d9aa4afe92..d8a6f64af0 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -170,26 +170,14 @@ 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;
- if (!ram) {
- fprintf(stderr, "%s (%05d): ERROR: cannot allocate %llu MB of RAM: %s\n",
- argv0, gettid(), ramsizeMB, strerror(errno));
- return -1;
- }
- 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;
- }
-
/* 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
@@ -198,8 +186,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 +213,6 @@ static int stressone(unsigned long long ramsizeMB)
}
}
}
-
- free(data);
- free(ram);
}
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v4 2/3] tests/migration: fix a typo in comment
2019-10-04 17:32 [PATCH v4 0/3] some fix in tests/migration Mao Zhongyi
2019-10-04 17:32 ` [PATCH v4 1/3] tests/migration: mem leak fix Mao Zhongyi
@ 2019-10-04 17:32 ` Mao Zhongyi
2019-10-21 16:15 ` Laurent Vivier
2019-10-04 17:32 ` [PATCH v4 3/3] tests/migration:fix unreachable path in stress test Mao Zhongyi
2019-10-23 3:30 ` [PATCH v4 0/3] some fix in tests/migration maozy
3 siblings, 1 reply; 8+ messages in thread
From: Mao Zhongyi @ 2019-10-04 17:32 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>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
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 d8a6f64af0..f9626d50ee 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -180,7 +180,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] 8+ messages in thread
* [PATCH v4 3/3] tests/migration:fix unreachable path in stress test
2019-10-04 17:32 [PATCH v4 0/3] some fix in tests/migration Mao Zhongyi
2019-10-04 17:32 ` [PATCH v4 1/3] tests/migration: mem leak fix Mao Zhongyi
2019-10-04 17:32 ` [PATCH v4 2/3] tests/migration: fix a typo in comment Mao Zhongyi
@ 2019-10-04 17:32 ` Mao Zhongyi
2019-10-23 8:05 ` Laurent Vivier
2019-10-23 3:30 ` [PATCH v4 0/3] some fix in tests/migration maozy
3 siblings, 1 reply; 8+ messages in thread
From: Mao Zhongyi @ 2019-10-04 17:32 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
and stress type to void to make the exit_failure() as the exit
function of main().
Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
---
tests/migration/stress.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index f9626d50ee..a062ef6b55 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);
@@ -186,7 +186,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();
@@ -225,7 +225,7 @@ static void *stressthread(void *arg)
return NULL;
}
-static int stress(unsigned long long ramsizeGB, int ncpus)
+static void stress(unsigned long long ramsizeGB, int ncpus)
{
size_t i;
unsigned long long ramsizeMB = ramsizeGB * 1024 / ncpus;
@@ -238,8 +238,6 @@ static int stress(unsigned long long ramsizeGB, int ncpus)
}
stressone(ramsizeMB);
-
- return 0;
}
@@ -335,8 +333,7 @@ int main(int argc, char **argv)
fprintf(stdout, "%s (%05d): INFO: RAM %llu GiB across %d CPUs\n",
argv0, gettid(), ramsizeGB, ncpus);
- if (stress(ramsizeGB, ncpus) < 0)
- exit_failure();
+ stress(ramsizeGB, ncpus);
- exit_success();
+ exit_failure();
}
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v4 2/3] tests/migration: fix a typo in comment
2019-10-04 17:32 ` [PATCH v4 2/3] tests/migration: fix a typo in comment Mao Zhongyi
@ 2019-10-21 16:15 ` Laurent Vivier
0 siblings, 0 replies; 8+ messages in thread
From: Laurent Vivier @ 2019-10-21 16:15 UTC (permalink / raw)
To: Mao Zhongyi, qemu-devel; +Cc: tony.nguyen, alex.bennee, armbru
Le 04/10/2019 à 19:32, Mao Zhongyi a écrit :
> 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>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> 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 d8a6f64af0..f9626d50ee 100644
> --- a/tests/migration/stress.c
> +++ b/tests/migration/stress.c
> @@ -180,7 +180,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);
>
Applied to my trivial-patches branch.
Thanks,
Laurent
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 0/3] some fix in tests/migration
2019-10-04 17:32 [PATCH v4 0/3] some fix in tests/migration Mao Zhongyi
` (2 preceding siblings ...)
2019-10-04 17:32 ` [PATCH v4 3/3] tests/migration:fix unreachable path in stress test Mao Zhongyi
@ 2019-10-23 3:30 ` maozy
3 siblings, 0 replies; 8+ messages in thread
From: maozy @ 2019-10-23 3:30 UTC (permalink / raw)
To: qemu-devel; +Cc: tony.nguyen, alex.bennee, armbru, laurent
Hi,
patch2 has been merged into the master by Laurent Vivier.
patch3 is still not reviewed.
So ping...
Thanks,
Mao
On 10/5/19 1:32 AM, Mao Zhongyi wrote:
> This patchset mainly fixes memory leak, typo and return
> value of stress function in stress test.
>
> v4-v3:
> p1:
> - remove redundant g_malloc return value judgment.
> [Laurent Vivier]
> p3:
> - always use exit_failure() as the exit function of main().
> [Laurent Vivier]
> - update the commit message.
>
> 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 | 36 ++++++++----------------------------
> 1 file changed, 8 insertions(+), 28 deletions(-)
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 3/3] tests/migration:fix unreachable path in stress test
2019-10-04 17:32 ` [PATCH v4 3/3] tests/migration:fix unreachable path in stress test Mao Zhongyi
@ 2019-10-23 8:05 ` Laurent Vivier
0 siblings, 0 replies; 8+ messages in thread
From: Laurent Vivier @ 2019-10-23 8:05 UTC (permalink / raw)
To: Mao Zhongyi, qemu-devel; +Cc: tony.nguyen, alex.bennee, armbru
Le 04/10/2019 à 19:32, Mao Zhongyi a écrit :
> If stressone() or stress() exits it's because of a failure
> because the test runs forever otherwise, so change stressone
> and stress type to void to make the exit_failure() as the exit
> function of main().
>
> Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
> ---
> tests/migration/stress.c | 13 +++++--------
> 1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/tests/migration/stress.c b/tests/migration/stress.c
> index f9626d50ee..a062ef6b55 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);
> @@ -186,7 +186,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();
> @@ -225,7 +225,7 @@ static void *stressthread(void *arg)
> return NULL;
> }
>
> -static int stress(unsigned long long ramsizeGB, int ncpus)
> +static void stress(unsigned long long ramsizeGB, int ncpus)
> {
> size_t i;
> unsigned long long ramsizeMB = ramsizeGB * 1024 / ncpus;
> @@ -238,8 +238,6 @@ static int stress(unsigned long long ramsizeGB, int ncpus)
> }
>
> stressone(ramsizeMB);
> -
> - return 0;
> }
>
>
> @@ -335,8 +333,7 @@ int main(int argc, char **argv)
> fprintf(stdout, "%s (%05d): INFO: RAM %llu GiB across %d CPUs\n",
> argv0, gettid(), ramsizeGB, ncpus);
>
> - if (stress(ramsizeGB, ncpus) < 0)
> - exit_failure();
> + stress(ramsizeGB, ncpus);
>
> - exit_success();
> + exit_failure();
> }
>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/3] tests/migration: mem leak fix
2019-10-04 17:32 ` [PATCH v4 1/3] tests/migration: mem leak fix Mao Zhongyi
@ 2019-10-23 9:45 ` Laurent Vivier
0 siblings, 0 replies; 8+ messages in thread
From: Laurent Vivier @ 2019-10-23 9:45 UTC (permalink / raw)
To: Mao Zhongyi, qemu-devel; +Cc: tony.nguyen, alex.bennee, armbru
Le 04/10/2019 à 19:32, 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 | 21 ++-------------------
> 1 file changed, 2 insertions(+), 19 deletions(-)
>
> diff --git a/tests/migration/stress.c b/tests/migration/stress.c
> index d9aa4afe92..d8a6f64af0 100644
> --- a/tests/migration/stress.c
> +++ b/tests/migration/stress.c
> @@ -170,26 +170,14 @@ 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;
>
> - if (!ram) {
> - fprintf(stderr, "%s (%05d): ERROR: cannot allocate %llu MB of RAM: %s\n",
> - argv0, gettid(), ramsizeMB, strerror(errno));
> - return -1;
> - }
> - 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;
> - }
> -
> /* 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
> @@ -198,8 +186,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 +213,6 @@ static int stressone(unsigned long long ramsizeMB)
> }
> }
> }
> -
> - free(data);
> - free(ram);
> }
>
>
>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-10-23 9:49 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-04 17:32 [PATCH v4 0/3] some fix in tests/migration Mao Zhongyi
2019-10-04 17:32 ` [PATCH v4 1/3] tests/migration: mem leak fix Mao Zhongyi
2019-10-23 9:45 ` Laurent Vivier
2019-10-04 17:32 ` [PATCH v4 2/3] tests/migration: fix a typo in comment Mao Zhongyi
2019-10-21 16:15 ` Laurent Vivier
2019-10-04 17:32 ` [PATCH v4 3/3] tests/migration:fix unreachable path in stress test Mao Zhongyi
2019-10-23 8:05 ` Laurent Vivier
2019-10-23 3:30 ` [PATCH v4 0/3] some fix in tests/migration maozy
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).