1#ifndef _LINUX_COMPACTION_H
2#define _LINUX_COMPACTION_H
3
4
5
6
7
8enum compact_priority {
9 COMPACT_PRIO_SYNC_LIGHT,
10 MIN_COMPACT_PRIORITY = COMPACT_PRIO_SYNC_LIGHT,
11 DEF_COMPACT_PRIORITY = COMPACT_PRIO_SYNC_LIGHT,
12 COMPACT_PRIO_ASYNC,
13 INIT_COMPACT_PRIORITY = COMPACT_PRIO_ASYNC
14};
15
16
17
18enum compact_result {
19
20 COMPACT_NOT_SUITABLE_ZONE,
21
22
23
24
25 COMPACT_SKIPPED,
26
27 COMPACT_DEFERRED,
28
29
30 COMPACT_INACTIVE = 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_PARTIAL,
56};
57
58struct alloc_context;
59
60#ifdef CONFIG_COMPACTION
61extern int sysctl_compact_memory;
62extern int sysctl_compaction_handler(struct ctl_table *table, int write,
63 void __user *buffer, size_t *length, loff_t *ppos);
64extern int sysctl_extfrag_threshold;
65extern int sysctl_extfrag_handler(struct ctl_table *table, int write,
66 void __user *buffer, size_t *length, loff_t *ppos);
67extern int sysctl_compact_unevictable_allowed;
68
69extern int fragmentation_index(struct zone *zone, unsigned int order);
70extern enum compact_result try_to_compact_pages(gfp_t gfp_mask,
71 unsigned int order, unsigned int alloc_flags,
72 const struct alloc_context *ac, enum compact_priority prio);
73extern void compact_pgdat(pg_data_t *pgdat, int order);
74extern void reset_isolation_suitable(pg_data_t *pgdat);
75extern enum compact_result compaction_suitable(struct zone *zone, int order,
76 unsigned int alloc_flags, int classzone_idx);
77
78extern void defer_compaction(struct zone *zone, int order);
79extern bool compaction_deferred(struct zone *zone, int order);
80extern void compaction_defer_reset(struct zone *zone, int order,
81 bool alloc_success);
82extern bool compaction_restarting(struct zone *zone, int order);
83
84
85static inline bool compaction_made_progress(enum compact_result result)
86{
87
88
89
90
91
92 if (result == COMPACT_PARTIAL)
93 return true;
94
95 return false;
96}
97
98
99static inline bool compaction_failed(enum compact_result result)
100{
101
102 if (result == COMPACT_COMPLETE)
103 return true;
104
105 return false;
106}
107
108
109
110
111
112static inline bool compaction_withdrawn(enum compact_result result)
113{
114
115
116
117
118 if (result == COMPACT_SKIPPED)
119 return true;
120
121
122
123
124
125
126
127
128 if (result == COMPACT_DEFERRED)
129 return true;
130
131
132
133
134
135 if (result == COMPACT_CONTENDED)
136 return true;
137
138
139
140
141
142 if (result == COMPACT_PARTIAL_SKIPPED)
143 return true;
144
145 return false;
146}
147
148
149bool compaction_zonelist_suitable(struct alloc_context *ac, int order,
150 int alloc_flags);
151
152extern int kcompactd_run(int nid);
153extern void kcompactd_stop(int nid);
154extern void wakeup_kcompactd(pg_data_t *pgdat, int order, int classzone_idx);
155
156#else
157static inline void compact_pgdat(pg_data_t *pgdat, int order)
158{
159}
160
161static inline void reset_isolation_suitable(pg_data_t *pgdat)
162{
163}
164
165static inline enum compact_result compaction_suitable(struct zone *zone, int order,
166 int alloc_flags, int classzone_idx)
167{
168 return COMPACT_SKIPPED;
169}
170
171static inline void defer_compaction(struct zone *zone, int order)
172{
173}
174
175static inline bool compaction_deferred(struct zone *zone, int order)
176{
177 return true;
178}
179
180static inline bool compaction_made_progress(enum compact_result result)
181{
182 return false;
183}
184
185static inline bool compaction_failed(enum compact_result result)
186{
187 return false;
188}
189
190static inline bool compaction_withdrawn(enum compact_result result)
191{
192 return true;
193}
194
195static inline int kcompactd_run(int nid)
196{
197 return 0;
198}
199static inline void kcompactd_stop(int nid)
200{
201}
202
203static inline void wakeup_kcompactd(pg_data_t *pgdat, int order, int classzone_idx)
204{
205}
206
207#endif
208
209#if defined(CONFIG_COMPACTION) && defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
210struct node;
211extern int compaction_register_node(struct node *node);
212extern void compaction_unregister_node(struct node *node);
213
214#else
215
216static inline int compaction_register_node(struct node *node)
217{
218 return 0;
219}
220
221static inline void compaction_unregister_node(struct node *node)
222{
223}
224#endif
225
226#endif
227