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.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.22 (GNU/Linux)
 
 iQIcBAABAgAGBQJk7VtOAAoJEN/yI9az/suchasP/j/7DQTggrrB/2lWhB79BTrT
 L+Tgljh9zynrJeL/OjvE7VD3sxDcHQmHprGT7FkdgIdd3fHl8GHnFz8L1CMLg63E
 i/4SY3RFIvmMqMrmBNx77+D6nSfezKrkwmoln7VGjK6rC0s86PRok+Dxf4SaoP1i
 cCeFOq2O0U/im1fQQl0uETqxYAX+StVRhnpWTqpPFBBaVCmCGQx3WWXGXXFOl5PB
 JNLgDX3lxSpSIfRK9vCb61gFe8gMp+5hUDZgfUln9fmXrO6NsVgHEjvsMqm9UZO1
 tNGSh1GNmO2du6m2iCzVChB8bfe9P3g/XAubfRIkqZtWZK8lhz1mVQEg4wJ4VgX1
 uMAi8gzpMV5Rdiy9MWYZW9sCuoiZepksBuGtrFMBXXyCpP76N+uWshfj+/Mp2mt0
 475ZiC4silwCeRDWH4UkTyNQtc7+WVRjZP0ToXuUOSyWFdyRPCQdAIDlUacxk/9p
 BSymBM2P760oa4IMCwhey5/WaFdfFFcMD4e2UwfTpafwY5uwVOTxN23k7+iCivQs
 3RbP8ghvakgNPTO+1HcdoRW/LrjnGn1mZ5qvLj1+f7slP5NEsBDZVEylQJIHjXh4
 oE8OwB/rRexlUGRUuIgMpVeEk8/LcEMy73I+dj/zSkfQEw8KuCp6EUB5HFiciS0/
 IG5X0TdcvAdicG8qmDGx
 =NKkN
 -----END PGP SIGNATURE-----

Merge tag 'dirtylimit-dirtyrate-pull-request' of https://github.com/newfriday/qemu into staging

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.

# -----BEGIN PGP SIGNATURE-----
# Version: GnuPG v2.0.22 (GNU/Linux)
#
# iQIcBAABAgAGBQJk7VtOAAoJEN/yI9az/suchasP/j/7DQTggrrB/2lWhB79BTrT
# L+Tgljh9zynrJeL/OjvE7VD3sxDcHQmHprGT7FkdgIdd3fHl8GHnFz8L1CMLg63E
# i/4SY3RFIvmMqMrmBNx77+D6nSfezKrkwmoln7VGjK6rC0s86PRok+Dxf4SaoP1i
# cCeFOq2O0U/im1fQQl0uETqxYAX+StVRhnpWTqpPFBBaVCmCGQx3WWXGXXFOl5PB
# JNLgDX3lxSpSIfRK9vCb61gFe8gMp+5hUDZgfUln9fmXrO6NsVgHEjvsMqm9UZO1
# tNGSh1GNmO2du6m2iCzVChB8bfe9P3g/XAubfRIkqZtWZK8lhz1mVQEg4wJ4VgX1
# uMAi8gzpMV5Rdiy9MWYZW9sCuoiZepksBuGtrFMBXXyCpP76N+uWshfj+/Mp2mt0
# 475ZiC4silwCeRDWH4UkTyNQtc7+WVRjZP0ToXuUOSyWFdyRPCQdAIDlUacxk/9p
# BSymBM2P760oa4IMCwhey5/WaFdfFFcMD4e2UwfTpafwY5uwVOTxN23k7+iCivQs
# 3RbP8ghvakgNPTO+1HcdoRW/LrjnGn1mZ5qvLj1+f7slP5NEsBDZVEylQJIHjXh4
# oE8OwB/rRexlUGRUuIgMpVeEk8/LcEMy73I+dj/zSkfQEw8KuCp6EUB5HFiciS0/
# IG5X0TdcvAdicG8qmDGx
# =NKkN
# -----END PGP SIGNATURE-----
# gpg: Signature made Mon 28 Aug 2023 22:43:26 EDT
# gpg:                using RSA key DFF223D6B3FECB9C
# gpg: Can't check signature: No public key

* tag 'dirtylimit-dirtyrate-pull-request' of https://github.com/newfriday/qemu:
  migration/dirtyrate: Fix precision losses and g_usleep overshoot
  softmmu/dirtylimit: Convert free to g_free
  softmmu: Fix dirtylimit memory leak

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Stefan Hajnoczi 2023-08-30 09:20:06 -04:00
commit ee89152d41
2 changed files with 20 additions and 16 deletions

View File

@ -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)

View File

@ -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();
@ -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);
}