pdflush内核线程池及其中隐含的竞争(3)
又是一大段注释,不知道你有没有看烦,反正我都有点儿腻烦了,本来只想就其间的竞争说两句,没想到扯出这么多东西!上面介绍的是线程池的算法:
- pdflush线程实例的数量介于MIN_PDFLUSH_THREADS和MAX_PDFLUSH_THREADS之间。
- 如果线程池持续1秒没有空闲线程,则创建一个新的线程。
- 如果那个最先睡眠的进程休息了超过1秒,则结束一个线程实例。
79 /* 80 * A structure for passing work to a pdflush thread. Also for passing 81 * state information between pdflush threads. Protected by pdflush_lock. 82 */ 83 struct pdflush_work { 84 struct task_struct *who; /* The thread */ 85 void (*fn)(unsigned long); /* A callback function */ 86 unsigned long arg0; /* An argument to the callback */ 87 struct list_head list; /* On pdflush_list, when idle */ 88 unsigned long when_i_went_to_sleep; 89 }; 90 |
上面定义了每个线程实例的节点数据结构,比较简明,不需要再废话。
现在,基本的数据结构的变量都浏览了一遍,接下来我们将从module_init这个入口着手分析:
232 static int __init pdflush_init(void) 233 { 234 int i; 235 236 for (i = 0; i < MIN_PDFLUSH_THREADS; i++) 237 start_one_pdflush_thread(); 238 return 0; 239 } 240 241 module_init(pdflush_init); |
创建MIN_PDFLUSH_THREADS个pdflush线程实例。请注意,这里只有module_init()定义,而没有module_exit(),言外之意就是:这个程序即使编译成内核模块,也是只能添加不能删除。请参看sys_delete_module()的实现:
File: kernel/module.c
609 /* If it has an init func, it must have an exit func to unload */ 610 if ((mod->init != NULL && mod->exit == NULL) 611 || mod->unsafe) { 612 forced = try_force(flags); 613 if (!forced) { 614 /* This module can't be removed */ 615 ret = -EBUSY; 616 goto out; 617 } 618 } |
- 上一篇:Linux日志文件系统及性能分析
- 下一篇:linux学习日记五 磁盘与文件系统管理