Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 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 | |
| 15 | #ifndef _LINUX_HUGETLB_CGROUP_H |
| 16 | #define _LINUX_HUGETLB_CGROUP_H |
| 17 | |
Sasha Levin | 309381fea | 2014-01-23 15:52:54 -0800 | [diff] [blame] | 18 | #include <linux/mmdebug.h> |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 19 | |
| 20 | struct hugetlb_cgroup; |
Aneesh Kumar K.V | 9dd540e | 2012-07-31 16:42:15 -0700 | [diff] [blame] | 21 | /* |
| 22 | * Minimum page order trackable by hugetlb cgroup. |
| 23 | * At least 3 pages are necessary for all the tracking information. |
| 24 | */ |
| 25 | #define HUGETLB_CGROUP_MIN_ORDER 2 |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 26 | |
| 27 | #ifdef CONFIG_CGROUP_HUGETLB |
Aneesh Kumar K.V | 9dd540e | 2012-07-31 16:42:15 -0700 | [diff] [blame] | 28 | |
| 29 | static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page) |
| 30 | { |
Sasha Levin | 309381fea | 2014-01-23 15:52:54 -0800 | [diff] [blame] | 31 | VM_BUG_ON_PAGE(!PageHuge(page), page); |
Aneesh Kumar K.V | 9dd540e | 2012-07-31 16:42:15 -0700 | [diff] [blame] | 32 | |
| 33 | if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER) |
| 34 | return NULL; |
| 35 | return (struct hugetlb_cgroup *)page[2].lru.next; |
| 36 | } |
| 37 | |
| 38 | static inline |
| 39 | int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg) |
| 40 | { |
Sasha Levin | 309381fea | 2014-01-23 15:52:54 -0800 | [diff] [blame] | 41 | VM_BUG_ON_PAGE(!PageHuge(page), page); |
Aneesh Kumar K.V | 9dd540e | 2012-07-31 16:42:15 -0700 | [diff] [blame] | 42 | |
| 43 | if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER) |
| 44 | return -1; |
| 45 | page[2].lru.next = (void *)h_cg; |
| 46 | return 0; |
| 47 | } |
| 48 | |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 49 | static inline bool hugetlb_cgroup_disabled(void) |
| 50 | { |
Tejun Heo | 073219e | 2014-02-08 10:36:58 -0500 | [diff] [blame] | 51 | if (hugetlb_cgrp_subsys.disabled) |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 52 | return true; |
| 53 | return false; |
| 54 | } |
| 55 | |
Aneesh Kumar K.V | 6d76dcf | 2012-07-31 16:42:18 -0700 | [diff] [blame] | 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, |
| 60 | struct page *page); |
| 61 | extern void hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages, |
| 62 | struct page *page); |
| 63 | extern void hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages, |
| 64 | struct hugetlb_cgroup *h_cg); |
Jianguo Wu | 7179e7b | 2012-12-18 14:23:19 -0800 | [diff] [blame] | 65 | extern void hugetlb_cgroup_file_init(void) __init; |
Aneesh Kumar K.V | 8e6ac7f | 2012-07-31 16:42:27 -0700 | [diff] [blame] | 66 | extern void hugetlb_cgroup_migrate(struct page *oldhpage, |
| 67 | struct page *newhpage); |
Aneesh Kumar K.V | 6d76dcf | 2012-07-31 16:42:18 -0700 | [diff] [blame] | 68 | |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 69 | #else |
Aneesh Kumar K.V | 9dd540e | 2012-07-31 16:42:15 -0700 | [diff] [blame] | 70 | static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page) |
| 71 | { |
| 72 | return NULL; |
| 73 | } |
| 74 | |
| 75 | static inline |
| 76 | int set_hugetlb_cgroup(struct page *page, struct hugetlb_cgroup *h_cg) |
| 77 | { |
| 78 | return 0; |
| 79 | } |
| 80 | |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 81 | static inline bool hugetlb_cgroup_disabled(void) |
| 82 | { |
| 83 | return true; |
| 84 | } |
| 85 | |
Aneesh Kumar K.V | 6d76dcf | 2012-07-31 16:42:18 -0700 | [diff] [blame] | 86 | static inline int |
| 87 | hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages, |
| 88 | struct hugetlb_cgroup **ptr) |
| 89 | { |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | static inline void |
| 94 | hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages, |
| 95 | struct hugetlb_cgroup *h_cg, |
| 96 | struct page *page) |
| 97 | { |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | static inline void |
| 102 | hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages, struct page *page) |
| 103 | { |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | static inline void |
| 108 | hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages, |
| 109 | struct hugetlb_cgroup *h_cg) |
| 110 | { |
| 111 | return; |
| 112 | } |
| 113 | |
Jianguo Wu | 7179e7b | 2012-12-18 14:23:19 -0800 | [diff] [blame] | 114 | static inline void hugetlb_cgroup_file_init(void) |
Aneesh Kumar K.V | abb8206 | 2012-07-31 16:42:24 -0700 | [diff] [blame] | 115 | { |
Aneesh Kumar K.V | abb8206 | 2012-07-31 16:42:24 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Aneesh Kumar K.V | 8e6ac7f | 2012-07-31 16:42:27 -0700 | [diff] [blame] | 118 | static inline void hugetlb_cgroup_migrate(struct page *oldhpage, |
| 119 | struct page *newhpage) |
| 120 | { |
| 121 | return; |
| 122 | } |
| 123 | |
Aneesh Kumar K.V | 2bc64a2 | 2012-07-31 16:42:12 -0700 | [diff] [blame] | 124 | #endif /* CONFIG_MEM_RES_CTLR_HUGETLB */ |
| 125 | #endif |