mm, swap: don't disable preemption while taking the per-CPU cache
RFC PATCH 1/1 mm, swap: don't disable preemption while taking the per-CPU cache
get_cpu_var() disables preemption and returns the per-CPU version of the variable. Disabling preemption is useful to ensure atomic access to the variable within the critical section.
In this case however, after the per-CPU version of the variable is obtained the ->free_lock is acquired. For that reason it seems the raw accessor could be used. It only seems that ->slots_ret should be retested (because with disabled preemption this variable can not be set to NULL otherwise).
--- mm/swap_slots.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
mm/swap_slots.c +2 -3
@@ -272,11 +272,11 @@ int free_swap_slot(swp_entry_t entry) {struct swap_slots_cache *cache; - cache = &get_cpu_var (swp_slots); + cache =raw_cpu_ptr (&swp_slots);if (use_swap_slot_cache && cache->slots_ret) {spin_lock_irq (&cache->free_lock);/* Swap slots cache may be deactivated before acquiring lock */ -if (!use_swap_slot_cache) { +if (!use_swap_slot_cache || !cache->slots_ret) {spin_unlock_irq (&cache->free_lock); goto direct_free; }
@@ -296,7 +296,6 @@ int free_swap_slot(swp_entry_t entry) direct_free:swapcache_free_entries (&entry,1 ); } -put_cpu_var (swp_slots);return 0 ; }
Signature · 7 lines
2.13.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Sebastian Andrzej Siewior
get_cpu_var()disables preemption and returns the per-CPU version of the variable. Disabling preemption is useful to ensure atomic access to the variable within the critical section.
In this case however, after the per-CPU version of the variable is obtained the ->free_lock is acquired. For that reason it seems the raw accessor could be used. It only seems that ->slots_ret should be retested (because with disabled preemption this variable can not be set to NULL otherwise).
The changelog doesn't explain, why does this change matter. Disabling preemption shortly before taking a spinlock shouldn't make much difference. I suspect you care because of RT, right? In that case spell that in the changelog and explain why it matters.
Other than hat the patch looks good to me.
Quoted 34 lines
Signed-off-by Sebastian Andrzej Siewior <[email protected]>--- mm/swap_slots.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)mm/swap_slots.c +2
-3@@ -272,11 +272,11 @@ int free_swap_slot(swp_entry_t entry) {struct swap_slots_cache *cache; - cache = &get_cpu_var (swp_slots); + cache =raw_cpu_ptr (&swp_slots);if (use_swap_slot_cache && cache->slots_ret) {spin_lock_irq (&cache->free_lock);/* Swap slots cache may be deactivated before acquiring lock */ -if (!use_swap_slot_cache) { +if (!use_swap_slot_cache || !cache->slots_ret) {spin_unlock_irq (&cache->free_lock); goto direct_free; }@@ -296,7 +296,6 @@ int free_swap_slot(swp_entry_t entry) direct_free:swapcache_free_entries (&entry,1 ); } -put_cpu_var (swp_slots);return 0 ; }Signature · 1 line
2.13.1
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/1 mm, swap: don't disable preemption while taking the per-CPU cache
get_cpu_var() disables preemption and returns the per-CPU version of the variable. Disabling preemption is useful to ensure atomic access to the variable within the critical section.
In this case however, after the per-CPU version of the variable is obtained the ->free_lock is acquired. For that reason it seems the raw accessor could be used. It only seems that ->slots_ret should be retested (because with disabled preemption this variable can not be set to NULL otherwise).
This popped up during PREEMPT-RT testing because it tries to take spinlocks in a preempt disabled section.
---
Quoted 4 lines · Michal Hocko
The changelog doesn't explain, why does this change matter. Disabling preemption shortly before taking a spinlock shouldn't make much difference. I suspect you care because of RT, right? In that case spell that in the changelog and explain why it matters.
yes, it is bad for RT. I added the RT pieces as explanation.
Quoted 1 line
Other than hat the patch looks good to me.
Thank you. +akpm.
mm/swap_slots.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
mm/swap_slots.c +2 -3
@@ -272,11 +272,11 @@ int free_swap_slot(swp_entry_t entry) {struct swap_slots_cache *cache; - cache = &get_cpu_var (swp_slots); + cache =raw_cpu_ptr (&swp_slots);if (use_swap_slot_cache && cache->slots_ret) {spin_lock_irq (&cache->free_lock);/* Swap slots cache may be deactivated before acquiring lock */ -if (!use_swap_slot_cache) { +if (!use_swap_slot_cache || !cache->slots_ret) {spin_unlock_irq (&cache->free_lock); goto direct_free; }
@@ -296,7 +296,6 @@ int free_swap_slot(swp_entry_t entry) direct_free:swapcache_free_entries (&entry,1 ); } -put_cpu_var (swp_slots);return 0 ; }
Signature · 7 lines
2.13.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · Sebastian Andrzej Siewior
get_cpu_var()disables preemption and returns the per-CPU version of the variable. Disabling preemption is useful to ensure atomic access to the variable within the critical section.
In this case however, after the per-CPU version of the variable is obtained the ->free_lock is acquired. For that reason it seems the raw accessor could be used. It only seems that ->slots_ret should be retested (because with disabled preemption this variable can not be set to NULL otherwise).
This popped up during PREEMPT-RT testing because it tries to take spinlocks in a preempt disabled section.
Ohh, because the spinlock can sleep with PREEMPT-RT right? Don't we have much more places like that? It is perfectly valid to take a spinlock while the preemption is disabled. E.g. we do take ptl lock inside kmap_atomic sections which disables preemption on 32b systems.
Quoted 1 line
Signed-off-by Sebastian Andrzej Siewior <[email protected]>
Quoted 45 lines
---
Quoted 4 lines · Michal Hocko
The changelog doesn't explain, why does this change matter. Disabling preemption shortly before taking a spinlock shouldn't make much difference. I suspect you care because of RT, right? In that case spell that in the changelog and explain why it matters.
yes, it is bad for RT. I added the RT pieces as explanation.
Quoted 1 line
Other than hat the patch looks good to me.
Thank you. +akpm.
mm/swap_slots.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)mm/swap_slots.c +2
-3@@ -272,11 +272,11 @@ int free_swap_slot(swp_entry_t entry) {struct swap_slots_cache *cache; - cache = &get_cpu_var (swp_slots); + cache =raw_cpu_ptr (&swp_slots);if (use_swap_slot_cache && cache->slots_ret) {spin_lock_irq (&cache->free_lock);/* Swap slots cache may be deactivated before acquiring lock */ -if (!use_swap_slot_cache) { +if (!use_swap_slot_cache || !cache->slots_ret) {spin_unlock_irq (&cache->free_lock); goto direct_free; }@@ -296,7 +296,6 @@ int free_swap_slot(swp_entry_t entry) direct_free:swapcache_free_entries (&entry,1 ); } -put_cpu_var (swp_slots);return 0 ; }Signature · 1 line
2.13.1
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 12 lines · Michal Hocko
Quoted 10 lines · Sebastian Andrzej Siewior
get_cpu_var()disables preemption and returns the per-CPU version of the variable. Disabling preemption is useful to ensure atomic access to the variable within the critical section.
In this case however, after the per-CPU version of the variable is obtained the ->free_lock is acquired. For that reason it seems the raw accessor could be used. It only seems that ->slots_ret should be retested (because with disabled preemption this variable can not be set to NULL otherwise).
This popped up during PREEMPT-RT testing because it tries to take spinlocks in a preempt disabled section.
Quoted 1 line
Ohh, because the spinlock can sleep with PREEMPT-RT right? Don't we have
yup.
Quoted 1 line
much more places like that? It is perfectly valid to take a spinlock
well we have more than just this one patch to fix things like that :) The easy/simple things (like this one which is valid in RT and !RT) I try to push upstream asap and the other remain in the RT tree.
Quoted 2 lines
while the preemption is disabled. E.g. we do take ptl lock inside
kmap_atomicsections which disables preemption on 32b systems.
we don't disable preemption in kmap_atomic(). It would be bad :)
Quoted 3 lines
Quoted 1 line
Signed-off-by Sebastian Andrzej Siewior <[email protected]>Acked-by Michal Hocko <[email protected]>
Thanks.
Sebastian
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 13 lines · Sebastian Andrzej Siewior
Quoted 12 lines · Michal Hocko
Quoted 10 lines · Sebastian Andrzej Siewior
get_cpu_var()disables preemption and returns the per-CPU version of the variable. Disabling preemption is useful to ensure atomic access to the variable within the critical section.
In this case however, after the per-CPU version of the variable is obtained the ->free_lock is acquired. For that reason it seems the raw accessor could be used. It only seems that ->slots_ret should be retested (because with disabled preemption this variable can not be set to NULL otherwise).
This popped up during PREEMPT-RT testing because it tries to take spinlocks in a preempt disabled section.
Quoted 7 lines
Quoted 1 line
Ohh, because the spinlock can sleep with PREEMPT-RT right? Don't we have
yup.
Quoted 1 line
much more places like that? It is perfectly valid to take a spinlock
well we have more than just this one patch to fix things like that :) The easy/simple things (like this one which is valid in RT and !RT) I try to push upstream asap and the other remain in the RT tree.
yeah, makes sense to me.
Quoted 3 lines
Quoted 2 lines
while the preemption is disabled. E.g. we do take ptl lock inside
kmap_atomicsections which disables preemption on 32b systems.we don't disable preemption in
kmap_atomic(). It would be bad :)
Ohh, I didn't know about that.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Sebastian Andrzej Siewior <[email protected]>Acked-by Michal Hocko <[email protected]>Thanks.
Sebastian
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>