diff options
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r-- | mm/memcontrol.c | 67 |
1 files changed, 61 insertions, 6 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index decace3bb57e..7288e9d85ca7 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/memcontrol.h> | 21 | #include <linux/memcontrol.h> |
22 | #include <linux/cgroup.h> | 22 | #include <linux/cgroup.h> |
23 | #include <linux/mm.h> | 23 | #include <linux/mm.h> |
24 | #include <linux/pagemap.h> | ||
24 | #include <linux/smp.h> | 25 | #include <linux/smp.h> |
25 | #include <linux/page-flags.h> | 26 | #include <linux/page-flags.h> |
26 | #include <linux/backing-dev.h> | 27 | #include <linux/backing-dev.h> |
@@ -139,6 +140,7 @@ enum charge_type { | |||
139 | MEM_CGROUP_CHARGE_TYPE_MAPPED, | 140 | MEM_CGROUP_CHARGE_TYPE_MAPPED, |
140 | MEM_CGROUP_CHARGE_TYPE_SHMEM, /* used by page migration of shmem */ | 141 | MEM_CGROUP_CHARGE_TYPE_SHMEM, /* used by page migration of shmem */ |
141 | MEM_CGROUP_CHARGE_TYPE_FORCE, /* used by force_empty */ | 142 | MEM_CGROUP_CHARGE_TYPE_FORCE, /* used by force_empty */ |
143 | MEM_CGROUP_CHARGE_TYPE_SWAPOUT, /* for accounting swapcache */ | ||
142 | NR_CHARGE_TYPE, | 144 | NR_CHARGE_TYPE, |
143 | }; | 145 | }; |
144 | 146 | ||
@@ -780,6 +782,33 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm, | |||
780 | MEM_CGROUP_CHARGE_TYPE_SHMEM, NULL); | 782 | MEM_CGROUP_CHARGE_TYPE_SHMEM, NULL); |
781 | } | 783 | } |
782 | 784 | ||
785 | #ifdef CONFIG_SWAP | ||
786 | int mem_cgroup_cache_charge_swapin(struct page *page, | ||
787 | struct mm_struct *mm, gfp_t mask, bool locked) | ||
788 | { | ||
789 | int ret = 0; | ||
790 | |||
791 | if (mem_cgroup_subsys.disabled) | ||
792 | return 0; | ||
793 | if (unlikely(!mm)) | ||
794 | mm = &init_mm; | ||
795 | if (!locked) | ||
796 | lock_page(page); | ||
797 | /* | ||
798 | * If not locked, the page can be dropped from SwapCache until | ||
799 | * we reach here. | ||
800 | */ | ||
801 | if (PageSwapCache(page)) { | ||
802 | ret = mem_cgroup_charge_common(page, mm, mask, | ||
803 | MEM_CGROUP_CHARGE_TYPE_SHMEM, NULL); | ||
804 | } | ||
805 | if (!locked) | ||
806 | unlock_page(page); | ||
807 | |||
808 | return ret; | ||
809 | } | ||
810 | #endif | ||
811 | |||
783 | void mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *ptr) | 812 | void mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *ptr) |
784 | { | 813 | { |
785 | struct page_cgroup *pc; | 814 | struct page_cgroup *pc; |
@@ -817,6 +846,9 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype) | |||
817 | if (mem_cgroup_subsys.disabled) | 846 | if (mem_cgroup_subsys.disabled) |
818 | return; | 847 | return; |
819 | 848 | ||
849 | if (PageSwapCache(page)) | ||
850 | return; | ||
851 | |||
820 | /* | 852 | /* |
821 | * Check if our page_cgroup is valid | 853 | * Check if our page_cgroup is valid |
822 | */ | 854 | */ |
@@ -825,12 +857,26 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype) | |||
825 | return; | 857 | return; |
826 | 858 | ||
827 | lock_page_cgroup(pc); | 859 | lock_page_cgroup(pc); |
828 | if ((ctype == MEM_CGROUP_CHARGE_TYPE_MAPPED && page_mapped(page)) | 860 | |
829 | || !PageCgroupUsed(pc)) { | 861 | if (!PageCgroupUsed(pc)) |
830 | /* This happens at race in zap_pte_range() and do_swap_page()*/ | 862 | goto unlock_out; |
831 | unlock_page_cgroup(pc); | 863 | |
832 | return; | 864 | switch (ctype) { |
865 | case MEM_CGROUP_CHARGE_TYPE_MAPPED: | ||
866 | if (page_mapped(page)) | ||
867 | goto unlock_out; | ||
868 | break; | ||
869 | case MEM_CGROUP_CHARGE_TYPE_SWAPOUT: | ||
870 | if (!PageAnon(page)) { /* Shared memory */ | ||
871 | if (page->mapping && !page_is_file_cache(page)) | ||
872 | goto unlock_out; | ||
873 | } else if (page_mapped(page)) /* Anon */ | ||
874 | goto unlock_out; | ||
875 | break; | ||
876 | default: | ||
877 | break; | ||
833 | } | 878 | } |
879 | |||
834 | ClearPageCgroupUsed(pc); | 880 | ClearPageCgroupUsed(pc); |
835 | mem = pc->mem_cgroup; | 881 | mem = pc->mem_cgroup; |
836 | 882 | ||
@@ -844,6 +890,10 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype) | |||
844 | css_put(&mem->css); | 890 | css_put(&mem->css); |
845 | 891 | ||
846 | return; | 892 | return; |
893 | |||
894 | unlock_out: | ||
895 | unlock_page_cgroup(pc); | ||
896 | return; | ||
847 | } | 897 | } |
848 | 898 | ||
849 | void mem_cgroup_uncharge_page(struct page *page) | 899 | void mem_cgroup_uncharge_page(struct page *page) |
@@ -863,6 +913,11 @@ void mem_cgroup_uncharge_cache_page(struct page *page) | |||
863 | __mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_CACHE); | 913 | __mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_CACHE); |
864 | } | 914 | } |
865 | 915 | ||
916 | void mem_cgroup_uncharge_swapcache(struct page *page) | ||
917 | { | ||
918 | __mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_SWAPOUT); | ||
919 | } | ||
920 | |||
866 | /* | 921 | /* |
867 | * Before starting migration, account PAGE_SIZE to mem_cgroup that the old | 922 | * Before starting migration, account PAGE_SIZE to mem_cgroup that the old |
868 | * page belongs to. | 923 | * page belongs to. |
@@ -920,7 +975,7 @@ void mem_cgroup_end_migration(struct mem_cgroup *mem, | |||
920 | ctype = MEM_CGROUP_CHARGE_TYPE_SHMEM; | 975 | ctype = MEM_CGROUP_CHARGE_TYPE_SHMEM; |
921 | 976 | ||
922 | /* unused page is not on radix-tree now. */ | 977 | /* unused page is not on radix-tree now. */ |
923 | if (unused && ctype != MEM_CGROUP_CHARGE_TYPE_MAPPED) | 978 | if (unused) |
924 | __mem_cgroup_uncharge_common(unused, ctype); | 979 | __mem_cgroup_uncharge_common(unused, ctype); |
925 | 980 | ||
926 | pc = lookup_page_cgroup(target); | 981 | pc = lookup_page_cgroup(target); |