memory-tiers.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_MEMORY_TIERS_H
  3. #define _LINUX_MEMORY_TIERS_H
  4. #include <linux/types.h>
  5. #include <linux/nodemask.h>
  6. #include <linux/kref.h>
  7. #include <linux/mmzone.h>
  8. /*
  9. * Each tier cover a abstrace distance chunk size of 128
  10. */
  11. #define MEMTIER_CHUNK_BITS 7
  12. #define MEMTIER_CHUNK_SIZE (1 << MEMTIER_CHUNK_BITS)
  13. /*
  14. * Smaller abstract distance values imply faster (higher) memory tiers. Offset
  15. * the DRAM adistance so that we can accommodate devices with a slightly lower
  16. * adistance value (slightly faster) than default DRAM adistance to be part of
  17. * the same memory tier.
  18. */
  19. #define MEMTIER_ADISTANCE_DRAM ((4 * MEMTIER_CHUNK_SIZE) + (MEMTIER_CHUNK_SIZE >> 1))
  20. #define MEMTIER_HOTPLUG_PRIO 100
  21. struct memory_tier;
  22. struct memory_dev_type {
  23. /* list of memory types that are part of same tier as this type */
  24. struct list_head tier_sibiling;
  25. /* abstract distance for this specific memory type */
  26. int adistance;
  27. /* Nodes of same abstract distance */
  28. nodemask_t nodes;
  29. struct kref kref;
  30. };
  31. #ifdef CONFIG_NUMA
  32. extern bool numa_demotion_enabled;
  33. struct memory_dev_type *alloc_memory_type(int adistance);
  34. void destroy_memory_type(struct memory_dev_type *memtype);
  35. void init_node_memory_type(int node, struct memory_dev_type *default_type);
  36. void clear_node_memory_type(int node, struct memory_dev_type *memtype);
  37. #ifdef CONFIG_MIGRATION
  38. int next_demotion_node(int node);
  39. void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets);
  40. bool node_is_toptier(int node);
  41. #else
  42. static inline int next_demotion_node(int node)
  43. {
  44. return NUMA_NO_NODE;
  45. }
  46. static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets)
  47. {
  48. *targets = NODE_MASK_NONE;
  49. }
  50. static inline bool node_is_toptier(int node)
  51. {
  52. return true;
  53. }
  54. #endif
  55. #else
  56. #define numa_demotion_enabled false
  57. /*
  58. * CONFIG_NUMA implementation returns non NULL error.
  59. */
  60. static inline struct memory_dev_type *alloc_memory_type(int adistance)
  61. {
  62. return NULL;
  63. }
  64. static inline void destroy_memory_type(struct memory_dev_type *memtype)
  65. {
  66. }
  67. static inline void init_node_memory_type(int node, struct memory_dev_type *default_type)
  68. {
  69. }
  70. static inline void clear_node_memory_type(int node, struct memory_dev_type *memtype)
  71. {
  72. }
  73. static inline int next_demotion_node(int node)
  74. {
  75. return NUMA_NO_NODE;
  76. }
  77. static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets)
  78. {
  79. *targets = NODE_MASK_NONE;
  80. }
  81. static inline bool node_is_toptier(int node)
  82. {
  83. return true;
  84. }
  85. #endif /* CONFIG_NUMA */
  86. #endif /* _LINUX_MEMORY_TIERS_H */