Skip to contentSkip to conversation

mm, slub: add cpus_read_lock/unlock() for slab_mem_going_offline_callback()

PATCH In review [email protected] 4 participants 6 messages Aug 16, 2021 – Aug 17, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm, slub: add cpus_read_lock/unlock() for slab_mem_going_offline_callback()

From: "Qiang.Zhang" <[email protected]>

The flush_all_cpus_locked() should be called with cpus_read_lock/unlock(), ensure flush_cpu_slab() can be executed on schedule_on CPU.

Fixes 1c84f3c91640 ("mm, slub: fix memory and cpu hotplug related lock ordering issues")
---
 mm/slub.c | 2 ++
 1 file changed, 2 insertions(+)
mm/slub.c +2 -0
index 5543d57cb128..cf3f93abbd3e 100644
@@ -4593,12 +4593,14 @@ static int slab_mem_going_offline_callback(void *arg)
 {
 	struct kmem_cache *s;
 
+	cpus_read_lock();
 	mutex_lock(&slab_mutex);
 	list_for_each_entry(s, &slab_caches, list) {
 		flush_all_cpus_locked(s);
 		__kmem_cache_do_shrink(s);
 	}
 	mutex_unlock(&slab_mutex);
+	cpus_read_unlock();
 
 	return 0;
 }
Signature · 1 line
2.17.1
#1 lore raw
Quoted 6 lines · On 16.08.21 09:46, [email protected] wrote:

From: "Qiang.Zhang" <[email protected]>

The flush_all_cpus_locked() should be called with cpus_read_lock/unlock(), ensure flush_cpu_slab() can be executed on schedule_on CPU.

Fixes 1c84f3c91640 ("mm, slub: fix memory and cpu hotplug related lock ordering issues")

Which branch contains this commit? At least not linux.git or linux-next

Quoted 15 lines
---
  mm/slub.c | 2 ++
  1 file changed, 2 insertions(+)
mm/slub.c +1 -0
index 5543d57cb128..cf3f93abbd3e 100644
@@ -4593,12 +4593,14 @@ static int slab_mem_going_offline_callback(void *arg)
  {
  	struct kmem_cache *s;
 
+	cpus_read_lock();

mm/slub.c static int slab_mem_going_offline_callback(void *arg) · line 4606

Quoted 10 lines
mm/slub.c +1 -0
  	mutex_lock(&slab_mutex);
  	list_for_each_entry(s, &slab_caches, list) {
  		flush_all_cpus_locked(s);
  		__kmem_cache_do_shrink(s);
  	}
  	mutex_unlock(&slab_mutex);
+	cpus_read_unlock();
 
  	return 0;
  }

Memory notifiers are getting called from online_pages()/offline_pages(), where we call memory_notify(MEM_GOING_OFFLINE, &arg) under mem_hotplug_begin().

mem_hotplug_begin() does a cpus_read_lock().

How does this even work or against which branch is this?

Signature · 3 lines
Thanks,

David / dhildenb
#2 lore raw

________________________________________
From: David Hildenbrand <[email protected]>
Sent: Monday, 16 August 2021 16:04
To: Zhang, Qiang; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] mm, slub: add cpus_read_lock/unlock() for slab_mem_going_offline_callback()

[Please note: This e-mail is from an EXTERNAL e-mail address]

Quoted 35 lines · On 16.08.21 09:46, [email protected] wrote:

From: "Qiang.Zhang" <[email protected]>

The flush_all_cpus_locked() should be called with cpus_read_lock/unlock(), ensure flush_cpu_slab() can be executed on schedule_on CPU.

Fixes 1c84f3c91640 ("mm, slub: fix memory and cpu hotplug related lock ordering issues")

Which branch contains this commit? At least not linux.git or linux-next

---
  mm/slub.c | 2 ++
  1 file changed, 2 insertions(+)
mm/slub.c +2 -0
index 5543d57cb128..cf3f93abbd3e 100644
@@ -4593,12 +4593,14 @@ static int slab_mem_going_offline_callback(void *arg)
  {
      struct kmem_cache *s;
 
+     cpus_read_lock();
      mutex_lock(&slab_mutex);
      list_for_each_entry(s, &slab_caches, list) {
              flush_all_cpus_locked(s);
              __kmem_cache_do_shrink(s);
      }
      mutex_unlock(&slab_mutex);
+     cpus_read_unlock();
 
      return 0;
  }
Quoted 5 lines

Memory notifiers are getting called from online_pages()/offline_pages(), where we call memory_notify(MEM_GOING_OFFLINE, &arg) under mem_hotplug_begin().

mem_hotplug_begin() does a cpus_read_lock().

Thanks David
this is my mistake, sorry make noise.

Quoted 7 lines

How does this even work or against which branch is this?

--
Thanks,

David / dhildenb

#3 lore raw
In reply to David Hildenbrand

Hi David,

Quoted 10 lines · On Mon, 16 Aug 2021 10:04:13 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 6 lines · On 16.08.21 09:46, [email protected] wrote:

From: "Qiang.Zhang" <[email protected]>

The flush_all_cpus_locked() should be called with cpus_read_lock/unlock(), ensure flush_cpu_slab() can be executed on schedule_on CPU.

Fixes 1c84f3c91640 ("mm, slub: fix memory and cpu hotplug related lock ordering issues")

Which branch contains this commit? At least not linux.git or linux-next

It is Andrew's mmotm which is included in linux-next but gets rebased often, so, for example, that SHA1 is no longer valid in linux-next today (is is now fd917c6407fb).

This (unfortunately) make Fixes tags less useful for mmotm :-(

Signature · 2 lines
Cheers,
Stephen Rothwell
#4 lore raw
Quoted 7 lines · Stephen Rothwell

Hi David,

Quoted 4 lines · On Mon, 16 Aug 2021 10:04:13 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 2 lines · On 16.08.21 09:46, [email protected] wrote:

From: "Qiang.Zhang" <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

The flush_all_cpus_locked() should be called with cpus_read_lock/unlock(), ensure flush_cpu_slab() can be executed on schedule_on CPU.

Fixes 1c84f3c91640 ("mm, slub: fix memory and cpu hotplug related lock ordering issues")

Which branch contains this commit? At least not linux.git or linux-next

It is Andrew's mmotm which is included in linux-next but gets rebased

Maybe I am blind or need more coffee:

https://www.ozlabs.org/~akpm/mmotm/series

Quoted 4 lines

often, so, for example, that SHA1 is no longer valid in linux-next today (is is now fd917c6407fb).

This (unfortunately) make Fixes tags less useful for mmotm :-(

Right, and it somewhat makes sense, because Andrew will actually squash patches before sending them further upstream.

Ideally, such fixes should be discussed in the respective patch series, because before they go upstream, they are still under development.

Signature · 3 lines
Thanks,

David / dhildenb
#5 lore raw
In reply to David Hildenbrand
Quoted 6 lines · David Hildenbrand
Quoted 5 lines · On 16.08.21 09:46, [email protected] wrote:

From: "Qiang.Zhang" <[email protected]>

The flush_all_cpus_locked() should be called with cpus_read_lock/unlock(), ensure flush_cpu_slab() can be executed on schedule_on CPU.

Quoted 6 lines
Quoted 1 line
Fixes 1c84f3c91640 ("mm, slub: fix memory and cpu hotplug related lock ordering issues")

Memory notifiers are getting called from online_pages()/offline_pages(), where we call memory_notify(MEM_GOING_OFFLINE, &arg) under mem_hotplug_begin().

mem_hotplug_begin() does a cpus_read_lock().

Exactly. Also flush_all_cpus_locked() has a lockdep assert for cpus_read_lock() which doesn't trigger in testing.

Quoted 2 lines

How does this even work or against which branch is this?