Commit b7abea9630bc8ffc663a751e46680db25c4cdf8d
Committed by
Linus Torvalds
1 parent
073e587ec2
Exists in
master
and in
4 other branches
memcg: make page->mapping NULL before uncharge
This patch tries to make page->mapping to be NULL before mem_cgroup_uncharge_cache_page() is called. "page->mapping == NULL" is a good check for "whether the page is still radix-tree or not". This patch also adds BUG_ON() to mem_cgroup_uncharge_cache_page(); Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Reviewed-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Cc: Balbir Singh <balbir@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 3 changed files with 9 additions and 3 deletions Side-by-side Diff
mm/filemap.c
... | ... | @@ -116,12 +116,12 @@ |
116 | 116 | { |
117 | 117 | struct address_space *mapping = page->mapping; |
118 | 118 | |
119 | - mem_cgroup_uncharge_cache_page(page); | |
120 | 119 | radix_tree_delete(&mapping->page_tree, page->index); |
121 | 120 | page->mapping = NULL; |
122 | 121 | mapping->nrpages--; |
123 | 122 | __dec_zone_page_state(page, NR_FILE_PAGES); |
124 | 123 | BUG_ON(page_mapped(page)); |
124 | + mem_cgroup_uncharge_cache_page(page); | |
125 | 125 | |
126 | 126 | /* |
127 | 127 | * Some filesystems seem to re-dirty the page even after |
mm/memcontrol.c
mm/migrate.c
... | ... | @@ -330,8 +330,6 @@ |
330 | 330 | __inc_zone_page_state(newpage, NR_FILE_PAGES); |
331 | 331 | |
332 | 332 | spin_unlock_irq(&mapping->tree_lock); |
333 | - if (!PageSwapCache(newpage)) | |
334 | - mem_cgroup_uncharge_cache_page(page); | |
335 | 333 | |
336 | 334 | return 0; |
337 | 335 | } |
... | ... | @@ -341,6 +339,8 @@ |
341 | 339 | */ |
342 | 340 | static void migrate_page_copy(struct page *newpage, struct page *page) |
343 | 341 | { |
342 | + int anon; | |
343 | + | |
344 | 344 | copy_highpage(newpage, page); |
345 | 345 | |
346 | 346 | if (PageError(page)) |
347 | 347 | |
... | ... | @@ -378,7 +378,12 @@ |
378 | 378 | #endif |
379 | 379 | ClearPagePrivate(page); |
380 | 380 | set_page_private(page, 0); |
381 | + /* page->mapping contains a flag for PageAnon() */ | |
382 | + anon = PageAnon(page); | |
381 | 383 | page->mapping = NULL; |
384 | + | |
385 | + if (!anon) /* This page was removed from radix-tree. */ | |
386 | + mem_cgroup_uncharge_cache_page(page); | |
382 | 387 | |
383 | 388 | /* |
384 | 389 | * If any waiters have accumulated on the new page then |