compaction.h 4.0 KB

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