From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Mon, 28 Apr 2008 20:31:34 +0900 From: KAMEZAWA Hiroyuki Subject: [RFC][PATCH 7/8] memcg: remove redundant checks Message-Id: <20080428203134.d7de02cc.kamezawa.hiroyu@jp.fujitsu.com> In-Reply-To: <20080428201900.ae25e086.kamezawa.hiroyu@jp.fujitsu.com> References: <20080428201900.ae25e086.kamezawa.hiroyu@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org Return-Path: To: KAMEZAWA Hiroyuki Cc: "linux-mm@kvack.org" , "balbir@linux.vnet.ibm.com" , "xemul@openvz.org" , "hugh@veritas.com" , "yamamoto@valinux.co.jp" List-ID: This patch needs review ;) Because of remove refcnt patch, it's very rare case to that mem_cgroup_charge_common() is called against a page which is accounted. mem_cgroup_charge_common() is called when. 1. a page is added into file cache. 2. an anon page is newly mapped. 3. a file-cache page is newly mapped. To rise a racy condition, above action against a page should occur at once. And, for case 3, we don't account it because it's already file cache. For avoiding accounting "File cache but not mapped" page, checking page->mapping is better than checking page_mapped(). Signed-off-by : KAMEZAWA Hiroyuki --- mm/memcontrol.c | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) Index: mm-2.6.25-mm1/mm/memcontrol.c =================================================================== --- mm-2.6.25-mm1.orig/mm/memcontrol.c +++ mm-2.6.25-mm1/mm/memcontrol.c @@ -527,28 +527,6 @@ static int mem_cgroup_charge_common(stru if (mem_cgroup_subsys.disabled) return 0; - /* - * Should page_cgroup's go to their own slab? - * One could optimize the performance of the charging routine - * by saving a bit in the page_flags and using it as a lock - * to see if the cgroup page already has a page_cgroup associated - * with it - */ -retry: - lock_page_cgroup(page); - pc = page_get_page_cgroup(page); - /* - * The page_cgroup exists and - * the page has already been accounted. - */ - if (unlikely(pc)) { - VM_BUG_ON(pc->page != page); - VM_BUG_ON(!pc->mem_cgroup); - unlock_page_cgroup(page); - goto done; - } - unlock_page_cgroup(page); - pc = kmem_cache_alloc(page_cgroup_cache, gfp_mask); if (unlikely(!pc)) goto err; @@ -604,15 +582,10 @@ retry: lock_page_cgroup(page); if (unlikely(page_get_page_cgroup(page))) { unlock_page_cgroup(page); - /* - * Another charge has been added to this page already. - * We take lock_page_cgroup(page) again and read - * page->cgroup, increment refcnt.... just retry is OK. - */ res_counter_uncharge(&mem->res, PAGE_SIZE); css_put(&mem->css); kmem_cache_free(page_cgroup_cache, pc); - goto retry; + goto done; } page_assign_page_cgroup(page, pc); @@ -633,7 +606,15 @@ err: int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask) { - if (page_mapped(page)) + /* + * If a page is file cache, it's already charged. If a page is anon + * and mapped, it's already charged. We accounts only *new* anon + * page here. We cannot use !PageAnon() here because a new page for + * anon is not marked as an anon page. we just checks a page has some + * objrmap context or not. + * Note that swap-cache's page->mapping is NULL. So we have no problem. + */ + if (page->mapping) return 0; if (unlikely(!mm)) mm = &init_mm; -- 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: email@kvack.org