From nobody Sat Nov 23 16:16:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=jd.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732222833089897.1394635026177; Thu, 21 Nov 2024 13:00:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tEEHc-00055G-CU; Thu, 21 Nov 2024 16:00:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tEBDo-0001jF-TI for qemu-devel@nongnu.org; Thu, 21 Nov 2024 12:44:05 -0500 Received: from [209.95.133.113] (helo=ZBMac-DY9GX4RFNX.localdomain) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tEBDl-0000vu-56 for qemu-devel@nongnu.org; Thu, 21 Nov 2024 12:44:04 -0500 Received: by ZBMac-DY9GX4RFNX.localdomain (Postfix, from userid 502) id AB8B72466CAA; Fri, 22 Nov 2024 01:34:16 +0800 (CST) From: wangfuqiang49 To: qemu-devel@nongnu.org, Paolo Bonzini , Peter Xu , Hyman Huang Cc: qinzheng13 , yaowenchao1 Subject: [PATCH] fix dirtyring not converge use small dirtylimit Date: Fri, 22 Nov 2024 01:34:16 +0800 Message-ID: <20241121173416.75950-1-wangfuqiang49@jd.com> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 209.95.133.113 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=209.95.133.113; envelope-from=wangfuqiang49@ZBMac-DY9GX4RFNX.localdomain; helo=ZBMac-DY9GX4RFNX.localdomain X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NO_DNS_FOR_FROM=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 21 Nov 2024 16:00:11 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1732222835212116600 Content-Type: text/plain; charset="utf-8" From: fuqiang wang 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=3D1), 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 --- accel/kvm/kvm-all.c | 6 +++++- include/hw/core/cpu.h | 1 + system/cpus.c | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) 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; =20 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); + } } } =20 @@ -3131,7 +3133,9 @@ int kvm_cpu_exec(CPUState *cpu) */ smp_rmb(); =20 + cpu->vcpu_in_kvm =3D true; run_ret =3D kvm_vcpu_ioctl(cpu, KVM_RUN, 0); + cpu->vcpu_in_kvm =3D false; =20 attrs =3D kvm_arch_post_run(cpu, run); =20 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; =20 /* 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 =3D ms->smp.threads; cpu->stopped =3D true; cpu->random_seed =3D qemu_guest_random_seed_thread_part1(); + cpu->vcpu_in_kvm =3D false; =20 if (!cpu->as) { /* If the target cpu hasn't set up any address spaces itself, --=20 2.47.0