Re: [patch 2/2] mm: memcontrol: fix missed end-writeback page accounting

From: Johannes Weiner
Date: Thu Oct 23 2014 - 09:57:41 EST


On Wed, Oct 22, 2014 at 01:39:36PM -0700, Andrew Morton wrote:
> On Wed, 22 Oct 2014 14:29:28 -0400 Johannes Weiner <hannes@xxxxxxxxxxx> wrote:
> > @@ -1061,9 +1062,10 @@ void page_add_file_rmap(struct page *page)
> > */
> > void page_remove_rmap(struct page *page)
> > {
> > + struct mem_cgroup *uninitialized_var(memcg);
> > bool anon = PageAnon(page);
> > - bool locked;
> > unsigned long flags;
> > + bool locked;
> >
> > /*
> > * The anon case has no mem_cgroup page_stat to update; but may
> > @@ -1071,7 +1073,7 @@ void page_remove_rmap(struct page *page)
> > * we hold the lock against page_stat move: so avoid it on anon.
> > */
> > if (!anon)
> > - mem_cgroup_begin_update_page_stat(page, &locked, &flags);
> > + memcg = mem_cgroup_begin_page_stat(page, &locked, &flags);
> >
> > /* page still mapped by someone else? */
> > if (!atomic_add_negative(-1, &page->_mapcount))
> > @@ -1096,8 +1098,7 @@ void page_remove_rmap(struct page *page)
> > -hpage_nr_pages(page));
> > } else {
> > __dec_zone_page_state(page, NR_FILE_MAPPED);
> > - mem_cgroup_dec_page_stat(page, MEM_CGROUP_STAT_FILE_MAPPED);
> > - mem_cgroup_end_update_page_stat(page, &locked, &flags);
> > + mem_cgroup_dec_page_stat(memcg, MEM_CGROUP_STAT_FILE_MAPPED);
> > }
> > if (unlikely(PageMlocked(page)))
> > clear_page_mlock(page);
> > @@ -1110,10 +1111,9 @@ void page_remove_rmap(struct page *page)
> > * Leaving it set also helps swapoff to reinstate ptes
> > * faster for those pages still in swapcache.
> > */
> > - return;
> > out:
> > if (!anon)
> > - mem_cgroup_end_update_page_stat(page, &locked, &flags);
> > + mem_cgroup_end_page_stat(memcg, locked, flags);
> > }
>
> The anon and file paths have as much unique code as they do common
> code. I wonder if page_remove_rmap() would come out better if split
> into two functions? I gave that a quick try and it came out OK-looking.

I agree, that looks better. How about this?

---