arch_init.c: Always be sure that 'encoded_buf' and 'current_buf' are lock protected
'encoded_buf' and 'current_buf' are lock protected during using in save_xbzrle_page() in ram_save_page(), and during freeing in migration_end().
So recommend to let them lock protected during starting, just like we have done to 'cache'.
--- arch_init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch_init.c +3 -1
@@ -783,12 +783,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque)error_report ("Error creating cache" );return -1 ; } -XBZRLE_cache_unlock ();/* We prefer not to abort if there is no memory */ XBZRLE .encoded_buf =g_try_malloc0 (TARGET_PAGE_SIZE );if (!XBZRLE .encoded_buf) {error_report ("Error allocating encoded_buf" ); +XBZRLE_cache_unlock ();return -1 ; }
@@ -797,8 +797,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque)error_report ("Error allocating current_buf" );g_free (XBZRLE .encoded_buf);XBZRLE .encoded_buf =NULL ; +XBZRLE_cache_unlock ();return -1 ; } +XBZRLE_cache_unlock ();acct_clear (); }
Signature · 1 line
1.7.11.7
Quoted 32 lines · Chen Gang
'
encoded_buf' and 'current_buf' are lock protected during using insave_xbzrle_page()inram_save_page(), and during freeing inmigration_end().So recommend to let them lock protected during starting, just like we have done to 'cache'.
Signed-off-by Chen Gang <[email protected]>--- arch_init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch_init.c +1
-1@@ -783,12 +783,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque)error_report ("Error creating cache" );return -1 ; } -XBZRLE_cache_unlock ();/* We prefer not to abort if there is no memory */ XBZRLE .encoded_buf =g_try_malloc0 (TARGET_PAGE_SIZE );if (!XBZRLE .encoded_buf) {error_report ("Error allocating encoded_buf" ); +XBZRLE_cache_unlock ();return -1 ; }
arch_init.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 806
Quoted 10 lines
arch_init.c +2
-0@@ -797,8 +797,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque)error_report ("Error allocating current_buf" );g_free (XBZRLE .encoded_buf);XBZRLE .encoded_buf =NULL ; +XBZRLE_cache_unlock ();return -1 ; } +XBZRLE_cache_unlock ();acct_clear (); }
It isn't necessary.
Best regards.
ChenLiang
Firstly, thank you very much for reviewing the related 2 patches.
Quoted 42 lines · ChenLiang
Quoted 40 lines · Chen Gang
'
encoded_buf' and 'current_buf' are lock protected during using insave_xbzrle_page()inram_save_page(), and during freeing inmigration_end().So recommend to let them lock protected during starting, just like we have done to 'cache'.
Signed-off-by Chen Gang <[email protected]>--- arch_init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch_init.c +3
-1@@ -783,12 +783,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque)error_report ("Error creating cache" );return -1 ; } -XBZRLE_cache_unlock ();/* We prefer not to abort if there is no memory */ XBZRLE .encoded_buf =g_try_malloc0 (TARGET_PAGE_SIZE );if (!XBZRLE .encoded_buf) {error_report ("Error allocating encoded_buf" ); +XBZRLE_cache_unlock ();return -1 ; }@@ -797,8 +797,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque)error_report ("Error allocating current_buf" );g_free (XBZRLE .encoded_buf);XBZRLE .encoded_buf =NULL ; +XBZRLE_cache_unlock ();return -1 ; } +XBZRLE_cache_unlock ();
Quoted 6 lines
arch_init.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 806
Quoted 2 lines
arch_init.c +0
-0acct_clear (); }It isn't necessary.
For me, it is still necessary to be improved.
- If this code is not performance sensitive:
"always lock protected" will let source code easy understanding for readers, and easy sustainable for maintainers.
- Else (performance sensitive):
Need give related comments to it (e.g. for performance reason, let it out of lock protected). So readers easily understand, and the related maintainers may notice about it at any time.
It is not good to give comments in a function, except the code is not used in normal way.
Thanks.
Signature · 3 lines
Chen Gang Open, share, and attitude like air, water, and life which God blessed
Quoted 6 lines · Chen Gang
'
encoded_buf' and 'current_buf' are lock protected during using insave_xbzrle_page()inram_save_page(), and during freeing inmigration_end().So recommend to let them lock protected during starting, just like we have done to 'cache'.
I'd recommend against routing locking patches through -trivial. The code has maintainers, and you cc'ed them.
Quoted 12 lines · * Chen Gang ([email protected]) wrote:
Firstly, thank you very much for reviewing the related 2 patches.
Quoted 8 lines · ChenLiang
Quoted 6 lines · Chen Gang
'
encoded_buf' and 'current_buf' are lock protected during using insave_xbzrle_page()inram_save_page(), and during freeing inmigration_end().So recommend to let them lock protected during starting, just like we have done to 'cache'.
This isn't one for Trivial - it needs some thought. Locks always need thought.
Quoted 46 lines
Quoted 32 lines
Quoted 32 lines
Signed-off-by Chen Gang <[email protected]>--- arch_init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch_init.c +3
-1@@ -783,12 +783,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque)error_report ("Error creating cache" );return -1 ; } -XBZRLE_cache_unlock ();/* We prefer not to abort if there is no memory */ XBZRLE .encoded_buf =g_try_malloc0 (TARGET_PAGE_SIZE );if (!XBZRLE .encoded_buf) {error_report ("Error allocating encoded_buf" ); +XBZRLE_cache_unlock ();return -1 ; }@@ -797,8 +797,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque)error_report ("Error allocating current_buf" );g_free (XBZRLE .encoded_buf);XBZRLE .encoded_buf =NULL ; +XBZRLE_cache_unlock ();return -1 ; } +XBZRLE_cache_unlock ();Quoted 6 lines
arch_init.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 806
Quoted 2 lines
arch_init.c +0
-0acct_clear (); }It isn't necessary.
For me, it is still necessary to be improved.
- If this code is not performance sensitive:
"always lock protected" will let source code easy understanding for readers, and easy sustainable for maintainers.
Quoted 8 lines
- Else (performance sensitive):
Need give related comments to it (e.g. for performance reason, let it out of lock protected). So readers easily understand, and the related maintainers may notice about it at any time.
It is not good to give comments in a function, except the code is not used in normal way.
I think the locks for the cache were originally there to handle the race between a resize (on the main thread) against the use (in the migration thread). That doesn't happen for the encoded_buf so I don't think we have that problem.
Is there any other case that it could race?
I can't see one - I think all of the other start/end is done within the migration thread.
Dave
Quoted 8 lines
Thanks.
Signature · 3 lines
Chen Gang Open, share, and attitude like air, water, and life which God blessed
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 6 lines · Markus Armbruster
Quoted 4 lines · Chen Gang
'
encoded_buf' and 'current_buf' are lock protected during using insave_xbzrle_page()inram_save_page(), and during freeing inmigration_end().
Quoted 6 lines
Quoted 2 lines
So recommend to let them lock protected during starting, just like we have done to 'cache'.
I'd recommend against routing locking patches through -trivial. The code has maintainers, and you cc'ed them.
OK, I shall remove -trivial for locking patches, next time.
Thanks.
Signature · 3 lines
Chen Gang Open, share, and attitude like air, water, and life which God blessed
Firstly, thank you very much for reviewing the related 2 patches.
Quoted 7 lines · Dr. David Alan Gilbert
Quoted 6 lines · * Chen Gang ([email protected]) wrote:
Firstly, thank you very much for reviewing the related 2 patches.
Quoted 2 lines · ChenLiang
On 2014/6/2 20:35, Chen Gang wrote:
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
'
encoded_buf' and 'current_buf' are lock protected during using insave_xbzrle_page()inram_save_page(), and during freeing inmigration_end().So recommend to let them lock protected during starting, just like we have done to 'cache'.
This isn't one for Trivial - it needs some thought. Locks always need thought.
OK, I shall notice about it next time.
"Locks always need thought", so prefer some 'templates' to simplify thinking, especially for some simple locks (not nested, either not performance sensitive).
Quoted 55 lines
Quoted 46 lines
Quoted 32 lines
Quoted 32 lines
Signed-off-by Chen Gang <[email protected]>--- arch_init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch_init.c +3
-1@@ -783,12 +783,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque)error_report ("Error creating cache" );return -1 ; } -XBZRLE_cache_unlock ();/* We prefer not to abort if there is no memory */ XBZRLE .encoded_buf =g_try_malloc0 (TARGET_PAGE_SIZE );if (!XBZRLE .encoded_buf) {error_report ("Error allocating encoded_buf" ); +XBZRLE_cache_unlock ();return -1 ; }@@ -797,8 +797,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque)error_report ("Error allocating current_buf" );g_free (XBZRLE .encoded_buf);XBZRLE .encoded_buf =NULL ; +XBZRLE_cache_unlock ();return -1 ; } +XBZRLE_cache_unlock ();Quoted 6 lines
arch_init.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 806
Quoted 2 lines
arch_init.c +0
-0acct_clear (); }It isn't necessary.
For me, it is still necessary to be improved.
- If this code is not performance sensitive:
"always lock protected" will let source code easy understanding for readers, and easy sustainable for maintainers.
Quoted 8 lines
- Else (performance sensitive):
Need give related comments to it (e.g. for performance reason, let it out of lock protected). So readers easily understand, and the related maintainers may notice about it at any time.
It is not good to give comments in a function, except the code is not used in normal way.
Quoted 8 lines
I think the locks for the cache were originally there to handle the race between a resize (on the main thread) against the use (in the migration thread). That doesn't happen for the
encoded_bufso I don't think we have that problem.Is there any other case that it could race?
I can't see one - I think all of the other start/end is done within the migration thread.
What you thought and what Chen Liang though are fine to me. But I guess it is a simple lock, if we let them always lock protected, we need not think them more.
One simple lock 'template' can be: "always let it lock protected during its whole life", that will let all related readers and maintainers easy understanding and avoid to think of more.
Our lock is not nested, although I am not quit sure whether it is performance sensitive (I guess not).
Thanks.
Signature · 3 lines
Chen Gang Open, share, and attitude like air, water, and life which God blessed