Dirty page rate and dirty page limit 20230829 patches
The following changes since commit f5fe7c17ac4e309e47e78f0f9761aebc8d2f2c81:
Merge tag 'pull-tcg-20230823-2' of https://gitlab.com/rth7680/qemu into staging (2023-08-28 16:07:04 -0400)
are available in the Git repository at:
https://github.com/newfriday/qemu.git tags/dirtylimit-dirtyrate-pull-request
for you to fetch changes up to 3eb82637fbf8c0471990b59e6733fd4beb1f9939:
migration/dirtyrate: Fix precision losses and g_usleep overshoot (2023-08-29 10:19:03 +0800)
----------------------------------------------------------------
Dirtylimit and dirtyrate 20230829 patches PULL request
Correct memory leaks in dirtylimit and accuracy losses in dirtyrate, respectively; make minor corrections to overshoot and memory deallocation.
This is v3 with a signed tag. Please apply.
Thanks, Yong.
----------------------------------------------------------------
Andrei Gudkov (1):
migration/dirtyrate: Fix precision losses and g_usleep overshoot
alloc.young (2):
softmmu: Fix dirtylimit memory leak
softmmu/dirtylimit: Convert free to g_free
migration/dirtyrate.c | 10 ++++++++-- softmmu/dirtylimit.c | 26 ++++++++++++-------------- 2 files changed, 20 insertions(+), 16 deletions(-)
Signature · 1 line
2.39.1
[PULL 2/3] softmmu/dirtylimit: Convert free to g_free
From: "alloc.young" <[email protected]>
Convert free to g_free to match g_new and g_malloc functions.
Message-Id: <SA1PR11MB67604ECD85AFF34BEB3072F7F5E3A@SA1PR11MB6760.namprd11.prod.outlook.com>
--- softmmu/dirtylimit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
softmmu/dirtylimit.c +5 -5
@@ -100,7 +100,7 @@ static void vcpu_dirty_rate_stat_collect(void) stat.rates[i].dirty_rate; } -free (stat.rates); +g_free (stat.rates); }static void *vcpu_dirty_rate_stat_thread (void *opaque)
@@ -171,10 +171,10 @@ void vcpu_dirty_rate_stat_initialize(void)void vcpu_dirty_rate_stat_finalize (void ) { -free (vcpu_dirty_rate_stat->stat.rates); +g_free (vcpu_dirty_rate_stat->stat.rates); vcpu_dirty_rate_stat->stat.rates =NULL ; -free (vcpu_dirty_rate_stat); +g_free (vcpu_dirty_rate_stat); vcpu_dirty_rate_stat =NULL ; }
@@ -220,10 +220,10 @@ void dirtylimit_state_initialize(void)void dirtylimit_state_finalize (void ) { -free (dirtylimit_state->states); +g_free (dirtylimit_state->states); dirtylimit_state->states =NULL ; -free (dirtylimit_state); +g_free (dirtylimit_state); dirtylimit_state =NULL ;trace_dirtylimit_state_finalize ();
Signature · 1 line
2.39.1
[PULL 1/3] softmmu: Fix dirtylimit memory leak
In reply to Hyman HuangFrom: "alloc.young" <[email protected]>
Fix memory leak in hmp_info_vcpu_dirty_limit,use g_autoptr to handle memory deallocation.
Message-Id: <SA1PR11MB6760B9AB7EAFBDAFB524ED06F5E3A@SA1PR11MB6760.namprd11.prod.outlook.com>
--- softmmu/dirtylimit.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
softmmu/dirtylimit.c +7 -9
@@ -653,7 +653,8 @@ struct DirtyLimitInfoList *qmp_query_vcpu_dirty_limit(Error **errp)void hmp_info_vcpu_dirty_limit (Monitor *mon,const QDict *qdict) { -DirtyLimitInfoList *limit, *head, *info =NULL ; +DirtyLimitInfoList *info; +g_autoptr (DirtyLimitInfoList) head =NULL ;Error *err =NULL ;if (!dirtylimit_in_service ()) {
@@ -661,20 +662,17 @@ void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)return ; } - info =qmp_query_vcpu_dirty_limit (&err); + head =qmp_query_vcpu_dirty_limit (&err);if (err) {hmp_handle_error (mon, err);return ; } - head = info; -for (limit = head; limit !=NULL ; limit = limit->next) { +for (info = head; info !=NULL ; info = info->next) {monitor_printf (mon,"vcpu[%" PRIi64"], limit rate %" PRIi64" (MB/s)," " current rate %" PRIi64" (MB/s)\n" , - limit->value->cpu_index, - limit->value->limit_rate, - limit->value->current_rate); + info->value->cpu_index, + info->value->limit_rate, + info->value->current_rate); } - -g_free (info); }
Signature · 1 line
2.39.1
Re: [PULL 1/3] softmmu: Fix dirtylimit memory leak
Quoted 4 lines · Hyman Huang
From: "alloc.young" <[email protected]>
Fix memory leak in hmp_info_vcpu_dirty_limit,use
g_autoptrto handle memory deallocation.
It does not feel like -stable-worthy, or am I wrong and it should be picked up for -stable?
Thanks,
/mjt
Re: [PULL 1/3] softmmu: Fix dirtylimit memory leak
Quoted 9 lines · Michael Tokarev
Quoted 4 lines · Hyman Huang
From: "alloc.young" <[email protected]>
Fix memory leak in hmp_info_vcpu_dirty_limit,use
g_autoptrto handle memory deallocation.It does not feel like -stable-worthy, or am I wrong and it should be picked up
for -stable?
Since the leak occurs when using the hmp command instead of qmp, which lowers the frequency, it is, in my opinion, somewhat tolerable for the dirtylimit feature.
It is undoubtedly not -stable-worthy for the memory leak issue by itself, which is regrettable. :( And the valgrind tool would be applied as much as possible for my further work.
Thanks,
Yong
Quoted 4 lines
Thanks,
/mjt
Signature · 1 line
Best regards
[PULL 3/3] migration/dirtyrate: Fix precision losses and g_usleep overshoot
In reply to Hyman HuangFrom: Andrei Gudkov <[email protected]>
Message-Id: <8ddb0d40d143f77aab8f602bd494e01e5fa01614.1691161009.git.gudkov.andrei@huawei.com>
--- migration/dirtyrate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
migration/dirtyrate.c +8 -2
@@ -57,6 +57,8 @@ static int64_t dirty_stat_wait(int64_t msec, int64_t initial_time) msec = current_time - initial_time; }else {g_usleep ((msec + initial_time - current_time) *1000 ); +/* g_usleep may overshoot */ + msec =qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) - initial_time; }return msec;
@@ -77,9 +79,13 @@ static int64_t do_calculate_dirtyrate(DirtyPageRecord dirty_pages, {uint64_t increased_dirty_pages = dirty_pages.end_pages - dirty_pages.start_pages; -uint64_t memory_size_MiB =qemu_target_pages_to_MiB (increased_dirty_pages); -return memory_size_MiB *1000 / calc_time_ms; +/* +* multiply by 1000ms/s _before_ converting down to megabytes +* to avoid losing precision +*/ +return qemu_target_pages_to_MiB (increased_dirty_pages *1000 ) / + calc_time_ms; }void global_dirty_log_change (unsigned int flag,bool start)
Signature · 1 line
2.39.1
Stefan Hajnoczi
AppliedApplied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/8.2 for any user-visible changes.