blob: 4cd4ddf64cc7f9dfeffcd71492b24b6f57e1e4a3 [file] [log] [blame]
Mel Gorman748446b2010-05-24 14:32:27 -07001#ifndef _LINUX_COMPACTION_H
2#define _LINUX_COMPACTION_H
3
Mel Gorman56de7262010-05-24 14:32:30 -07004/* Return values for compact_zone() and try_to_compact_pages() */
Vlastimil Babka53853e22014-10-09 15:27:02 -07005/* compaction didn't start as it was deferred due to past failures */
6#define COMPACT_DEFERRED 0
Mel Gorman56de7262010-05-24 14:32:30 -07007/* compaction didn't start as it was not possible or direct reclaim was more suitable */
Vlastimil Babka53853e22014-10-09 15:27:02 -07008#define COMPACT_SKIPPED 1
Mel Gorman56de7262010-05-24 14:32:30 -07009/* compaction should continue to another pageblock */
Vlastimil Babka53853e22014-10-09 15:27:02 -070010#define COMPACT_CONTINUE 2
Mel Gorman56de7262010-05-24 14:32:30 -070011/* direct compaction partially compacted a zone and there are suitable pages */
Vlastimil Babka53853e22014-10-09 15:27:02 -070012#define COMPACT_PARTIAL 3
Mel Gorman56de7262010-05-24 14:32:30 -070013/* The full zone was compacted */
Vlastimil Babka53853e22014-10-09 15:27:02 -070014#define COMPACT_COMPLETE 4
Joonsoo Kim837d0262015-02-11 15:27:06 -080015/* For more detailed tracepoint output */
16#define COMPACT_NO_SUITABLE_PAGE 5
17#define COMPACT_NOT_SUITABLE_ZONE 6
Vlastimil Babka2d1e1042015-11-05 18:48:02 -080018#define COMPACT_CONTENDED 7
Vlastimil Babkafa6c7b42015-11-05 18:47:56 -080019/* When adding new states, please adjust include/trace/events/compaction.h */
Mel Gorman748446b2010-05-24 14:32:27 -070020
Vlastimil Babka1f9efde2014-10-09 15:27:14 -070021/* Used to signal whether compaction detected need_sched() or lock contention */
22/* No contention detected */
23#define COMPACT_CONTENDED_NONE 0
24/* Either need_sched() was true or fatal signal pending */
25#define COMPACT_CONTENDED_SCHED 1
26/* Zone lock or lru_lock was contended in async compaction */
27#define COMPACT_CONTENDED_LOCK 2
28
Vlastimil Babka1a6d53a2015-02-11 15:25:44 -080029struct alloc_context; /* in mm/internal.h */
30
Mel Gorman76ab0f52010-05-24 14:32:28 -070031#ifdef CONFIG_COMPACTION
32extern int sysctl_compact_memory;
33extern int sysctl_compaction_handler(struct ctl_table *table, int write,
34 void __user *buffer, size_t *length, loff_t *ppos);
Mel Gorman5e771902010-05-24 14:32:31 -070035extern int sysctl_extfrag_threshold;
36extern int sysctl_extfrag_handler(struct ctl_table *table, int write,
37 void __user *buffer, size_t *length, loff_t *ppos);
Eric B Munson5bbe3542015-04-15 16:13:20 -070038extern int sysctl_compact_unevictable_allowed;
Mel Gorman56de7262010-05-24 14:32:30 -070039
40extern int fragmentation_index(struct zone *zone, unsigned int order);
Vlastimil Babka1a6d53a2015-02-11 15:25:44 -080041extern unsigned long try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
42 int alloc_flags, const struct alloc_context *ac,
43 enum migrate_mode mode, int *contended);
Andrew Morton7103f162013-02-22 16:32:33 -080044extern void compact_pgdat(pg_data_t *pgdat, int order);
Mel Gorman62997022012-10-08 16:32:47 -070045extern void reset_isolation_suitable(pg_data_t *pgdat);
Vlastimil Babkaebff3982014-12-10 15:43:22 -080046extern unsigned long compaction_suitable(struct zone *zone, int order,
47 int alloc_flags, int classzone_idx);
Mel Gorman4f92e252010-05-24 14:32:32 -070048
Joonsoo Kim24e27162015-02-11 15:27:09 -080049extern void defer_compaction(struct zone *zone, int order);
50extern bool compaction_deferred(struct zone *zone, int order);
51extern void compaction_defer_reset(struct zone *zone, int order,
52 bool alloc_success);
53extern bool compaction_restarting(struct zone *zone, int order);
Mel Gorman62997022012-10-08 16:32:47 -070054
Mel Gorman56de7262010-05-24 14:32:30 -070055#else
Vlastimil Babka1a6d53a2015-02-11 15:25:44 -080056static inline unsigned long try_to_compact_pages(gfp_t gfp_mask,
57 unsigned int order, int alloc_flags,
58 const struct alloc_context *ac,
59 enum migrate_mode mode, int *contended)
Mel Gorman56de7262010-05-24 14:32:30 -070060{
61 return COMPACT_CONTINUE;
62}
63
Andrew Morton7103f162013-02-22 16:32:33 -080064static inline void compact_pgdat(pg_data_t *pgdat, int order)
Rik van Riel7be62de2012-03-21 16:33:52 -070065{
Rik van Riel7be62de2012-03-21 16:33:52 -070066}
67
Mel Gorman62997022012-10-08 16:32:47 -070068static inline void reset_isolation_suitable(pg_data_t *pgdat)
69{
70}
71
Vlastimil Babkaebff3982014-12-10 15:43:22 -080072static inline unsigned long compaction_suitable(struct zone *zone, int order,
73 int alloc_flags, int classzone_idx)
Mel Gorman3e7d3442011-01-13 15:45:56 -080074{
75 return COMPACT_SKIPPED;
76}
77
Rik van Rielaff62242012-03-21 16:33:52 -070078static inline void defer_compaction(struct zone *zone, int order)
Mel Gorman4f92e252010-05-24 14:32:32 -070079{
80}
81
Rik van Rielaff62242012-03-21 16:33:52 -070082static inline bool compaction_deferred(struct zone *zone, int order)
Mel Gorman4f92e252010-05-24 14:32:32 -070083{
Gavin Shanc59e2612012-07-31 16:42:49 -070084 return true;
Mel Gorman4f92e252010-05-24 14:32:32 -070085}
86
Mel Gorman76ab0f52010-05-24 14:32:28 -070087#endif /* CONFIG_COMPACTION */
88
Mel Gormaned4a6d72010-05-24 14:32:29 -070089#if defined(CONFIG_COMPACTION) && defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
90extern int compaction_register_node(struct node *node);
91extern void compaction_unregister_node(struct node *node);
92
93#else
94
95static inline int compaction_register_node(struct node *node)
96{
97 return 0;
98}
99
100static inline void compaction_unregister_node(struct node *node)
101{
102}
103#endif /* CONFIG_COMPACTION && CONFIG_SYSFS && CONFIG_NUMA */
104
Mel Gorman748446b2010-05-24 14:32:27 -0700105#endif /* _LINUX_COMPACTION_H */