hugetlb_cgroup.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. 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_PAGE(!PageHuge(page), page);
  27. if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
  28. return NULL;
  29. return (struct hugetlb_cgroup *)page[2].private;
  30. }
  31. static inline
  32. int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
  33. {
  34. VM_BUG_ON_PAGE(!PageHuge(page), page);
  35. if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
  36. return -1;
  37. page[2].private = (unsigned long)h_cg;
  38. return 0;
  39. }
  40. static inline bool hugetlb_cgroup_disabled(void)
  41. {
  42. return !cgroup_subsys_enabled(hugetlb_cgrp_subsys);
  43. }
  44. extern int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
  45. struct hugetlb_cgroup **ptr);
  46. extern void hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
  47. struct hugetlb_cgroup *h_cg,
  48. struct page *page);
  49. extern void hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages,
  50. struct page *page);
  51. extern void hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
  52. struct hugetlb_cgroup *h_cg);
  53. extern void hugetlb_cgroup_file_init(void) __init;
  54. extern void hugetlb_cgroup_migrate(struct page *oldhpage,
  55. struct page *newhpage);
  56. #else
  57. static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
  58. {
  59. return NULL;
  60. }
  61. static inline
  62. int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
  63. {
  64. return 0;
  65. }
  66. static inline bool hugetlb_cgroup_disabled(void)
  67. {
  68. return true;
  69. }
  70. static inline int
  71. hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
  72. struct hugetlb_cgroup **ptr)
  73. {
  74. return 0;
  75. }
  76. static inline void
  77. hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
  78. struct hugetlb_cgroup *h_cg,
  79. struct page *page)
  80. {
  81. return;
  82. }
  83. static inline void
  84. hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages, struct page *page)
  85. {
  86. return;
  87. }
  88. static inline void
  89. hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
  90. struct hugetlb_cgroup *h_cg)
  91. {
  92. return;
  93. }
  94. static inline void hugetlb_cgroup_file_init(void)
  95. {
  96. }
  97. static inline void hugetlb_cgroup_migrate(struct page *oldhpage,
  98. struct page *newhpage)
  99. {
  100. return;
  101. }
  102. #endif /* CONFIG_MEM_RES_CTLR_HUGETLB */
  103. #endif