public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* VM performance issue in KVM guests.
@ 2010-04-10  8:16 Zhang, Xiantao
  2010-04-10 19:27 ` Avi Kivity
  0 siblings, 1 reply; 16+ messages in thread
From: Zhang, Xiantao @ 2010-04-10  8:16 UTC (permalink / raw)
  To: kvm@vger.kernel.org, Avi Kivity, Marcelo Tosatti
  Cc: Yang, Xiaowei, Dong, Eddie, Li, Xin

[-- Attachment #1: Type: text/plain, Size: 2442 bytes --]

Hi, all  
  We are working on the scalability work for KVM guests, and found one big issue exists in linux scheduler and it may impact guest's performance and scalability a lot for some special workloads running in VM.  In the current Linux scheduler, there are some features to enhance App's performance which are defined in the file kvm.git/kernel/sched_features.h. Certainly, they are mostly beneficial optimizations to improve system's performance, but unluckily, some of them may hurt VM's performance and scalablity in KVM case 
  We know that if two or more vcpus of one guests are scheduled to one same logical processor,  same CPU utilization may generate less valid output due mutual lock in VM's OS than that are scheduled to different logical processors  .And we also know that VM's vcpus are emulated or executed through the threads of Qemu for KVM.  If the vcpu threads of qemu are often pulled to one same logical processor by some features of Linux scheduler, kvm guests'performance may be hurt a lot.  In our performance testing,  the results also show this performance bottleneck due to this issue. After analysis about Linux scheduler, we found it is indeed caused by the known features of Linux schduler, such as AFFINE_WAKEUPS, SYNC_WAKEUPS etc. With these features on, linux schduler often tries to schedule the vcpu threads of one guests to one same logical processor when vcpus are over-committed and logical processors are saturated. Once the vcpu threads of one VM are scheduled to the same LP, system performance drops dramatically with some workloads(like webbench running in windows OS).  
   To verify this finding, we also worked out a simple patch attached in the mail to dynamially switch off the two sheduler features mentioned above when scheduler knows the scheduling tasks are vcpu threads, and we found the the whole system's performance and scalability are improved a lot.  Certatinly, this patch is not good for upstream, but it can enlighten us to think how to optimize Linux scheduler and we also want to initiate the discussion about how to make LINUX's scheduler more friendly to virtualization.  Besides, this issue maybe not only kvm's special issue, insteadly it should be a common issue for host-based VMs, and we also expect that we can have an elegant solution to thoroughly resolve the performance or scalability gap compared with hypervisor-based VMs.  
Any comments ?
Thanks!
Xiantao

[-- Attachment #2: sheduler_issue_fix.patch --]
[-- Type: application/octet-stream, Size: 2038 bytes --]

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index bd5a616..1ec1ffc 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -471,7 +471,7 @@ static inline int kvm_deassign_device(struct kvm *kvm,
 static inline void kvm_guest_enter(void)
 {
 	account_system_vtime(current);
-	current->flags |= PF_VCPU;
+	current->flags |= PF_VCPU | PF_NO_WAKE_AFFINE;
 }
 
 static inline void kvm_guest_exit(void)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 75e6e60..0406bd0 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1733,6 +1733,7 @@ extern cputime_t task_gtime(struct task_struct *p);
 #define PF_EXITING	0x00000004	/* getting shut down */
 #define PF_EXITPIDONE	0x00000008	/* pi exit done on shut down */
 #define PF_VCPU		0x00000010	/* I'm a virtual CPU */
+#define PF_NO_WAKE_AFFINE 0x00000020	/* No wakeup affinity for this process */
 #define PF_FORKNOEXEC	0x00000040	/* forked but didn't exec */
 #define PF_MCE_PROCESS  0x00000080      /* process policy on mce errors */
 #define PF_SUPERPRIV	0x00000100	/* used super-user privileges */
diff --git a/kernel/sched.c b/kernel/sched.c
index 3c11ae0..4d859ec 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -2343,7 +2343,7 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state,
 	unsigned long flags;
 	struct rq *rq, *orig_rq;
 
-	if (!sched_feat(SYNC_WAKEUPS))
+	if ((p->flags & PF_NO_WAKE_AFFINE) || !sched_feat(SYNC_WAKEUPS))
 		wake_flags &= ~WF_SYNC;
 
 	this_cpu = get_cpu();
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index 37087a7..3defb3f 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -1366,7 +1366,7 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag
 	int sync = wake_flags & WF_SYNC;
 
 	if (sd_flag & SD_BALANCE_WAKE) {
-		if (sched_feat(AFFINE_WAKEUPS) &&
+		if (!(p->flags & PF_NO_WAKE_AFFINE) && sched_feat(AFFINE_WAKEUPS) &&
 		    cpumask_test_cpu(cpu, &p->cpus_allowed))
 			want_affine = 1;
 		new_cpu = prev_cpu;

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2010-04-19  1:32 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-10  8:16 VM performance issue in KVM guests Zhang, Xiantao
2010-04-10 19:27 ` Avi Kivity
2010-04-12  2:04   ` Zhang, Xiantao
2010-04-12  6:40     ` Avi Kivity
2010-04-13  0:50       ` Zhang, Xiantao
2010-04-13  6:46         ` Avi Kivity
2010-04-14  3:24           ` Zhang, Xiantao
2010-04-14  8:14             ` Avi Kivity
2010-04-16  2:27               ` Zhang, Xiantao
2010-04-17 19:02                 ` Avi Kivity
     [not found]       ` <p2o2eae271004142158xaa5da968ueff0c2afe6894f9d@mail.gmail.com>
2010-04-15  8:18         ` Avi Kivity
2010-04-15 13:33           ` Peter Zijlstra
2010-04-15 16:43             ` Srivatsa Vaddagiri
2010-04-16 10:40               ` Peter Zijlstra
2010-04-19  1:32               ` Zhang, Xiantao
2010-04-17 19:04             ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox