compaction.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #ifndef _LINUX_COMPACTION_H
  2. #define _LINUX_COMPACTION_H
  3. /* Return values for compact_zone() and try_to_compact_pages() */
  4. /* compaction didn't start as it was deferred due to past failures */
  5. #define COMPACT_DEFERRED 0
  6. /* compaction didn't start as it was not possible or direct reclaim was more suitable */
  7. #define COMPACT_SKIPPED 1
  8. /* compaction should continue to another pageblock */
  9. #define COMPACT_CONTINUE 2
  10. /* direct compaction partially compacted a zone and there are suitable pages */
  11. #define COMPACT_PARTIAL 3
  12. /* The full zone was compacted */
  13. #define COMPACT_COMPLETE 4
  14. #ifdef CONFIG_COMPACTION
  15. extern int sysctl_compact_memory;
  16. extern int sysctl_compaction_handler(struct ctl_table *table, int write,
  17. void __user *buffer, size_t *length, loff_t *ppos);
  18. extern int sysctl_extfrag_threshold;
  19. extern int sysctl_extfrag_handler(struct ctl_table *table, int write,
  20. void __user *buffer, size_t *length, loff_t *ppos);
  21. extern int fragmentation_index(struct zone *zone, unsigned int order);
  22. extern unsigned long try_to_compact_pages(struct zonelist *zonelist,
  23. int order, gfp_t gfp_mask, nodemask_t *mask,
  24. enum migrate_mode mode, bool *contended,
  25. struct zone **candidate_zone);
  26. extern void compact_pgdat(pg_data_t *pgdat, int order);
  27. extern void reset_isolation_suitable(pg_data_t *pgdat);
  28. extern unsigned long compaction_suitable(struct zone *zone, int order);
  29. /* Do not skip compaction more than 64 times */
  30. #define COMPACT_MAX_DEFER_SHIFT 6
  31. /*
  32. * Compaction is deferred when compaction fails to result in a page
  33. * allocation success. 1 << compact_defer_limit compactions are skipped up
  34. * to a limit of 1 << COMPACT_MAX_DEFER_SHIFT
  35. */
  36. static inline void defer_compaction(struct zone *zone, int order)
  37. {
  38. zone->compact_considered = 0;
  39. zone->compact_defer_shift++;
  40. if (order < zone->compact_order_failed)
  41. zone->compact_order_failed = order;
  42. if (zone->compact_defer_shift > COMPACT_MAX_DEFER_SHIFT)
  43. zone->compact_defer_shift = COMPACT_MAX_DEFER_SHIFT;
  44. }
  45. /* Returns true if compaction should be skipped this time */
  46. static inline bool compaction_deferred(struct zone *zone, int order)
  47. {
  48. unsigned long defer_limit = 1UL << zone->compact_defer_shift;
  49. if (order < zone->compact_order_failed)
  50. return false;
  51. /* Avoid possible overflow */
  52. if (++zone->compact_considered > defer_limit)
  53. zone->compact_considered = defer_limit;
  54. return zone->compact_considered < defer_limit;
  55. }
  56. /*
  57. * Update defer tracking counters after successful compaction of given order,
  58. * which means an allocation either succeeded (alloc_success == true) or is
  59. * expected to succeed.
  60. */
  61. static inline void compaction_defer_reset(struct zone *zone, int order,
  62. bool alloc_success)
  63. {
  64. if (alloc_success) {
  65. zone->compact_considered = 0;
  66. zone->compact_defer_shift = 0;
  67. }
  68. if (order >= zone->compact_order_failed)
  69. zone->compact_order_failed = order + 1;
  70. }
  71. /* Returns true if restarting compaction after many failures */
  72. static inline bool compaction_restarting(struct zone *zone, int order)
  73. {
  74. if (order < zone->compact_order_failed)
  75. return false;
  76. return zone->compact_defer_shift == COMPACT_MAX_DEFER_SHIFT &&
  77. zone->compact_considered >= 1UL << zone->compact_defer_shift;
  78. }
  79. #else
  80. static inline unsigned long try_to_compact_pages(struct zonelist *zonelist,
  81. int order, gfp_t gfp_mask, nodemask_t *nodemask,
  82. enum migrate_mode mode, bool *contended,
  83. struct zone **candidate_zone)
  84. {
  85. return COMPACT_CONTINUE;
  86. }
  87. static inline void compact_pgdat(pg_data_t *pgdat, int order)
  88. {
  89. }
  90. static inline void reset_isolation_suitable(pg_data_t *pgdat)
  91. {
  92. }
  93. static inline unsigned long compaction_suitable(struct zone *zone, int order)
  94. {
  95. return COMPACT_SKIPPED;
  96. }
  97. static inline void defer_compaction(struct zone *zone, int order)
  98. {
  99. }
  100. static inline bool compaction_deferred(struct zone *zone, int order)
  101. {
  102. return true;
  103. }
  104. #endif /* CONFIG_COMPACTION */
  105. #if defined(CONFIG_COMPACTION) && defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
  106. extern int compaction_register_node(struct node *node);
  107. extern void compaction_unregister_node(struct node *node);
  108. #else
  109. static inline int compaction_register_node(struct node *node)
  110. {
  111. return 0;
  112. }
  113. static inline void compaction_unregister_node(struct node *node)
  114. {
  115. }
  116. #endif /* CONFIG_COMPACTION && CONFIG_SYSFS && CONFIG_NUMA */
  117. #endif /* _LINUX_COMPACTION_H */