The patch titled Subject: memcg: workingset: remove folio_memcg_rcu usage has been added to the -mm mm-unstable branch. Its filename is memcg-workingset-remove-folio_memcg_rcu-usage.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/memcg-workingset-remove-folio_memcg_rcu-usage.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Shakeel Butt <shakeel.butt@xxxxxxxxx> Subject: memcg: workingset: remove folio_memcg_rcu usage Date: Sat, 26 Oct 2024 09:37:07 -0700 The function workingset_activation() is called from folio_mark_accessed() with the guarantee that the given folio can not be freed under us in workingset_activation(). In addition, the association of the folio and its memcg can not be broken here because charge migration is no more. There is no need to use folio_memcg_rcu. Simply use folio_memcg_charged() because that is what this function cares about. Link: https://lkml.kernel.org/r/20241026163707.2479526-1-shakeel.butt@xxxxxxxxx Signed-off-by: Shakeel Butt <shakeel.butt@xxxxxxxxx> Suggested-by: Yu Zhao <yuzhao@xxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Roman Gushchin <roman.gushchin@xxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Muchun Song <songmuchun@xxxxxxxxxxxxx> Cc: Hugh Dickins <hughd@xxxxxxxxxx> Cc: Yosry Ahmed <yosryahmed@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/memcontrol.h | 35 ----------------------------------- mm/workingset.c | 14 ++------------ 2 files changed, 2 insertions(+), 47 deletions(-) --- a/include/linux/memcontrol.h~memcg-workingset-remove-folio_memcg_rcu-usage +++ a/include/linux/memcontrol.h @@ -443,35 +443,6 @@ static inline bool folio_memcg_charged(s return __folio_memcg(folio) != NULL; } -/** - * folio_memcg_rcu - Locklessly get the memory cgroup associated with a folio. - * @folio: Pointer to the folio. - * - * This function assumes that the folio is known to have a - * proper memory cgroup pointer. It's not safe to call this function - * against some type of folios, e.g. slab folios or ex-slab folios. - * - * Return: A pointer to the memory cgroup associated with the folio, - * or NULL. - */ -static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio) -{ - unsigned long memcg_data = READ_ONCE(folio->memcg_data); - - VM_BUG_ON_FOLIO(folio_test_slab(folio), folio); - - if (memcg_data & MEMCG_DATA_KMEM) { - struct obj_cgroup *objcg; - - objcg = (void *)(memcg_data & ~OBJEXTS_FLAGS_MASK); - return obj_cgroup_memcg(objcg); - } - - WARN_ON_ONCE(!rcu_read_lock_held()); - - return (struct mem_cgroup *)(memcg_data & ~OBJEXTS_FLAGS_MASK); -} - /* * folio_memcg_check - Get the memory cgroup associated with a folio. * @folio: Pointer to the folio. @@ -1084,12 +1055,6 @@ static inline struct mem_cgroup *folio_m return NULL; } -static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio) -{ - WARN_ON_ONCE(!rcu_read_lock_held()); - return NULL; -} - static inline struct mem_cgroup *folio_memcg_check(struct folio *folio) { return NULL; --- a/mm/workingset.c~memcg-workingset-remove-folio_memcg_rcu-usage +++ a/mm/workingset.c @@ -591,22 +591,12 @@ void workingset_refault(struct folio *fo */ void workingset_activation(struct folio *folio) { - struct mem_cgroup *memcg; - - rcu_read_lock(); /* * Filter non-memcg pages here, e.g. unmap can call * mark_page_accessed() on VDSO pages. - * - * XXX: See workingset_refault() - this should return - * root_mem_cgroup even for !CONFIG_MEMCG. */ - memcg = folio_memcg_rcu(folio); - if (!mem_cgroup_disabled() && !memcg) - goto out; - workingset_age_nonresident(folio_lruvec(folio), folio_nr_pages(folio)); -out: - rcu_read_unlock(); + if (mem_cgroup_disabled() || folio_memcg_charged(folio)) + workingset_age_nonresident(folio_lruvec(folio), folio_nr_pages(folio)); } /* _ Patches currently in -mm which might be from shakeel.butt@xxxxxxxxx are mm-optimize-truncation-of-shadow-entries.patch mm-optimize-invalidation-of-shadow-entries.patch mm-truncate-reset-xa_has_values-flag-on-each-iteration.patch memcg-add-tracing-for-memcg-stat-updates.patch memcg-add-tracing-for-memcg-stat-updates-v2.patch memcg-v1-fully-deprecate-move_charge_at_immigrate.patch memcg-v1-remove-charge-move-code.patch memcg-v1-no-need-for-memcg-locking-for-dirty-tracking.patch memcg-v1-no-need-for-memcg-locking-for-writeback-tracking.patch memcg-v1-no-need-for-memcg-locking-for-mglru.patch memcg-v1-remove-memcg-move-locking-code.patch memcg-workingset-remove-folio_memcg_rcu-usage.patch