501d7513aac1bba793e65d06c92bee9dde5d9205
[linux-2.6-block.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 /* compaction didn't start as it was deferred due to past failures */
6 #define COMPACT_DEFERRED        0
7 /* compaction didn't start as it was not possible or direct reclaim was more suitable */
8 #define COMPACT_SKIPPED         1
9 /* compaction should continue to another pageblock */
10 #define COMPACT_CONTINUE        2
11 /* direct compaction partially compacted a zone and there are suitable pages */
12 #define COMPACT_PARTIAL         3
13 /* The full zone was compacted */
14 #define COMPACT_COMPLETE        4
15 /* For more detailed tracepoint output */
16 #define COMPACT_NO_SUITABLE_PAGE        5
17 #define COMPACT_NOT_SUITABLE_ZONE       6
18 /* When adding new state, please change compaction_status_string, too */
19
20 /* Used to signal whether compaction detected need_sched() or lock contention */
21 /* No contention detected */
22 #define COMPACT_CONTENDED_NONE  0
23 /* Either need_sched() was true or fatal signal pending */
24 #define COMPACT_CONTENDED_SCHED 1
25 /* Zone lock or lru_lock was contended in async compaction */
26 #define COMPACT_CONTENDED_LOCK  2
27
28 struct alloc_context; /* in mm/internal.h */
29
30 #ifdef CONFIG_COMPACTION
31 extern int sysctl_compact_memory;
32 extern int sysctl_compaction_handler(struct ctl_table *table, int write,
33                         void __user *buffer, size_t *length, loff_t *ppos);
34 extern int sysctl_extfrag_threshold;
35 extern int sysctl_extfrag_handler(struct ctl_table *table, int write,
36                         void __user *buffer, size_t *length, loff_t *ppos);
37
38 extern int fragmentation_index(struct zone *zone, unsigned int order);
39 extern unsigned long try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
40                         int alloc_flags, const struct alloc_context *ac,
41                         enum migrate_mode mode, int *contended);
42 extern void compact_pgdat(pg_data_t *pgdat, int order);
43 extern void reset_isolation_suitable(pg_data_t *pgdat);
44 extern unsigned long compaction_suitable(struct zone *zone, int order,
45                                         int alloc_flags, int classzone_idx);
46
47 /* Do not skip compaction more than 64 times */
48 #define COMPACT_MAX_DEFER_SHIFT 6
49
50 /*
51  * Compaction is deferred when compaction fails to result in a page
52  * allocation success. 1 << compact_defer_limit compactions are skipped up
53  * to a limit of 1 << COMPACT_MAX_DEFER_SHIFT
54  */
55 static inline void defer_compaction(struct zone *zone, int order)
56 {
57         zone->compact_considered = 0;
58         zone->compact_defer_shift++;
59
60         if (order < zone->compact_order_failed)
61                 zone->compact_order_failed = order;
62
63         if (zone->compact_defer_shift > COMPACT_MAX_DEFER_SHIFT)
64                 zone->compact_defer_shift = COMPACT_MAX_DEFER_SHIFT;
65 }
66
67 /* Returns true if compaction should be skipped this time */
68 static inline bool compaction_deferred(struct zone *zone, int order)
69 {
70         unsigned long defer_limit = 1UL << zone->compact_defer_shift;
71
72         if (order < zone->compact_order_failed)
73                 return false;
74
75         /* Avoid possible overflow */
76         if (++zone->compact_considered > defer_limit)
77                 zone->compact_considered = defer_limit;
78
79         return zone->compact_considered < defer_limit;
80 }
81
82 /*
83  * Update defer tracking counters after successful compaction of given order,
84  * which means an allocation either succeeded (alloc_success == true) or is
85  * expected to succeed.
86  */
87 static inline void compaction_defer_reset(struct zone *zone, int order,
88                 bool alloc_success)
89 {
90         if (alloc_success) {
91                 zone->compact_considered = 0;
92                 zone->compact_defer_shift = 0;
93         }
94         if (order >= zone->compact_order_failed)
95                 zone->compact_order_failed = order + 1;
96 }
97
98 /* Returns true if restarting compaction after many failures */
99 static inline bool compaction_restarting(struct zone *zone, int order)
100 {
101         if (order < zone->compact_order_failed)
102                 return false;
103
104         return zone->compact_defer_shift == COMPACT_MAX_DEFER_SHIFT &&
105                 zone->compact_considered >= 1UL << zone->compact_defer_shift;
106 }
107
108 #else
109 static inline unsigned long try_to_compact_pages(gfp_t gfp_mask,
110                         unsigned int order, int alloc_flags,
111                         const struct alloc_context *ac,
112                         enum migrate_mode mode, int *contended)
113 {
114         return COMPACT_CONTINUE;
115 }
116
117 static inline void compact_pgdat(pg_data_t *pgdat, int order)
118 {
119 }
120
121 static inline void reset_isolation_suitable(pg_data_t *pgdat)
122 {
123 }
124
125 static inline unsigned long compaction_suitable(struct zone *zone, int order,
126                                         int alloc_flags, int classzone_idx)
127 {
128         return COMPACT_SKIPPED;
129 }
130
131 static inline void defer_compaction(struct zone *zone, int order)
132 {
133 }
134
135 static inline bool compaction_deferred(struct zone *zone, int order)
136 {
137         return true;
138 }
139
140 #endif /* CONFIG_COMPACTION */
141
142 #if defined(CONFIG_COMPACTION) && defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
143 extern int compaction_register_node(struct node *node);
144 extern void compaction_unregister_node(struct node *node);
145
146 #else
147
148 static inline int compaction_register_node(struct node *node)
149 {
150         return 0;
151 }
152
153 static inline void compaction_unregister_node(struct node *node)
154 {
155 }
156 #endif /* CONFIG_COMPACTION && CONFIG_SYSFS && CONFIG_NUMA */
157
158 #endif /* _LINUX_COMPACTION_H */