LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: pjq

200+行Kernel补丁显著改善Linux桌面性能

[复制链接]
 楼主| 发表于 2010-11-17 22:41:17 | 显示全部楼层
用上了5楼的补丁,cfs-2010-11-17-04-55-47.patch.tar.bz2
怎样测试能看出效果呢。
回复 支持 反对

使用道具 举报

发表于 2010-11-17 23:57:09 | 显示全部楼层
我用的是gentoo-sources,直接打上这个补丁,

方法很简单,不会的同学跟我做:

创建目录:

/etc/portage/patches/sys-kernel/gentoo-sources

然后创建一个新文件cfs-autogroup.patch,文件内容在下面。

补丁内容跟jarryson发的zen上的补丁有所区别,实际上就是作者直接提交的内容。

cfs-autogroup.patch内容如下:


  1. Index: linux-2.6.36.git/include/linux/sched.h
  2. ===================================================================
  3. --- linux-2.6.36.git.orig/include/linux/sched.h
  4. +++ linux-2.6.36.git/include/linux/sched.h
  5. @@ -1900,6 +1900,20 @@ int sched_rt_handler(struct ctl_table *t

  6. extern unsigned int sysctl_sched_compat_yield;

  7. +#ifdef CONFIG_SCHED_DESKTOP
  8. +int sched_tty_sched_handler(struct ctl_table *table, int write,
  9. +                void __user *buffer, size_t *lenp,
  10. +                loff_t *ppos);
  11. +
  12. +extern unsigned int sysctl_sched_tty_sched_enabled;
  13. +
  14. +void tty_sched_create_group(struct tty_struct *tty);
  15. +void tty_sched_destroy_group(struct tty_struct *tty);
  16. +#else
  17. +static inline void tty_sched_create_group(struct tty_struct *tty) { }
  18. +static inline void tty_sched_destroy_group(struct tty_struct *tty) { }
  19. +#endif
  20. +
  21. #ifdef CONFIG_RT_MUTEXES
  22. extern int rt_mutex_getprio(struct task_struct *p);
  23. extern void rt_mutex_setprio(struct task_struct *p, int prio);
  24. Index: linux-2.6.36.git/include/linux/tty.h
  25. ===================================================================
  26. --- linux-2.6.36.git.orig/include/linux/tty.h
  27. +++ linux-2.6.36.git/include/linux/tty.h
  28. @@ -327,6 +327,9 @@ struct tty_struct {
  29.         /* If the tty has a pending do_SAK, queue it here - akpm */
  30.         struct work_struct SAK_work;
  31.         struct tty_port *port;
  32. +#ifdef CONFIG_SCHED_DESKTOP
  33. +        struct task_group *tg;
  34. +#endif
  35. };

  36. /* Each of a tty's open files has private_data pointing to tty_file_private */
  37. Index: linux-2.6.36.git/kernel/sched.c
  38. ===================================================================
  39. --- linux-2.6.36.git.orig/kernel/sched.c
  40. +++ linux-2.6.36.git/kernel/sched.c
  41. @@ -78,6 +78,7 @@

  42. #include "sched_cpupri.h"
  43. #include "workqueue_sched.h"
  44. +#include "sched_tty.h"

  45. #define CREATE_TRACE_POINTS
  46. #include <trace/events/sched.h>
  47. @@ -612,11 +613,16 @@ static inline int cpu_of(struct rq *rq)
  48.   */
  49. static inline struct task_group *task_group(struct task_struct *p)
  50. {
  51. +        struct task_group *tg;
  52.         struct cgroup_subsys_state *css;

  53.         css = task_subsys_state_check(p, cpu_cgroup_subsys_id,
  54.                         lockdep_is_held(&task_rq(p)->lock));
  55. -        return container_of(css, struct task_group, css);
  56. +        tg = container_of(css, struct task_group, css);
  57. +
  58. +        tty_sched_check_attach(p, &tg);
  59. +
  60. +        return tg;
  61. }

  62. /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
  63. @@ -1920,6 +1926,7 @@ static void deactivate_task(struct rq *r
  64. #include "sched_idletask.c"
  65. #include "sched_fair.c"
  66. #include "sched_rt.c"
  67. +#include "sched_tty.c"
  68. #ifdef CONFIG_SCHED_DEBUG
  69. # include "sched_debug.c"
  70. #endif
  71. Index: linux-2.6.36.git/drivers/char/tty_io.c
  72. ===================================================================
  73. --- linux-2.6.36.git.orig/drivers/char/tty_io.c
  74. +++ linux-2.6.36.git/drivers/char/tty_io.c
  75. @@ -185,6 +185,7 @@ void free_tty_struct(struct tty_struct *
  76. {
  77.         kfree(tty->write_buf);
  78.         tty_buffer_free_all(tty);
  79. +        tty_sched_destroy_group(tty);
  80.         kfree(tty);
  81. }

  82. @@ -2823,6 +2824,7 @@ void initialize_tty_struct(struct tty_st
  83.         tty->ops = driver->ops;
  84.         tty->index = idx;
  85.         tty_line_name(driver, idx, tty->name);
  86. +        tty_sched_create_group(tty);
  87. }

  88. /**
  89. Index: linux-2.6.36.git/kernel/sched_tty.h
  90. ===================================================================
  91. --- /dev/null
  92. +++ linux-2.6.36.git/kernel/sched_tty.h
  93. @@ -0,0 +1,7 @@
  94. +#ifdef CONFIG_SCHED_DESKTOP
  95. +static inline void
  96. +tty_sched_check_attach(struct task_struct *p, struct task_group **tg);
  97. +#else
  98. +static inline void
  99. +tty_sched_check_attach(struct task_struct *p, struct task_group **tg) { }
  100. +#endif
  101. Index: linux-2.6.36.git/kernel/sched_tty.c
  102. ===================================================================
  103. --- /dev/null
  104. +++ linux-2.6.36.git/kernel/sched_tty.c
  105. @@ -0,0 +1,128 @@
  106. +#ifdef CONFIG_SCHED_DESKTOP
  107. +#include <linux/tty.h>
  108. +
  109. +unsigned int __read_mostly sysctl_sched_tty_sched_enabled = 1;
  110. +
  111. +void tty_sched_create_group(struct tty_struct *tty)
  112. +{
  113. +        tty->tg = sched_create_group(&init_task_group);
  114. +        if (IS_ERR(tty->tg)) {
  115. +                tty->tg = &init_task_group;
  116. +                 WARN_ON(1);
  117. +        }
  118. +}
  119. +EXPORT_SYMBOL(tty_sched_create_group);
  120. +
  121. +void tty_sched_destroy_group(struct tty_struct *tty)
  122. +{
  123. +        if (tty->tg && tty->tg != &init_task_group)
  124. +                sched_destroy_group(tty->tg);
  125. +}
  126. +EXPORT_SYMBOL(tty_sched_destroy_group);
  127. +
  128. +static inline void
  129. +tty_sched_check_attach(struct task_struct *p, struct task_group **tg)
  130. +{
  131. +        struct tty_struct *tty;
  132. +        int attach = 0, enabled = sysctl_sched_tty_sched_enabled;
  133. +
  134. +        rcu_read_lock();
  135. +        tty = p->signal->tty;
  136. +        if (!tty)
  137. +                goto out_unlock;
  138. +
  139. +        if (enabled && *tg == &root_task_group) {
  140. +                *tg = p->signal->tty->tg;
  141. +                attach = 1;
  142. +        } else if (!enabled && *tg == tty->tg) {
  143. +                *tg = &root_task_group;
  144. +                attach = 1;
  145. +        }
  146. +
  147. +        if (attach && !p->se.on_rq) {
  148. +                p->se.vruntime -= cfs_rq_of(&p->se)->min_vruntime;
  149. +                p->se.vruntime += (*tg)->cfs_rq[task_cpu(p)]->min_vruntime;
  150. +        }
  151. +
  152. +out_unlock:
  153. +        rcu_read_unlock();
  154. +}
  155. +
  156. +void tty_sched_move_task(struct task_struct *p, struct task_group *tg)
  157. +{
  158. +        struct sched_entity *se = &p->se;
  159. +        struct rq *rq;
  160. +        unsigned long flags;
  161. +        int on_rq, running, cpu;
  162. +
  163. +        rq = task_rq_lock(p, &flags);
  164. +
  165. +        running = task_current(rq, p);
  166. +        on_rq = se->on_rq;
  167. +        cpu = rq->cpu;
  168. +
  169. +        if (on_rq)
  170. +                dequeue_task(rq, p, 0);
  171. +        if (unlikely(running))
  172. +                p->sched_class->put_prev_task(rq, p);
  173. +
  174. +        if (!on_rq)
  175. +                se->vruntime -= cfs_rq_of(se)->min_vruntime;
  176. +
  177. +        se->cfs_rq = tg->cfs_rq[cpu];
  178. +        se->parent = tg->se[cpu];
  179. +
  180. +        p->rt.rt_rq  = tg->rt_rq[cpu];
  181. +        p->rt.parent = tg->rt_se[cpu];
  182. +
  183. +        if (!on_rq)
  184. +                se->vruntime += cfs_rq_of(se)->min_vruntime;
  185. +
  186. +        if (unlikely(running))
  187. +                p->sched_class->set_curr_task(rq);
  188. +        if (on_rq)
  189. +                enqueue_task(rq, p, 0);
  190. +
  191. +        task_rq_unlock(rq, &flags);
  192. +}
  193. +
  194. +int sched_tty_sched_handler(struct ctl_table *table, int write,
  195. +                void __user *buffer, size_t *lenp,
  196. +                loff_t *ppos)
  197. +{
  198. +        struct task_struct *p, *t;
  199. +        struct task_group *tg;
  200. +        unsigned long flags;
  201. +        int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  202. +
  203. +        if (ret || !write)
  204. +                return ret;
  205. +
  206. +        read_lock_irqsave(&tasklist_lock, flags);
  207. +
  208. +        rcu_read_lock();
  209. +        for_each_process(p) {
  210. +                tg = task_group(p);
  211. +                tty_sched_move_task(p, tg);
  212. +                list_for_each_entry_rcu(t, &p->thread_group, thread_group) {
  213. +                        tty_sched_move_task(t, tg);
  214. +                }
  215. +        }
  216. +        rcu_read_unlock();
  217. +
  218. +        read_unlock_irqrestore(&tasklist_lock, flags);
  219. +
  220. +        return 0;
  221. +}
  222. +
  223. +static int __init setup_tty_sched(char *str)
  224. +{
  225. +        unsigned long val;
  226. +
  227. +        val = simple_strtoul(str, NULL, 0);
  228. +        sysctl_sched_tty_sched_enabled = val ? 1 : 0;
  229. +
  230. +        return 1;
  231. +}
  232. +__setup("ttysched=", setup_tty_sched);
  233. +#endif
  234. Index: linux-2.6.36.git/kernel/sysctl.c
  235. ===================================================================
  236. --- linux-2.6.36.git.orig/kernel/sysctl.c
  237. +++ linux-2.6.36.git/kernel/sysctl.c
  238. @@ -384,6 +384,17 @@ static struct ctl_table kern_table[] = {
  239.                 .mode                = 0644,
  240.                 .proc_handler        = proc_dointvec,
  241.         },
  242. +#ifdef CONFIG_SCHED_DESKTOP
  243. +        {
  244. +                .procname        = "sched_tty_sched_enabled",
  245. +                .data                = &sysctl_sched_tty_sched_enabled,
  246. +                .maxlen                = sizeof(unsigned int),
  247. +                .mode                = 0644,
  248. +                .proc_handler        = sched_tty_sched_handler,
  249. +                .extra1                = &zero,
  250. +                .extra2                = &one,
  251. +        },
  252. +#endif
  253. #ifdef CONFIG_PROVE_LOCKING
  254.         {
  255.                 .procname        = "prove_locking",
  256. Index: linux-2.6.36.git/init/Kconfig
  257. ===================================================================
  258. --- linux-2.6.36.git.orig/init/Kconfig
  259. +++ linux-2.6.36.git/init/Kconfig
  260. @@ -652,6 +652,19 @@ config DEBUG_BLK_CGROUP

  261. endif # CGROUPS

  262. +config SCHED_DESKTOP
  263. +        bool "Desktop centric group scheduling"
  264. +        depends on EXPERIMENTAL
  265. +        select CGROUPS
  266. +        select CGROUP_SCHED
  267. +        select FAIR_GROUP_SCHED
  268. +        select RT_GROUP_SCHED
  269. +        select BLK_CGROUP
  270. +        help
  271. +          This option optimizes the group scheduler for common desktop workloads,
  272. +          by creating separate per tty groups. This separation of workloads isolates
  273. +          aggressive CPU burners (like build jobs) from desktop applications.
  274. +
  275. config MM_OWNER
  276.         bool

复制代码
回复 支持 反对

使用道具 举报

发表于 2010-11-17 23:59:32 | 显示全部楼层
另外,打上补丁后要在内核配置界面选择:Desktop centric group scheduling

不过老实说我还真没看出什么区别,我的本子是i7 840QM的,8G内存,7200转硬盘,平时用的时候也很少卡,用上了一样很少卡
回复 支持 反对

使用道具 举报

发表于 2010-11-18 03:48:40 | 显示全部楼层
现在我又倾向于ck所说的,没有必要使用类似补丁。。应该使用别的方法来让高负载任务控制负载。而不是所有任务都控制。
回复 支持 反对

使用道具 举报

发表于 2010-11-18 03:58:03 | 显示全部楼层
如某大所言:「如果打上了還爽不出來,'make -j64'」
回复 支持 反对

使用道具 举报

发表于 2010-11-18 07:29:10 | 显示全部楼层
其实偶没打补丁,在高负载情况下,也没感觉多少卡嘛...
那个I/O的补丁我倒有些兴趣,现在瓶颈都在硬盘了...
回复 支持 反对

使用道具 举报

发表于 2010-11-18 08:26:38 | 显示全部楼层
膜拜各种i7.。。。。

老CPU用户内牛满面的路过。。。
高负载放1080P神马的。。
我把所有程序关掉都放不了720P T T
回复 支持 反对

使用道具 举报

发表于 2010-11-18 09:04:42 | 显示全部楼层
Post by shierji;2120172
膜拜各种i7.。。。。

老CPU用户内牛满面的路过。。。
高负载放1080P神马的。。
我把所有程序关掉都放不了720P T T


我是旧本本裸奔下720p都不给力
回复 支持 反对

使用道具 举报

发表于 2010-11-18 14:51:13 | 显示全部楼层
6.5年前的老本儿用户飘过……
回复 支持 反对

使用道具 举报

发表于 2010-11-18 16:21:03 | 显示全部楼层

to hubert_star

Post by hubert_star;2120156
另外,打上补丁后要在内核配置界面选择:Desktop centric group scheduling

不过老实说我还真没看出什么区别,我的本子是i7 840QM的,8G内存,7200转硬盘,平时用的时候也很少卡,用上了一样很少卡


什么型号的本子,好用吗? 想以后升级的时候参考一下。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表