我是靠谱客的博主 健壮铃铛,这篇文章主要介绍kswapd进程,现在分享给大家,希望可以做个参考。

kswapd函数

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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进程内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(75)

评论列表共有 0 条评论

立即
投稿
返回
顶部