Skip to content

Commit cfa4494

Browse files
Johannes Weinertorvalds
authored andcommitted
mm: memcg: lookup_page_cgroup (almost) never returns NULL
Pages have their corresponding page_cgroup descriptors set up before they are used in userspace, and thus managed by a memory cgroup. The only time where lookup_page_cgroup() can return NULL is in the CONFIG_DEBUG_VM-only page sanity checking code that executes while feeding pages into the page allocator for the first time. Remove the NULL checks against lookup_page_cgroup() results from all callsites where we know that corresponding page_cgroup descriptors must be allocated, and add a comment to the callsite that actually does have to check the return value. [[email protected]: stop oops in mem_cgroup_update_page_stat()] Signed-off-by: Johannes Weiner <[email protected]> Acked-by: KAMEZAWA Hiroyuki <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Balbir Singh <[email protected]> Cc: David Rientjes <[email protected]> Signed-off-by: Hugh Dickins <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 0e574a9 commit cfa4494

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

mm/memcontrol.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ void mem_cgroup_update_page_stat(struct page *page,
19601960
bool need_unlock = false;
19611961
unsigned long uninitialized_var(flags);
19621962

1963-
if (unlikely(!pc))
1963+
if (mem_cgroup_disabled())
19641964
return;
19651965

19661966
rcu_read_lock();
@@ -2735,8 +2735,6 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
27352735
}
27362736

27372737
pc = lookup_page_cgroup(page);
2738-
BUG_ON(!pc); /* XXX: remove this and move pc lookup into commit */
2739-
27402738
ret = __mem_cgroup_try_charge(mm, gfp_mask, nr_pages, &memcg, oom);
27412739
if (ret || !memcg)
27422740
return ret;
@@ -3008,7 +3006,7 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
30083006
* Check if our page_cgroup is valid
30093007
*/
30103008
pc = lookup_page_cgroup(page);
3011-
if (unlikely(!pc || !PageCgroupUsed(pc)))
3009+
if (unlikely(!PageCgroupUsed(pc)))
30123010
return NULL;
30133011

30143012
lock_page_cgroup(pc);
@@ -3436,6 +3434,11 @@ static struct page_cgroup *lookup_page_cgroup_used(struct page *page)
34363434
struct page_cgroup *pc;
34373435

34383436
pc = lookup_page_cgroup(page);
3437+
/*
3438+
* Can be NULL while feeding pages into the page allocator for
3439+
* the first time, i.e. during boot or memory hotplug;
3440+
* or when mem_cgroup_disabled().
3441+
*/
34393442
if (likely(pc) && PageCgroupUsed(pc))
34403443
return pc;
34413444
return NULL;

0 commit comments

Comments
 (0)