diff mbox series

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

Message ID 20210816074605.30336-1-qiang.zhang@windriver.com (mailing list archive)
State New
Headers show
Series mm, slub: add cpus_read_lock/unlock() for slab_mem_going_offline_callback() | expand

Commit Message

Zhang, Qiang Aug. 16, 2021, 7:46 a.m. UTC
From: "Qiang.Zhang" <qiang.zhang@windriver.com>

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")
Signed-off-by: Qiang.Zhang <qiang.zhang@windriver.com>
---
 mm/slub.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

David Hildenbrand Aug. 16, 2021, 8:04 a.m. UTC | #1
On 16.08.21 09:46, qiang.zhang@windriver.com wrote:
> From: "Qiang.Zhang" <qiang.zhang@windriver.com>
> 
> 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

> Signed-off-by: Qiang.Zhang <qiang.zhang@windriver.com>
> ---
>   mm/slub.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 5543d57cb128..cf3f93abbd3e 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -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;
>   }
> 

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?
Stephen Rothwell Aug. 16, 2021, 8:17 a.m. UTC | #2
Hi David,

On Mon, 16 Aug 2021 10:04:13 +0200 David Hildenbrand <david@redhat.com> wrote:
>
> On 16.08.21 09:46, qiang.zhang@windriver.com wrote:
> > From: "Qiang.Zhang" <qiang.zhang@windriver.com>
> > 
> > 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 :-(
David Hildenbrand Aug. 16, 2021, 8:23 a.m. UTC | #3
On 16.08.21 10:17, Stephen Rothwell wrote:
> Hi David,
> 
> On Mon, 16 Aug 2021 10:04:13 +0200 David Hildenbrand <david@redhat.com> wrote:
>>
>> On 16.08.21 09:46, qiang.zhang@windriver.com wrote:
>>> From: "Qiang.Zhang" <qiang.zhang@windriver.com>
>>>
>>> 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

> 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.
Vlastimil Babka Aug. 17, 2021, 7:57 a.m. UTC | #4
On 8/16/21 10:04 AM, David Hildenbrand wrote:
> On 16.08.21 09:46, qiang.zhang@windriver.com wrote:
>> From: "Qiang.Zhang" <qiang.zhang@windriver.com>
>>
>> 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")
> 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.

> How does this even work or against which branch is this?
>
diff mbox series

Patch

diff --git a/mm/slub.c b/mm/slub.c
index 5543d57cb128..cf3f93abbd3e 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -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;
 }