From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail143.messagelabs.com (mail143.messagelabs.com [216.82.254.35]) by kanga.kvack.org (Postfix) with ESMTP id 804976B003D for ; Tue, 21 Apr 2009 00:09:50 -0400 (EDT) Date: Tue, 21 Apr 2009 13:05:49 +0900 From: Daisuke Nishimura Subject: Re: [PATCH] fix unused/stale swap cache handling on memcg v3 Message-Id: <20090421130549.72cd1d6a.nishimura@mxp.nes.nec.co.jp> In-Reply-To: <20090421115749.bcb12fa7.kamezawa.hiroyu@jp.fujitsu.com> References: <20090317135702.4222e62e.nishimura@mxp.nes.nec.co.jp> <432ace3655a26d2d492a56303369a88a.squirrel@webmail-b.css.fujitsu.com> <20090320164520.f969907a.kamezawa.hiroyu@jp.fujitsu.com> <20090323104555.cb7cd059.nishimura@mxp.nes.nec.co.jp> <20090323114118.8b45105f.kamezawa.hiroyu@jp.fujitsu.com> <20090323140419.40235ce3.nishimura@mxp.nes.nec.co.jp> <20090323142242.f6659457.kamezawa.hiroyu@jp.fujitsu.com> <20090324173218.4de33b90.nishimura@mxp.nes.nec.co.jp> <20090325085713.6f0b7b74.kamezawa.hiroyu@jp.fujitsu.com> <20090417153455.c6fe2ba6.nishimura@mxp.nes.nec.co.jp> <20090417155411.76901324.kamezawa.hiroyu@jp.fujitsu.com> <20090417165036.bdca7163.nishimura@mxp.nes.nec.co.jp> <20090417165806.4ca40a08.kamezawa.hiroyu@jp.fujitsu.com> <20090417171201.6c79bee5.nishimura@mxp.nes.nec.co.jp> <20090417171343.e848481f.kamezawa.hiroyu@jp.fujitsu.com> <20090421113525.29332f3d.nishimura@mxp.nes.nec.co.jp> <20090421115749.bcb12fa7.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 To: KAMEZAWA Hiroyuki Cc: nishimura@mxp.nes.nec.co.jp, Daisuke Nishimura , linux-mm , Balbir Singh , Hugh Dickins List-ID: On Tue, 21 Apr 2009 11:57:49 +0900, KAMEZAWA Hiroyuki wrote: > On Tue, 21 Apr 2009 11:35:25 +0900 > Daisuke Nishimura wrote: > > > @@ -785,6 +786,23 @@ activate_locked: > > SetPageActive(page); > > pgactivate++; > > keep_locked: > > + if (!scanning_global_lru(sc) && PageSwapCache(page)) { > > + struct page_cgroup *pc; > > + > > + pc = lookup_page_cgroup(page); > > + /* > > + * Used bit of swapcache is solid under page lock. > > + */ > > + if (unlikely(!PageCgroupUsed(pc))) > > + /* > > + * This can happen if the page is free'ed by > > + * the owner process before it is added to > > + * swapcache. > > + * These swapcache cannot be managed by memcg > > + * well, so free it here. > > + */ > > + try_to_free_swap(page); > > + } > > unlock_page(page); > > keep: > > list_add(&page->lru, &ret_pages); > > > > This cannot prevent type-1 orphan SwapCache(caused by the race > > between exit() and swap-in readahead). > > Type-1 can pressure the memsw usage(trigger OOM if memsw.limit is set, as a result) > > and make struct mem_cgroup unfreeable even after rmdir(because it holds refcount > > to mem_cgroup). > Hmm. > free_swap_cache() > -> trylock_page() => failure case ? > Yes, but there is another case: processA | processB -------------------------------------+------------------------------------- (free_swap_and_cache()) | (read_swap_cache_async()) | swap_duplicate() swap_entry_free() == 1 | find_get_page() -> cannot find | | __set_page_locked() | add_to_swap_cache() | lru_cache_add_anon() | doesn't link this page to memcg's | LRU, because of !PageCgroupUsed. > add following codes. > == > 588 page = find_get_page(&swapper_space, entry.val); > 589 if (page && !trylock_page(page)) { > mem_cgroup_retry_free_swap_lazy(page); <===== > 590 page_cache_release(page); > 591 page = NULL; > 592 } > == > and do some kind of lazy ops..I'll try some. > > > > > Do you have any ideas to solve orphan SwapCache problem by adding some hooks to shrink_zone() ? > > (scan some pages from global LRU and check whether it's orphan SwapCache or not by > > adding some code like above ?) > > > > And, what do you think about adding above code to shrink_page_list() ? > > I think it might be unnecessary if we can solve the problem in another way, though. > > > > I think your hook itself is not very bad. (even if we remove this later..) > I think it depends on how we fix the type-1 whether we should remove this or not. Anyway, I'll leave it as it is for now. Thanks, Daisuke Nishimura. -- 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