Files
linux/mm
Muchun Song 02f4bbefca mm: kmem: add lockdep assertion to obj_cgroup_memcg
obj_cgroup_memcg() is supposed to safe to prevent the returned memory
cgroup from being freed only when the caller is holding the rcu read lock
or objcg_lock or cgroup_mutex.  It is very easy to ignore thoes conditions
when users call some upper APIs which call obj_cgroup_memcg() internally
like mem_cgroup_from_slab_obj() (See the link below).  So it is better to
add lockdep assertion to obj_cgroup_memcg() to find those issues ASAP.

Because there is no user of obj_cgroup_memcg() holding objcg_lock to make
the returned memory cgroup safe, do not add objcg_lock assertion (We
should export objcg_lock if we really want to do).  Additionally, this is
some internal implementation detail of memcg and should not be accessible
outside memcg code.

Some users like __mem_cgroup_uncharge() do not care the lifetime of the
returned memory cgroup, which just want to know if the folio is charged to
a memory cgroup, therefore, they do not need to hold the needed locks.  In
which case, introduce a new helper folio_memcg_charged() to do this. 
Compare it to folio_memcg(), it could eliminate a memory access of
objcg->memcg for kmem, actually, a really small gain.

[songmuchun@bytedance.com: fix split_page_memcg()]
  Link: https://lkml.kernel.org/r/20240819080415.44964-1-songmuchun@bytedance.com
Link: https://lore.kernel.org/all/20240718083607.42068-1-songmuchun@bytedance.com/
Link: https://lkml.kernel.org/r/20240814093415.17634-1-songmuchun@bytedance.com
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-09-01 20:26:14 -07:00
..
2024-07-03 19:29:59 -07:00
2024-09-01 20:26:01 -07:00
2023-12-12 10:11:32 +01:00
2024-09-01 20:26:07 -07:00
2023-04-12 17:36:23 -07:00
2024-09-01 20:26:07 -07:00
2024-09-01 20:26:07 -07:00
2022-10-03 14:02:43 -07:00
2024-09-01 20:26:10 -07:00
2024-07-03 19:30:17 -07:00
2024-08-15 22:16:13 -07:00
2024-09-01 20:26:01 -07:00
2024-09-01 20:26:07 -07:00
2024-08-15 22:16:14 -07:00
2024-07-10 12:14:54 -07:00
2024-09-01 20:26:04 -07:00
2024-08-15 22:16:14 -07:00
2023-04-12 17:36:23 -07:00
2024-09-01 20:26:13 -07:00
2024-04-25 20:55:48 -07:00
2024-04-25 20:55:48 -07:00