mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
mm: memcontrol/slab: Use helpers to access slab page's memcg_data
To gather all direct accesses to struct page's memcg_data field in one place, let's introduce 3 new helpers to use in the slab accounting code: struct obj_cgroup **page_objcgs(struct page *page); struct obj_cgroup **page_objcgs_check(struct page *page); bool set_page_objcgs(struct page *page, struct obj_cgroup **objcgs); They are similar to the corresponding API for generic pages, except that the setter can return false, indicating that the value has been already set from a different thread. Signed-off-by: Roman Gushchin <guro@fb.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Reviewed-by: Shakeel Butt <shakeelb@google.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Link: https://lkml.kernel.org/r/20201027001657.3398190-3-guro@fb.com Link: https://lore.kernel.org/bpf/20201201215900.3569844-3-guro@fb.com
This commit is contained in:
committed by
Alexei Starovoitov
parent
bcfe06bf26
commit
270c6a7146
@@ -2899,7 +2899,7 @@ int memcg_alloc_page_obj_cgroups(struct page *page, struct kmem_cache *s,
|
||||
if (!vec)
|
||||
return -ENOMEM;
|
||||
|
||||
if (cmpxchg(&page->memcg_data, 0, (unsigned long)vec | 0x1UL))
|
||||
if (!set_page_objcgs(page, vec))
|
||||
kfree(vec);
|
||||
else
|
||||
kmemleak_not_leak(vec);
|
||||
@@ -2933,12 +2933,12 @@ struct mem_cgroup *mem_cgroup_from_obj(void *p)
|
||||
* Memcg membership data for each individual object is saved in
|
||||
* the page->obj_cgroups.
|
||||
*/
|
||||
if (page_has_obj_cgroups(page)) {
|
||||
if (page_objcgs_check(page)) {
|
||||
struct obj_cgroup *objcg;
|
||||
unsigned int off;
|
||||
|
||||
off = obj_to_index(page->slab_cache, page, p);
|
||||
objcg = page_obj_cgroups(page)[off];
|
||||
objcg = page_objcgs(page)[off];
|
||||
if (objcg)
|
||||
return obj_cgroup_memcg(objcg);
|
||||
|
||||
|
Reference in New Issue
Block a user