page-flags-layout.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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"
  23. #endif
  24. #define ZONES_WIDTH ZONES_SHIFT
  25. #ifdef CONFIG_SPARSEMEM
  26. #include <asm/sparsemem.h>
  27. #define SECTIONS_SHIFT (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS)
  28. #else
  29. #define SECTIONS_SHIFT 0
  30. #endif
  31. #ifndef BUILD_VDSO32_64
  32. /*
  33. * page->flags layout:
  34. *
  35. * There are five possibilities for how page->flags get laid out. The first
  36. * pair is for the normal case without sparsemem. The second pair is for
  37. * sparsemem when there is plenty of space for node and section information.
  38. * The last is when there is insufficient space in page->flags and a separate
  39. * lookup is necessary.
  40. *
  41. * No sparsemem or sparsemem vmemmap: | NODE | ZONE | ... | FLAGS |
  42. * " plus space for last_cpupid: | NODE | ZONE | LAST_CPUPID ... | FLAGS |
  43. * classic sparse with space for node:| SECTION | NODE | ZONE | ... | FLAGS |
  44. * " plus space for last_cpupid: | SECTION | NODE | ZONE | LAST_CPUPID ... | FLAGS |
  45. * classic sparse no space for node: | SECTION | ZONE | ... | FLAGS |
  46. */
  47. #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
  48. #define SECTIONS_WIDTH SECTIONS_SHIFT
  49. #else
  50. #define SECTIONS_WIDTH 0
  51. #endif
  52. #if ZONES_WIDTH + LRU_GEN_WIDTH + SECTIONS_WIDTH + NODES_SHIFT \
  53. <= BITS_PER_LONG - NR_PAGEFLAGS
  54. #define NODES_WIDTH NODES_SHIFT
  55. #elif defined(CONFIG_SPARSEMEM_VMEMMAP)
  56. #error "Vmemmap: No space for nodes field in page flags"
  57. #else
  58. #define NODES_WIDTH 0
  59. #endif
  60. /*
  61. * Note that this #define MUST have a value so that it can be tested with
  62. * the IS_ENABLED() macro.
  63. */
  64. #if NODES_SHIFT != 0 && NODES_WIDTH == 0
  65. #define NODE_NOT_IN_PAGE_FLAGS 1
  66. #endif
  67. #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
  68. #define KASAN_TAG_WIDTH 8
  69. #else
  70. #define KASAN_TAG_WIDTH 0
  71. #endif
  72. #ifdef CONFIG_NUMA_BALANCING
  73. #define LAST__PID_SHIFT 8
  74. #define LAST__PID_MASK ((1 << LAST__PID_SHIFT)-1)
  75. #define LAST__CPU_SHIFT NR_CPUS_BITS
  76. #define LAST__CPU_MASK ((1 << LAST__CPU_SHIFT)-1)
  77. #define LAST_CPUPID_SHIFT (LAST__PID_SHIFT+LAST__CPU_SHIFT)
  78. #else
  79. #define LAST_CPUPID_SHIFT 0
  80. #endif
  81. #if ZONES_WIDTH + LRU_GEN_WIDTH + SECTIONS_WIDTH + NODES_WIDTH + \
  82. KASAN_TAG_WIDTH + LAST_CPUPID_SHIFT <= BITS_PER_LONG - NR_PAGEFLAGS
  83. #define LAST_CPUPID_WIDTH LAST_CPUPID_SHIFT
  84. #else
  85. #define LAST_CPUPID_WIDTH 0
  86. #endif
  87. #if LAST_CPUPID_SHIFT != 0 && LAST_CPUPID_WIDTH == 0
  88. #define LAST_CPUPID_NOT_IN_PAGE_FLAGS
  89. #endif
  90. #if ZONES_WIDTH + LRU_GEN_WIDTH + SECTIONS_WIDTH + NODES_WIDTH + \
  91. KASAN_TAG_WIDTH + LAST_CPUPID_WIDTH > BITS_PER_LONG - NR_PAGEFLAGS
  92. #error "Not enough bits in page flags"
  93. #endif
  94. /* see the comment on MAX_NR_TIERS */
  95. #define LRU_REFS_WIDTH min(__LRU_REFS_WIDTH, BITS_PER_LONG - NR_PAGEFLAGS - \
  96. ZONES_WIDTH - LRU_GEN_WIDTH - SECTIONS_WIDTH - \
  97. NODES_WIDTH - KASAN_TAG_WIDTH - LAST_CPUPID_WIDTH)
  98. #endif
  99. #endif /* _LINUX_PAGE_FLAGS_LAYOUT */