Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright IBM Corporation, 2012
0003  * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
0004  *
0005  * This program is free software; you can redistribute it and/or modify it
0006  * under the terms of version 2.1 of the GNU Lesser General Public License
0007  * as published by the Free Software Foundation.
0008  *
0009  * This program is distributed in the hope that it would be useful, but
0010  * WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0012  *
0013  */
0014 
0015 #ifndef _LINUX_HUGETLB_CGROUP_H
0016 #define _LINUX_HUGETLB_CGROUP_H
0017 
0018 #include <linux/mmdebug.h>
0019 
0020 struct hugetlb_cgroup;
0021 struct resv_map;
0022 struct file_region;
0023 
0024 #ifdef CONFIG_CGROUP_HUGETLB
0025 /*
0026  * Minimum page order trackable by hugetlb cgroup.
0027  * At least 4 pages are necessary for all the tracking information.
0028  * The second tail page (hpage[SUBPAGE_INDEX_CGROUP]) is the fault
0029  * usage cgroup. The third tail page (hpage[SUBPAGE_INDEX_CGROUP_RSVD])
0030  * is the reservation usage cgroup.
0031  */
0032 #define HUGETLB_CGROUP_MIN_ORDER order_base_2(__MAX_CGROUP_SUBPAGE_INDEX + 1)
0033 
0034 enum hugetlb_memory_event {
0035     HUGETLB_MAX,
0036     HUGETLB_NR_MEMORY_EVENTS,
0037 };
0038 
0039 struct hugetlb_cgroup_per_node {
0040     /* hugetlb usage in pages over all hstates. */
0041     unsigned long usage[HUGE_MAX_HSTATE];
0042 };
0043 
0044 struct hugetlb_cgroup {
0045     struct cgroup_subsys_state css;
0046 
0047     /*
0048      * the counter to account for hugepages from hugetlb.
0049      */
0050     struct page_counter hugepage[HUGE_MAX_HSTATE];
0051 
0052     /*
0053      * the counter to account for hugepage reservations from hugetlb.
0054      */
0055     struct page_counter rsvd_hugepage[HUGE_MAX_HSTATE];
0056 
0057     atomic_long_t events[HUGE_MAX_HSTATE][HUGETLB_NR_MEMORY_EVENTS];
0058     atomic_long_t events_local[HUGE_MAX_HSTATE][HUGETLB_NR_MEMORY_EVENTS];
0059 
0060     /* Handle for "hugetlb.events" */
0061     struct cgroup_file events_file[HUGE_MAX_HSTATE];
0062 
0063     /* Handle for "hugetlb.events.local" */
0064     struct cgroup_file events_local_file[HUGE_MAX_HSTATE];
0065 
0066     struct hugetlb_cgroup_per_node *nodeinfo[];
0067 };
0068 
0069 static inline struct hugetlb_cgroup *
0070 __hugetlb_cgroup_from_page(struct page *page, bool rsvd)
0071 {
0072     VM_BUG_ON_PAGE(!PageHuge(page), page);
0073 
0074     if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
0075         return NULL;
0076     if (rsvd)
0077         return (void *)page_private(page + SUBPAGE_INDEX_CGROUP_RSVD);
0078     else
0079         return (void *)page_private(page + SUBPAGE_INDEX_CGROUP);
0080 }
0081 
0082 static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
0083 {
0084     return __hugetlb_cgroup_from_page(page, false);
0085 }
0086 
0087 static inline struct hugetlb_cgroup *
0088 hugetlb_cgroup_from_page_rsvd(struct page *page)
0089 {
0090     return __hugetlb_cgroup_from_page(page, true);
0091 }
0092 
0093 static inline int __set_hugetlb_cgroup(struct page *page,
0094                        struct hugetlb_cgroup *h_cg, bool rsvd)
0095 {
0096     VM_BUG_ON_PAGE(!PageHuge(page), page);
0097 
0098     if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER)
0099         return -1;
0100     if (rsvd)
0101         set_page_private(page + SUBPAGE_INDEX_CGROUP_RSVD,
0102                  (unsigned long)h_cg);
0103     else
0104         set_page_private(page + SUBPAGE_INDEX_CGROUP,
0105                  (unsigned long)h_cg);
0106     return 0;
0107 }
0108 
0109 static inline int set_hugetlb_cgroup(struct page *page,
0110                      struct hugetlb_cgroup *h_cg)
0111 {
0112     return __set_hugetlb_cgroup(page, h_cg, false);
0113 }
0114 
0115 static inline int set_hugetlb_cgroup_rsvd(struct page *page,
0116                       struct hugetlb_cgroup *h_cg)
0117 {
0118     return __set_hugetlb_cgroup(page, h_cg, true);
0119 }
0120 
0121 static inline bool hugetlb_cgroup_disabled(void)
0122 {
0123     return !cgroup_subsys_enabled(hugetlb_cgrp_subsys);
0124 }
0125 
0126 static inline void hugetlb_cgroup_put_rsvd_cgroup(struct hugetlb_cgroup *h_cg)
0127 {
0128     css_put(&h_cg->css);
0129 }
0130 
0131 static inline void resv_map_dup_hugetlb_cgroup_uncharge_info(
0132                         struct resv_map *resv_map)
0133 {
0134     if (resv_map->css)
0135         css_get(resv_map->css);
0136 }
0137 
0138 static inline void resv_map_put_hugetlb_cgroup_uncharge_info(
0139                         struct resv_map *resv_map)
0140 {
0141     if (resv_map->css)
0142         css_put(resv_map->css);
0143 }
0144 
0145 extern int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
0146                     struct hugetlb_cgroup **ptr);
0147 extern int hugetlb_cgroup_charge_cgroup_rsvd(int idx, unsigned long nr_pages,
0148                          struct hugetlb_cgroup **ptr);
0149 extern void hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
0150                      struct hugetlb_cgroup *h_cg,
0151                      struct page *page);
0152 extern void hugetlb_cgroup_commit_charge_rsvd(int idx, unsigned long nr_pages,
0153                           struct hugetlb_cgroup *h_cg,
0154                           struct page *page);
0155 extern void hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages,
0156                      struct page *page);
0157 extern void hugetlb_cgroup_uncharge_page_rsvd(int idx, unsigned long nr_pages,
0158                           struct page *page);
0159 
0160 extern void hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
0161                        struct hugetlb_cgroup *h_cg);
0162 extern void hugetlb_cgroup_uncharge_cgroup_rsvd(int idx, unsigned long nr_pages,
0163                         struct hugetlb_cgroup *h_cg);
0164 extern void hugetlb_cgroup_uncharge_counter(struct resv_map *resv,
0165                         unsigned long start,
0166                         unsigned long end);
0167 
0168 extern void hugetlb_cgroup_uncharge_file_region(struct resv_map *resv,
0169                         struct file_region *rg,
0170                         unsigned long nr_pages,
0171                         bool region_del);
0172 
0173 extern void hugetlb_cgroup_file_init(void) __init;
0174 extern void hugetlb_cgroup_migrate(struct page *oldhpage,
0175                    struct page *newhpage);
0176 
0177 #else
0178 static inline void hugetlb_cgroup_uncharge_file_region(struct resv_map *resv,
0179                                struct file_region *rg,
0180                                unsigned long nr_pages,
0181                                bool region_del)
0182 {
0183 }
0184 
0185 static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page)
0186 {
0187     return NULL;
0188 }
0189 
0190 static inline struct hugetlb_cgroup *
0191 hugetlb_cgroup_from_page_resv(struct page *page)
0192 {
0193     return NULL;
0194 }
0195 
0196 static inline struct hugetlb_cgroup *
0197 hugetlb_cgroup_from_page_rsvd(struct page *page)
0198 {
0199     return NULL;
0200 }
0201 
0202 static inline int set_hugetlb_cgroup(struct page *page,
0203                      struct hugetlb_cgroup *h_cg)
0204 {
0205     return 0;
0206 }
0207 
0208 static inline int set_hugetlb_cgroup_rsvd(struct page *page,
0209                       struct hugetlb_cgroup *h_cg)
0210 {
0211     return 0;
0212 }
0213 
0214 static inline bool hugetlb_cgroup_disabled(void)
0215 {
0216     return true;
0217 }
0218 
0219 static inline void hugetlb_cgroup_put_rsvd_cgroup(struct hugetlb_cgroup *h_cg)
0220 {
0221 }
0222 
0223 static inline void resv_map_dup_hugetlb_cgroup_uncharge_info(
0224                         struct resv_map *resv_map)
0225 {
0226 }
0227 
0228 static inline void resv_map_put_hugetlb_cgroup_uncharge_info(
0229                         struct resv_map *resv_map)
0230 {
0231 }
0232 
0233 static inline int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
0234                            struct hugetlb_cgroup **ptr)
0235 {
0236     return 0;
0237 }
0238 
0239 static inline int hugetlb_cgroup_charge_cgroup_rsvd(int idx,
0240                             unsigned long nr_pages,
0241                             struct hugetlb_cgroup **ptr)
0242 {
0243     return 0;
0244 }
0245 
0246 static inline void hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
0247                         struct hugetlb_cgroup *h_cg,
0248                         struct page *page)
0249 {
0250 }
0251 
0252 static inline void
0253 hugetlb_cgroup_commit_charge_rsvd(int idx, unsigned long nr_pages,
0254                   struct hugetlb_cgroup *h_cg,
0255                   struct page *page)
0256 {
0257 }
0258 
0259 static inline void hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages,
0260                         struct page *page)
0261 {
0262 }
0263 
0264 static inline void hugetlb_cgroup_uncharge_page_rsvd(int idx,
0265                              unsigned long nr_pages,
0266                              struct page *page)
0267 {
0268 }
0269 static inline void hugetlb_cgroup_uncharge_cgroup(int idx,
0270                           unsigned long nr_pages,
0271                           struct hugetlb_cgroup *h_cg)
0272 {
0273 }
0274 
0275 static inline void
0276 hugetlb_cgroup_uncharge_cgroup_rsvd(int idx, unsigned long nr_pages,
0277                     struct hugetlb_cgroup *h_cg)
0278 {
0279 }
0280 
0281 static inline void hugetlb_cgroup_uncharge_counter(struct resv_map *resv,
0282                            unsigned long start,
0283                            unsigned long end)
0284 {
0285 }
0286 
0287 static inline void hugetlb_cgroup_file_init(void)
0288 {
0289 }
0290 
0291 static inline void hugetlb_cgroup_migrate(struct page *oldhpage,
0292                       struct page *newhpage)
0293 {
0294 }
0295 
0296 #endif  /* CONFIG_MEM_RES_CTLR_HUGETLB */
0297 #endif