Skip to contentSkip to conversation

memcg: fix try_get_mem_cgroup_from_swapcache()

PATCH In review Daisuke Nishimura 3 participants 7 messages Apr 27, 2009 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH 1/1 memcg: fix try_get_mem_cgroup_from_swapcache()

In reply to a message not in the archive

From: Daisuke Nishimura <[email protected]>

memcg: fix try_get_mem_cgroup_from_swapcache()

This is a bugfix for commit 3c776e64660028236313f0e54f3a9945764422df(included 2.6.30-rc1). Used bit of swapcache is solid under page lock, but considering move_account, pc->mem_cgroup is not.

We need lock_page_cgroup() anyway.

---
 mm/memcontrol.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
mm/memcontrol.c +2 -3
index ccc69b4..84f856c 100644
@@ -1024,9 +1024,7 @@ static struct mem_cgroup *try_get_mem_cgroup_from_swapcache(struct page *page)
 		return NULL;
 
 	pc = lookup_page_cgroup(page);
-	/*
-	 * Used bit of swapcache is solid under page lock.
-	 */
+	lock_page_cgroup(pc);
 	if (PageCgroupUsed(pc)) {
 		mem = pc->mem_cgroup;
 		if (mem && !css_tryget(&mem->css))
@@ -1040,6 +1038,7 @@ static struct mem_cgroup *try_get_mem_cgroup_from_swapcache(struct page *page)
 			mem = NULL;
 		rcu_read_unlock();
 	}
+	unlock_page_cgroup(pc);
 	return mem;
 }
 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Acked-by on v1 1/1
#2 lore raw
Quoted 11 lines · On Mon, 27 Apr 2009 09:51:00 +0900 Daisuke Nishimura…

From: Daisuke Nishimura <[email protected]>

memcg: fix try_get_mem_cgroup_from_swapcache()

This is a bugfix for commit 3c776e64660028236313f0e54f3a9945764422df(included 2.6.30-rc1). Used bit of swapcache is solid under page lock, but considering move_account, pc->mem_cgroup is not.

We need lock_page_cgroup() anyway.

you are right.

Quoted 21 lines
---
 mm/memcontrol.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
mm/memcontrol.c +1 -3
index ccc69b4..84f856c 100644
@@ -1024,9 +1024,7 @@ static struct mem_cgroup *try_get_mem_cgroup_from_swapcache(struct page *page)
 		return NULL;
 
 	pc = lookup_page_cgroup(page);
-	/*
-	 * Used bit of swapcache is solid under page lock.
-	 */
+	lock_page_cgroup(pc);
 	if (PageCgroupUsed(pc)) {
 		mem = pc->mem_cgroup;
 		if (mem && !css_tryget(&mem->css))

mm/memcontrol.c static struct mem_cgroup *try_get_mem_cgroup_from_swapcache(struct page *page) · line 1044

Quoted 7 lines
mm/memcontrol.c +1 -0
@@ -1040,6 +1038,7 @@ static struct mem_cgroup *try_get_mem_cgroup_from_swapcache(struct page *page)
 			mem = NULL;
 		rcu_read_unlock();
 	}
+	unlock_page_cgroup(pc);
 	return mem;
 }
 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
In reply to Daisuke Nishimura
Quoted 11 lines · * [email protected] <[email protected]> [2009-04-27…

From: Daisuke Nishimura <[email protected]>

memcg: fix try_get_mem_cgroup_from_swapcache()

This is a bugfix for commit 3c776e64660028236313f0e54f3a9945764422df(included 2.6.30-rc1). Used bit of swapcache is solid under page lock, but considering move_account, pc->mem_cgroup is not.

We need lock_page_cgroup() anyway.

I think we need to start documenting the locks the page_cgroup lock nests under.

If memcg_tasklist were a spinlock instead of mutex, could we use that instead of page_cgroup lock, since we care only about task migration?

Signature · 7 lines
	Balbir

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw
Quoted 10 lines · On Mon, 27 Apr 2009 12:23:58 +0530 Balbir Singh <[email protected]>…
Quoted 8 lines · * [email protected] <[email protected]> [2009-04-27…

From: Daisuke Nishimura <[email protected]>

memcg: fix try_get_mem_cgroup_from_swapcache()

This is a bugfix for commit 3c776e64660028236313f0e54f3a9945764422df(included 2.6.30-rc1). Used bit of swapcache is solid under page lock, but considering move_account, pc->mem_cgroup is not.

Quoted 7 lines
Quoted 3 lines

We need lock_page_cgroup() anyway.

I think we need to start documenting the locks the page_cgroup lock nests under.

Addin some comments on source code may be necessary.

Quoted 3 lines

If memcg_tasklist were a spinlock instead of mutex, could we use that instead of page_cgroup lock, since we care only about task migration?

Hmm ? Another problem ? I can't catch what you ask. move_account() is a function called by force_empty()->"move account to parent"

Thanks,
-Kame

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
Quoted 20 lines · KAMEZAWA Hiroyuki
Quoted 10 lines · On Mon, 27 Apr 2009 12:23:58 +0530 Balbir Singh <[email protected]>…
Quoted 8 lines · * [email protected] <[email protected]> [2009-04-27…

From: Daisuke Nishimura <[email protected]>

memcg: fix try_get_mem_cgroup_from_swapcache()

This is a bugfix for commit 3c776e64660028236313f0e54f3a9945764422df(included 2.6.30-rc1). Used bit of swapcache is solid under page lock, but considering move_account, pc->mem_cgroup is not.

Quoted 7 lines
Quoted 3 lines

We need lock_page_cgroup() anyway.

I think we need to start documenting the locks the page_cgroup lock nests under.

Quoted 8 lines

Addin some comments on source code may be necessary.

Quoted 3 lines

If memcg_tasklist were a spinlock instead of mutex, could we use that instead of page_cgroup lock, since we care only about task migration?

Hmm ? Another problem ? I can't catch what you ask. move_account() is a function called by force_empty()->"move account to parent"

IIUC, pc->mem_cgroup might change due to task migration and that is why we've added the page cgroup lock. If the race is between task migration and force_empty(), we can use the memcg_tasklist by making it a spinlock.

Signature · 7 lines
	Balbir

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw
Quoted 28 lines · On Mon, 27 Apr 2009 12:33:42 +0530 Balbir Singh <[email protected]>…
Quoted 26 lines · KAMEZAWA Hiroyuki
Quoted 10 lines · On Mon, 27 Apr 2009 12:23:58 +0530 Balbir Singh <[email protected]>…
Quoted 8 lines · * [email protected] <[email protected]> [2009-04-27…

From: Daisuke Nishimura <[email protected]>

memcg: fix try_get_mem_cgroup_from_swapcache()

This is a bugfix for commit 3c776e64660028236313f0e54f3a9945764422df(included 2.6.30-rc1). Used bit of swapcache is solid under page lock, but considering move_account, pc->mem_cgroup is not.

Quoted 7 lines
Quoted 3 lines

We need lock_page_cgroup() anyway.

I think we need to start documenting the locks the page_cgroup lock nests under.

Addin some comments on source code may be necessary.

Quoted 3 lines

If memcg_tasklist were a spinlock instead of mutex, could we use that instead of page_cgroup lock, since we care only about task migration?

Quoted 5 lines
Quoted 2 lines

Hmm ? Another problem ? I can't catch what you ask. move_account() is a function called by force_empty()->"move account to parent"

IIUC, pc->mem_cgroup might change due to task migration and that is why we've added the page cgroup lock.

"task" migration ? I think it's "page" migration.

"page cgroup lock" is necessary because we have to modify 2 params (pc->flags and pc->mem_cgroup) at once.

Quoted 4 lines

If the race is between task
migration and force_empty(), we can use the memcg_tasklist by making it a spinlock.

The race is between force_empty() and any other swap accounitng ops. This patch is good enough from my point of view.

Thanks,
-kame

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Acked-by
#7 lore raw
Quoted 31 lines · KAMEZAWA Hiroyuki
Quoted 28 lines · On Mon, 27 Apr 2009 12:33:42 +0530 Balbir Singh <[email protected]>…
Quoted 26 lines · KAMEZAWA Hiroyuki
Quoted 10 lines · On Mon, 27 Apr 2009 12:23:58 +0530 Balbir Singh <[email protected]>…
Quoted 8 lines · * [email protected] <[email protected]> [2009-04-27…

From: Daisuke Nishimura <[email protected]>

memcg: fix try_get_mem_cgroup_from_swapcache()

This is a bugfix for commit 3c776e64660028236313f0e54f3a9945764422df(included 2.6.30-rc1). Used bit of swapcache is solid under page lock, but considering move_account, pc->mem_cgroup is not.

Quoted 7 lines
Quoted 3 lines

We need lock_page_cgroup() anyway.

I think we need to start documenting the locks the page_cgroup lock nests under.

Addin some comments on source code may be necessary.

Quoted 3 lines

If memcg_tasklist were a spinlock instead of mutex, could we use that instead of page_cgroup lock, since we care only about task migration?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Hmm ? Another problem ? I can't catch what you ask. move_account() is a function called by force_empty()->"move account to parent"

IIUC, pc->mem_cgroup might change due to task migration and that is why we've added the page cgroup lock.

"task" migration ? I think it's "page" migration.

OK

Quoted 3 lines

"page cgroup lock" is necessary because we have to modify 2 params (pc->flags and pc->mem_cgroup) at once.

Yes, definitely!

Quoted 6 lines
Quoted 4 lines

If the race is between task
migration and force_empty(), we can use the memcg_tasklist by making it a spinlock.

The race is between force_empty() and any other swap accounitng ops. This patch is good enough from my point of view.

Fair enough

Signature · 7 lines
	Balbir

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>