From: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
Hugh Dickins <hugh@veritas.com>,
nishimura@mxp.nes.nec.co.jp
Subject: Re: [BUGFIX][PATCH mmotm] memcg fix swap accounting leak
Date: Fri, 12 Dec 2008 18:43:41 +0900 [thread overview]
Message-ID: <20081212184341.b62903a7.nishimura@mxp.nes.nec.co.jp> (raw)
In-Reply-To: <20081212172930.282caa38.kamezawa.hiroyu@jp.fujitsu.com>
(add CC: Hugh Dickins <hugh@veritas.com>)
On Fri, 12 Dec 2008 17:29:30 +0900, KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:
>
> From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>
> Fix swap-page-fault charge leak of memcg.
>
> Now, memcg has hooks to swap-out operation and checks SwapCache is really
> unused or not. That check depends on contents of struct page.
> I.e. If PageAnon(page) && page_mapped(page), the page is recoginized as
> still-in-use.
>
> Now, reuse_swap_page() calles delete_from_swap_cache() before establishment
> of any rmap. Then, in followinig sequence
>
> (Page fault with WRITE)
> Assume the page is SwapCache "on memory (still charged)"
> try_charge() (charge += PAGESIZE)
> commit_charge()
> => (Check page_cgroup and found PCG_USED bit, charge-=PAGE_SIZE
> because it seems already charged.)
> reuse_swap_page()
> -> delete_from_swapcache()
> -> mem_cgroup_uncharge_swapcache() (charge -= PAGESIZE)
> ......
>
> too much uncharge.....
>
> To avoid this, move commit_charge() after page_mapcount() goes up to 1.
> By this,
> Assume the page is SwapCache "on memory"
> try_charge() (charge += PAGESIZE)
> reuse_swap_page() (may charge -= PAGESIZE if PCG_USED is set)
> commit_charge() (Ony if page_cgroup is marked as PCG_USED,
> charge -= PAGESIZE)
> Accounting will be correct.
>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
I've confirmed that the problem you reported offline is fixed, but...
> ---
> mm/memory.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> Index: mmotm-2.6.28-Dec11/mm/memory.c
> ===================================================================
> --- mmotm-2.6.28-Dec11.orig/mm/memory.c
> +++ mmotm-2.6.28-Dec11/mm/memory.c
> @@ -2433,17 +2433,17 @@ static int do_swap_page(struct mm_struct
> * which may delete_from_swap_cache().
> */
>
The comment here says:
/*
* The page isn't present yet, go ahead with the fault.
*
* Be careful about the sequence of operations here.
* To get its accounting right, reuse_swap_page() must be called
* while the page is counted on swap but not yet in mapcount i.e.
* before page_add_anon_rmap() and swap_free(); try_to_free_swap()
* must be called after the swap_free(), or it will never succeed.
* And mem_cgroup_commit_charge_swapin(), which uses the swp_entry
* in page->private, must be called before reuse_swap_page(),
* which may delete_from_swap_cache().
*/
Hmm.. should we save page->private before calling reuse_swap_page and pass it
to mem_cgroup_commit_charge_swapin(I think it cannot be changed because the page
is locked)?
Thanks,
Daisuke Nishimura.
> - mem_cgroup_commit_charge_swapin(page, ptr);
> inc_mm_counter(mm, anon_rss);
> pte = mk_pte(page, vma->vm_page_prot);
> if (write_access && reuse_swap_page(page)) {
> pte = maybe_mkwrite(pte_mkdirty(pte), vma);
> write_access = 0;
> }
> -
> flush_icache_page(vma, page);
> set_pte_at(mm, address, page_table, pte);
> page_add_anon_rmap(page, vma, address);
> + /* It's better to call commit-charge after rmap is established */
> + mem_cgroup_commit_charge_swapin(page, ptr);
>
> swap_free(entry);
> if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
>
next prev parent reply other threads:[~2008-12-12 9:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-12 8:29 KAMEZAWA Hiroyuki
2008-12-12 9:43 ` Daisuke Nishimura [this message]
2008-12-12 11:16 ` KAMEZAWA Hiroyuki
2008-12-13 7:03 ` [BUGFIX][PATCH mmotm] memcg fix swap accounting leak (v2) KAMEZAWA Hiroyuki
2008-12-13 9:49 ` Hugh Dickins
2008-12-13 10:27 ` KAMEZAWA Hiroyuki
2008-12-15 7:07 ` [BUGFIX][PATCH mmotm] memcg fix swap accounting leak (v3) KAMEZAWA Hiroyuki
2008-12-15 8:37 ` Balbir Singh
2008-12-15 8:40 ` KAMEZAWA Hiroyuki
2008-12-15 10:34 ` Hugh Dickins
2008-12-16 4:02 ` [PATCH mmotm] memcg: fix for documentation (Re: [BUGFIX][PATCH mmotm] memcg fix swap accounting leak (v3)) Daisuke Nishimura
2008-12-16 4:53 ` KAMEZAWA Hiroyuki
2008-12-13 10:38 ` [BUGFIX][PATCH mmotm] memcg fix swap accounting leak (v2) KAMEZAWA Hiroyuki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081212184341.b62903a7.nishimura@mxp.nes.nec.co.jp \
--to=nishimura@mxp.nes.nec.co.jp \
--cc=akpm@linux-foundation.org \
--cc=balbir@linux.vnet.ibm.com \
--cc=hugh@veritas.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox