提交 b7abea96 编写于 作者: K KAMEZAWA Hiroyuki 提交者: Linus Torvalds

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: NKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Reviewed-by: NDaisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 073e587e
...@@ -116,12 +116,12 @@ void __remove_from_page_cache(struct page *page) ...@@ -116,12 +116,12 @@ void __remove_from_page_cache(struct page *page)
{ {
struct address_space *mapping = page->mapping; struct address_space *mapping = page->mapping;
mem_cgroup_uncharge_cache_page(page);
radix_tree_delete(&mapping->page_tree, page->index); radix_tree_delete(&mapping->page_tree, page->index);
page->mapping = NULL; page->mapping = NULL;
mapping->nrpages--; mapping->nrpages--;
__dec_zone_page_state(page, NR_FILE_PAGES); __dec_zone_page_state(page, NR_FILE_PAGES);
BUG_ON(page_mapped(page)); BUG_ON(page_mapped(page));
mem_cgroup_uncharge_cache_page(page);
/* /*
* Some filesystems seem to re-dirty the page even after * Some filesystems seem to re-dirty the page even after
......
...@@ -734,6 +734,7 @@ void mem_cgroup_uncharge_page(struct page *page) ...@@ -734,6 +734,7 @@ void mem_cgroup_uncharge_page(struct page *page)
void mem_cgroup_uncharge_cache_page(struct page *page) void mem_cgroup_uncharge_cache_page(struct page *page)
{ {
VM_BUG_ON(page_mapped(page)); VM_BUG_ON(page_mapped(page));
VM_BUG_ON(page->mapping);
__mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_CACHE); __mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_CACHE);
} }
......
...@@ -330,8 +330,6 @@ static int migrate_page_move_mapping(struct address_space *mapping, ...@@ -330,8 +330,6 @@ static int migrate_page_move_mapping(struct address_space *mapping,
__inc_zone_page_state(newpage, NR_FILE_PAGES); __inc_zone_page_state(newpage, NR_FILE_PAGES);
spin_unlock_irq(&mapping->tree_lock); spin_unlock_irq(&mapping->tree_lock);
if (!PageSwapCache(newpage))
mem_cgroup_uncharge_cache_page(page);
return 0; return 0;
} }
...@@ -341,6 +339,8 @@ static int migrate_page_move_mapping(struct address_space *mapping, ...@@ -341,6 +339,8 @@ static int migrate_page_move_mapping(struct address_space *mapping,
*/ */
static void migrate_page_copy(struct page *newpage, struct page *page) static void migrate_page_copy(struct page *newpage, struct page *page)
{ {
int anon;
copy_highpage(newpage, page); copy_highpage(newpage, page);
if (PageError(page)) if (PageError(page))
...@@ -378,8 +378,13 @@ static void migrate_page_copy(struct page *newpage, struct page *page) ...@@ -378,8 +378,13 @@ static void migrate_page_copy(struct page *newpage, struct page *page)
#endif #endif
ClearPagePrivate(page); ClearPagePrivate(page);
set_page_private(page, 0); set_page_private(page, 0);
/* page->mapping contains a flag for PageAnon() */
anon = PageAnon(page);
page->mapping = NULL; page->mapping = NULL;
if (!anon) /* This page was removed from radix-tree. */
mem_cgroup_uncharge_cache_page(page);
/* /*
* If any waiters have accumulated on the new page then * If any waiters have accumulated on the new page then
* wake them up. * wake them up.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册