diff options
-rw-r--r-- | include/linux/memcontrol.h | 31 | ||||
-rw-r--r-- | mm/memcontrol.c | 16 | ||||
-rw-r--r-- | mm/rmap.c | 4 |
3 files changed, 37 insertions, 14 deletions
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 159a0762aeaf..067115ce6b3e 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h | |||
@@ -25,6 +25,11 @@ struct page_cgroup; | |||
25 | struct page; | 25 | struct page; |
26 | struct mm_struct; | 26 | struct mm_struct; |
27 | 27 | ||
28 | /* Stats that can be updated by kernel. */ | ||
29 | enum mem_cgroup_page_stat_item { | ||
30 | MEMCG_NR_FILE_MAPPED, /* # of pages charged as file rss */ | ||
31 | }; | ||
32 | |||
28 | extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan, | 33 | extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan, |
29 | struct list_head *dst, | 34 | struct list_head *dst, |
30 | unsigned long *scanned, int order, | 35 | unsigned long *scanned, int order, |
@@ -121,7 +126,22 @@ static inline bool mem_cgroup_disabled(void) | |||
121 | return false; | 126 | return false; |
122 | } | 127 | } |
123 | 128 | ||
124 | void mem_cgroup_update_file_mapped(struct page *page, int val); | 129 | void mem_cgroup_update_page_stat(struct page *page, |
130 | enum mem_cgroup_page_stat_item idx, | ||
131 | int val); | ||
132 | |||
133 | static inline void mem_cgroup_inc_page_stat(struct page *page, | ||
134 | enum mem_cgroup_page_stat_item idx) | ||
135 | { | ||
136 | mem_cgroup_update_page_stat(page, idx, 1); | ||
137 | } | ||
138 | |||
139 | static inline void mem_cgroup_dec_page_stat(struct page *page, | ||
140 | enum mem_cgroup_page_stat_item idx) | ||
141 | { | ||
142 | mem_cgroup_update_page_stat(page, idx, -1); | ||
143 | } | ||
144 | |||
125 | unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, | 145 | unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, |
126 | gfp_t gfp_mask); | 146 | gfp_t gfp_mask); |
127 | u64 mem_cgroup_get_limit(struct mem_cgroup *mem); | 147 | u64 mem_cgroup_get_limit(struct mem_cgroup *mem); |
@@ -293,8 +313,13 @@ mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p) | |||
293 | { | 313 | { |
294 | } | 314 | } |
295 | 315 | ||
296 | static inline void mem_cgroup_update_file_mapped(struct page *page, | 316 | static inline void mem_cgroup_inc_page_stat(struct page *page, |
297 | int val) | 317 | enum mem_cgroup_page_stat_item idx) |
318 | { | ||
319 | } | ||
320 | |||
321 | static inline void mem_cgroup_dec_page_stat(struct page *page, | ||
322 | enum mem_cgroup_page_stat_item idx) | ||
298 | { | 323 | { |
299 | } | 324 | } |
300 | 325 | ||
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 741206ffdace..3d8a0c79dece 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -1600,7 +1600,8 @@ bool mem_cgroup_handle_oom(struct mem_cgroup *mem, gfp_t mask) | |||
1600 | * possibility of race condition. If there is, we take a lock. | 1600 | * possibility of race condition. If there is, we take a lock. |
1601 | */ | 1601 | */ |
1602 | 1602 | ||
1603 | static void mem_cgroup_update_file_stat(struct page *page, int idx, int val) | 1603 | void mem_cgroup_update_page_stat(struct page *page, |
1604 | enum mem_cgroup_page_stat_item idx, int val) | ||
1604 | { | 1605 | { |
1605 | struct mem_cgroup *mem; | 1606 | struct mem_cgroup *mem; |
1606 | struct page_cgroup *pc = lookup_page_cgroup(page); | 1607 | struct page_cgroup *pc = lookup_page_cgroup(page); |
@@ -1623,30 +1624,27 @@ static void mem_cgroup_update_file_stat(struct page *page, int idx, int val) | |||
1623 | goto out; | 1624 | goto out; |
1624 | } | 1625 | } |
1625 | 1626 | ||
1626 | this_cpu_add(mem->stat->count[idx], val); | ||
1627 | |||
1628 | switch (idx) { | 1627 | switch (idx) { |
1629 | case MEM_CGROUP_STAT_FILE_MAPPED: | 1628 | case MEMCG_NR_FILE_MAPPED: |
1630 | if (val > 0) | 1629 | if (val > 0) |
1631 | SetPageCgroupFileMapped(pc); | 1630 | SetPageCgroupFileMapped(pc); |
1632 | else if (!page_mapped(page)) | 1631 | else if (!page_mapped(page)) |
1633 | ClearPageCgroupFileMapped(pc); | 1632 | ClearPageCgroupFileMapped(pc); |
1633 | idx = MEM_CGROUP_STAT_FILE_MAPPED; | ||
1634 | break; | 1634 | break; |
1635 | default: | 1635 | default: |
1636 | BUG(); | 1636 | BUG(); |
1637 | } | 1637 | } |
1638 | 1638 | ||
1639 | this_cpu_add(mem->stat->count[idx], val); | ||
1640 | |||
1639 | out: | 1641 | out: |
1640 | if (unlikely(need_unlock)) | 1642 | if (unlikely(need_unlock)) |
1641 | unlock_page_cgroup(pc); | 1643 | unlock_page_cgroup(pc); |
1642 | rcu_read_unlock(); | 1644 | rcu_read_unlock(); |
1643 | return; | 1645 | return; |
1644 | } | 1646 | } |
1645 | 1647 | EXPORT_SYMBOL(mem_cgroup_update_page_stat); | |
1646 | void mem_cgroup_update_file_mapped(struct page *page, int val) | ||
1647 | { | ||
1648 | mem_cgroup_update_file_stat(page, MEM_CGROUP_STAT_FILE_MAPPED, val); | ||
1649 | } | ||
1650 | 1648 | ||
1651 | /* | 1649 | /* |
1652 | * size of first charge trial. "32" comes from vmscan.c's magic value. | 1650 | * size of first charge trial. "32" comes from vmscan.c's magic value. |
@@ -937,7 +937,7 @@ void page_add_file_rmap(struct page *page) | |||
937 | { | 937 | { |
938 | if (atomic_inc_and_test(&page->_mapcount)) { | 938 | if (atomic_inc_and_test(&page->_mapcount)) { |
939 | __inc_zone_page_state(page, NR_FILE_MAPPED); | 939 | __inc_zone_page_state(page, NR_FILE_MAPPED); |
940 | mem_cgroup_update_file_mapped(page, 1); | 940 | mem_cgroup_inc_page_stat(page, MEMCG_NR_FILE_MAPPED); |
941 | } | 941 | } |
942 | } | 942 | } |
943 | 943 | ||
@@ -979,7 +979,7 @@ void page_remove_rmap(struct page *page) | |||
979 | NR_ANON_TRANSPARENT_HUGEPAGES); | 979 | NR_ANON_TRANSPARENT_HUGEPAGES); |
980 | } else { | 980 | } else { |
981 | __dec_zone_page_state(page, NR_FILE_MAPPED); | 981 | __dec_zone_page_state(page, NR_FILE_MAPPED); |
982 | mem_cgroup_update_file_mapped(page, -1); | 982 | mem_cgroup_dec_page_stat(page, MEMCG_NR_FILE_MAPPED); |
983 | } | 983 | } |
984 | /* | 984 | /* |
985 | * It would be tidy to reset the PageAnon mapping here, | 985 | * It would be tidy to reset the PageAnon mapping here, |