[Devel,RHEL7,COMMIT] ms/mm: memcg: push !mm handling out to page cache charge function

Submitted by Konstantin Khorenko on Jan. 16, 2017, 4:27 p.m.

Details

Message ID 201701161627.v0GGR4BK027484@finist_cl7.x64_64.work.ct
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko Jan. 16, 2017, 4:27 p.m.
The commit is pushed to "branch-rh7-3.10.0-514.vz7.27.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.vz7.27.10
------>
commit ea4e7e1523644c3b6e753f815455374913c9cbad
Author: Johannes Weiner <hannes@cmpxchg.org>
Date:   Mon Jan 16 20:27:04 2017 +0400

    ms/mm: memcg: push !mm handling out to page cache charge function
    
    Only page cache charges can happen without an mm context, so push this
    special case out of the inner core and into the cache charge function.
    
    An ancient comment explains that the mm can also be NULL in case the
    task is currently being migrated, but that is not actually true with the
    current case, so just remove it.
    
    Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Michal Hocko <mhocko@suse.cz>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    
    https://jira.sw.ru/browse/PSBM-51558
    (cherry picked from commit 284f39afeaa4ab1409b8f43b29cdea3007960ee3)
    Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 mm/memcontrol.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index be1c492..7b2a99f 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2870,15 +2870,6 @@  static int __mem_cgroup_try_charge(struct mm_struct *mm,
 
 	if (gfp_mask & __GFP_NOFAIL)
 		oom = false;
-
-	/*
-	 * We always charge the cgroup the mm_struct belongs to.
-	 * The mm_struct's mem_cgroup changes on task migration if the
-	 * thread group leader migrates. It's possible that mm is not
-	 * set, if so charge the root memcg (happens for pagecache usage).
-	 */
-	if (!*ptr && !mm)
-		*ptr = root_mem_cgroup;
 again:
 	if (*ptr) { /* css should be a valid one */
 		memcg = *ptr;
@@ -3971,6 +3962,12 @@  int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
 		return 0;
 
 	if (!PageSwapCache(page)) {
+		/*
+		 * Page cache insertions can happen without an actual
+		 * task context, e.g. during disk probing on boot.
+		 */
+		if (!mm)
+			memcg = root_mem_cgroup;
 		ret = __mem_cgroup_try_charge(mm, gfp_mask, 1, &memcg, true);
 		if (ret != -ENOMEM)
 			__mem_cgroup_commit_charge(memcg, page, 1, type, false);