pdflush内核线程池及其中隐含的竞争(4)
498 #ifdef CONFIG_MODULE_FORCE_UNLOAD 499 static inline int try_force(unsigned int flags) 500 { 501 int ret = (flags O_TRUNC); 502 if (ret) 503 add_taint(TAINT_FORCED_MODULE); 504 return ret; 505 } 50
498 #ifdef CONFIG_MODULE_FORCE_UNLOAD 499 static inline int try_force(unsigned int flags) 500 { 501 int ret = (flags & O_TRUNC); 502 if (ret) 503 add_taint(TAINT_FORCED_MODULE); 504 return ret; 505 } 506 #else 507 static inline int try_force(unsigned int flags) 508 { 509 return 0; 510 } 511 #endif /* CONFIG_MODULE_FORCE_UNLOAD */ |
可见,除非编译的时候选择了模块强制卸载(注意:这个选项比较危险,不要尝试)的选项,否则这样的模块是不允许被卸载的。再次回到pdflush:
227 static void start_one_pdflush_thread(void) 228 { 229 kthread_run(pdflush, NULL, "pdflush"); 230 } 231 |
用kthread_run借助kthread帮助线程生成pdflush内核线程实例:
164 /* 165 * Of course, my_work wants to be just a local in __pdflush(). It is 166 * separated out in this manner to hopefully prevent the compiler from 167 * performing unfortunate optimisations against the auto variables. Because 168 * these are visible to other tasks and CPUs. (No problem has actually 169 * been observed. This is just paranoia). 170 */ 这段注释比较有意思,为了防止编译器将局部变量my_work优化成寄存器变量,所以这里整个处理流程转变成了pdflush套__pdflush的方式。实际上,局部变量的采用相对于动态申请内存,无论是在空间利用率还是在时间效率上都是有好处的。 171 static int pdflush(void *dummy) 172 { 173 struct pdflush_work my_work; 174 cpumask_t cpus_allowed; 175 176 /* 177 * pdflush can spend a lot of time doing encryption via dm-crypt. We 178 * don't want to do that at keventd's priority. 179 */ 180 set_user_nice(current, 0); 微调优先级,提高系统的整体响应。 181 182 /* 183 * Some configs put our parent kthread in a limited cpuset, 184 * which kthread() overrides, forcing cpus_allowed == CPU_MASK_ALL. 185 * Our needs are more modest - cut back to our cpusets cpus_allowed. 186 * This is needed as pdflush's are dynamically created and destroyed. 187 * The boottime pdflush's are easily placed w/o these 2 lines. 188 */ 189 cpus_allowed = cpuset_cpus_allowed(current); 190 set_cpus_allowed(current, cpus_allowed); 设置允许运行的CPU集合掩码。 191 192 return __pdflush(&my_work); 193 } |
- 上一篇:Linux日志文件系统及性能分析
- 下一篇:linux学习日记五 磁盘与文件系统管理
精彩图集
精彩文章