Commit 26174efd42100eefac67732c0c12f41a205fa335

Authored by KAMEZAWA Hiroyuki
Committed by Linus Torvalds
1 parent 1489ebad8b

memcg: generic filestat update interface

This patch extracts the core logic from mem_cgroup_update_file_mapped() as
mem_cgroup_update_file_stat() and adds a wrapper.

As a planned future update, memory cgroup has to count dirty pages to
implement dirty_ratio/limit.  And more, the number of dirty pages is
required to kick flusher thread to start writeback.  (Now, no kick.)

This patch is preparation for it and makes other statistics implementation
clearer.  Just a clean up.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Reviewed-by: Greg Thelen <gthelen@google.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 18 additions and 7 deletions Side-by-side Diff

... ... @@ -1591,7 +1591,8 @@
1591 1591 * small, we check MEM_CGROUP_ON_MOVE percpu value and detect there are
1592 1592 * possibility of race condition. If there is, we take a lock.
1593 1593 */
1594   -void mem_cgroup_update_file_mapped(struct page *page, int val)
  1594 +
  1595 +static void mem_cgroup_update_file_stat(struct page *page, int idx, int val)
1595 1596 {
1596 1597 struct mem_cgroup *mem;
1597 1598 struct page_cgroup *pc = lookup_page_cgroup(page);
1598 1599  
... ... @@ -1613,13 +1614,18 @@
1613 1614 if (!mem || !PageCgroupUsed(pc))
1614 1615 goto out;
1615 1616 }
1616   - if (val > 0) {
1617   - this_cpu_inc(mem->stat->count[MEM_CGROUP_STAT_FILE_MAPPED]);
1618   - SetPageCgroupFileMapped(pc);
1619   - } else {
1620   - this_cpu_dec(mem->stat->count[MEM_CGROUP_STAT_FILE_MAPPED]);
1621   - if (!page_mapped(page)) /* for race between dec->inc counter */
  1617 +
  1618 + this_cpu_add(mem->stat->count[idx], val);
  1619 +
  1620 + switch (idx) {
  1621 + case MEM_CGROUP_STAT_FILE_MAPPED:
  1622 + if (val > 0)
  1623 + SetPageCgroupFileMapped(pc);
  1624 + else if (!page_mapped(page))
1622 1625 ClearPageCgroupFileMapped(pc);
  1626 + break;
  1627 + default:
  1628 + BUG();
1623 1629 }
1624 1630  
1625 1631 out:
... ... @@ -1627,6 +1633,11 @@
1627 1633 unlock_page_cgroup(pc);
1628 1634 rcu_read_unlock();
1629 1635 return;
  1636 +}
  1637 +
  1638 +void mem_cgroup_update_file_mapped(struct page *page, int val)
  1639 +{
  1640 + mem_cgroup_update_file_stat(page, MEM_CGROUP_STAT_FILE_MAPPED, val);
1630 1641 }
1631 1642  
1632 1643 /*