pageblock-flags.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Macros for manipulating and testing flags related to a
  4. * pageblock_nr_pages number of pages.
  5. *
  6. * Copyright (C) IBM Corporation, 2006
  7. *
  8. * Original author, Mel Gorman
  9. * Major cleanups and reduction of bit operations, Andy Whitcroft
  10. */
  11. #ifndef PAGEBLOCK_FLAGS_H
  12. #define PAGEBLOCK_FLAGS_H
  13. #include <linux/types.h>
  14. #define PB_migratetype_bits 3
  15. /* Bit indices that affect a whole block of pages */
  16. enum pageblock_bits {
  17. PB_migrate,
  18. PB_migrate_end = PB_migrate + PB_migratetype_bits - 1,
  19. /* 3 bits required for migrate types */
  20. PB_migrate_skip,/* If set the block is skipped by compaction */
  21. /*
  22. * Assume the bits will always align on a word. If this assumption
  23. * changes then get/set pageblock needs updating.
  24. */
  25. NR_PAGEBLOCK_BITS
  26. };
  27. #ifdef CONFIG_HUGETLB_PAGE
  28. #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE
  29. /* Huge page sizes are variable */
  30. extern unsigned int pageblock_order;
  31. #else /* CONFIG_HUGETLB_PAGE_SIZE_VARIABLE */
  32. /*
  33. * Huge pages are a constant size, but don't exceed the maximum allocation
  34. * granularity.
  35. */
  36. #define pageblock_order min_t(unsigned int, HUGETLB_PAGE_ORDER, MAX_ORDER - 1)
  37. #endif /* CONFIG_HUGETLB_PAGE_SIZE_VARIABLE */
  38. #else /* CONFIG_HUGETLB_PAGE */
  39. /* If huge pages are not used, group by MAX_ORDER_NR_PAGES */
  40. #define pageblock_order (MAX_ORDER-1)
  41. #endif /* CONFIG_HUGETLB_PAGE */
  42. #define pageblock_nr_pages (1UL << pageblock_order)
  43. #define pageblock_align(pfn) ALIGN((pfn), pageblock_nr_pages)
  44. #define pageblock_aligned(pfn) IS_ALIGNED((pfn), pageblock_nr_pages)
  45. #define pageblock_start_pfn(pfn) ALIGN_DOWN((pfn), pageblock_nr_pages)
  46. #define pageblock_end_pfn(pfn) ALIGN((pfn) + 1, pageblock_nr_pages)
  47. /* Forward declaration */
  48. struct page;
  49. unsigned long get_pfnblock_flags_mask(const struct page *page,
  50. unsigned long pfn,
  51. unsigned long mask);
  52. void set_pfnblock_flags_mask(struct page *page,
  53. unsigned long flags,
  54. unsigned long pfn,
  55. unsigned long mask);
  56. /* Declarations for getting and setting flags. See mm/page_alloc.c */
  57. #ifdef CONFIG_COMPACTION
  58. #define get_pageblock_skip(page) \
  59. get_pfnblock_flags_mask(page, page_to_pfn(page), \
  60. (1 << (PB_migrate_skip)))
  61. #define clear_pageblock_skip(page) \
  62. set_pfnblock_flags_mask(page, 0, page_to_pfn(page), \
  63. (1 << PB_migrate_skip))
  64. #define set_pageblock_skip(page) \
  65. set_pfnblock_flags_mask(page, (1 << PB_migrate_skip), \
  66. page_to_pfn(page), \
  67. (1 << PB_migrate_skip))
  68. #else
  69. static inline bool get_pageblock_skip(struct page *page)
  70. {
  71. return false;
  72. }
  73. static inline void clear_pageblock_skip(struct page *page)
  74. {
  75. }
  76. static inline void set_pageblock_skip(struct page *page)
  77. {
  78. }
  79. #endif /* CONFIG_COMPACTION */
  80. #endif /* PAGEBLOCK_FLAGS_H */