some fix in tests/migration
v4 cover some fix in tests/migration
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]
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(-)
Signature · 1 line
2.17.1
PATCH v4 1/3 tests/migration: mem leak fix
‘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().
--- tests/migration/stress.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-)
tests/migration/stress.c +2 -19
@@ -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); }
Signature · 1 line
2.17.1
Re: [PATCH v4 1/3] tests/migration: mem leak fix
Le 04/10/2019 à 19:32, Mao Zhongyi a écrit :
Quoted 55 lines
‘data’ has the possibility of memory leaks, so use the glib macros
g_autofreerecommended byCODING_STYLE.rstto automatically release the memory that returned fromg_malloc().Signed-off-by Mao Zhongyi <[email protected]>Reviewed-by Alex Bennée <[email protected]>--- tests/migration/stress.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-)tests/migration/stress.c +2
-16@@ -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 ; }
tests/migration/stress.c static int stressone(unsigned long long ramsizeMB) · line 218
Quoted 9 lines
tests/migration/stress.c +0
-3@@ -227,9 +213,6 @@ static int stressone(unsigned long long ramsizeMB) } } } - -free (data); -free (ram); }
PATCH v4 2/3 tests/migration: fix a typo in comment
In reply to Mao Zhongyi--- tests/migration/stress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/migration/stress.c +1 -1
@@ -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 );
Signature · 1 line
2.17.1
Laurent Vivier
AppliedRe: [PATCH v4 2/3] tests/migration: fix a typo in comment
Le 04/10/2019 à 19:32, Mao Zhongyi a écrit :
Quoted 14 lines
Signed-off-by Mao Zhongyi <[email protected]>Reviewed-by Alex Bennée <[email protected]>Reviewed-by Laurent Vivier <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>--- tests/migration/stress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/migration/stress.c +0
-0
tests/migration/stress.c static int stressone(unsigned long long ramsizeMB) · line 186
Quoted 8 lines
tests/migration/stress.c +1
-1@@ -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
PATCH v4 3/3 tests/migration:fix unreachable path in stress test
In reply to Mao ZhongyiIf 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().
--- tests/migration/stress.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
tests/migration/stress.c +5 -8
@@ -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 (); }
Signature · 1 line
2.17.1
Re: [PATCH v4 3/3] tests/migration:fix unreachable path in stress test
Le 04/10/2019 à 19:32, Mao Zhongyi a écrit :
Quoted 52 lines
If
stressone()orstress()exits it's because of a failure because the test runs forever otherwise, so change stressone and stress type to void to make theexit_failure()as the exit function ofmain().Signed-off-by Mao Zhongyi <[email protected]>--- tests/migration/stress.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)tests/migration/stress.c +3
-5@@ -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 ; }
tests/migration/stress.c int main(int argc, char **argv) · line 339
Quoted 10 lines
tests/migration/stress.c +2
-3@@ -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 (); }
Hi,
patch2 has been merged into the master by Laurent Vivier. patch3 is still not reviewed.
So ping...
Thanks,
Mao
Quoted 38 lines · Mao Zhongyi
This patchset mainly fixes memory leak, typo and return value of stress function in stress test.
v4-v3:
p1:
- remove redundantg_mallocreturn value judgment. [Laurent Vivier]
p3:
- always useexit_failure()as the exit function ofmain(). [Laurent Vivier]
- update the commit message.
v3->v2:
p1:
- replace malloc withg_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:
- useg_autofreeto release memory automatically instead
offree(). [Alex Bennée]Mao Zhongyi (3):
tests/migration: mem leak fix tests/migration: fix a typo in comment tests/migration:fix unreachable path in stress testtests/migration/stress.c | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-)