1
2#ifndef _LINUX_COMPACTION_H
3#define _LINUX_COMPACTION_H
4
5
6
7
8
9enum compact_priority {
10 COMPACT_PRIO_SYNC_FULL,
11 MIN_COMPACT_PRIORITY = COMPACT_PRIO_SYNC_FULL,
12 COMPACT_PRIO_SYNC_LIGHT,
13 MIN_COMPACT_COSTLY_PRIORITY = COMPACT_PRIO_SYNC_LIGHT,
14 DEF_COMPACT_PRIORITY = COMPACT_PRIO_SYNC_LIGHT,
15 COMPACT_PRIO_ASYNC,
16 INIT_COMPACT_PRIORITY = COMPACT_PRIO_ASYNC
17};
18
19
20
21enum compact_result {
22
23 COMPACT_NOT_SUITABLE_ZONE,
24
25
26
27
28 COMPACT_SKIPPED,
29
30 COMPACT_DEFERRED,
31
32
33 COMPACT_NO_SUITABLE_PAGE,
34
35 COMPACT_CONTINUE,
36
37
38
39
40
41 COMPACT_COMPLETE,
42
43
44
45
46 COMPACT_PARTIAL_SKIPPED,
47
48
49 COMPACT_CONTENDED,
50
51
52
53
54
55 COMPACT_SUCCESS,
56};
57
58struct alloc_context;
59
60
61
62
63
64
65static inline unsigned long compact_gap(unsigned int order)
66{
67
68
69
70
71
72
73
74
75
76
77
78
79
80 return 2UL << order;
81}
82
83#ifdef CONFIG_COMPACTION
84extern unsigned int sysctl_compaction_proactiveness;
85extern int sysctl_compaction_handler(struct ctl_table *table, int write,
86 void *buffer, size_t *length, loff_t *ppos);
87extern int compaction_proactiveness_sysctl_handler(struct ctl_table *table,
88 int write, void *buffer, size_t *length, loff_t *ppos);
89extern int sysctl_extfrag_threshold;
90extern int sysctl_compact_unevictable_allowed;
91
92extern unsigned int extfrag_for_order(struct zone *zone, unsigned int order);
93extern int fragmentation_index(struct zone *zone, unsigned int order);
94extern enum compact_result try_to_compact_pages(gfp_t gfp_mask,
95 unsigned int order, unsigned int alloc_flags,
96 const struct alloc_context *ac, enum compact_priority prio,
97 struct page **page);
98extern void reset_isolation_suitable(pg_data_t *pgdat);
99extern enum compact_result compaction_suitable(struct zone *zone, int order,
100 unsigned int alloc_flags, int highest_zoneidx);
101
102extern void compaction_defer_reset(struct zone *zone, int order,
103 bool alloc_success);
104
105
106static inline bool compaction_made_progress(enum compact_result result)
107{
108
109
110
111
112
113 if (result == COMPACT_SUCCESS)
114 return true;
115
116 return false;
117}
118
119
120static inline bool compaction_failed(enum compact_result result)
121{
122
123 if (result == COMPACT_COMPLETE)
124 return true;
125
126 return false;
127}
128
129
130static inline bool compaction_needs_reclaim(enum compact_result result)
131{
132
133
134
135
136 if (result == COMPACT_SKIPPED)
137 return true;
138
139 return false;
140}
141
142
143
144
145
146
147static inline bool compaction_withdrawn(enum compact_result result)
148{
149
150
151
152
153
154
155
156 if (result == COMPACT_DEFERRED)
157 return true;
158
159
160
161
162
163 if (result == COMPACT_CONTENDED)
164 return true;
165
166
167
168
169
170 if (result == COMPACT_PARTIAL_SKIPPED)
171 return true;
172
173 return false;
174}
175
176
177bool compaction_zonelist_suitable(struct alloc_context *ac, int order,
178 int alloc_flags);
179
180extern int kcompactd_run(int nid);
181extern void kcompactd_stop(int nid);
182extern void wakeup_kcompactd(pg_data_t *pgdat, int order, int highest_zoneidx);
183
184#else
185static inline void reset_isolation_suitable(pg_data_t *pgdat)
186{
187}
188
189static inline enum compact_result compaction_suitable(struct zone *zone, int order,
190 int alloc_flags, int highest_zoneidx)
191{
192 return COMPACT_SKIPPED;
193}
194
195static inline bool compaction_made_progress(enum compact_result result)
196{
197 return false;
198}
199
200static inline bool compaction_failed(enum compact_result result)
201{
202 return false;
203}
204
205static inline bool compaction_needs_reclaim(enum compact_result result)
206{
207 return false;
208}
209
210static inline bool compaction_withdrawn(enum compact_result result)
211{
212 return true;
213}
214
215static inline int kcompactd_run(int nid)
216{
217 return 0;
218}
219static inline void kcompactd_stop(int nid)
220{
221}
222
223static inline void wakeup_kcompactd(pg_data_t *pgdat,
224 int order, int highest_zoneidx)
225{
226}
227
228#endif
229
230struct node;
231#if defined(CONFIG_COMPACTION) && defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
232extern int compaction_register_node(struct node *node);
233extern void compaction_unregister_node(struct node *node);
234
235#else
236
237static inline int compaction_register_node(struct node *node)
238{
239 return 0;
240}
241
242static inline void compaction_unregister_node(struct node *node)
243{
244}
245#endif
246
247#endif
248