Skip to content

Commit

Permalink
memcg: workingset: remove folio_memcg_rcu usage
Browse files Browse the repository at this point in the history
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.

[[email protected]: provide folio_memcg_charged stub for CONFIG_MEMCG=n]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Shakeel Butt <[email protected]>
Suggested-by: Yu Zhao <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Roman Gushchin <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Muchun Song <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Yosry Ahmed <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
shakeelb authored and akpm00 committed Nov 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 642c66d commit 906c38f
Showing 2 changed files with 4 additions and 44 deletions.
34 changes: 2 additions & 32 deletions include/linux/memcontrol.h
Original file line number Diff line number Diff line change
@@ -443,35 +443,6 @@ static inline bool folio_memcg_charged(struct folio *folio)
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,10 +1055,9 @@ static inline struct mem_cgroup *folio_memcg(struct folio *folio)
return NULL;
}

static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio)
static inline bool folio_memcg_charged(struct folio *folio)
{
WARN_ON_ONCE(!rcu_read_lock_held());
return NULL;
return false;
}

static inline struct mem_cgroup *folio_memcg_check(struct folio *folio)
14 changes: 2 additions & 12 deletions mm/workingset.c
Original file line number Diff line number Diff line change
@@ -591,22 +591,12 @@ void workingset_refault(struct folio *folio, void *shadow)
*/
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));
}

/*

0 comments on commit 906c38f

Please sign in to comment.