From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: balbir@linux.vnet.ibm.com
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
"containers@lists.osdl.org" <containers@lists.osdl.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH][for -mm] Fix and Enhancements for memory cgroup [3/6] add helper function for page_cgroup
Date: Tue, 9 Oct 2007 20:26:42 +0900 [thread overview]
Message-ID: <20071009202642.9f174445.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <470B617C.1060504@linux.vnet.ibm.com>
On Tue, 09 Oct 2007 16:39:48 +0530
Balbir Singh <balbir@linux.vnet.ibm.com> wrote:
> > +static inline int
> > +page_cgroup_assign_new_page_cgroup(struct page *page, struct page_cgroup *pc)
> > +{
> > + int ret = 0;
> > +
> > + lock_page_cgroup(page);
> > + if (!page_get_page_cgroup(page))
> > + page_assign_page_cgroup(page, pc);
> > + else
> > + ret = 1;
> > + unlock_page_cgroup(page);
> > + return ret;
> > +}
> > +
>
> Some comment on when the assignment can fail, for example if page
> already has a page_cgroup associated with it, would be nice.
>
Sure ,will add.
> > +
> > +static inline struct page_cgroup *
> > +clear_page_cgroup(struct page *page, struct page_cgroup *pc)
> > +{
> > + struct page_cgroup *ret;
> > + /* lock and clear */
> > + lock_page_cgroup(page);
> > + ret = page_get_page_cgroup(page);
> > + if (likely(ret == pc))
> > + page_assign_page_cgroup(page, NULL);
> > + unlock_page_cgroup(page);
> > + return ret;
> > +}
> > +
>
> We could add a comment stating that clearing would fail if the page's
> cgroup is not pc
>
will add, too.
> > +
> > static void __mem_cgroup_move_lists(struct page_cgroup *pc, bool active)
> > {
> > if (active)
> > @@ -260,7 +289,7 @@ int mem_cgroup_charge(struct page *page,
> > gfp_t gfp_mask)
> > {
> > struct mem_cgroup *mem;
> > - struct page_cgroup *pc, *race_pc;
> > + struct page_cgroup *pc;
> > unsigned long flags;
> > unsigned long nr_retries = MEM_CGROUP_RECLAIM_RETRIES;
> >
> > @@ -353,24 +382,16 @@ noreclaim:
> > goto free_pc;
> > }
> >
> > - lock_page_cgroup(page);
> > - /*
> > - * Check if somebody else beat us to allocating the page_cgroup
> > - */
> > - race_pc = page_get_page_cgroup(page);
> > - if (race_pc) {
> > - kfree(pc);
> > - pc = race_pc;
> > - atomic_inc(&pc->ref_cnt);
> > - res_counter_uncharge(&mem->res, PAGE_SIZE);
> > - css_put(&mem->css);
> > - goto done;
> > - }
> > -
> > atomic_set(&pc->ref_cnt, 1);
> > pc->mem_cgroup = mem;
> > pc->page = page;
> > - page_assign_page_cgroup(page, pc);
> > + if (page_cgroup_assign_new_page_cgroup(page, pc)) {
> > + /* race ... undo and retry */
> > + res_counter_uncharge(&mem->res, PAGE_SIZE);
> > + css_put(&mem->css);
> > + kfree(pc);
> > + goto retry;
>
> This part is a bit confusing, why do we want to retry. If someone
> else charged the page already, we just continue, we let the other
> task take the charge and add this page to it's cgroup
>
Okay. will add precise text.
> > + }
> >
> > spin_lock_irqsave(&mem->lru_lock, flags);
> > list_add(&pc->lru, &mem->active_list);
> > @@ -421,17 +442,18 @@ void mem_cgroup_uncharge(struct page_cgr
> >
> > if (atomic_dec_and_test(&pc->ref_cnt)) {
> > page = pc->page;
> > - lock_page_cgroup(page);
> > - mem = pc->mem_cgroup;
> > - css_put(&mem->css);
> > - page_assign_page_cgroup(page, NULL);
> > - unlock_page_cgroup(page);
> > - res_counter_uncharge(&mem->res, PAGE_SIZE);
> > -
> > - spin_lock_irqsave(&mem->lru_lock, flags);
> > - list_del_init(&pc->lru);
> > - spin_unlock_irqrestore(&mem->lru_lock, flags);
> > - kfree(pc);
> > + /*
> > + * Obetaion page->cgroup and clear it under lock.
> ^^^^^^^^
> Not sure if I've come across this word before
Sorry (>_<;
Get page->cgroup and clear it under lock.
>
> > + */
> > + if (clear_page_cgroup(page, pc) == pc) {
>
> OK.. so we've come so far and seen that pc has changed underneath us,
> what do we do with this pc?
>
Hmm... How about this ?
==
if (clear_page_cgroup(page, pc) == pc) {
/* do usual work */
} else {
BUG();
}
== or BUG_ON(clear_page_cgroup(page, pc) != pc)
I have no clear idea when this race will occur.
But this "lock and clear" behavior is sane, I think.
Thanks,
-kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2007-10-09 11:26 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-09 9:46 [PATCH][for -mm] Fix and Enhancements for memory cgroup [0/6] intro KAMEZAWA Hiroyuki
2007-10-09 9:49 ` [PATCH][for -mm] Fix and Enhancements for memory cgroup [1/6] fix refcnt race in charge/uncharge KAMEZAWA Hiroyuki
2007-10-09 10:38 ` Balbir Singh
2007-10-09 22:31 ` YAMAMOTO Takashi
2007-10-10 0:34 ` KAMEZAWA Hiroyuki
2007-10-09 9:50 ` [PATCH][for -mm] Fix and Enhancements for memory cgroup [2/6] fix err handling in charging KAMEZAWA Hiroyuki
2007-10-09 10:48 ` Balbir Singh
2007-10-09 9:51 ` [PATCH][for -mm] Fix and Enhancements for memory cgroup [3/6] add helper function for page_cgroup KAMEZAWA Hiroyuki
2007-10-09 11:09 ` Balbir Singh
2007-10-09 11:26 ` KAMEZAWA Hiroyuki [this message]
2007-10-10 0:38 ` KAMEZAWA Hiroyuki
2007-10-09 9:53 ` [PATCH][for -mm] Fix and Enhancements for memory cgroup [4/6] avoid handling !LRU page in mem_cgroup_isolate_pages KAMEZAWA Hiroyuki
2007-10-09 15:35 ` Balbir Singh
2007-10-09 9:54 ` [PATCH][for -mm] Fix and Enhancements for memory cgroup [5/6] memory cgroup and migration fix KAMEZAWA Hiroyuki
2007-10-09 16:26 ` Balbir Singh
2007-10-09 9:55 ` [PATCH][for -mm] Fix and Enhancements for memory cgroup [6/6] add force reclaim interface KAMEZAWA Hiroyuki
2007-10-09 18:44 ` Balbir Singh
2007-10-10 0:41 ` KAMEZAWA Hiroyuki
2007-10-09 10:30 ` [PATCH][for -mm] Fix and Enhancements for memory cgroup [0/6] intro Balbir Singh
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=20071009202642.9f174445.kamezawa.hiroyu@jp.fujitsu.com \
--to=kamezawa.hiroyu@jp.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=balbir@linux.vnet.ibm.com \
--cc=containers@lists.osdl.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