compaction.h 2.8 KB

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