2 * Copyright IBM Corporation, 2012
3 * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
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.
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.
15 #ifndef _LINUX_HUGETLB_CGROUP_H
16 #define _LINUX_HUGETLB_CGROUP_H
18 #include <linux/res_counter.h>
20 struct hugetlb_cgroup
;
22 * Minimum page order trackable by hugetlb cgroup.
23 * At least 3 pages are necessary for all the tracking information.
25 #define HUGETLB_CGROUP_MIN_ORDER 2
27 #ifdef CONFIG_CGROUP_HUGETLB
29 static inline struct hugetlb_cgroup
*hugetlb_cgroup_from_page(struct page
*page
)
31 VM_BUG_ON(!PageHuge(page
));
33 if (compound_order(page
) < HUGETLB_CGROUP_MIN_ORDER
)
35 return (struct hugetlb_cgroup
*)page
[2].lru
.next
;
39 int set_hugetlb_cgroup(struct page
*page
, struct hugetlb_cgroup
*h_cg
)
41 VM_BUG_ON(!PageHuge(page
));
43 if (compound_order(page
) < HUGETLB_CGROUP_MIN_ORDER
)
45 page
[2].lru
.next
= (void *)h_cg
;
49 static inline bool hugetlb_cgroup_disabled(void)
51 if (hugetlb_subsys
.disabled
)
56 extern int hugetlb_cgroup_charge_cgroup(int idx
, unsigned long nr_pages
,
57 struct hugetlb_cgroup
**ptr
);
58 extern void hugetlb_cgroup_commit_charge(int idx
, unsigned long nr_pages
,
59 struct hugetlb_cgroup
*h_cg
,
61 extern void hugetlb_cgroup_uncharge_page(int idx
, unsigned long nr_pages
,
63 extern void hugetlb_cgroup_uncharge_cgroup(int idx
, unsigned long nr_pages
,
64 struct hugetlb_cgroup
*h_cg
);
65 extern void hugetlb_cgroup_file_init(void) __init
;
66 extern void hugetlb_cgroup_migrate(struct page
*oldhpage
,
67 struct page
*newhpage
);
70 static inline struct hugetlb_cgroup
*hugetlb_cgroup_from_page(struct page
*page
)
76 int set_hugetlb_cgroup(struct page
*page
, struct hugetlb_cgroup
*h_cg
)
81 static inline bool hugetlb_cgroup_disabled(void)
87 hugetlb_cgroup_charge_cgroup(int idx
, unsigned long nr_pages
,
88 struct hugetlb_cgroup
**ptr
)
94 hugetlb_cgroup_commit_charge(int idx
, unsigned long nr_pages
,
95 struct hugetlb_cgroup
*h_cg
,
102 hugetlb_cgroup_uncharge_page(int idx
, unsigned long nr_pages
, struct page
*page
)
108 hugetlb_cgroup_uncharge_cgroup(int idx
, unsigned long nr_pages
,
109 struct hugetlb_cgroup
*h_cg
)
114 static inline void hugetlb_cgroup_file_init(void)
118 static inline void hugetlb_cgroup_migrate(struct page
*oldhpage
,
119 struct page
*newhpage
)
124 #endif /* CONFIG_MEM_RES_CTLR_HUGETLB */