Browse Source

vhost: apply cgroup to vhost workers

Apply the cgroup of the owner task to the created vhost worker.

Based on patches from Sridhar Samudrala's and Tejun Heo.
Later we'll need to also apply cpumask and probably priority
of the owner process.

Discussion on the best way to do this is still ongoing.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Sridhar Samudrala <samudrala.sridhar@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Michael S. Tsirkin 15 years ago
parent
commit
9e3d195720
1 changed files with 6 additions and 0 deletions
  1. 6 0
      drivers/vhost/vhost.c

+ 6 - 0
drivers/vhost/vhost.c

@@ -23,6 +23,7 @@
 #include <linux/highmem.h>
 #include <linux/highmem.h>
 #include <linux/slab.h>
 #include <linux/slab.h>
 #include <linux/kthread.h>
 #include <linux/kthread.h>
+#include <linux/cgroup.h>
 
 
 #include <linux/net.h>
 #include <linux/net.h>
 #include <linux/if_packet.h>
 #include <linux/if_packet.h>
@@ -253,9 +254,14 @@ static long vhost_dev_set_owner(struct vhost_dev *dev)
 	}
 	}
 
 
 	dev->worker = worker;
 	dev->worker = worker;
+	err = cgroup_attach_task_current_cg(worker);
+	if (err)
+		goto err_cgroup;
 	wake_up_process(worker);	/* avoid contributing to loadavg */
 	wake_up_process(worker);	/* avoid contributing to loadavg */
 
 
 	return 0;
 	return 0;
+err_cgroup:
+	kthread_stop(worker);
 err_worker:
 err_worker:
 	if (dev->mm)
 	if (dev->mm)
 		mmput(dev->mm);
 		mmput(dev->mm);