概述
kswapd函数
1138 static int kswapd(void *p)
1139 {
1140
unsigned long order;
1141
pg_data_t *pgdat = (pg_data_t*)p;
1142
struct task_struct *tsk = current;
1143
DEFINE_WAIT(wait);
1144
struct reclaim_state reclaim_state = {
1145
.reclaimed_slab = 0,
1146
};
1147
cpumask_t cpumask;
1148
1149
daemonize("kswapd%d", pgdat->node_id);
1150
cpumask = node_to_cpumask(pgdat->node_id);
1151
if (!cpus_empty(cpumask))
1152
set_cpus_allowed(tsk, cpumask);
1153
current->reclaim_state = &reclaim_state;
1154
1155
/*
1156
* Tell the memory management that we're a "memory allocator",
1157
* and that if we need more memory we should get access to it
1158
* regardless (see "__alloc_pages()"). "kswapd" should
1159
* never get caught in the normal page freeing logic.
1160
*
1161
* (Kswapd normally doesn't need memory anyway, but sometimes
1162
* you need a small amount of memory in order to be able to
1163
* page out something else, and this flag essentially protects
1164
* us from recursively trying to free more memory as we're
1165
* trying to free the first piece of memory in the first place).
1166
*/
1167
tsk->flags |= PF_MEMALLOC|PF_KSWAPD;
1168
1169
order = 0;
1170
printk(KERN_ERR "tom kswapd initrn");
1171
for ( ; ; ) {
1172
unsigned long new_order;
1173
if (current->flags & PF_FREEZE)
1174
refrigerator(PF_FREEZE);
1175
1176
prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
1177
new_order = pgdat->kswapd_max_order;
1178
pgdat->kswapd_max_order = 0;
1179
1180
printk(KERN_ERR "tom kswapd init order=%x new_order=%xrn",order,new_order);
1181
if (order < new_order) {
1182
/*
1183
* Don't sleep if someone wants a larger 'order'
1184
* allocation
1185
*/
1186
order = new_order;
1187
} else {
1188
printk(KERN_ERR "tom kswapd init before schedulern");
1189
schedule();
1190
order = pgdat->kswapd_max_order;
1191
printk(KERN_ERR "tom kswapd init after schedulern");
1192
}
1193
finish_wait(&pgdat->kswapd_wait, &wait);
1194
1195
printk(KERN_ERR "tom kswapd init 111rn");
1196
balance_pgdat(pgdat, 0, order);
1197
}
1198
return 0;
1199 }
说明:系统初始化后,在1189行schedule()后进入休眠。在__alloc_page的函数中使用wakeup_kswapd唤醒这个进程,然后kswapd会在1190行进行运行,在1196行进入balance_pgdat函数,进行内存释放工作。
balance_pgdat函数
最后
以上就是健壮铃铛为你收集整理的kswapd进程的全部内容,希望文章能够帮你解决kswapd进程所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复