compaction.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. extern unsigned long compaction_suitable(struct zone *zone, int order);
  23. extern unsigned long compact_zone_order(struct zone *zone, int order,
  24. gfp_t gfp_mask);
  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)
  33. {
  34. zone->compact_considered = 0;
  35. zone->compact_defer_shift++;
  36. if (zone->compact_defer_shift > COMPACT_MAX_DEFER_SHIFT)
  37. zone->compact_defer_shift = COMPACT_MAX_DEFER_SHIFT;
  38. }
  39. /* Returns true if compaction should be skipped this time */
  40. static inline bool compaction_deferred(struct zone *zone)
  41. {
  42. unsigned long defer_limit = 1UL << zone->compact_defer_shift;
  43. /* Avoid possible overflow */
  44. if (++zone->compact_considered > defer_limit)
  45. zone->compact_considered = defer_limit;
  46. return zone->compact_considered < (1UL << zone->compact_defer_shift);
  47. }
  48. #else
  49. static inline unsigned long try_to_compact_pages(struct zonelist *zonelist,
  50. int order, gfp_t gfp_mask, nodemask_t *nodemask)
  51. {
  52. return COMPACT_CONTINUE;
  53. }
  54. static inline unsigned long compaction_suitable(struct zone *zone, int order)
  55. {
  56. return COMPACT_SKIPPED;
  57. }
  58. static inline unsigned long compact_zone_order(struct zone *zone, int order,
  59. gfp_t gfp_mask)
  60. {
  61. return 0;
  62. }
  63. static inline void defer_compaction(struct zone *zone)
  64. {
  65. }
  66. static inline bool compaction_deferred(struct zone *zone)
  67. {
  68. return 1;
  69. }
  70. #endif /* CONFIG_COMPACTION */
  71. #if defined(CONFIG_COMPACTION) && defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
  72. extern int compaction_register_node(struct node *node);
  73. extern void compaction_unregister_node(struct node *node);
  74. #else
  75. static inline int compaction_register_node(struct node *node)
  76. {
  77. return 0;
  78. }
  79. static inline void compaction_unregister_node(struct node *node)
  80. {
  81. }
  82. #endif /* CONFIG_COMPACTION && CONFIG_SYSFS && CONFIG_NUMA */
  83. #endif /* _LINUX_COMPACTION_H */