compaction.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 not possible or direct reclaim was more suitable */
  5. #define COMPACT_SKIPPED 0
  6. /* compaction should continue to another pageblock */
  7. #define COMPACT_CONTINUE 1
  8. /* direct compaction partially compacted a zone and there are suitable pages */
  9. #define COMPACT_PARTIAL 2
  10. /* The full zone was compacted */
  11. #define COMPACT_COMPLETE 3
  12. #ifdef CONFIG_COMPACTION
  13. extern int sysctl_compact_memory;
  14. extern int sysctl_compaction_handler(struct ctl_table *table, int write,
  15. void __user *buffer, size_t *length, loff_t *ppos);
  16. extern int sysctl_extfrag_threshold;
  17. extern int sysctl_extfrag_handler(struct ctl_table *table, int write,
  18. void __user *buffer, size_t *length, loff_t *ppos);
  19. extern int fragmentation_index(struct zone *zone, unsigned int order);
  20. extern unsigned long try_to_compact_pages(struct zonelist *zonelist,
  21. int order, gfp_t gfp_mask, nodemask_t *mask,
  22. bool sync, bool *contended);
  23. extern void compact_pgdat(pg_data_t *pgdat, int order);
  24. extern void reset_isolation_suitable(pg_data_t *pgdat);
  25. extern unsigned long compaction_suitable(struct zone *zone, int order);
  26. /* Do not skip compaction more than 64 times */
  27. #define COMPACT_MAX_DEFER_SHIFT 6
  28. /*
  29. * Compaction is deferred when compaction fails to result in a page
  30. * allocation success. 1 << compact_defer_limit compactions are skipped up
  31. * to a limit of 1 << COMPACT_MAX_DEFER_SHIFT
  32. */
  33. static inline void defer_compaction(struct zone *zone, int order)
  34. {
  35. zone->compact_considered = 0;
  36. zone->compact_defer_shift++;
  37. if (order < zone->compact_order_failed)
  38. zone->compact_order_failed = order;
  39. if (zone->compact_defer_shift > COMPACT_MAX_DEFER_SHIFT)
  40. zone->compact_defer_shift = COMPACT_MAX_DEFER_SHIFT;
  41. }
  42. /* Returns true if compaction should be skipped this time */
  43. static inline bool compaction_deferred(struct zone *zone, int order)
  44. {
  45. unsigned long defer_limit = 1UL << zone->compact_defer_shift;
  46. if (order < zone->compact_order_failed)
  47. return false;
  48. /* Avoid possible overflow */
  49. if (++zone->compact_considered > defer_limit)
  50. zone->compact_considered = defer_limit;
  51. return zone->compact_considered < defer_limit;
  52. }
  53. /* Returns true if restarting compaction after many failures */
  54. static inline bool compaction_restarting(struct zone *zone, int order)
  55. {
  56. if (order < zone->compact_order_failed)
  57. return false;
  58. return zone->compact_defer_shift == COMPACT_MAX_DEFER_SHIFT &&
  59. zone->compact_considered >= 1UL << zone->compact_defer_shift;
  60. }
  61. #else
  62. static inline unsigned long try_to_compact_pages(struct zonelist *zonelist,
  63. int order, gfp_t gfp_mask, nodemask_t *nodemask,
  64. bool sync, bool *contended)
  65. {
  66. return COMPACT_CONTINUE;
  67. }
  68. static inline void compact_pgdat(pg_data_t *pgdat, int order)
  69. {
  70. }
  71. static inline void reset_isolation_suitable(pg_data_t *pgdat)
  72. {
  73. }
  74. static inline unsigned long compaction_suitable(struct zone *zone, int order)
  75. {
  76. return COMPACT_SKIPPED;
  77. }
  78. static inline void defer_compaction(struct zone *zone, int order)
  79. {
  80. }
  81. static inline bool compaction_deferred(struct zone *zone, int order)
  82. {
  83. return true;
  84. }
  85. #endif /* CONFIG_COMPACTION */
  86. #if defined(CONFIG_COMPACTION) && defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
  87. extern int compaction_register_node(struct node *node);
  88. extern void compaction_unregister_node(struct node *node);
  89. #else
  90. static inline int compaction_register_node(struct node *node)
  91. {
  92. return 0;
  93. }
  94. static inline void compaction_unregister_node(struct node *node)
  95. {
  96. }
  97. #endif /* CONFIG_COMPACTION && CONFIG_SYSFS && CONFIG_NUMA */
  98. #endif /* _LINUX_COMPACTION_H */