All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] memcg: workingset: remove folio_memcg_rcu usage
@ 2024-10-26 16:37 Shakeel Butt
  2024-10-27  5:09 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Shakeel Butt @ 2024-10-26 16:37 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Muchun Song,
	Hugh Dickins, Yosry Ahmed, linux-mm, cgroups, linux-kernel,
	Meta kernel team, Yu Zhao

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.

Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Suggested-by: Yu Zhao <yuzhao@google.com>
---
Andrew, please put this patch after charge migration deprecation series.

Changes since v1:
- Fix for mem_cgroup_disabled(). (Yu Zhao)

 include/linux/memcontrol.h | 35 -----------------------------------
 mm/workingset.c            | 14 ++------------
 2 files changed, 2 insertions(+), 47 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 932534291ca2..89a1e9f10e1b 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -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,12 +1055,6 @@ static inline struct mem_cgroup *folio_memcg(struct folio *folio)
 	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;
diff --git a/mm/workingset.c b/mm/workingset.c
index 4b58ef535a17..a4705e196545 100644
--- a/mm/workingset.c
+++ b/mm/workingset.c
@@ -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));
 }
 
 /*
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] memcg: workingset: remove folio_memcg_rcu usage
  2024-10-26 16:37 [PATCH v2] memcg: workingset: remove folio_memcg_rcu usage Shakeel Butt
@ 2024-10-27  5:09 ` kernel test robot
  2024-10-27  5:09 ` kernel test robot
  2024-10-27  6:55 ` Shakeel Butt
  2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2024-10-27  5:09 UTC (permalink / raw)
  To: Shakeel Butt; +Cc: llvm, oe-kbuild-all

Hi Shakeel,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master v6.12-rc4 next-20241025]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Shakeel-Butt/memcg-workingset-remove-folio_memcg_rcu-usage/20241027-003815
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20241026163707.2479526-1-shakeel.butt%40linux.dev
patch subject: [PATCH v2] memcg: workingset: remove folio_memcg_rcu usage
config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20241027/202410271328.q4gVeNsh-lkp@intel.com/config)
compiler: clang version 19.1.2 (https://github.com/llvm/llvm-project 7ba7d8e2f7b6445b60679da826210cdde29eaf8b)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241027/202410271328.q4gVeNsh-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410271328.q4gVeNsh-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from mm/workingset.c:8:
   In file included from include/linux/memcontrol.h:21:
   In file included from include/linux/mm.h:2213:
   include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     518 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   In file included from mm/workingset.c:9:
   include/linux/mm_inline.h:47:41: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
      47 |         __mod_lruvec_state(lruvec, NR_LRU_BASE + lru, nr_pages);
         |                                    ~~~~~~~~~~~ ^ ~~~
   include/linux/mm_inline.h:49:22: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
      49 |                                 NR_ZONE_LRU_BASE + lru, nr_pages);
         |                                 ~~~~~~~~~~~~~~~~ ^ ~~~
>> mm/workingset.c:598:31: error: call to undeclared function 'folio_memcg_charged'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     598 |         if (mem_cgroup_disabled() || folio_memcg_charged(folio))
         |                                      ^
   mm/workingset.c:598:31: note: did you mean 'folio_memcg_check'?
   include/linux/memcontrol.h:1058:34: note: 'folio_memcg_check' declared here
    1058 | static inline struct mem_cgroup *folio_memcg_check(struct folio *folio)
         |                                  ^
   3 warnings and 1 error generated.


vim +/folio_memcg_charged +598 mm/workingset.c

   587	
   588	/**
   589	 * workingset_activation - note a page activation
   590	 * @folio: Folio that is being activated.
   591	 */
   592	void workingset_activation(struct folio *folio)
   593	{
   594		/*
   595		 * Filter non-memcg pages here, e.g. unmap can call
   596		 * mark_page_accessed() on VDSO pages.
   597		 */
 > 598		if (mem_cgroup_disabled() || folio_memcg_charged(folio))
   599			workingset_age_nonresident(folio_lruvec(folio), folio_nr_pages(folio));
   600	}
   601	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] memcg: workingset: remove folio_memcg_rcu usage
  2024-10-26 16:37 [PATCH v2] memcg: workingset: remove folio_memcg_rcu usage Shakeel Butt
  2024-10-27  5:09 ` kernel test robot
@ 2024-10-27  5:09 ` kernel test robot
  2024-10-27  6:55 ` Shakeel Butt
  2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2024-10-27  5:09 UTC (permalink / raw)
  To: Shakeel Butt; +Cc: oe-kbuild-all

Hi Shakeel,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master v6.12-rc4 next-20241025]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Shakeel-Butt/memcg-workingset-remove-folio_memcg_rcu-usage/20241027-003815
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20241026163707.2479526-1-shakeel.butt%40linux.dev
patch subject: [PATCH v2] memcg: workingset: remove folio_memcg_rcu usage
config: sh-secureedge5410_defconfig (https://download.01.org/0day-ci/archive/20241027/202410271316.RPNBjlOR-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 13.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241027/202410271316.RPNBjlOR-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410271316.RPNBjlOR-lkp@intel.com/

All errors (new ones prefixed by >>):

   mm/workingset.c: In function 'workingset_activation':
>> mm/workingset.c:598:38: error: implicit declaration of function 'folio_memcg_charged'; did you mean 'folio_memcg_check'? [-Werror=implicit-function-declaration]
     598 |         if (mem_cgroup_disabled() || folio_memcg_charged(folio))
         |                                      ^~~~~~~~~~~~~~~~~~~
         |                                      folio_memcg_check
   cc1: some warnings being treated as errors


vim +598 mm/workingset.c

   587	
   588	/**
   589	 * workingset_activation - note a page activation
   590	 * @folio: Folio that is being activated.
   591	 */
   592	void workingset_activation(struct folio *folio)
   593	{
   594		/*
   595		 * Filter non-memcg pages here, e.g. unmap can call
   596		 * mark_page_accessed() on VDSO pages.
   597		 */
 > 598		if (mem_cgroup_disabled() || folio_memcg_charged(folio))
   599			workingset_age_nonresident(folio_lruvec(folio), folio_nr_pages(folio));
   600	}
   601	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] memcg: workingset: remove folio_memcg_rcu usage
  2024-10-26 16:37 [PATCH v2] memcg: workingset: remove folio_memcg_rcu usage Shakeel Butt
  2024-10-27  5:09 ` kernel test robot
  2024-10-27  5:09 ` kernel test robot
@ 2024-10-27  6:55 ` Shakeel Butt
  2024-10-27 17:33   ` SeongJae Park
  2 siblings, 1 reply; 5+ messages in thread
From: Shakeel Butt @ 2024-10-27  6:55 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Muchun Song,
	Hugh Dickins, Yosry Ahmed, linux-mm, cgroups, linux-kernel,
	Meta kernel team, Yu Zhao

On Sat, Oct 26, 2024 at 09:37:07AM GMT, Shakeel Butt wrote:
> 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.
> 
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
> Suggested-by: Yu Zhao <yuzhao@google.com>
> ---
> Andrew, please put this patch after charge migration deprecation series.
> 
> Changes since v1:
> - Fix for mem_cgroup_disabled(). (Yu Zhao)
> 

It seems like folio_memcg_charged() is not defined for CONFIG_MEMCG=n
config option. The following stub should fix the build for such config.


diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 89a1e9f10e1b..5502aa8e138e 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1055,6 +1055,11 @@ static inline struct mem_cgroup *folio_memcg(struct folio *folio)
 	return NULL;
 }
 
+static inline bool folio_memcg_charged(struct folio *folio)
+{
+	return false;
+}
+
 static inline struct mem_cgroup *folio_memcg_check(struct folio *folio)
 {
 	return NULL;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] memcg: workingset: remove folio_memcg_rcu usage
  2024-10-27  6:55 ` Shakeel Butt
@ 2024-10-27 17:33   ` SeongJae Park
  0 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2024-10-27 17:33 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: SeongJae Park, Andrew Morton, Johannes Weiner, Michal Hocko,
	Roman Gushchin, Muchun Song, Hugh Dickins, Yosry Ahmed, linux-mm,
	cgroups, linux-kernel, Meta kernel team, Yu Zhao

On Sat, 26 Oct 2024 23:55:14 -0700 Shakeel Butt <shakeel.butt@linux.dev> wrote:

[...]
 It seems like folio_memcg_charged() is not defined for CONFIG_MEMCG=n
> config option. The following stub should fix the build for such config.
> 
> 
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 89a1e9f10e1b..5502aa8e138e 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -1055,6 +1055,11 @@ static inline struct mem_cgroup *folio_memcg(struct folio *folio)
>  	return NULL;
>  }
>  
> +static inline bool folio_memcg_charged(struct folio *folio)
> +{
> +	return false;
> +}
> +
>  static inline struct mem_cgroup *folio_memcg_check(struct folio *folio)
>  {
>  	return NULL;

Tested-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-27 17:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-26 16:37 [PATCH v2] memcg: workingset: remove folio_memcg_rcu usage Shakeel Butt
2024-10-27  5:09 ` kernel test robot
2024-10-27  5:09 ` kernel test robot
2024-10-27  6:55 ` Shakeel Butt
2024-10-27 17:33   ` SeongJae Park

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.