page-flags-layout.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef PAGE_FLAGS_LAYOUT_H
  3. #define PAGE_FLAGS_LAYOUT_H
  4. #include <linux/numa.h>
  5. #include <generated/bounds.h>
  6. /*
  7. * When a memory allocation must conform to specific limitations (such
  8. * as being suitable for DMA) the caller will pass in hints to the
  9. * allocator in the gfp_mask, in the zone modifier bits. These bits
  10. * are used to select a priority ordered list of memory zones which
  11. * match the requested limits. See gfp_zone() in include/linux/gfp.h
  12. */
  13. #if MAX_NR_ZONES < 2
  14. #define ZONES_SHIFT 0
  15. #elif MAX_NR_ZONES <= 2
  16. #define ZONES_SHIFT 1
  17. #elif MAX_NR_ZONES <= 4
  18. #define ZONES_SHIFT 2
  19. #elif MAX_NR_ZONES <= 8
  20. #define ZONES_SHIFT 3
  21. #else
  22. #error ZONES_SHIFT -- too many zones configured adjust calculation
  23. #endif
  24. #ifdef CONFIG_SPARSEMEM
  25. #include <asm/sparsemem.h>
  26. /* SECTION_SHIFT #bits space required to store a section # */
  27. #define SECTIONS_SHIFT (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS)
  28. #endif /* CONFIG_SPARSEMEM */
  29. #ifndef BUILD_VDSO32_64
  30. /*
  31. * page->flags layout:
  32. *
  33. * There are five possibilities for how page->flags get laid out. The first
  34. * pair is for the normal case without sparsemem. The second pair is for
  35. * sparsemem when there is plenty of space for node and section information.
  36. * The last is when there is insufficient space in page->flags and a separate
  37. * lookup is necessary.
  38. *
  39. * No sparsemem or sparsemem vmemmap: | NODE | ZONE | ... | FLAGS |
  40. * " plus space for last_cpupid: | NODE | ZONE | LAST_CPUPID ... | FLAGS |
  41. * classic sparse with space for node:| SECTION | NODE | ZONE | ... | FLAGS |
  42. * " plus space for last_cpupid: | SECTION | NODE | ZONE | LAST_CPUPID ... | FLAGS |
  43. * classic sparse no space for node: | SECTION | ZONE | ... | FLAGS |
  44. */
  45. #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
  46. #define SECTIONS_WIDTH SECTIONS_SHIFT
  47. #else
  48. #define SECTIONS_WIDTH 0
  49. #endif
  50. #define ZONES_WIDTH ZONES_SHIFT
  51. #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
  52. #define NODES_WIDTH NODES_SHIFT
  53. #else
  54. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  55. #error "Vmemmap: No space for nodes field in page flags"
  56. #endif
  57. #define NODES_WIDTH 0
  58. #endif
  59. #ifdef CONFIG_NUMA_BALANCING
  60. #define LAST__PID_SHIFT 8
  61. #define LAST__PID_MASK ((1 << LAST__PID_SHIFT)-1)
  62. #define LAST__CPU_SHIFT NR_CPUS_BITS
  63. #define LAST__CPU_MASK ((1 << LAST__CPU_SHIFT)-1)
  64. #define LAST_CPUPID_SHIFT (LAST__PID_SHIFT+LAST__CPU_SHIFT)
  65. #else
  66. #define LAST_CPUPID_SHIFT 0
  67. #endif
  68. #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
  69. #define KASAN_TAG_WIDTH 8
  70. #else
  71. #define KASAN_TAG_WIDTH 0
  72. #endif
  73. #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT+LAST_CPUPID_SHIFT+KASAN_TAG_WIDTH \
  74. <= BITS_PER_LONG - NR_PAGEFLAGS
  75. #define LAST_CPUPID_WIDTH LAST_CPUPID_SHIFT
  76. #else
  77. #define LAST_CPUPID_WIDTH 0
  78. #endif
  79. #if SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH+LAST_CPUPID_WIDTH+KASAN_TAG_WIDTH \
  80. > BITS_PER_LONG - NR_PAGEFLAGS
  81. #error "Not enough bits in page flags"
  82. #endif
  83. /*
  84. * We are going to use the flags for the page to node mapping if its in
  85. * there. This includes the case where there is no node, so it is implicit.
  86. * Note that this #define MUST have a value so that it can be tested with
  87. * the IS_ENABLED() macro.
  88. */
  89. #if !(NODES_WIDTH > 0 || NODES_SHIFT == 0)
  90. #define NODE_NOT_IN_PAGE_FLAGS 1
  91. #endif
  92. #if defined(CONFIG_NUMA_BALANCING) && LAST_CPUPID_WIDTH == 0
  93. #define LAST_CPUPID_NOT_IN_PAGE_FLAGS
  94. #endif
  95. #endif
  96. #endif /* _LINUX_PAGE_FLAGS_LAYOUT */