diff mbox series

fix dirtyring not converge use small dirtylimit

Message ID 20241121173416.75950-1-wangfuqiang49@jd.com (mailing list archive)
State New
Headers show
Series fix dirtyring not converge use small dirtylimit | expand

Commit Message

wangfuqiang49 Nov. 21, 2024, 5:34 p.m. UTC
From: fuqiang wang <wangfuqiang49@jd.com>

When using a low dirtylimit to restrict a VM with a high dirty ratio,
such as in the guestperf test scenario compr-dirty-limit-period-1000
(dirtylimit=1), this can lead to too long sleep times for the vcpu
threads and the migration thread may have to wait vcpu thread due to the
kick operation, and during this waiting period, the guest will make some
dirty pages at a high speed, which causes convergence issues.

However, during the vcpu thread sleeping, it is not in kernel space
(kvm), so there is no need to wait for a kick.

Signed-off-by: wangfuqiang49 <wangfuqiang49@jd.com>
---
 accel/kvm/kvm-all.c   | 6 +++++-
 include/hw/core/cpu.h | 1 +
 system/cpus.c         | 1 +
 3 files changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 801cff16a5..86b1b8a6c6 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -926,7 +926,9 @@  static void kvm_cpu_synchronize_kick_all(void)
     CPUState *cpu;
 
     CPU_FOREACH(cpu) {
-        run_on_cpu(cpu, do_kvm_cpu_synchronize_kick, RUN_ON_CPU_NULL);
+        if (cpu->vcpu_in_kvm) {
+            run_on_cpu(cpu, do_kvm_cpu_synchronize_kick, RUN_ON_CPU_NULL);
+        }
     }
 }
 
@@ -3131,7 +3133,9 @@  int kvm_cpu_exec(CPUState *cpu)
          */
         smp_rmb();
 
+        cpu->vcpu_in_kvm = true;
         run_ret = kvm_vcpu_ioctl(cpu, KVM_RUN, 0);
+        cpu->vcpu_in_kvm = false;
 
         attrs = kvm_arch_post_run(cpu, run);
 
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index db8a6fbc6e..853aba4ef7 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -537,6 +537,7 @@  struct CPUState {
     uint64_t dirty_pages;
     int kvm_vcpu_stats_fd;
     bool vcpu_dirty;
+    bool vcpu_in_kvm;
 
     /* Use by accel-block: CPU is executing an ioctl() */
     QemuLockCnt in_ioctl_lock;
diff --git a/system/cpus.c b/system/cpus.c
index 1c818ff682..572c7e4f4d 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -670,6 +670,7 @@  void qemu_init_vcpu(CPUState *cpu)
     cpu->nr_threads =  ms->smp.threads;
     cpu->stopped = true;
     cpu->random_seed = qemu_guest_random_seed_thread_part1();
+    cpu->vcpu_in_kvm = false;
 
     if (!cpu->as) {
         /* If the target cpu hasn't set up any address spaces itself,