hugetlb_internal.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Internal HugeTLB definitions.
  4. * (C) Nadia Yvette Chambers, April 2004
  5. */
  6. #ifndef _LINUX_HUGETLB_INTERNAL_H
  7. #define _LINUX_HUGETLB_INTERNAL_H
  8. #include <linux/hugetlb.h>
  9. #include <linux/hugetlb_cgroup.h>
  10. /*
  11. * Check if the hstate represents gigantic pages but gigantic page
  12. * runtime support is not available. This is a common condition used to
  13. * skip operations that cannot be performed on gigantic pages when runtime
  14. * support is disabled.
  15. */
  16. static inline bool hstate_is_gigantic_no_runtime(struct hstate *h)
  17. {
  18. return hstate_is_gigantic(h) && !gigantic_page_runtime_supported();
  19. }
  20. /*
  21. * common helper functions for hstate_next_node_to_{alloc|free}.
  22. * We may have allocated or freed a huge page based on a different
  23. * nodes_allowed previously, so h->next_node_to_{alloc|free} might
  24. * be outside of *nodes_allowed. Ensure that we use an allowed
  25. * node for alloc or free.
  26. */
  27. static inline int next_node_allowed(int nid, nodemask_t *nodes_allowed)
  28. {
  29. nid = next_node_in(nid, *nodes_allowed);
  30. VM_BUG_ON(nid >= MAX_NUMNODES);
  31. return nid;
  32. }
  33. static inline int get_valid_node_allowed(int nid, nodemask_t *nodes_allowed)
  34. {
  35. if (!node_isset(nid, *nodes_allowed))
  36. nid = next_node_allowed(nid, nodes_allowed);
  37. return nid;
  38. }
  39. /*
  40. * returns the previously saved node ["this node"] from which to
  41. * allocate a persistent huge page for the pool and advance the
  42. * next node from which to allocate, handling wrap at end of node
  43. * mask.
  44. */
  45. static inline int hstate_next_node_to_alloc(int *next_node,
  46. nodemask_t *nodes_allowed)
  47. {
  48. int nid;
  49. VM_BUG_ON(!nodes_allowed);
  50. nid = get_valid_node_allowed(*next_node, nodes_allowed);
  51. *next_node = next_node_allowed(nid, nodes_allowed);
  52. return nid;
  53. }
  54. /*
  55. * helper for remove_pool_hugetlb_folio() - return the previously saved
  56. * node ["this node"] from which to free a huge page. Advance the
  57. * next node id whether or not we find a free huge page to free so
  58. * that the next attempt to free addresses the next node.
  59. */
  60. static inline int hstate_next_node_to_free(struct hstate *h, nodemask_t *nodes_allowed)
  61. {
  62. int nid;
  63. VM_BUG_ON(!nodes_allowed);
  64. nid = get_valid_node_allowed(h->next_nid_to_free, nodes_allowed);
  65. h->next_nid_to_free = next_node_allowed(nid, nodes_allowed);
  66. return nid;
  67. }
  68. #define for_each_node_mask_to_alloc(next_node, nr_nodes, node, mask) \
  69. for (nr_nodes = nodes_weight(*mask); \
  70. nr_nodes > 0 && \
  71. ((node = hstate_next_node_to_alloc(next_node, mask)) || 1); \
  72. nr_nodes--)
  73. #define for_each_node_mask_to_free(hs, nr_nodes, node, mask) \
  74. for (nr_nodes = nodes_weight(*mask); \
  75. nr_nodes > 0 && \
  76. ((node = hstate_next_node_to_free(hs, mask)) || 1); \
  77. nr_nodes--)
  78. extern void remove_hugetlb_folio(struct hstate *h, struct folio *folio,
  79. bool adjust_surplus);
  80. extern void add_hugetlb_folio(struct hstate *h, struct folio *folio,
  81. bool adjust_surplus);
  82. extern void init_new_hugetlb_folio(struct folio *folio);
  83. extern void prep_and_add_allocated_folios(struct hstate *h,
  84. struct list_head *folio_list);
  85. extern long demote_pool_huge_page(struct hstate *src,
  86. nodemask_t *nodes_allowed,
  87. unsigned long nr_to_demote);
  88. extern ssize_t __nr_hugepages_store_common(bool obey_mempolicy,
  89. struct hstate *h, int nid,
  90. unsigned long count, size_t len);
  91. extern void hugetlb_sysfs_init(void) __init;
  92. #ifdef CONFIG_SYSCTL
  93. extern void hugetlb_sysctl_init(void);
  94. #else
  95. static inline void hugetlb_sysctl_init(void) { }
  96. #endif
  97. #endif /* _LINUX_HUGETLB_INTERNAL_H */