hugetlb_cgroup.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright IBM Corporation, 2012
  3. * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2.1 of the GNU Lesser General Public License
  7. * as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. *
  13. */
  14. #ifndef _LINUX_HUGETLB_CGROUP_H
  15. #define _LINUX_HUGETLB_CGROUP_H
  16. #include <linux/res_counter.h>
  17. struct hugetlb_cgroup;
  18. /*
  19. * Minimum page order trackable by hugetlb cgroup.
  20. * At least 3 pages are necessary for all the tracking information.
  21. */
  22. #define HUGETLB_CGROUP_MIN_ORDER 2
  23. #ifdef CONFIG_CGROUP_HUGETLB
  24. static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
  25. {
  26. VM_BUG_ON(!PageHuge(page));
  27. if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
  28. return NULL;
  29. return (struct hugetlb_cgroup *)page[2].lru.next;
  30. }
  31. static inline
  32. int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
  33. {
  34. VM_BUG_ON(!PageHuge(page));
  35. if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
  36. return -1;
  37. page[2].lru.next = (void *)h_cg;
  38. return 0;
  39. }
  40. static inline bool hugetlb_cgroup_disabled(void)
  41. {
  42. if (hugetlb_subsys.disabled)
  43. return true;
  44. return false;
  45. }
  46. extern int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
  47. struct hugetlb_cgroup **ptr);
  48. extern void hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
  49. struct hugetlb_cgroup *h_cg,
  50. struct page *page);
  51. extern void hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages,
  52. struct page *page);
  53. extern void hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
  54. struct hugetlb_cgroup *h_cg);
  55. extern int hugetlb_cgroup_file_init(int idx) __init;
  56. extern void hugetlb_cgroup_migrate(struct page *oldhpage,
  57. struct page *newhpage);
  58. #else
  59. static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
  60. {
  61. return NULL;
  62. }
  63. static inline
  64. int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
  65. {
  66. return 0;
  67. }
  68. static inline bool hugetlb_cgroup_disabled(void)
  69. {
  70. return true;
  71. }
  72. static inline int
  73. hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
  74. struct hugetlb_cgroup **ptr)
  75. {
  76. return 0;
  77. }
  78. static inline void
  79. hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
  80. struct hugetlb_cgroup *h_cg,
  81. struct page *page)
  82. {
  83. return;
  84. }
  85. static inline void
  86. hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages, struct page *page)
  87. {
  88. return;
  89. }
  90. static inline void
  91. hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
  92. struct hugetlb_cgroup *h_cg)
  93. {
  94. return;
  95. }
  96. static inline int __init hugetlb_cgroup_file_init(int idx)
  97. {
  98. return 0;
  99. }
  100. static inline void hugetlb_cgroup_migrate(struct page *oldhpage,
  101. struct page *newhpage)
  102. {
  103. return;
  104. }
  105. #endif /* CONFIG_MEM_RES_CTLR_HUGETLB */
  106. #endif