Skip to contentSkip to conversation

support dirty restraint on vCPU

PATCH Superseded [email protected] 3 participants 13 messages Nov 30, 2021 – Dec 3, 2021

v7 of 25 Superseded Latest is v25 →

lore
Share & tools
lore
#0 lore raw

v7 cover support dirty restraint on vCPU

From: Hyman Huang(黄勇) <[email protected]>

The patch [2/3] has not been touched so far. Any corrections and suggetions are welcome.

Please review, thanks!

v7:
- rebase on master
- polish the comments and error message according to the advices given by Markus
- introduce dirtylimit_enabled function to pre-check if dirty page limit is enabled before canceling.

v6:
- rebase on master
- fix dirtylimit setup crash found by Markus
- polish the comments according to the advice given by Markus
- adjust the qemu qmp command tag to 7.0

v5:
- rebase on master
- adjust the throttle algorithm by removing the tuning in RESTRAINT_RATIO case so that dirty page rate could reachs the quota more quickly.
- fix percentage update in throttle iteration.

v4:
- rebase on master
- modify the following points according to the advice given by Markus
1. move the defination into migration.json
2. polish the comments of set-dirty-limit
3. do the syntax check and change dirty rate to dirty page rate

Thanks for the carefule reviews made by Markus.

Please review, thanks!

v3:
- rebase on master
- modify the following points according to the advice given by Markus
1. remove the DirtyRateQuotaVcpu and use its field as option directly
2. add comments to show details of what dirtylimit setup do
3. explain how to use dirtylimit in combination with existing qmp commands "calc-dirty-rate" and "query-dirty-rate" in documentation.

Thanks for the carefule reviews made by Markus.

Please review, thanks!

Hyman

v2:
- rebase on master
- modify the following points according to the advices given by Juan
1. rename dirtyrestraint to dirtylimit
2. implement the full lifecyle function of dirtylimit_calc, include dirtylimit_calc and dirtylimit_calc_quit
3. introduce 'quit' field in dirtylimit_calc_state to implement the dirtylimit_calc_quit
4. remove the ready_cond and ready_mtx since it may not be suitable
5. put the 'record_dirtypage' function code at the beggining of the file
6. remove the unnecesary return;
- other modifications has been made after code review
1. introduce 'bmap' and 'nr' field in dirtylimit_state to record the number of running thread forked by dirtylimit
2. stop the dirtyrate calculation thread if all the dirtylimit thread are stopped
3. do some renaming works

     dirtyrate calulation thread -> dirtylimit-calc
     dirtylimit thread -> dirtylimit-{cpu_index}
     function name do_dirtyrestraint -> dirtylimit_check
     qmp command dirty-restraint -> set-drity-limit
     qmp command dirty-restraint-cancel -> cancel-dirty-limit
     header file dirtyrestraint.h -> dirtylimit.h

Please review, thanks !

thanks for the accurate and timely advices given by Juan. we really appreciate it if corrections and suggetions about this patchset are proposed.

Best Regards !

Hyman

v1:
this patchset introduce a mechanism to impose dirty restraint on vCPU, aiming to keep the vCPU running in a certain dirtyrate given by user. dirty restraint on vCPU maybe an alternative method to implement convergence logic for live migration, which could improve guest memory performance during migration compared with traditional method in theory.

For the current live migration implementation, the convergence logic throttles all vCPUs of the VM, which has some side effects. -'read processes' on vCPU will be unnecessarily penalized
- throttle increase percentage step by step, which seems struggling to find the optimal throttle percentage when dirtyrate is high.
- hard to predict the remaining time of migration if the throttling percentage reachs 99%

to a certain extent, the dirty restraint machnism can fix these effects by throttling at vCPU granularity during migration.

the implementation is rather straightforward, we calculate vCPU dirtyrate via the Dirty Ring mechanism periodically as the commit 0e21bf246 "implement dirty-ring dirtyrate calculation" does, for vCPU that be specified to impose dirty restraint, we throttle it periodically as the auto-converge does, once after throttling, we compare the quota dirtyrate with current dirtyrate, if current dirtyrate is not under the quota, increase the throttling percentage until current dirtyrate is under the quota.

this patchset is the basis of implmenting a new auto-converge method for live migration, we introduce two qmp commands for impose/cancel the dirty restraint on specified vCPU, so it also can be an independent api to supply the upper app such as libvirt, which can use it to implement the convergence logic during live migration, supplemented with the qmp 'calc-dirty-rate' command or whatever.

we post this patchset for RFC and any corrections and suggetions about the implementation, api, throttleing algorithm or whatever are very appreciated!

Please review, thanks !

Best Regards !

Hyman Huang (3):
migration/dirtyrate: implement vCPU dirtyrate calculation periodically
cpu-throttle: implement vCPU throttle
cpus-common: implement dirty page limit on vCPU

 cpus-common.c                 |  48 +++++++
 include/exec/memory.h         |   5 +-
 include/hw/core/cpu.h         |   9 ++
 include/sysemu/cpu-throttle.h |  30 ++++
 include/sysemu/dirtylimit.h   |  44 ++++++
 migration/dirtyrate.c         | 139 +++++++++++++++++--
 migration/dirtyrate.h         |   2 +
 qapi/migration.json           |  43 ++++++
 softmmu/cpu-throttle.c        | 316 ++++++++++++++++++++++++++++++++++++++++++
 softmmu/trace-events          |   5 +
 softmmu/vl.c                  |   1 +
 11 files changed, 631 insertions(+), 11 deletions(-)
 create mode 100644 include/sysemu/dirtylimit.h
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v7 1/3 migration/dirtyrate: implement vCPU dirtyrate calculation periodically

From: Hyman Huang(黄勇) <[email protected]>

Introduce the third method GLOBAL_DIRTY_LIMIT of dirty tracking for calculate dirtyrate periodly for dirty restraint.

Implement thread for calculate dirtyrate periodly, which will be used for dirty restraint.

Add dirtylimit.h to introduce the util function for dirty limit implementation.

---
 include/exec/memory.h       |   5 +-
 include/sysemu/dirtylimit.h |  44 ++++++++++++++
 migration/dirtyrate.c       | 139 ++++++++++++++++++++++++++++++++++++++++----
 migration/dirtyrate.h       |   2 +
 4 files changed, 179 insertions(+), 11 deletions(-)
 create mode 100644 include/sysemu/dirtylimit.h
include/exec/memory.h +4 -1
index 20f1b27..606bec8 100644
@@ -69,7 +69,10 @@ static inline void fuzz_dma_read_cb(size_t addr,
 /* Dirty tracking enabled because measuring dirty rate */
 #define GLOBAL_DIRTY_DIRTY_RATE (1U << 1)
 
-#define GLOBAL_DIRTY_MASK  (0x3)
+/* Dirty tracking enabled because dirty limit */
+#define GLOBAL_DIRTY_LIMIT      (1U << 2)
+
+#define GLOBAL_DIRTY_MASK  (0x7)
 
 extern unsigned int global_dirty_tracking;
 
include/sysemu/dirtylimit.h new file +44 -0

44 lines not on this page · raw message

migration/dirtyrate.c +129 -10

157 lines not on this page · raw message

migration/dirtyrate.h +2 -0
index 69d4c5b..e96acdc 100644
@@ -70,6 +70,8 @@ typedef struct VcpuStat {
     DirtyRateVcpu *rates; /* array of dirty rate for each vcpu */
 } VcpuStat;
 
+typedef struct VcpuStat DirtyRatesData;
+
 /*
  * Store calculation statistics for each measure.
  */
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH v7 1/3] migration/dirtyrate: implement vCPU dirtyrate calculation periodically

Quoted 13 lines · On Tue, Nov 30, 2021 at 06:28:11PM +0800, [email protected] wrote:
migration/dirtyrate.c +13 -0
+static void dirtylimit_calc_func(void)
+{
+    CPUState *cpu;
+    DirtyPageRecord *dirty_pages;
+    int64_t start_time, end_time, calc_time;
+    DirtyRateVcpu rate;
+    int i = 0;
+
+    dirty_pages = g_malloc0(sizeof(*dirty_pages) *
+        dirtylimit_calc_state->data.nvcpu);
+
+    dirtylimit_global_dirty_log_start();
+

migration/dirtyrate.c static struct DirtyRateStat DirtyStat; · line 105

Quoted 10 lines
migration/dirtyrate.c +10 -0
+    CPU_FOREACH(cpu) {
+        record_dirtypages(dirty_pages, cpu, true);
+    }
+
+    start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+    g_usleep(DIRTYLIMIT_CALC_TIME_MS * 1000);
+    end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+    calc_time = end_time - start_time;
+
+    dirtylimit_global_dirty_log_stop();

I haven't looked into the details, but.. I'm wondering whether we should just keep the dirty ring enabled during the whole process of throttling.

start/stop can be expensive, especially when huge pages are used, start dirty tracking will start to do huge page split. While right after the "stop" all the huge pages will need to be rebuild again.

David from Google is even proposing a kernel change to eagerly splitting huge pages when dirty tracking is enabled.

So I think we can keep the dirty tracking enabled until all the vcpu throttles are stopped.

Quoted 4 lines
migration/dirtyrate.c +4 -0
+
+    CPU_FOREACH(cpu) {
+        record_dirtypages(dirty_pages, cpu, false);
+    }
Signature · 1 line
Peter Xu
#3 lore raw

Re: [PATCH v7 1/3] migration/dirtyrate: implement vCPU dirtyrate calculation periodically

Quoted 32 lines · Peter Xu
Quoted 13 lines · On Tue, Nov 30, 2021 at 06:28:11PM +0800, [email protected] wrote:
migration/dirtyrate.c +13 -0
+static void dirtylimit_calc_func(void)
+{
+    CPUState *cpu;
+    DirtyPageRecord *dirty_pages;
+    int64_t start_time, end_time, calc_time;
+    DirtyRateVcpu rate;
+    int i = 0;
+
+    dirty_pages = g_malloc0(sizeof(*dirty_pages) *
+        dirtylimit_calc_state->data.nvcpu);
+
+    dirtylimit_global_dirty_log_start();
+

migration/dirtyrate.c static struct DirtyRateStat DirtyStat; · line 105

Quoted 10 lines
migration/dirtyrate.c +10 -0
+    CPU_FOREACH(cpu) {
+        record_dirtypages(dirty_pages, cpu, true);
+    }
+
+    start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+    g_usleep(DIRTYLIMIT_CALC_TIME_MS * 1000);
+    end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+    calc_time = end_time - start_time;
+
+    dirtylimit_global_dirty_log_stop();

I haven't looked into the details, but.. I'm wondering whether we should just keep the dirty ring enabled during the whole process of throttling.

start/stop can be expensive, especially when huge pages are used, start dirty tracking will start to do huge page split. While right after the "stop" all the huge pages will need to be rebuild again.

Quoted 5 lines

David from Google is even proposing a kernel change to eagerly splitting huge pages when dirty tracking is enabled.

So I think we can keep the dirty tracking enabled until all the vcpu throttles are stopped.

Yes, it's a good idea and i'll try this out next version.

Quoted 6 lines
Quoted 5 lines
migration/dirtyrate.c +4 -0
+
+    CPU_FOREACH(cpu) {
+        record_dirtypages(dirty_pages, cpu, false);
+    }
Signature · 2 lines
Best Regards
Hyman Huang(黄勇)
#4 lore raw

PATCH v7 2/3 cpu-throttle: implement vCPU throttle

In reply to [email protected]

From: Hyman Huang(黄勇) <[email protected]>

Impose dirty restraint on vCPU by kicking it and sleep as the auto-converge does during migration, but just kick the specified vCPU instead, not all vCPUs of vm.

Start a thread to track the dirtylimit status and adjust the throttle pencentage dynamically depend on current and quota dirtyrate.

Introduce the util function in the header for dirtylimit implementation.

---
 include/sysemu/cpu-throttle.h |  30 ++++
 softmmu/cpu-throttle.c        | 316 ++++++++++++++++++++++++++++++++++++++++++
 softmmu/trace-events          |   5 +
 3 files changed, 351 insertions(+)
include/sysemu/cpu-throttle.h +30 -0
index d65bdef..334e5e2 100644
@@ -65,4 +65,34 @@ bool cpu_throttle_active(void);
  */
 int cpu_throttle_get_percentage(void);
 
+/**
+ * dirtylimit_enabled
+ *
+ * Returns: %true if dirty page limit for vCPU is enabled, %false otherwise.
+ */
+bool dirtylimit_enabled(int cpu_index);
+
+/**
+ * dirtylimit_state_init:
+ *
+ * initialize golobal state for dirtylimit
+ */
+void dirtylimit_state_init(int max_cpus);
+
+/**
+ * dirtylimit_vcpu:
+ *
+ * impose dirtylimit on vcpu util reaching the quota dirtyrate
+ */
+void dirtylimit_vcpu(int cpu_index,
+                     uint64_t quota);
+/**
+ * dirtylimit_cancel_vcpu:
+ *
+ * cancel dirtylimit for the specified vcpu
+ *
+ * Returns: the number of running threads for dirtylimit
+ */
+int dirtylimit_cancel_vcpu(int cpu_index);
+
 #endif /* SYSEMU_CPU_THROTTLE_H */
softmmu/cpu-throttle.c +316 -0

328 lines not on this page · raw message

softmmu/trace-events +5 -0
index 9c88887..a7c9c04 100644
@@ -31,3 +31,8 @@ runstate_set(int current_state, const char *current_state_str, int new_state, co
 system_wakeup_request(int reason) "reason=%d"
 qemu_system_shutdown_request(int reason) "reason=%d"
 qemu_system_powerdown_request(void) ""
+
+#cpu-throttle.c
+dirtylimit_state_init(int max_cpus) "dirtylimit state init: max cpus %d"
+dirtylimit_impose(int cpu_index, uint64_t quota, uint64_t current, int pct) "CPU[%d] impose dirtylimit: quota %" PRIu64 ", current %" PRIu64 ", percentage %d"
+dirtylimit_vcpu(int cpu_index, uint64_t quota) "CPU[%d] set quota dirtylimit %"PRIu64
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v7 3/3 cpus-common: implement dirty page limit on vCPU

In reply to [email protected]

From: Hyman Huang(黄勇) <[email protected]>

Implement dirtyrate calculation periodically basing on dirty-ring and throttle vCPU until it reachs the quota dirty page rate given by user.

Introduce qmp commands set-dirty-limit/cancel-dirty-limit to set/cancel dirty page limit on vCPU.

---
 cpus-common.c         | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/core/cpu.h |  9 +++++++++
 qapi/migration.json   | 43 +++++++++++++++++++++++++++++++++++++++++++
 softmmu/vl.c          |  1 +
 4 files changed, 101 insertions(+)
cpus-common.c +48 -0
index 6e73d3e..86c7712 100644
@@ -23,6 +23,11 @@
 #include "hw/core/cpu.h"
 #include "sysemu/cpus.h"
 #include "qemu/lockable.h"
+#include "sysemu/dirtylimit.h"
+#include "sysemu/cpu-throttle.h"
+#include "sysemu/kvm.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-migration.h"
 
 static QemuMutex qemu_cpu_list_lock;
 static QemuCond exclusive_cond;
@@ -352,3 +357,46 @@ void process_queued_cpu_work(CPUState *cpu)
     qemu_mutex_unlock(&cpu->work_mutex);
     qemu_cond_broadcast(&qemu_work_cond);
 }
+
+void qmp_set_dirty_limit(int64_t idx,
+                         uint64_t dirtyrate,
+                         Error **errp)
+{
+    if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
+        error_setg(errp, "setting a dirty page limit requires KVM with"
+                   " accelerator property 'dirty-ring-size' set'");
+        return;
+    }
+
+    dirtylimit_calc();
+    dirtylimit_vcpu(idx, dirtyrate);
+}
+
+void qmp_cancel_dirty_limit(int64_t idx,
+                            Error **errp)
+{
+    if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
+        error_setg(errp, "KVM with accelerator property 'dirty-ring-size'"
+                   " not set, abort canceling a dirty page limit");
+        return;
+    }
+
+    if (!dirtylimit_enabled(idx)) {
+        error_setg(errp, "dirty page limit for the CPU %ld not set", idx);
+        return;
+    }
+
+    if (unlikely(!dirtylimit_cancel_vcpu(idx))) {
+        dirtylimit_calc_quit();
+    }
+}
+
+void dirtylimit_setup(int max_cpus)
+{
+    if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
+        return;
+    }
+
+    dirtylimit_calc_state_init(max_cpus);
+    dirtylimit_state_init(max_cpus);
+}
include/hw/core/cpu.h +9 -0
index e948e81..11df012 100644
@@ -881,6 +881,15 @@ void end_exclusive(void);
  */
 void qemu_init_vcpu(CPUState *cpu);
 
+/**
+ * dirtylimit_setup:
+ *
+ * Initializes the global state of dirtylimit calculation and
+ * dirtylimit itself. This is prepared for vCPU dirtylimit which
+ * could be triggered during vm lifecycle.
+ */
+void dirtylimit_setup(int max_cpus);
+
 #define SSTEP_ENABLE  0x1  /* Enable simulated HW single stepping */
 #define SSTEP_NOIRQ   0x2  /* Do not use IRQ while single stepping */
 #define SSTEP_NOTIMER 0x4  /* Do not Timers while single stepping */
qapi/migration.json +43 -0

49 lines not on this page · raw message

softmmu/vl.c +1 -0
index 620a1f1..0f83ce3 100644
@@ -3777,5 +3777,6 @@ void qemu_init(int argc, char **argv, char **envp)
     qemu_init_displays();
     accel_setup_post(current_machine);
     os_setup_post();
+    dirtylimit_setup(current_machine->smp.max_cpus);
     resume_mux_open();
 }
Signature · 1 line
1.8.3.1
#6 lore raw

Re: [PATCH v7 3/3] cpus-common: implement dirty page limit on vCPU

Quoted 32 lines · On Tue, Nov 30, 2021 at 06:28:13PM +0800, [email protected] wrote:

##

qapi/migration.json +31 -0
+# @set-dirty-limit:
+#
+# Set the upper limit of dirty page rate for a virtual CPU.
+#
+# Requires KVM with accelerator property "dirty-ring-size" set.
+# A virtual CPU's dirty page rate is a measure of its memory load.
+# To observe dirty page rates, use @calc-dirty-rate.
+#
+# @cpu-index: index of the virtual CPU.
+#
+# @dirty-rate: upper limit for the specified vCPU's dirty page rate (MB/s)
+#
+# Since: 7.0
+#
+# Example:
+#   {"execute": "set-dirty-limit"}
+#    "arguments": { "cpu-index": 0,
+#                   "dirty-rate": 200 } }
+#
+##
+{ 'command': 'set-dirty-limit',
+  'data': { 'cpu-index': 'int', 'dirty-rate': 'uint64' } }
+
+##
+# @cancel-dirty-limit:
+#
+# Cancel the dirty page limit for the vCPU which has been set with
+# set-dirty-limit command. Note that this command requires support from
+# dirty ring, same as the "set-dirty-limit" command.
+#
+# @cpu-index: index of the virtual CPU to cancel the dirty page limit

qapi/migration.json line 1893

Quoted 10 lines
qapi/migration.json +10 -0
+#
+# Since: 7.0
+#
+# Example:
+#   {"execute": "cancel-dirty-limit"}
+#    "arguments": { "cpu-index": 0 } }
+#
+##
+{ 'command': 'cancel-dirty-limit',
+  'data': { 'cpu-index': 'int' } }

This seems to be overloaded to be a standalone cmd..

How about:

  { "cmd": "vcpu-dirty-limit",
    "arguments": {
      "cpu": $cpu,
      "enable": true/false,
      "dirty-rate": 100,
    }
  }

If "enable"==false, then "dirty-rate" can be ignored and it'll shut down the throttling on vcpu N. Then this command will literally merge the two you proposed.

It'll be nice if we provide yet another command:

  { "cmd": "query-vcpu-dirty-limit",
    "arguments": {
      "*cpu": $cpu,
    }
  }

When $cpu is specified, we return (cpu=$cpu, real_dirty_rate, target_dirty_rate) for this vcpu. When $cpu is not specified, we return an array of that containing all the vcpus.

It'll be nicer to enhance the output of the query command to e.g. have a global "enabled"=true/false as long as any vcpu has throttle enabled then the global throttle is enabled. I didn't think more than that, but how's that sound so far?

Thanks,

Signature · 1 line
Peter Xu
#7 lore raw

Re: [PATCH v7 3/3] cpus-common: implement dirty page limit on vCPU

Quoted 68 lines · Peter Xu
Quoted 32 lines · On Tue, Nov 30, 2021 at 06:28:13PM +0800, [email protected] wrote:

##

qapi/migration.json +31 -0
+# @set-dirty-limit:
+#
+# Set the upper limit of dirty page rate for a virtual CPU.
+#
+# Requires KVM with accelerator property "dirty-ring-size" set.
+# A virtual CPU's dirty page rate is a measure of its memory load.
+# To observe dirty page rates, use @calc-dirty-rate.
+#
+# @cpu-index: index of the virtual CPU.
+#
+# @dirty-rate: upper limit for the specified vCPU's dirty page rate (MB/s)
+#
+# Since: 7.0
+#
+# Example:
+#   {"execute": "set-dirty-limit"}
+#    "arguments": { "cpu-index": 0,
+#                   "dirty-rate": 200 } }
+#
+##
+{ 'command': 'set-dirty-limit',
+  'data': { 'cpu-index': 'int', 'dirty-rate': 'uint64' } }
+
+##
+# @cancel-dirty-limit:
+#
+# Cancel the dirty page limit for the vCPU which has been set with
+# set-dirty-limit command. Note that this command requires support from
+# dirty ring, same as the "set-dirty-limit" command.
+#
+# @cpu-index: index of the virtual CPU to cancel the dirty page limit

qapi/migration.json line 1893

Quoted 10 lines
qapi/migration.json +10 -0
+#
+# Since: 7.0
+#
+# Example:
+#   {"execute": "cancel-dirty-limit"}
+#    "arguments": { "cpu-index": 0 } }
+#
+##
+{ 'command': 'cancel-dirty-limit',
+  'data': { 'cpu-index': 'int' } }

This seems to be overloaded to be a standalone cmd..

How about:

   { "cmd": "vcpu-dirty-limit",
     "arguments": {
       "cpu": $cpu,
       "enable": true/false,
       "dirty-rate": 100,
     }
   }

If "enable"==false, then "dirty-rate" can be ignored and it'll shut down the throttling on vcpu N. Then this command will literally merge the two you proposed.

It'll be nice if we provide yet another command:

   { "cmd": "query-vcpu-dirty-limit",
     "arguments": {
       "*cpu": $cpu,
     }
   }
Quoted 8 lines

When $cpu is specified, we return (cpu=$cpu, real_dirty_rate, target_dirty_rate) for this vcpu. When $cpu is not specified, we return an array of that containing all the vcpus.

It'll be nicer to enhance the output of the query command to e.g. have a global "enabled"=true/false as long as any vcpu has throttle enabled then the global throttle is enabled. I didn't think more than that, but how's that sound so far?

Soud good, it makes the command easier for programmers to use and understand, i'll try this out next version.

Quoted 3 lines

Thanks,

Signature · 2 lines
Best Regards
Hyman Huang(黄勇)
Acked-by on v7 3/3
#8 lore raw

Re: [PATCH v7 3/3] cpus-common: implement dirty page limit on vCPU

In reply to [email protected]
Quoted 50 lines · [email protected] writes:

From: Hyman Huang(黄勇) <[email protected]>

Implement dirtyrate calculation periodically basing on dirty-ring and throttle vCPU until it reachs the quota dirty page rate given by user.

Introduce qmp commands set-dirty-limit/cancel-dirty-limit to set/cancel dirty page limit on vCPU.

---
 cpus-common.c         | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/core/cpu.h |  9 +++++++++
 qapi/migration.json   | 43 +++++++++++++++++++++++++++++++++++++++++++
 softmmu/vl.c          |  1 +
 4 files changed, 101 insertions(+)
cpus-common.c +18 -0
index 6e73d3e..86c7712 100644
@@ -23,6 +23,11 @@
 #include "hw/core/cpu.h"
 #include "sysemu/cpus.h"
 #include "qemu/lockable.h"
+#include "sysemu/dirtylimit.h"
+#include "sysemu/cpu-throttle.h"
+#include "sysemu/kvm.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-migration.h"
 
 static QemuMutex qemu_cpu_list_lock;
 static QemuCond exclusive_cond;
@@ -352,3 +357,46 @@ void process_queued_cpu_work(CPUState *cpu)
     qemu_mutex_unlock(&cpu->work_mutex);
     qemu_cond_broadcast(&qemu_work_cond);
 }
+
+void qmp_set_dirty_limit(int64_t idx,
+                         uint64_t dirtyrate,
+                         Error **errp)
+{
+    if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
+        error_setg(errp, "setting a dirty page limit requires KVM with"
+                   " accelerator property 'dirty-ring-size' set'");
+        return;
+    }
+
+    dirtylimit_calc();
+    dirtylimit_vcpu(idx, dirtyrate);

cpus-common.c void process_queued_cpu_work(CPUState *cpu) · line 382

Quoted 10 lines
cpus-common.c +10 -0
+}
+
+void qmp_cancel_dirty_limit(int64_t idx,
+                            Error **errp)
+{
+    if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
+        error_setg(errp, "KVM with accelerator property 'dirty-ring-size'"
+                   " not set, abort canceling a dirty page limit");
+        return;
+    }

Is this check actually needed? It's not when !dirtylimit_enabled(idx).

cpus-common.c void process_queued_cpu_work(CPUState *cpu) · line 385

Quoted 3 lines
cpus-common.c +3 -0
+
+    if (!dirtylimit_enabled(idx)) {
+        error_setg(errp, "dirty page limit for the CPU %ld not set", idx);

"for CPU"

cpus-common.c void process_queued_cpu_work(CPUState *cpu) · line 389

Quoted 4 lines
cpus-common.c +4 -0
+        return;
+    }
+
+    if (unlikely(!dirtylimit_cancel_vcpu(idx))) {

I don't think unlikely() matters here.

Quoted 62 lines
cpus-common.c +13 -0
+        dirtylimit_calc_quit();
+    }
+}
+
+void dirtylimit_setup(int max_cpus)
+{
+    if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
+        return;
+    }
+
+    dirtylimit_calc_state_init(max_cpus);
+    dirtylimit_state_init(max_cpus);
+}
include/hw/core/cpu.h +9 -0
index e948e81..11df012 100644
@@ -881,6 +881,15 @@ void end_exclusive(void);
  */
 void qemu_init_vcpu(CPUState *cpu);
 
+/**
+ * dirtylimit_setup:
+ *
+ * Initializes the global state of dirtylimit calculation and
+ * dirtylimit itself. This is prepared for vCPU dirtylimit which
+ * could be triggered during vm lifecycle.
+ */
+void dirtylimit_setup(int max_cpus);
+
 #define SSTEP_ENABLE  0x1  /* Enable simulated HW single stepping */
 #define SSTEP_NOIRQ   0x2  /* Do not use IRQ while single stepping */
 #define SSTEP_NOTIMER 0x4  /* Do not Timers while single stepping */
qapi/migration.json +21 -0
index bbfd48c..57c9a63 100644
@@ -1850,6 +1850,49 @@
 { 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' }
 
 ##
+# @set-dirty-limit:
+#
+# Set the upper limit of dirty page rate for a virtual CPU.
+#
+# Requires KVM with accelerator property "dirty-ring-size" set.
+# A virtual CPU's dirty page rate is a measure of its memory load.
+# To observe dirty page rates, use @calc-dirty-rate.
+#
+# @cpu-index: index of the virtual CPU.
+#
+# @dirty-rate: upper limit for the specified vCPU's dirty page rate (MB/s)
+#
+# Since: 7.0
+#
+# Example:
+#   {"execute": "set-dirty-limit"}
+#    "arguments": { "cpu-index": 0,
+#                   "dirty-rate": 200 } }
+#
+##
+{ 'command': 'set-dirty-limit',

qapi/migration.json line 1883

Quoted 10 lines
qapi/migration.json +10 -0
+  'data': { 'cpu-index': 'int', 'dirty-rate': 'uint64' } }
+
+##
+# @cancel-dirty-limit:
+#
+# Cancel the dirty page limit for the vCPU which has been set with
+# set-dirty-limit command. Note that this command requires support from
+# dirty ring, same as the "set-dirty-limit" command.
+#
+# @cpu-index: index of the virtual CPU to cancel the dirty page limit

I'd go with

# @cpu-index: index of the virtual CPU.

Quoted 20 lines
qapi/migration.json +12 -0
+#
+# Since: 7.0
+#
+# Example:
+#   {"execute": "cancel-dirty-limit"}
+#    "arguments": { "cpu-index": 0 } }
+#
+##
+{ 'command': 'cancel-dirty-limit',
+  'data': { 'cpu-index': 'int' } }
+
+##
 # @snapshot-save:
 #
 # Save a VM snapshot
softmmu/vl.c +0 -0
index 620a1f1..0f83ce3 100644

softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 3782

Quoted 6 lines
softmmu/vl.c +1 -0
@@ -3777,5 +3777,6 @@ void qemu_init(int argc, char **argv, char **envp)
     qemu_init_displays();
     accel_setup_post(current_machine);
     os_setup_post();
+    dirtylimit_setup(current_machine->smp.max_cpus);
     resume_mux_open();
 }

QAPI schema:

#9 lore raw

Re: [PATCH v7 3/3] cpus-common: implement dirty page limit on vCPU

Quoted 56 lines · Markus Armbruster
Quoted 54 lines · [email protected] writes:

From: Hyman Huang(黄勇) <[email protected]>

Implement dirtyrate calculation periodically basing on dirty-ring and throttle vCPU until it reachs the quota dirty page rate given by user.

Introduce qmp commands set-dirty-limit/cancel-dirty-limit to set/cancel dirty page limit on vCPU.

---
  cpus-common.c         | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
  include/hw/core/cpu.h |  9 +++++++++
  qapi/migration.json   | 43 +++++++++++++++++++++++++++++++++++++++++++
  softmmu/vl.c          |  1 +
  4 files changed, 101 insertions(+)
cpus-common.c +22 -0
index 6e73d3e..86c7712 100644
@@ -23,6 +23,11 @@
  #include "hw/core/cpu.h"
  #include "sysemu/cpus.h"
  #include "qemu/lockable.h"
+#include "sysemu/dirtylimit.h"
+#include "sysemu/cpu-throttle.h"
+#include "sysemu/kvm.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-migration.h"
 
  static QemuMutex qemu_cpu_list_lock;
  static QemuCond exclusive_cond;
@@ -352,3 +357,46 @@ void process_queued_cpu_work(CPUState *cpu)
      qemu_mutex_unlock(&cpu->work_mutex);
      qemu_cond_broadcast(&qemu_work_cond);
  }
+
+void qmp_set_dirty_limit(int64_t idx,
+                         uint64_t dirtyrate,
+                         Error **errp)
+{
+    if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
+        error_setg(errp, "setting a dirty page limit requires KVM with"
+                   " accelerator property 'dirty-ring-size' set'");
+        return;
+    }
+
+    dirtylimit_calc();
+    dirtylimit_vcpu(idx, dirtyrate);
+}
+
+void qmp_cancel_dirty_limit(int64_t idx,
+                            Error **errp)
Quoted 8 lines

cpus-common.c void process_queued_cpu_work(CPUState *cpu) · line 382

Quoted 6 lines
cpus-common.c +6 -0
+{
+    if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
+        error_setg(errp, "KVM with accelerator property 'dirty-ring-size'"
+                   " not set, abort canceling a dirty page limit");
+        return;
+    }

Is this check actually needed? It's not when !dirtylimit_enabled(idx).

The logic never go there if user follows the enable/disable step, but just in case one call the qmp "cancel-dirty-limit" only. Anyway, the set/cancel has been merged into one in latest version. And we do check before doing anything in both case.

Quoted 5 lines

cpus-common.c void process_queued_cpu_work(CPUState *cpu) · line 385

Quoted 4 lines
cpus-common.c +3 -0
+
+    if (!dirtylimit_enabled(idx)) {
+        error_setg(errp, "dirty page limit for the CPU %ld not set", idx);
Quoted 8 lines

"for CPU"

cpus-common.c void process_queued_cpu_work(CPUState *cpu) · line 389

Quoted 4 lines
cpus-common.c +4 -0
+        return;
+    }
+
+    if (unlikely(!dirtylimit_cancel_vcpu(idx))) {

I don't think unlikely() matters here.

Ok, i dropped the compilation syntax in latest version.

Quoted 76 lines
Quoted 63 lines
cpus-common.c +13 -0
+        dirtylimit_calc_quit();
+    }
+}
+
+void dirtylimit_setup(int max_cpus)
+{
+    if (!kvm_enabled() || !kvm_dirty_ring_enabled()) {
+        return;
+    }
+
+    dirtylimit_calc_state_init(max_cpus);
+    dirtylimit_state_init(max_cpus);
+}
include/hw/core/cpu.h +9 -0
index e948e81..11df012 100644
@@ -881,6 +881,15 @@ void end_exclusive(void);
   */
  void qemu_init_vcpu(CPUState *cpu);
 
+/**
+ * dirtylimit_setup:
+ *
+ * Initializes the global state of dirtylimit calculation and
+ * dirtylimit itself. This is prepared for vCPU dirtylimit which
+ * could be triggered during vm lifecycle.
+ */
+void dirtylimit_setup(int max_cpus);
+
  #define SSTEP_ENABLE  0x1  /* Enable simulated HW single stepping */
  #define SSTEP_NOIRQ   0x2  /* Do not use IRQ while single stepping */
  #define SSTEP_NOTIMER 0x4  /* Do not Timers while single stepping */
qapi/migration.json +21 -0
index bbfd48c..57c9a63 100644
@@ -1850,6 +1850,49 @@
  { 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' }
 
  ##
+# @set-dirty-limit:
+#
+# Set the upper limit of dirty page rate for a virtual CPU.
+#
+# Requires KVM with accelerator property "dirty-ring-size" set.
+# A virtual CPU's dirty page rate is a measure of its memory load.
+# To observe dirty page rates, use @calc-dirty-rate.
+#
+# @cpu-index: index of the virtual CPU.
+#
+# @dirty-rate: upper limit for the specified vCPU's dirty page rate (MB/s)
+#
+# Since: 7.0
+#
+# Example:
+#   {"execute": "set-dirty-limit"}
+#    "arguments": { "cpu-index": 0,
+#                   "dirty-rate": 200 } }
+#
+##
+{ 'command': 'set-dirty-limit',

qapi/migration.json line 1883

Quoted 10 lines
qapi/migration.json +10 -0
+  'data': { 'cpu-index': 'int', 'dirty-rate': 'uint64' } }
+
+##
+# @cancel-dirty-limit:
+#
+# Cancel the dirty page limit for the vCPU which has been set with
+# set-dirty-limit command. Note that this command requires support from
+# dirty ring, same as the "set-dirty-limit" command.
+#
+# @cpu-index: index of the virtual CPU to cancel the dirty page limit

I'd go with

Quoted 1 line

# @cpu-index: index of the virtual CPU.

Ok.

Quoted 29 lines
Quoted 21 lines
qapi/migration.json +12 -0
+#
+# Since: 7.0
+#
+# Example:
+#   {"execute": "cancel-dirty-limit"}
+#    "arguments": { "cpu-index": 0 } }
+#
+##
+{ 'command': 'cancel-dirty-limit',
+  'data': { 'cpu-index': 'int' } }
+
+##
  # @snapshot-save:
  #
  # Save a VM snapshot
softmmu/vl.c +0 -0
index 620a1f1..0f83ce3 100644

softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 3782

Quoted 6 lines
softmmu/vl.c +1 -0
@@ -3777,5 +3777,6 @@ void qemu_init(int argc, char **argv, char **envp)
      qemu_init_displays();
      accel_setup_post(current_machine);
      os_setup_post();
+    dirtylimit_setup(current_machine->smp.max_cpus);
      resume_mux_open();
  }

QAPI schema:

Quoted 1 line

Thanks Markus very much for reviewing the code, :)

Quoted 1 line
Signature · 3 lines
Best regard

Hyman Huang(黄勇)
#10 lore raw
In reply to [email protected]
Quoted 4 lines · On Tue, Nov 30, 2021 at 06:28:10PM +0800, [email protected] wrote:

From: Hyman Huang(黄勇) <[email protected]>

The patch [2/3] has not been touched so far. Any corrections and suggetions are welcome.

I played with it today, but the vcpu didn't got throttled as expected.

What I did was starting two workload with 500mb/s, each pinned on one vcpu thread:

[root@fedora ~]# pgrep -fa mig_mon 595 ./mig_mon mm_dirty 1000 500 sequential 604 ./mig_mon mm_dirty 1000 500 sequential [root@fedora ~]# taskset -pc 595 pid 595's current affinity list: 2 [root@fedora ~]# taskset -pc 604 pid 604's current affinity list: 3

Then start throttle with 100mb/s:

(QEMU) set-dirty-limit cpu-index=3 dirty-rate=100 {"return": {}}
(QEMU) set-dirty-limit cpu-index=2 dirty-rate=100 {"return": {}}

I can see the workload dropped a tiny little bit (perhaps 500mb -> 499mb), then it keeps going..

Further throttle won't work too:

(QEMU) set-dirty-limit cpu-index=2 dirty-rate=10 {"return": {}}

Funnily, the ssh client got slowed down instead... :(

Yong, how did you test it?

Signature · 1 line
Peter Xu
#11 lore raw

1.
Start vm with kernel+initrd.img with qemu command line as following:

[root@Hyman_server1 fast_qemu]# cat vm.sh
#!/bin/bash

/usr/bin/qemu-system-x86_64 \
    -display none -vga none \
    -name guest=simple_vm,debug-threads=on \
    -monitor stdio \
    -machine pc-i440fx-2.12 \
    -accel kvm,dirty-ring-size=65536 -cpu host \
    -kernel /home/work/fast_qemu/vmlinuz-5.13.0-rc4+ \
    -initrd /home/work/fast_qemu/initrd-stress.img \
    -append "noapic edd=off printk.time=1 noreplace-smp 
cgroup_disable=memory pci=noearly console=ttyS0 debug ramsize=1500 ratio=1 sleep=1" \
    -chardev file,id=charserial0,path=/var/log/vm_console.log \
    -serial chardev:charserial0 \
    -qmp unix:/tmp/qmp-sock,server,nowait \
    -D /var/log/vm.log \
    --trace events=/home/work/fast_qemu/events \
    -m 4096 -smp 2 -device sga

2.
Enable the dirtylimit trace event which will output to /var/log/vm.log [root@Hyman_server1 fast_qemu]# cat /home/work/fast_qemu/events dirtylimit_state_init
dirtylimit_vcpu
dirtylimit_impose
dirtyrate_do_calculate_vcpu

3.
Connect the qmp server with low level qmp client and set-dirty-limit

[root@Hyman_server1 my_qemu]# python3.6 ./scripts/qmp/qmp-shell -v -p /tmp/qmp-sock

Welcome to the QMP low-level shell!
Connected to QEMU 6.1.92

(QEMU) set-dirty-limit cpu-index=1 dirty-rate=400

{
    "arguments": {
        "cpu-index": 1,
        "dirty-rate": 400
    },
    "execute": "set-dirty-limit"
}

4.
observe the vcpu current dirty rate and quota dirty rate...

[root@Hyman_server1 ~]# tail -f /var/log/vm.log
dirtylimit_state_init dirtylimit state init: max cpus 2 dirtylimit_vcpu CPU[1] set quota dirtylimit 400
dirtylimit_impose CPU[1] impose dirtylimit: quota 400, current 0, percentage 0 dirtyrate_do_calculate_vcpu vcpu[0]: 1075 MB/s dirtyrate_do_calculate_vcpu vcpu[1]: 1061 MB/s
dirtylimit_impose CPU[1] impose dirtylimit: quota 400, current 1061, percentage 62 dirtyrate_do_calculate_vcpu vcpu[0]: 1133 MB/s dirtyrate_do_calculate_vcpu vcpu[1]: 380 MB/s
dirtylimit_impose CPU[1] impose dirtylimit: quota 400, current 380, percentage 57 dirtyrate_do_calculate_vcpu vcpu[0]: 1227 MB/s dirtyrate_do_calculate_vcpu vcpu[1]: 464 MB/s

We can observe that vcpu-1's dirtyrate is about 400MB/s with dirty page limit set and the vcpu-0 is not affected.

5.
observe the vm stress info...
[root@Hyman_server1 fast_qemu]# tail -f /var/log/vm_console.log

[    0.838051] Run /init as init process
[    0.839216]   with arguments:
[    0.840153]     /init
[    0.840882]   with environment:
[    0.841884]     HOME=/
[    0.842649]     TERM=linux
[    0.843478]     edd=off
[    0.844233]     ramsize=1500
[    0.845079]     ratio=1
[    0.845829]     sleep=1
/init (00001): INFO: RAM 1500 MiB across 2 CPUs, ratio 1, sleep 1 us
[    1.158011] random: init: uninitialized urandom read (4096 bytes read)
[    1.448205] random: init: uninitialized urandom read (4096 bytes read)

/init (00001): INFO: 1638282593684ms copied 1 GB in 00729ms /init (00110): INFO: 1638282593964ms copied 1 GB in 00719ms /init (00001): INFO: 1638282594405ms copied 1 GB in 00719ms /init (00110): INFO: 1638282594677ms copied 1 GB in 00713ms /init (00001): INFO: 1638282595093ms copied 1 GB in 00686ms /init (00110): INFO: 1638282595339ms copied 1 GB in 00662ms /init (00001): INFO: 1638282595764ms copied 1 GB in 00670m

PS: the kernel and initrd images comes from:

kernel image: vmlinuz-5.13.0-rc4+, normal centos vmlinuz copied from /boot directory

initrd.img: initrd-stress.img, only contains a stress binary, which compiled from qemu source tests/migration/stress.c and run as init in vm.

you can view README.md file of my project "met"(https://github.com/newfriday/met) to compile the initrd-stress.img. :)

Quoted 38 lines · Peter Xu
Quoted 4 lines · On Tue, Nov 30, 2021 at 06:28:10PM +0800, [email protected] wrote:

From: Hyman Huang(黄勇) <[email protected]>

The patch [2/3] has not been touched so far. Any corrections and suggetions are welcome.

I played with it today, but the vcpu didn't got throttled as expected.

What I did was starting two workload with 500mb/s, each pinned on one vcpu thread:

[root@fedora ~]# pgrep -fa mig_mon 595 ./mig_mon mm_dirty 1000 500 sequential 604 ./mig_mon mm_dirty 1000 500 sequential [root@fedora ~]# taskset -pc 595 pid 595's current affinity list: 2 [root@fedora ~]# taskset -pc 604 pid 604's current affinity list: 3

Then start throttle with 100mb/s:

(QEMU) set-dirty-limit cpu-index=3 dirty-rate=100 {"return": {}}
(QEMU) set-dirty-limit cpu-index=2 dirty-rate=100 {"return": {}}

I can see the workload dropped a tiny little bit (perhaps 500mb -> 499mb), then it keeps going..

Further throttle won't work too:

(QEMU) set-dirty-limit cpu-index=2 dirty-rate=10 {"return": {}}

Funnily, the ssh client got slowed down instead... :(

Yong, how did you test it?

Signature · 2 lines
Best Regards
Hyman Huang(黄勇)
#12 lore raw
Quoted 94 lines · Hyman Huang

1.
Start vm with kernel+initrd.img with qemu command line as following:

[root@Hyman_server1 fast_qemu]# cat vm.sh
#!/bin/bash
/usr/bin/qemu-system-x86_64 \
    -display none -vga none \
    -name guest=simple_vm,debug-threads=on \
    -monitor stdio \
    -machine pc-i440fx-2.12 \
    -accel kvm,dirty-ring-size=65536 -cpu host \
    -kernel /home/work/fast_qemu/vmlinuz-5.13.0-rc4+ \
    -initrd /home/work/fast_qemu/initrd-stress.img \
    -append "noapic edd=off printk.time=1 noreplace-smp
cgroup_disable=memory pci=noearly console=ttyS0 debug ramsize=1500 ratio=1 sleep=1" \
    -chardev file,id=charserial0,path=/var/log/vm_console.log \
    -serial chardev:charserial0 \
    -qmp unix:/tmp/qmp-sock,server,nowait \
    -D /var/log/vm.log \
    --trace events=/home/work/fast_qemu/events \
    -m 4096 -smp 2 -device sga

2.
Enable the dirtylimit trace event which will output to /var/log/vm.log [root@Hyman_server1 fast_qemu]# cat /home/work/fast_qemu/events dirtylimit_state_init
dirtylimit_vcpu
dirtylimit_impose
dirtyrate_do_calculate_vcpu

3.
Connect the qmp server with low level qmp client and set-dirty-limit

[root@Hyman_server1 my_qemu]# python3.6 ./scripts/qmp/qmp-shell -v -p /tmp/qmp-sock

Welcome to the QMP low-level shell!
Connected to QEMU 6.1.92

(QEMU) set-dirty-limit cpu-index=1 dirty-rate=400

{
    "arguments": {
        "cpu-index": 1,
        "dirty-rate": 400
    },
    "execute": "set-dirty-limit"
}

4.
observe the vcpu current dirty rate and quota dirty rate...

[root@Hyman_server1 ~]# tail -f /var/log/vm.log
dirtylimit_state_init dirtylimit state init: max cpus 2 dirtylimit_vcpu CPU[1] set quota dirtylimit 400
dirtylimit_impose CPU[1] impose dirtylimit: quota 400, current 0, percentage 0 dirtyrate_do_calculate_vcpu vcpu[0]: 1075 MB/s dirtyrate_do_calculate_vcpu vcpu[1]: 1061 MB/s
dirtylimit_impose CPU[1] impose dirtylimit: quota 400, current 1061, percentage 62 dirtyrate_do_calculate_vcpu vcpu[0]: 1133 MB/s dirtyrate_do_calculate_vcpu vcpu[1]: 380 MB/s
dirtylimit_impose CPU[1] impose dirtylimit: quota 400, current 380, percentage 57 dirtyrate_do_calculate_vcpu vcpu[0]: 1227 MB/s dirtyrate_do_calculate_vcpu vcpu[1]: 464 MB/s

We can observe that vcpu-1's dirtyrate is about 400MB/s with dirty page limit set and the vcpu-0 is not affected.

5.
observe the vm stress info...
[root@Hyman_server1 fast_qemu]# tail -f /var/log/vm_console.log [    0.838051] Run /init as init process
[    0.839216]   with arguments:
[    0.840153]     /init
[    0.840882]   with environment:
[    0.841884]     HOME=/
[    0.842649]     TERM=linux
[    0.843478]     edd=off
[    0.844233]     ramsize=1500
[    0.845079]     ratio=1
[    0.845829]     sleep=1
/init (00001): INFO: RAM 1500 MiB across 2 CPUs, ratio 1, sleep 1 us [    1.158011] random: init: uninitialized urandom read (4096 bytes read) [    1.448205] random: init: uninitialized urandom read (4096 bytes read) /init (00001): INFO: 1638282593684ms copied 1 GB in 00729ms /init (00110): INFO: 1638282593964ms copied 1 GB in 00719ms /init (00001): INFO: 1638282594405ms copied 1 GB in 00719ms /init (00110): INFO: 1638282594677ms copied 1 GB in 00713ms /init (00001): INFO: 1638282595093ms copied 1 GB in 00686ms /init (00110): INFO: 1638282595339ms copied 1 GB in 00662ms /init (00001): INFO: 1638282595764ms copied 1 GB in 00670m

PS: the kernel and initrd images comes from:

Quoted 36 lines

kernel image: vmlinuz-5.13.0-rc4+, normal centos vmlinuz copied from /boot directory

initrd.img: initrd-stress.img, only contains a stress binary, which compiled from qemu source tests/migration/stress.c and run as init in vm.

you can view README.md file of my project "met"(https://github.com/newfriday/met) to compile the initrd-stress.img. :)

Quoted 28 lines · Peter Xu
Quoted 4 lines · On Tue, Nov 30, 2021 at 06:28:10PM +0800, [email protected] wrote:

From: Hyman Huang(黄勇) <[email protected]>

The patch [2/3] has not been touched so far. Any corrections and suggetions are welcome.

I played with it today, but the vcpu didn't got throttled as expected.

What I did was starting two workload with 500mb/s, each pinned on one vcpu thread:

[root@fedora ~]# pgrep -fa mig_mon 595 ./mig_mon mm_dirty 1000 500 sequential 604 ./mig_mon mm_dirty 1000 500 sequential [root@fedora ~]# taskset -pc 595 pid 595's current affinity list: 2 [root@fedora ~]# taskset -pc 604 pid 604's current affinity list: 3

Then start throttle with 100mb/s:

(QEMU) set-dirty-limit cpu-index=3 dirty-rate=100 {"return": {}}
(QEMU) set-dirty-limit cpu-index=2 dirty-rate=100 {"return": {}}

I can see the workload dropped a tiny little bit (perhaps 500mb -> 499mb), then it keeps going..

The test step above i listed assume that dirtyrate calculated by dirtylimit_calc_func via dirty-ring is accurate, which differ from your test policy.

The macro DIRTYLIMIT_CALC_TIME_MS used as calculation period in migration/dirtyrate.c has a big affect on result. So "how we define the right dirtyrate" is worth discussing.

Anyway, one of our target is to improve the memory performence during migration, so i think memory write/read speed in vm is a convincing metric. I'll test the dirtyrate in the way your metioned and analyze the result.

Quoted 11 lines
Quoted 10 lines

Further throttle won't work too:

(QEMU) set-dirty-limit cpu-index=2 dirty-rate=10 {"return": {}}

Funnily, the ssh client got slowed down instead... :(

Yong, how did you test it?

Signature · 2 lines
Best Regards
Hyman Huang(黄勇)