Re: [RFC][BUGFIX][PATCH 2/2] memcg: fix file mapped underflow at migration (v3)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: KAMEZAWA Hiroyuki
Date: Sunday, April 18, 2010 - 9:18 pm

On Mon, 19 Apr 2010 12:42:25 +0900
Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> wrote:


v2 can't handle migration-failure case of freed swapcache and the used page
was swapped-out case. I think.

All "page" in following is ANON.


     mem_cgroup_prepare_migration()
	     charge against new page.
     
     try_to_unmap()
        -> mapcount goes down to 0.
             -> an old page is unchaged
     
     move_to_new_page()
        -> may fail. (in some case.)   ----(*1)

     remap the old page to pte.

     mem_cgroup_end_migration()
		(at success *1)
		check charge for newpage is valid or not (*2)

		(at fail *1)
		uncharge new page.
		What we should do for an old page. ---(*3)

At (*2). (*3), there are several cases.

(*2) migration was succeeded.
    1. The new page was successfully remapped.
	-> Nothing to do.
    2. The new page was remapped but finally unmapped before (*3)
	-> page_remove_rmap() will catch the event.
    3. The new page was not remapped.
	-> page_remove_rmap() can't catch the event. end_migraion() has to
	uncharge it.

(*3) migration was failed.
    1. The old page was successfully remapped.
	-> We have to recharge against the old page. (But it may hit OOM.)
    2. The old page wasn't remapped.
        -> mapcount is 0. No new charge will happen.
    3. The old page wasn't remapped but SwapCache.
        -> mapcount is 0. We have to recharge against the old page (But it may hit OOM)

Maybe other seqence I couldn't write will exist......IMHO, "we have to recharge it because
it's uncharged.." is bad idea. It seems hard to maintainace..


When we use MIGRATION flag.
After migaration.

    1. Agaisnt new page, we remove MIGRATION flag and try to uncharge() it again.

    2. Agaisnt old page, we remove MIGRATION flag and try to uncharge it again.

NOTE:  I noticed my v3 patch is buggy when the page-is-swapped-out case. It seems
       mem_cgroup_uncharge_swapcache() has to wait for migration ends or some
       other case handling. (Anyway, this race exists only after unlock_page(newpage).
       So, wait for MIGRATION ends in spin will not be very bad.)


To me, things are much simpler than now, we have to know what kind of magics behind us...

Maybe I can think of other tricks for handling them...but using a FLAG and prevent uncharge
is the simplest, I think.


Thanks,
-Kame




--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC][BUGFIX][PATCH] memcg: fix underflow of mapped_file stat, Daisuke Nishimura, (Mon Apr 12, 9:42 pm)
Re: [RFC][BUGFIX][PATCH] memcg: fix underflow of mapped_fi ..., KAMEZAWA Hiroyuki, (Mon Apr 12, 11:14 pm)
Re: [RFC][BUGFIX][PATCH] memcg: fix underflow of mapped_fi ..., Daisuke Nishimura, (Tue Apr 13, 5:54 pm)
Re: [RFC][BUGFIX][PATCH] memcg: fix underflow of mapped_fi ..., KAMEZAWA Hiroyuki, (Tue Apr 13, 6:03 pm)
Re: [RFC][BUGFIX][PATCH] memcg: fix underflow of mapped_fi ..., KAMEZAWA Hiroyuki, (Tue Apr 13, 6:40 pm)
Re: [RFC][BUGFIX][PATCH] memcg: fix underflow of mapped_fi ..., KAMEZAWA Hiroyuki, (Tue Apr 13, 6:56 pm)
Re: [RFC][BUGFIX][PATCH] memcg: fix underflow of mapped_fi ..., KAMEZAWA Hiroyuki, (Tue Apr 13, 8:06 pm)
Re: [RFC][BUGFIX][PATCH] memcg: fix underflow of mapped_fi ..., Daisuke Nishimura, (Tue Apr 13, 10:31 pm)
Re: [RFC][BUGFIX][PATCH] memcg: fix underflow of mapped_fi ..., KAMEZAWA Hiroyuki, (Tue Apr 13, 10:40 pm)
Re: [RFC][BUGFIX][PATCH] memcg: fix underflow of mapped_fi ..., Daisuke Nishimura, (Wed Apr 14, 7:22 pm)
[RFC][BUGFIX][PATCH 1/2] memcg: fix charge bypass route of ..., KAMEZAWA Hiroyuki, (Wed Apr 14, 8:05 pm)
[RFC][BUGFIX][PATCH 2/2] memcg: fix file mapped underflow ..., KAMEZAWA Hiroyuki, (Wed Apr 14, 8:06 pm)
Re: [RFC][BUGFIX][PATCH 1/2] memcg: fix charge bypass rout ..., Daisuke Nishimura, (Wed Apr 14, 11:43 pm)
Re: [RFC][BUGFIX][PATCH 1/2] memcg: fix charge bypass rout ..., KAMEZAWA Hiroyuki, (Wed Apr 14, 11:56 pm)
[RFC][BUGFIX][PATCH 2/2] memcg: fix file mapped underflow ..., KAMEZAWA Hiroyuki, (Fri Apr 16, 3:31 am)
Interleave policy on 2M pages (was Re: [RFC][BUGFIX][PATCH ..., Christoph Lameter, (Fri Apr 16, 9:13 am)
Re: Interleave policy on 2M pages (was Re: [RFC][BUGFIX][P ..., Andrea Arcangeli, (Fri Apr 16, 10:51 am)
Re: [RFC][BUGFIX][PATCH 2/2] memcg: fix file mapped underf ..., Daisuke Nishimura, (Sun Apr 18, 8:42 pm)
Re: [RFC][BUGFIX][PATCH 2/2] memcg: fix file mapped underf ..., KAMEZAWA Hiroyuki, (Sun Apr 18, 9:18 pm)
Re: [RFC][BUGFIX][PATCH 2/2] memcg: fix file mapped underf ..., Daisuke Nishimura, (Mon Apr 19, 1:07 am)
Re: [RFC][BUGFIX][PATCH 2/2] memcg: fix file mapped underf ..., KAMEZAWA Hiroyuki, (Mon Apr 19, 1:26 am)
Re: [RFC][BUGFIX][PATCH 2/2] memcg: fix file mapped underf ..., Daisuke Nishimura, (Mon Apr 19, 9:20 pm)
Re: [RFC][BUGFIX][PATCH 2/2] memcg: fix file mapped underf ..., KAMEZAWA Hiroyuki, (Mon Apr 19, 9:26 pm)
Re: [RFC][BUGFIX][PATCH 2/2] memcg: fix file mapped underf ..., KAMEZAWA Hiroyuki, (Tue Apr 20, 2:19 am)
Re: [RFC][BUGFIX][PATCH 2/2] memcg: fix file mapped underf ..., Daisuke Nishimura, (Fri Apr 23, 1:08 am)
Re: [RFC][BUGFIX][PATCH 2/2] memcg: fix file mapped underf ..., KAMEZAWA Hiroyuki, (Fri Apr 23, 1:23 am)