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/mmdebug.h>
19 #include <linux/res_counter.h>
21 struct hugetlb_cgroup;
23 * Minimum page order trackable by hugetlb cgroup.
24 * At least 3 pages are necessary for all the tracking information.
26 #define HUGETLB_CGROUP_MIN_ORDER 2
28 #ifdef CONFIG_CGROUP_HUGETLB
30 static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
32 VM_BUG_ON_PAGE(!PageHuge(page), page);
34 if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
36 return (struct hugetlb_cgroup *)page[2].lru.next;
40 int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
42 VM_BUG_ON_PAGE(!PageHuge(page), page);
44 if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
46 page[2].lru.next = (void *)h_cg;
50 static inline bool hugetlb_cgroup_disabled(void)
52 if (hugetlb_subsys.disabled)
57 extern int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
58 struct hugetlb_cgroup **ptr);
59 extern void hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
60 struct hugetlb_cgroup *h_cg,
62 extern void hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages,
64 extern void hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
65 struct hugetlb_cgroup *h_cg);
66 extern void hugetlb_cgroup_file_init(void) __init;
67 extern void hugetlb_cgroup_migrate(struct page *oldhpage,
68 struct page *newhpage);
71 static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
77 int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg)
82 static inline bool hugetlb_cgroup_disabled(void)
88 hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
89 struct hugetlb_cgroup **ptr)
95 hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
96 struct hugetlb_cgroup *h_cg,
103 hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages, struct page *page)
109 hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
110 struct hugetlb_cgroup *h_cg)
115 static inline void hugetlb_cgroup_file_init(void)
119 static inline void hugetlb_cgroup_migrate(struct page *oldhpage,
120 struct page *newhpage)
125 #endif /* CONFIG_MEM_RES_CTLR_HUGETLB */