Skip to content

Commit 906c38f

Browse files
shakeelbakpm00
authored andcommitted
memcg: workingset: remove folio_memcg_rcu usage
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. [akpm@linux-foundation.org: provide folio_memcg_charged stub for CONFIG_MEMCG=n] Link: https://lkml.kernel.org/r/20241026163707.2479526-1-shakeel.butt@linux.dev Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev> Suggested-by: Yu Zhao <yuzhao@google.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Muchun Song <songmuchun@bytedance.com> Cc: Hugh Dickins <hughd@google.com> Cc: Yosry Ahmed <yosryahmed@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 642c66d commit 906c38f

File tree

2 files changed

+4
-44
lines changed

2 files changed

+4
-44
lines changed

include/linux/memcontrol.h

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -443,35 +443,6 @@ static inline bool folio_memcg_charged(struct folio *folio)
443443
return __folio_memcg(folio) != NULL;
444444
}
445445

446-
/**
447-
* folio_memcg_rcu - Locklessly get the memory cgroup associated with a folio.
448-
* @folio: Pointer to the folio.
449-
*
450-
* This function assumes that the folio is known to have a
451-
* proper memory cgroup pointer. It's not safe to call this function
452-
* against some type of folios, e.g. slab folios or ex-slab folios.
453-
*
454-
* Return: A pointer to the memory cgroup associated with the folio,
455-
* or NULL.
456-
*/
457-
static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio)
458-
{
459-
unsigned long memcg_data = READ_ONCE(folio->memcg_data);
460-
461-
VM_BUG_ON_FOLIO(folio_test_slab(folio), folio);
462-
463-
if (memcg_data & MEMCG_DATA_KMEM) {
464-
struct obj_cgroup *objcg;
465-
466-
objcg = (void *)(memcg_data & ~OBJEXTS_FLAGS_MASK);
467-
return obj_cgroup_memcg(objcg);
468-
}
469-
470-
WARN_ON_ONCE(!rcu_read_lock_held());
471-
472-
return (struct mem_cgroup *)(memcg_data & ~OBJEXTS_FLAGS_MASK);
473-
}
474-
475446
/*
476447
* folio_memcg_check - Get the memory cgroup associated with a folio.
477448
* @folio: Pointer to the folio.
@@ -1084,10 +1055,9 @@ static inline struct mem_cgroup *folio_memcg(struct folio *folio)
10841055
return NULL;
10851056
}
10861057

1087-
static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio)
1058+
static inline bool folio_memcg_charged(struct folio *folio)
10881059
{
1089-
WARN_ON_ONCE(!rcu_read_lock_held());
1090-
return NULL;
1060+
return false;
10911061
}
10921062

10931063
static inline struct mem_cgroup *folio_memcg_check(struct folio *folio)

mm/workingset.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -591,22 +591,12 @@ void workingset_refault(struct folio *folio, void *shadow)
591591
*/
592592
void workingset_activation(struct folio *folio)
593593
{
594-
struct mem_cgroup *memcg;
595-
596-
rcu_read_lock();
597594
/*
598595
* Filter non-memcg pages here, e.g. unmap can call
599596
* mark_page_accessed() on VDSO pages.
600-
*
601-
* XXX: See workingset_refault() - this should return
602-
* root_mem_cgroup even for !CONFIG_MEMCG.
603597
*/
604-
memcg = folio_memcg_rcu(folio);
605-
if (!mem_cgroup_disabled() && !memcg)
606-
goto out;
607-
workingset_age_nonresident(folio_lruvec(folio), folio_nr_pages(folio));
608-
out:
609-
rcu_read_unlock();
598+
if (mem_cgroup_disabled() || folio_memcg_charged(folio))
599+
workingset_age_nonresident(folio_lruvec(folio), folio_nr_pages(folio));
610600
}
611601

612602
/*

0 commit comments

Comments
 (0)