hugetlb_cgroup.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #else
  56. static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
  57. {
  58. return NULL;
  59. }
  60. static inline
  61. int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
  62. {
  63. return 0;
  64. }
  65. static inline bool hugetlb_cgroup_disabled(void)
  66. {
  67. return true;
  68. }
  69. static inline int
  70. hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
  71. struct hugetlb_cgroup **ptr)
  72. {
  73. return 0;
  74. }
  75. static inline void
  76. hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
  77. struct hugetlb_cgroup *h_cg,
  78. struct page *page)
  79. {
  80. return;
  81. }
  82. static inline void
  83. hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages, struct page *page)
  84. {
  85. return;
  86. }
  87. static inline void
  88. hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
  89. struct hugetlb_cgroup *h_cg)
  90. {
  91. return;
  92. }
  93. #endif /* CONFIG_MEM_RES_CTLR_HUGETLB */
  94. #endif