0001
0002 #ifndef _LINUX_COMPACTION_H
0003 #define _LINUX_COMPACTION_H
0004
0005
0006
0007
0008
0009 enum compact_priority {
0010 COMPACT_PRIO_SYNC_FULL,
0011 MIN_COMPACT_PRIORITY = COMPACT_PRIO_SYNC_FULL,
0012 COMPACT_PRIO_SYNC_LIGHT,
0013 MIN_COMPACT_COSTLY_PRIORITY = COMPACT_PRIO_SYNC_LIGHT,
0014 DEF_COMPACT_PRIORITY = COMPACT_PRIO_SYNC_LIGHT,
0015 COMPACT_PRIO_ASYNC,
0016 INIT_COMPACT_PRIORITY = COMPACT_PRIO_ASYNC
0017 };
0018
0019
0020
0021 enum compact_result {
0022
0023 COMPACT_NOT_SUITABLE_ZONE,
0024
0025
0026
0027
0028 COMPACT_SKIPPED,
0029
0030 COMPACT_DEFERRED,
0031
0032
0033 COMPACT_NO_SUITABLE_PAGE,
0034
0035 COMPACT_CONTINUE,
0036
0037
0038
0039
0040
0041 COMPACT_COMPLETE,
0042
0043
0044
0045
0046 COMPACT_PARTIAL_SKIPPED,
0047
0048
0049 COMPACT_CONTENDED,
0050
0051
0052
0053
0054
0055 COMPACT_SUCCESS,
0056 };
0057
0058 struct alloc_context;
0059
0060
0061
0062
0063
0064
0065 static inline unsigned long compact_gap(unsigned int order)
0066 {
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 return 2UL << order;
0081 }
0082
0083 #ifdef CONFIG_COMPACTION
0084 extern unsigned int sysctl_compaction_proactiveness;
0085 extern int sysctl_compaction_handler(struct ctl_table *table, int write,
0086 void *buffer, size_t *length, loff_t *ppos);
0087 extern int compaction_proactiveness_sysctl_handler(struct ctl_table *table,
0088 int write, void *buffer, size_t *length, loff_t *ppos);
0089 extern int sysctl_extfrag_threshold;
0090 extern int sysctl_compact_unevictable_allowed;
0091
0092 extern unsigned int extfrag_for_order(struct zone *zone, unsigned int order);
0093 extern int fragmentation_index(struct zone *zone, unsigned int order);
0094 extern enum compact_result try_to_compact_pages(gfp_t gfp_mask,
0095 unsigned int order, unsigned int alloc_flags,
0096 const struct alloc_context *ac, enum compact_priority prio,
0097 struct page **page);
0098 extern void reset_isolation_suitable(pg_data_t *pgdat);
0099 extern enum compact_result compaction_suitable(struct zone *zone, int order,
0100 unsigned int alloc_flags, int highest_zoneidx);
0101
0102 extern void compaction_defer_reset(struct zone *zone, int order,
0103 bool alloc_success);
0104
0105
0106 static inline bool compaction_made_progress(enum compact_result result)
0107 {
0108
0109
0110
0111
0112
0113 if (result == COMPACT_SUCCESS)
0114 return true;
0115
0116 return false;
0117 }
0118
0119
0120 static inline bool compaction_failed(enum compact_result result)
0121 {
0122
0123 if (result == COMPACT_COMPLETE)
0124 return true;
0125
0126 return false;
0127 }
0128
0129
0130 static inline bool compaction_needs_reclaim(enum compact_result result)
0131 {
0132
0133
0134
0135
0136 if (result == COMPACT_SKIPPED)
0137 return true;
0138
0139 return false;
0140 }
0141
0142
0143
0144
0145
0146
0147 static inline bool compaction_withdrawn(enum compact_result result)
0148 {
0149
0150
0151
0152
0153
0154
0155
0156 if (result == COMPACT_DEFERRED)
0157 return true;
0158
0159
0160
0161
0162
0163 if (result == COMPACT_CONTENDED)
0164 return true;
0165
0166
0167
0168
0169
0170 if (result == COMPACT_PARTIAL_SKIPPED)
0171 return true;
0172
0173 return false;
0174 }
0175
0176
0177 bool compaction_zonelist_suitable(struct alloc_context *ac, int order,
0178 int alloc_flags);
0179
0180 extern void kcompactd_run(int nid);
0181 extern void kcompactd_stop(int nid);
0182 extern void wakeup_kcompactd(pg_data_t *pgdat, int order, int highest_zoneidx);
0183
0184 #else
0185 static inline void reset_isolation_suitable(pg_data_t *pgdat)
0186 {
0187 }
0188
0189 static inline enum compact_result compaction_suitable(struct zone *zone, int order,
0190 int alloc_flags, int highest_zoneidx)
0191 {
0192 return COMPACT_SKIPPED;
0193 }
0194
0195 static inline bool compaction_made_progress(enum compact_result result)
0196 {
0197 return false;
0198 }
0199
0200 static inline bool compaction_failed(enum compact_result result)
0201 {
0202 return false;
0203 }
0204
0205 static inline bool compaction_needs_reclaim(enum compact_result result)
0206 {
0207 return false;
0208 }
0209
0210 static inline bool compaction_withdrawn(enum compact_result result)
0211 {
0212 return true;
0213 }
0214
0215 static inline void kcompactd_run(int nid)
0216 {
0217 }
0218 static inline void kcompactd_stop(int nid)
0219 {
0220 }
0221
0222 static inline void wakeup_kcompactd(pg_data_t *pgdat,
0223 int order, int highest_zoneidx)
0224 {
0225 }
0226
0227 #endif
0228
0229 struct node;
0230 #if defined(CONFIG_COMPACTION) && defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
0231 extern int compaction_register_node(struct node *node);
0232 extern void compaction_unregister_node(struct node *node);
0233
0234 #else
0235
0236 static inline int compaction_register_node(struct node *node)
0237 {
0238 return 0;
0239 }
0240
0241 static inline void compaction_unregister_node(struct node *node)
0242 {
0243 }
0244 #endif
0245
0246 #endif