Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Shakeel Butt and committed by
Andrew Morton
906c38ff 642c66d8

+4 -44
+2 -32
include/linux/memcontrol.h
··· 443 443 return __folio_memcg(folio) != NULL; 444 444 } 445 445 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 - 475 446 /* 476 447 * folio_memcg_check - Get the memory cgroup associated with a folio. 477 448 * @folio: Pointer to the folio. ··· 1055 1084 return NULL; 1056 1085 } 1057 1086 1058 - static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio) 1087 + static inline bool folio_memcg_charged(struct folio *folio) 1059 1088 { 1060 - WARN_ON_ONCE(!rcu_read_lock_held()); 1061 - return NULL; 1089 + return false; 1062 1090 } 1063 1091 1064 1092 static inline struct mem_cgroup *folio_memcg_check(struct folio *folio)
+2 -12
mm/workingset.c
··· 591 591 */ 592 592 void workingset_activation(struct folio *folio) 593 593 { 594 - struct mem_cgroup *memcg; 595 - 596 - rcu_read_lock(); 597 594 /* 598 595 * Filter non-memcg pages here, e.g. unmap can call 599 596 * mark_page_accessed() on VDSO pages. 600 - * 601 - * XXX: See workingset_refault() - this should return 602 - * root_mem_cgroup even for !CONFIG_MEMCG. 603 597 */ 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)); 610 600 } 611 601 612 602 /*