Skip to contentSkip to conversation

memcg: remove charge variable in unmap_and_move

PATCH In review Minchan Kim 3 participants 4 messages Jan 11, 2011

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

PATCH 1/1 memcg: remove charge variable in unmap_and_move

memcg charge/uncharge could be handled by mem_cgroup_[prepare/end] migration itself so charge local variable in unmap_and_move lost the role since we introduced 01b1ae63c2.

In addition, the variable name is not good like below.

int unmap_and_move()

{
	charge = mem_cgroup_prepare_migration(xxx);
	..
		BUG_ON(charge); <-- BUG if it is charged?
		..
		uncharge:
		if (!charge)    <-- why do we have to uncharge !charge?
			mem_group_end_migration(xxx);
	..
}

So let's remove unnecessary and confusing variable.

---
 mm/migrate.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
mm/migrate.c +4 -8
index b8a32da..e393841 100644
@@ -623,7 +623,6 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
 	struct page *newpage = get_new_page(page, private, &result);
 	int remap_swapcache = 1;
 	int rcu_locked = 0;
-	int charge = 0;
 	struct mem_cgroup *mem = NULL;
 	struct anon_vma *anon_vma = NULL;
 
@@ -662,12 +661,10 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
 	}
 
 	/* charge against new page */
-	charge = mem_cgroup_prepare_migration(page, newpage, &mem);
-	if (charge == -ENOMEM) {
-		rc = -ENOMEM;
+	rc = mem_cgroup_prepare_migration(page, newpage, &mem);
+	if (rc == -ENOMEM)
 		goto unlock;
-	}
-	BUG_ON(charge);
+	BUG_ON(rc);
 
 	if (PageWriteback(page)) {
 		if (!force || !sync)
@@ -760,8 +757,7 @@ rcu_unlock:
 	if (rcu_locked)
 		rcu_read_unlock();
 uncharge:
-	if (!charge)
-		mem_cgroup_end_migration(mem, page, newpage, rc == 0);
+	mem_cgroup_end_migration(mem, page, newpage, rc == 0);
 unlock:
 	unlock_page(page);
 
Signature · 8 lines
1.7.0.4

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 18 lines · On Tue, 11 Jan 2011 15:00:50 +0900 Minchan Kim <[email protected]> wrote:

memcg charge/uncharge could be handled by mem_cgroup_[prepare/end] migration itself so charge local variable in unmap_and_move lost the role since we introduced 01b1ae63c2.

In addition, the variable name is not good like below.

int unmap_and_move()

{
	charge = mem_cgroup_prepare_migration(xxx);
	..
		BUG_ON(charge); <-- BUG if it is charged?
		..
		uncharge:
		if (!charge)    <-- why do we have to uncharge !charge?
			mem_group_end_migration(xxx);
	..
}
Quoted 6 lines

So let's remove unnecessary and confusing variable.

Ack.

Thanks,
-Kame

#2 lore raw
In reply to Minchan Kim

Hi,

Quoted 57 lines · On Tue, 11 Jan 2011 15:00:50 +0900 Minchan Kim <[email protected]> wrote:

memcg charge/uncharge could be handled by mem_cgroup_[prepare/end] migration itself so charge local variable in unmap_and_move lost the role since we introduced 01b1ae63c2.

In addition, the variable name is not good like below.

int unmap_and_move()

{
	charge = mem_cgroup_prepare_migration(xxx);
	..
		BUG_ON(charge); <-- BUG if it is charged?
		..
		uncharge:
		if (!charge)    <-- why do we have to uncharge !charge?
			mem_group_end_migration(xxx);
	..
}

So let's remove unnecessary and confusing variable.

---
 mm/migrate.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
mm/migrate.c +3 -6
index b8a32da..e393841 100644
@@ -623,7 +623,6 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
 	struct page *newpage = get_new_page(page, private, &result);
 	int remap_swapcache = 1;
 	int rcu_locked = 0;
-	int charge = 0;
 	struct mem_cgroup *mem = NULL;
 	struct anon_vma *anon_vma = NULL;
 
@@ -662,12 +661,10 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
 	}
 
 	/* charge against new page */
-	charge = mem_cgroup_prepare_migration(page, newpage, &mem);
-	if (charge == -ENOMEM) {
-		rc = -ENOMEM;
+	rc = mem_cgroup_prepare_migration(page, newpage, &mem);
+	if (rc == -ENOMEM)
 		goto unlock;
-	}
-	BUG_ON(charge);
+	BUG_ON(rc);
 
 	if (PageWriteback(page)) {
 		if (!force || !sync)

mm/migrate.c rcu_unlock: · line 763

Quoted 9 lines
mm/migrate.c +1 -2
@@ -760,8 +757,7 @@ rcu_unlock:
 	if (rcu_locked)
 		rcu_read_unlock();
 uncharge:
-	if (!charge)
-		mem_cgroup_end_migration(mem, page, newpage, rc == 0);
+	mem_cgroup_end_migration(mem, page, newpage, rc == 0);
 unlock:
 	unlock_page(page);
 

I proposed pseud code like above, but it's wrong unfortunately. If mem_cgroup_prepare_migration() has succeeded, rc is overwritten to 0. So even if we failed before calling move_to_new_page(), rc is 0 and mem_cgroup_end_migration() mis-understand this migration has succeeded.

And, it seems to be just a bit off-topic, the place of the comment "prepare cgroup just returns 0 or -ENOMEM" isn't good, seeing the commit e8589cc1, which introduced the comment first.

So, we should do like:

	/* charge against new page */
	if (mem_cgroup_end_migration(page, &newpage, &mem)) {
		/* prepare_migration just returns 0 or -ENOMEM */
		rc = -ENOMEM;
		goto unlock;
	}

	if (PageWriteback(page)) {
		...

uncharge:

	mem_cgroup_end_migration(mem, page, newpage, rc == 0);

or, overwrite rc to -EAGAIN again.
I don't stick to checking "BUG_ON(charge)" personally.

Thanks,
Daisuke Nishimura.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 59 lines · Daisuke Nishimura

Hi,

Quoted 54 lines · On Tue, 11 Jan 2011 15:00:50 +0900 Minchan Kim <[email protected]> wrote:

memcg charge/uncharge could be handled by mem_cgroup_[prepare/end] migration itself so charge local variable in unmap_and_move lost the role since we introduced 01b1ae63c2.

In addition, the variable name is not good like below.

int unmap_and_move()

{
	charge = mem_cgroup_prepare_migration(xxx);
	..
		BUG_ON(charge); <-- BUG if it is charged?
		..
		uncharge:
		if (!charge)    <-- why do we have to uncharge !charge?
			mem_group_end_migration(xxx);
	..
}

So let's remove unnecessary and confusing variable.

---
 mm/migrate.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
mm/migrate.c +3 -6
index b8a32da..e393841 100644
@@ -623,7 +623,6 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
 	struct page *newpage = get_new_page(page, private, &result);
 	int remap_swapcache = 1;
 	int rcu_locked = 0;
-	int charge = 0;
 	struct mem_cgroup *mem = NULL;
 	struct anon_vma *anon_vma = NULL;
 
@@ -662,12 +661,10 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
 	}
 
 	/* charge against new page */
-	charge = mem_cgroup_prepare_migration(page, newpage, &mem);
-	if (charge == -ENOMEM) {
-		rc = -ENOMEM;
+	rc = mem_cgroup_prepare_migration(page, newpage, &mem);
+	if (rc == -ENOMEM)
 		goto unlock;
-	}
-	BUG_ON(charge);
+	BUG_ON(rc);
 
Quoted 16 lines

mm/migrate.c rcu_unlock: · line 763

Quoted 12 lines
mm/migrate.c +1 -2
 	if (PageWriteback(page)) {
 		if (!force || !sync)
@@ -760,8 +757,7 @@ rcu_unlock:
 	if (rcu_locked)
 		rcu_read_unlock();
 uncharge:
-	if (!charge)
-		mem_cgroup_end_migration(mem, page, newpage, rc == 0);
+	mem_cgroup_end_migration(mem, page, newpage, rc == 0);
 unlock:
 	unlock_page(page);
 

I proposed pseud code like above, but it's wrong unfortunately. If mem_cgroup_prepare_migration() has succeeded, rc is overwritten to 0. So even if we failed before calling move_to_new_page(), rc is 0 and mem_cgroup_end_migration() mis-understand this migration has succeeded.

Right. I missed it.
Thanks for the review.

Quoted 5 lines

And, it seems to be just a bit off-topic, the place of the comment "prepare cgroup just returns 0 or -ENOMEM" isn't good, seeing the commit e8589cc1, which introduced the comment first.

Quoted 8 lines

So, we should do like:

	/* charge against new page */
	if (mem_cgroup_end_migration(page, &newpage, &mem)) {
		/* prepare_migration just returns 0 or -ENOMEM */
		rc = -ENOMEM;
		goto unlock;
	}

Hmm.. I don't think so. The comment should be in there which is initialized the variable but comment is confusing. So instead of moving, I will fix the comment.

Quoted 9 lines
	if (PageWriteback(page)) {
		...

uncharge:

	mem_cgroup_end_migration(mem, page, newpage, rc == 0);

or, overwrite rc to -EAGAIN again.
I don't stick to checking "BUG_ON(charge)" personally.

I agree. BUG_ON is meaningless.
I will resend the patch.

Thanks. :)

Quoted 4 lines

Thanks,
Daisuke Nishimura.

Signature · 9 lines
Kind regards,
Minchan Kim

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>