Skip to content

Commit

Permalink
mm: memcg: push !mm handling out to page cache charge function
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Michal Hocko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
hnaz authored and torvalds committed Apr 7, 2014
1 parent 1bec6b3 commit 284f39a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2703,15 +2703,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;
Expand Down Expand Up @@ -4038,6 +4029,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);
Expand Down

0 comments on commit 284f39a

Please sign in to comment.