Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 284f39a

Browse files
hnaztorvalds
authored andcommitted
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 <[email protected]> Cc: Michal Hocko <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1bec6b3 commit 284f39a

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

mm/memcontrol.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,15 +2703,6 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
27032703

27042704
if (gfp_mask & __GFP_NOFAIL)
27052705
oom = false;
2706-
2707-
/*
2708-
* We always charge the cgroup the mm_struct belongs to.
2709-
* The mm_struct's mem_cgroup changes on task migration if the
2710-
* thread group leader migrates. It's possible that mm is not
2711-
* set, if so charge the root memcg (happens for pagecache usage).
2712-
*/
2713-
if (!*ptr && !mm)
2714-
*ptr = root_mem_cgroup;
27152706
again:
27162707
if (*ptr) { /* css should be a valid one */
27172708
memcg = *ptr;
@@ -4038,6 +4029,12 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
40384029
return 0;
40394030

40404031
if (!PageSwapCache(page)) {
4032+
/*
4033+
* Page cache insertions can happen without an actual
4034+
* task context, e.g. during disk probing on boot.
4035+
*/
4036+
if (!mm)
4037+
memcg = root_mem_cgroup;
40414038
ret = __mem_cgroup_try_charge(mm, gfp_mask, 1, &memcg, true);
40424039
if (ret != -ENOMEM)
40434040
__mem_cgroup_commit_charge(memcg, page, 1, type, false);

0 commit comments

Comments
 (0)