aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2013-05-24 18:55:15 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-05-24 19:22:51 -0400
commit28ccddf7952c496df2a51ce5aee4f2a058a98bab (patch)
tree6c8b8ebc4677f2b2fab0bf61a9a4c860970c82e9 /mm
parent26549c8d36a64d9130e4c0f32412be7ba6180923 (diff)
mm: memcg: remove incorrect VM_BUG_ON for swap cache pages in uncharge
Commit 0c59b89c81ea ("mm: memcg: push down PageSwapCache check into uncharge entry functions") added a VM_BUG_ON() on PageSwapCache in the uncharge path after checking that page flag once, assuming that the state is stable in all paths, but this is not the case and the condition triggers in user environments. An uncharge after the last page table reference to the page goes away can race with reclaim adding the page to swap cache. Swap cache pages are usually uncharged when they are freed after swapout, from a path that also handles swap usage accounting and memcg lifetime management. However, since the last page table reference is gone and thus no references to the swap slot left, the swap slot will be freed shortly when reclaim attempts to write the page to disk. The whole swap accounting is not even necessary. So while the race condition for which this VM_BUG_ON was added is real and actually existed all along, there are no negative effects. Remove the VM_BUG_ON again. Reported-by: Heiko Carstens <heiko.carstens@de.ibm.com> Reported-by: Lingzhu Xiang <lxiang@redhat.com> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Hugh Dickins <hughd@google.com> Acked-by: Michal Hocko <mhocko@suse.cz> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/memcontrol.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index cb1c9dedf9b6..010d6c14129a 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4108,8 +4108,6 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype,
4108 if (mem_cgroup_disabled()) 4108 if (mem_cgroup_disabled())
4109 return NULL; 4109 return NULL;
4110 4110
4111 VM_BUG_ON(PageSwapCache(page));
4112
4113 if (PageTransHuge(page)) { 4111 if (PageTransHuge(page)) {
4114 nr_pages <<= compound_order(page); 4112 nr_pages <<= compound_order(page);
4115 VM_BUG_ON(!PageTransHuge(page)); 4113 VM_BUG_ON(!PageTransHuge(page));
@@ -4205,6 +4203,18 @@ void mem_cgroup_uncharge_page(struct page *page)
4205 if (page_mapped(page)) 4203 if (page_mapped(page))
4206 return; 4204 return;
4207 VM_BUG_ON(page->mapping && !PageAnon(page)); 4205 VM_BUG_ON(page->mapping && !PageAnon(page));
4206 /*
4207 * If the page is in swap cache, uncharge should be deferred
4208 * to the swap path, which also properly accounts swap usage
4209 * and handles memcg lifetime.
4210 *
4211 * Note that this check is not stable and reclaim may add the
4212 * page to swap cache at any time after this. However, if the
4213 * page is not in swap cache by the time page->mapcount hits
4214 * 0, there won't be any page table references to the swap
4215 * slot, and reclaim will free it and not actually write the
4216 * page to disk.
4217 */
4208 if (PageSwapCache(page)) 4218 if (PageSwapCache(page))
4209 return; 4219 return;
4210 __mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_ANON, false); 4220 __mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_ANON, false);