11f228712ed5edf158935803aa2f9e304b1c6662
[cascardo/linux.git] / include / linux / compaction.h
1 #ifndef _LINUX_COMPACTION_H
2 #define _LINUX_COMPACTION_H
3
4 /* Return values for compact_zone() and try_to_compact_pages() */
5 /* When adding new states, please adjust include/trace/events/compaction.h */
6 enum compact_result {
7         /*
8          * compaction didn't start as it was not possible or direct reclaim
9          * was more suitable
10          */
11         COMPACT_SKIPPED,
12         /* compaction didn't start as it was deferred due to past failures */
13         COMPACT_DEFERRED,
14         /* compaction not active last round */
15         COMPACT_INACTIVE = COMPACT_DEFERRED,
16
17         /* compaction should continue to another pageblock */
18         COMPACT_CONTINUE,
19         /*
20          * direct compaction partially compacted a zone and there are suitable
21          * pages
22          */
23         COMPACT_PARTIAL,
24         /* The full zone was compacted */
25         COMPACT_COMPLETE,
26         /* For more detailed tracepoint output */
27         COMPACT_NO_SUITABLE_PAGE,
28         COMPACT_NOT_SUITABLE_ZONE,
29         COMPACT_CONTENDED,
30 };
31
32 /* Used to signal whether compaction detected need_sched() or lock contention */
33 /* No contention detected */
34 #define COMPACT_CONTENDED_NONE  0
35 /* Either need_sched() was true or fatal signal pending */
36 #define COMPACT_CONTENDED_SCHED 1
37 /* Zone lock or lru_lock was contended in async compaction */
38 #define COMPACT_CONTENDED_LOCK  2
39
40 struct alloc_context; /* in mm/internal.h */
41
42 #ifdef CONFIG_COMPACTION
43 extern int sysctl_compact_memory;
44 extern int sysctl_compaction_handler(struct ctl_table *table, int write,
45                         void __user *buffer, size_t *length, loff_t *ppos);
46 extern int sysctl_extfrag_threshold;
47 extern int sysctl_extfrag_handler(struct ctl_table *table, int write,
48                         void __user *buffer, size_t *length, loff_t *ppos);
49 extern int sysctl_compact_unevictable_allowed;
50
51 extern int fragmentation_index(struct zone *zone, unsigned int order);
52 extern enum compact_result try_to_compact_pages(gfp_t gfp_mask,
53                         unsigned int order,
54                 unsigned int alloc_flags, const struct alloc_context *ac,
55                 enum migrate_mode mode, int *contended);
56 extern void compact_pgdat(pg_data_t *pgdat, int order);
57 extern void reset_isolation_suitable(pg_data_t *pgdat);
58 extern enum compact_result compaction_suitable(struct zone *zone, int order,
59                 unsigned int alloc_flags, int classzone_idx);
60
61 extern void defer_compaction(struct zone *zone, int order);
62 extern bool compaction_deferred(struct zone *zone, int order);
63 extern void compaction_defer_reset(struct zone *zone, int order,
64                                 bool alloc_success);
65 extern bool compaction_restarting(struct zone *zone, int order);
66
67 extern int kcompactd_run(int nid);
68 extern void kcompactd_stop(int nid);
69 extern void wakeup_kcompactd(pg_data_t *pgdat, int order, int classzone_idx);
70
71 #else
72 static inline enum compact_result try_to_compact_pages(gfp_t gfp_mask,
73                         unsigned int order, int alloc_flags,
74                         const struct alloc_context *ac,
75                         enum migrate_mode mode, int *contended)
76 {
77         return COMPACT_CONTINUE;
78 }
79
80 static inline void compact_pgdat(pg_data_t *pgdat, int order)
81 {
82 }
83
84 static inline void reset_isolation_suitable(pg_data_t *pgdat)
85 {
86 }
87
88 static inline enum compact_result compaction_suitable(struct zone *zone, int order,
89                                         int alloc_flags, int classzone_idx)
90 {
91         return COMPACT_SKIPPED;
92 }
93
94 static inline void defer_compaction(struct zone *zone, int order)
95 {
96 }
97
98 static inline bool compaction_deferred(struct zone *zone, int order)
99 {
100         return true;
101 }
102
103 static inline int kcompactd_run(int nid)
104 {
105         return 0;
106 }
107 static inline void kcompactd_stop(int nid)
108 {
109 }
110
111 static inline void wakeup_kcompactd(pg_data_t *pgdat, int order, int classzone_idx)
112 {
113 }
114
115 #endif /* CONFIG_COMPACTION */
116
117 #if defined(CONFIG_COMPACTION) && defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
118 extern int compaction_register_node(struct node *node);
119 extern void compaction_unregister_node(struct node *node);
120
121 #else
122
123 static inline int compaction_register_node(struct node *node)
124 {
125         return 0;
126 }
127
128 static inline void compaction_unregister_node(struct node *node)
129 {
130 }
131 #endif /* CONFIG_COMPACTION && CONFIG_SYSFS && CONFIG_NUMA */
132
133 #endif /* _LINUX_COMPACTION_H */