Re: [PATCH v5 2/4] memcg: move memcg reclaimable page into tail of inactive list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Kame,

On Fri, Feb 18, 2011 at 1:04 AM, KAMEZAWA Hiroyuki
<kamezawa.hiroyu@xxxxxxxxxxxxxx> wrote:
> On Fri, 18 Feb 2011 00:08:20 +0900
> Minchan Kim <minchan.kim@xxxxxxxxx> wrote:
>
>> The rotate_reclaimable_page function moves just written out
>> pages, which the VM wanted to reclaim, to the end of the
>> inactive list. ÂThat way the VM will find those pages first
>> next time it needs to free memory.
>> This patch apply the rule in memcg.
>> It can help to prevent unnecessary working page eviction of memcg.
>>
>> Acked-by: Balbir Singh <balbir@xxxxxxxxxxxxxxxxxx>
>> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
>> Reviewed-by: Rik van Riel <riel@xxxxxxxxxx>
>> Cc: KOSAKI Motohiro <kosaki.motohiro@xxxxxxxxxxxxxx>
>> Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
>> Signed-off-by: Minchan Kim <minchan.kim@xxxxxxxxx>
>> ---
>> Changelog since v4:
>> Â- add acked-by and reviewed-by
>> Â- change description - suggested by Rik
>>
>> Âinclude/linux/memcontrol.h | Â Â6 ++++++
>> Âmm/memcontrol.c      Â|  27 +++++++++++++++++++++++++++
>> Âmm/swap.c         Â|  Â3 ++-
>> Â3 files changed, 35 insertions(+), 1 deletions(-)
>>
>> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
>> index 3da48ae..5a5ce70 100644
>> --- a/include/linux/memcontrol.h
>> +++ b/include/linux/memcontrol.h
>> @@ -62,6 +62,7 @@ extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â gfp_t gfp_mask);
>> Âextern void mem_cgroup_add_lru_list(struct page *page, enum lru_list lru);
>> Âextern void mem_cgroup_del_lru_list(struct page *page, enum lru_list lru);
>> +extern void mem_cgroup_rotate_reclaimable_page(struct page *page);
>> Âextern void mem_cgroup_rotate_lru_list(struct page *page, enum lru_list lru);
>> Âextern void mem_cgroup_del_lru(struct page *page);
>> Âextern void mem_cgroup_move_lists(struct page *page,
>> @@ -215,6 +216,11 @@ static inline void mem_cgroup_del_lru_list(struct page *page, int lru)
>> Â Â Â return ;
>> Â}
>>
>> +static inline inline void mem_cgroup_rotate_reclaimable_page(struct page *page)
>> +{
>> + Â Â return ;
>> +}
>> +
>> Âstatic inline void mem_cgroup_rotate_lru_list(struct page *page, int lru)
>> Â{
>> Â Â Â return ;
>> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>> index 686f1ce..ab8bdff 100644
>> --- a/mm/memcontrol.c
>> +++ b/mm/memcontrol.c
>> @@ -813,6 +813,33 @@ void mem_cgroup_del_lru(struct page *page)
>> Â Â Â mem_cgroup_del_lru_list(page, page_lru(page));
>> Â}
>>
>> +/*
>> + * Writeback is about to end against a page which has been marked for immediate
>> + * reclaim. ÂIf it still appears to be reclaimable, move it to the tail of the
>> + * inactive list.
>> + */
>> +void mem_cgroup_rotate_reclaimable_page(struct page *page)
>> +{
>> + Â Â struct mem_cgroup_per_zone *mz;
>> + Â Â struct page_cgroup *pc;
>> + Â Â enum lru_list lru = page_lru_base_type(page);
>> +
>> + Â Â if (mem_cgroup_disabled())
>> + Â Â Â Â Â Â return;
>> +
>> + Â Â pc = lookup_page_cgroup(page);
>> + Â Â /*
>> + Â Â Â* Used bit is set without atomic ops but after smp_wmb().
>> + Â Â Â* For making pc->mem_cgroup visible, insert smp_rmb() here.
>> + Â Â Â*/
>> + Â Â smp_rmb();
>> + Â Â /* unused or root page is not rotated. */
>> + Â Â if (!PageCgroupUsed(pc) || mem_cgroup_is_root(pc->mem_cgroup))
>> + Â Â Â Â Â Â return;
>> + Â Â mz = page_cgroup_zoneinfo(pc->mem_cgroup, page);
>> + Â Â list_move_tail(&pc->lru, &mz->lists[lru]);
>> +}
>> +
>
> Hmm, I'm sorry I misunderstand this. IIUC, page_lru_base_type() always returns
> LRU_INACTIVE_XXX and this function may move page from active LRU to inactive LRU.
>
> Then, LRU counters for memcg should be updated.

Goal of mem_cgroup_rotate_reclaimable_page is same with rotate_reclaimable_page.
It means the page was already in inactive list.
Look at the check !PageActive(page).

But if you want to make the function generally(ie, support
active->inactive, too), I don't mind it. but if you want it, let's
make rotate_reclaimable_page to general function, too. but now any
user doesn't use it.

Thanks for the careful review.

>
> Could you replace after lookup like this ?
>
> Â Â VM_BUG_ON(!PageCgroupAcctLRU(pc)) Â/* Implies this pages must be on some LRU */
> Â Â if (!PageCgroupUsed(pc))
> Â Â Â Â Â return;
> Â Â /* Used bit check is not necessary, because there is a case Unused page
> Â Â Â Âis lazily on LRU. We trust AcctLRU bit. */
> Â Â mz = page_cgroup_zoneinfo(pc->mem_cgroup, page);
> Â Â MEM_CGROUP_ZSTAT(mz, page_lru(page)) -= 1 << compound_order(page);
> Â Â MEM_CGROUP_ZSTAT(mz, lru) += 1 << compound_order(page)
> Â Â if (mem_cgroup_is_root(pc->mem_cgroup))
> Â Â Â Â Â return;
> Â Â list_move_tail(&pc->lru, &mz->lists[lru])
>
>
> Thanks,
> -Kame
>> Âvoid mem_cgroup_rotate_lru_list(struct page *page, enum lru_list lru)
>> Â{
>> Â Â Â struct mem_cgroup_per_zone *mz;
>> diff --git a/mm/swap.c b/mm/swap.c
>> index 4aea806..1b9e4eb 100644
>> --- a/mm/swap.c
>> +++ b/mm/swap.c
>> @@ -200,8 +200,9 @@ static void pagevec_move_tail(struct pagevec *pvec)
>> Â Â Â Â Â Â Â Â Â Â Â spin_lock(&zone->lru_lock);
>> Â Â Â Â Â Â Â }
>> Â Â Â Â Â Â Â if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
>> - Â Â Â Â Â Â Â Â Â Â int lru = page_lru_base_type(page);
>> + Â Â Â Â Â Â Â Â Â Â enum lru_list lru = page_lru_base_type(page);
>> Â Â Â Â Â Â Â Â Â Â Â list_move_tail(&page->lru, &zone->lru[lru].list);
>> + Â Â Â Â Â Â Â Â Â Â mem_cgroup_rotate_reclaimable_page(page);
>> Â Â Â Â Â Â Â Â Â Â Â pgmoved++;
>> Â Â Â Â Â Â Â }
>> Â Â Â }
>> --
>> 1.7.1
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@xxxxxxxxxxxxxxx
>> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at Âhttp://www.tux.org/lkml/
>>
>
>



-- 
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxxx  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]