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/mmdebug.h>
  17. #include <linux/res_counter.h>
  18. struct hugetlb_cgroup;
  19. /*
  20. * Minimum page order trackable by hugetlb cgroup.
  21. * At least 3 pages are necessary for all the tracking information.
  22. */
  23. #define HUGETLB_CGROUP_MIN_ORDER 2
  24. #ifdef CONFIG_CGROUP_HUGETLB
  25. static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
  26. {
  27. VM_BUG_ON_PAGE(!PageHuge(page), page);
  28. if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
  29. return NULL;
  30. return (struct hugetlb_cgroup *)page[2].lru.next;
  31. }
  32. static inline
  33. int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
  34. {
  35. VM_BUG_ON_PAGE(!PageHuge(page), page);
  36. if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
  37. return -1;
  38. page[2].lru.next = (void *)h_cg;
  39. return 0;
  40. }
  41. static inline bool hugetlb_cgroup_disabled(void)
  42. {
  43. if (hugetlb_cgrp_subsys.disabled)
  44. return true;
  45. return false;
  46. }
  47. extern int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
  48. struct hugetlb_cgroup **ptr);
  49. extern void hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
  50. struct hugetlb_cgroup *h_cg,
  51. struct page *page);
  52. extern void hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages,
  53. struct page *page);
  54. extern void hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
  55. struct hugetlb_cgroup *h_cg);
  56. extern void hugetlb_cgroup_file_init(void) __init;
  57. extern void hugetlb_cgroup_migrate(struct page *oldhpage,
  58. struct page *newhpage);
  59. #else
  60. static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
  61. {
  62. return NULL;
  63. }
  64. static inline
  65. int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
  66. {
  67. return 0;
  68. }
  69. static inline bool hugetlb_cgroup_disabled(void)
  70. {
  71. return true;
  72. }
  73. static inline int
  74. hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
  75. struct hugetlb_cgroup **ptr)
  76. {
  77. return 0;
  78. }
  79. static inline void
  80. hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
  81. struct hugetlb_cgroup *h_cg,
  82. struct page *page)
  83. {
  84. return;
  85. }
  86. static inline void
  87. hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages, struct page *page)
  88. {
  89. return;
  90. }
  91. static inline void
  92. hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
  93. struct hugetlb_cgroup *h_cg)
  94. {
  95. return;
  96. }
  97. static inline void hugetlb_cgroup_file_init(void)
  98. {
  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