compaction.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 int compact_pgdat(pg_data_t *pgdat, int order);
  24. extern unsigned long compaction_suitable(struct zone *zone, int order);
  25. /* Do not skip compaction more than 64 times */
  26. #define COMPACT_MAX_DEFER_SHIFT 6
  27. /*
  28. * Compaction is deferred when compaction fails to result in a page
  29. * allocation success. 1 << compact_defer_limit compactions are skipped up
  30. * to a limit of 1 << COMPACT_MAX_DEFER_SHIFT
  31. */
  32. static inline void defer_compaction(struct zone *zone, int order)
  33. {
  34. zone->compact_considered = 0;
  35. zone->compact_defer_shift++;
  36. if (order < zone->compact_order_failed)
  37. zone->compact_order_failed = order;
  38. if (zone->compact_defer_shift > COMPACT_MAX_DEFER_SHIFT)
  39. zone->compact_defer_shift = COMPACT_MAX_DEFER_SHIFT;
  40. }
  41. /* Returns true if compaction should be skipped this time */
  42. static inline bool compaction_deferred(struct zone *zone, int order)
  43. {
  44. unsigned long defer_limit = 1UL << zone->compact_defer_shift;
  45. if (order < zone->compact_order_failed)
  46. return false;
  47. /* Avoid possible overflow */
  48. if (++zone->compact_considered > defer_limit)
  49. zone->compact_considered = defer_limit;
  50. return zone->compact_considered < defer_limit;
  51. }
  52. #else
  53. static inline unsigned long try_to_compact_pages(struct zonelist *zonelist,
  54. int order, gfp_t gfp_mask, nodemask_t *nodemask,
  55. bool sync, bool *contended)
  56. {
  57. return COMPACT_CONTINUE;
  58. }
  59. static inline int compact_pgdat(pg_data_t *pgdat, int order)
  60. {
  61. return COMPACT_CONTINUE;
  62. }
  63. static inline unsigned long compaction_suitable(struct zone *zone, int order)
  64. {
  65. return COMPACT_SKIPPED;
  66. }
  67. static inline void defer_compaction(struct zone *zone, int order)
  68. {
  69. }
  70. static inline bool compaction_deferred(struct zone *zone, int order)
  71. {
  72. return true;
  73. }
  74. #endif /* CONFIG_COMPACTION */
  75. #if defined(CONFIG_COMPACTION) && defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
  76. extern int compaction_register_node(struct node *node);
  77. extern void compaction_unregister_node(struct node *node);
  78. #else
  79. static inline int compaction_register_node(struct node *node)
  80. {
  81. return 0;
  82. }
  83. static inline void compaction_unregister_node(struct node *node)
  84. {
  85. }
  86. #endif /* CONFIG_COMPACTION && CONFIG_SYSFS && CONFIG_NUMA */
  87. #endif /* _LINUX_COMPACTION_H */