diff options
author | Hugh Dickins <hughd@google.com> | 2011-08-03 19:21:24 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-08-03 20:25:24 -0400 |
commit | aa3b189551ad8e5cc1d9c663735c131650238278 (patch) | |
tree | c789ab5c7f890a6065811d8bba15a784caf9e859 /mm/memcontrol.c | |
parent | 54af60421822bb9cb664dd5cd7aac46c01ccfcf8 (diff) |
tmpfs: convert mem_cgroup shmem to radix-swap
Remove mem_cgroup_shmem_charge_fallback(): it was only required when we
had to move swappage to filecache with GFP_NOWAIT.
Remove the GFP_NOWAIT special case from mem_cgroup_cache_charge(), by
moving its call out from shmem_add_to_page_cache() to two of thats three
callers. But leave it doing mem_cgroup_uncharge_cache_page() on error:
although asymmetrical, it's easier for all 3 callers to handle.
These two changes would also be appropriate if anyone were to start
using shmem_read_mapping_page_gfp() with GFP_NOWAIT.
Remove mem_cgroup_get_shmem_target(): mc_handle_file_pte() can test
radix_tree_exceptional_entry() to get what it needs for itself.
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r-- | mm/memcontrol.c | 66 |
1 files changed, 9 insertions, 57 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5f84d2351ddb..f4ec4e7ca4cd 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -35,7 +35,6 @@ | |||
35 | #include <linux/limits.h> | 35 | #include <linux/limits.h> |
36 | #include <linux/mutex.h> | 36 | #include <linux/mutex.h> |
37 | #include <linux/rbtree.h> | 37 | #include <linux/rbtree.h> |
38 | #include <linux/shmem_fs.h> | ||
39 | #include <linux/slab.h> | 38 | #include <linux/slab.h> |
40 | #include <linux/swap.h> | 39 | #include <linux/swap.h> |
41 | #include <linux/swapops.h> | 40 | #include <linux/swapops.h> |
@@ -2873,30 +2872,6 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm, | |||
2873 | return 0; | 2872 | return 0; |
2874 | if (PageCompound(page)) | 2873 | if (PageCompound(page)) |
2875 | return 0; | 2874 | return 0; |
2876 | /* | ||
2877 | * Corner case handling. This is called from add_to_page_cache() | ||
2878 | * in usual. But some FS (shmem) precharges this page before calling it | ||
2879 | * and call add_to_page_cache() with GFP_NOWAIT. | ||
2880 | * | ||
2881 | * For GFP_NOWAIT case, the page may be pre-charged before calling | ||
2882 | * add_to_page_cache(). (See shmem.c) check it here and avoid to call | ||
2883 | * charge twice. (It works but has to pay a bit larger cost.) | ||
2884 | * And when the page is SwapCache, it should take swap information | ||
2885 | * into account. This is under lock_page() now. | ||
2886 | */ | ||
2887 | if (!(gfp_mask & __GFP_WAIT)) { | ||
2888 | struct page_cgroup *pc; | ||
2889 | |||
2890 | pc = lookup_page_cgroup(page); | ||
2891 | if (!pc) | ||
2892 | return 0; | ||
2893 | lock_page_cgroup(pc); | ||
2894 | if (PageCgroupUsed(pc)) { | ||
2895 | unlock_page_cgroup(pc); | ||
2896 | return 0; | ||
2897 | } | ||
2898 | unlock_page_cgroup(pc); | ||
2899 | } | ||
2900 | 2875 | ||
2901 | if (unlikely(!mm)) | 2876 | if (unlikely(!mm)) |
2902 | mm = &init_mm; | 2877 | mm = &init_mm; |
@@ -3486,31 +3461,6 @@ void mem_cgroup_end_migration(struct mem_cgroup *mem, | |||
3486 | cgroup_release_and_wakeup_rmdir(&mem->css); | 3461 | cgroup_release_and_wakeup_rmdir(&mem->css); |
3487 | } | 3462 | } |
3488 | 3463 | ||
3489 | /* | ||
3490 | * A call to try to shrink memory usage on charge failure at shmem's swapin. | ||
3491 | * Calling hierarchical_reclaim is not enough because we should update | ||
3492 | * last_oom_jiffies to prevent pagefault_out_of_memory from invoking global OOM. | ||
3493 | * Moreover considering hierarchy, we should reclaim from the mem_over_limit, | ||
3494 | * not from the memcg which this page would be charged to. | ||
3495 | * try_charge_swapin does all of these works properly. | ||
3496 | */ | ||
3497 | int mem_cgroup_shmem_charge_fallback(struct page *page, | ||
3498 | struct mm_struct *mm, | ||
3499 | gfp_t gfp_mask) | ||
3500 | { | ||
3501 | struct mem_cgroup *mem; | ||
3502 | int ret; | ||
3503 | |||
3504 | if (mem_cgroup_disabled()) | ||
3505 | return 0; | ||
3506 | |||
3507 | ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &mem); | ||
3508 | if (!ret) | ||
3509 | mem_cgroup_cancel_charge_swapin(mem); /* it does !mem check */ | ||
3510 | |||
3511 | return ret; | ||
3512 | } | ||
3513 | |||
3514 | #ifdef CONFIG_DEBUG_VM | 3464 | #ifdef CONFIG_DEBUG_VM |
3515 | static struct page_cgroup *lookup_page_cgroup_used(struct page *page) | 3465 | static struct page_cgroup *lookup_page_cgroup_used(struct page *page) |
3516 | { | 3466 | { |
@@ -5330,15 +5280,17 @@ static struct page *mc_handle_file_pte(struct vm_area_struct *vma, | |||
5330 | pgoff = pte_to_pgoff(ptent); | 5280 | pgoff = pte_to_pgoff(ptent); |
5331 | 5281 | ||
5332 | /* page is moved even if it's not RSS of this task(page-faulted). */ | 5282 | /* page is moved even if it's not RSS of this task(page-faulted). */ |
5333 | if (!mapping_cap_swap_backed(mapping)) { /* normal file */ | 5283 | page = find_get_page(mapping, pgoff); |
5334 | page = find_get_page(mapping, pgoff); | 5284 | |
5335 | } else { /* shmem/tmpfs file. we should take account of swap too. */ | 5285 | #ifdef CONFIG_SWAP |
5336 | swp_entry_t ent; | 5286 | /* shmem/tmpfs may report page out on swap: account for that too. */ |
5337 | mem_cgroup_get_shmem_target(inode, pgoff, &page, &ent); | 5287 | if (radix_tree_exceptional_entry(page)) { |
5288 | swp_entry_t swap = radix_to_swp_entry(page); | ||
5338 | if (do_swap_account) | 5289 | if (do_swap_account) |
5339 | entry->val = ent.val; | 5290 | *entry = swap; |
5291 | page = find_get_page(&swapper_space, swap.val); | ||
5340 | } | 5292 | } |
5341 | 5293 | #endif | |
5342 | return page; | 5294 | return page; |
5343 | } | 5295 | } |
5344 | 5296 | ||