mm/page_alloc: remove repetitious local_irq_save() in __zone_pcp_update()
Subsystems (2)
PATCH 1/1 mm/page_alloc: remove repetitious local_irq_save() in __zone_pcp_update()
__zone_pcp_update() is called via stop_machine(), which already disables local irq.
--- mm/page_alloc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
mm/page_alloc.c +1 -3
@@ -6179,7 +6179,7 @@ static int __meminit __zone_pcp_update(void *data) {struct zone *zone = data;int cpu; -unsigned long batch =zone_batchsize (zone), flags; +unsigned long batch =zone_batchsize (zone);for_each_possible_cpu (cpu) {struct per_cpu_pageset *pset;
@@ -6188,12 +6188,10 @@ static int __meminit __zone_pcp_update(void *data) pset =per_cpu_ptr (zone->pageset, cpu); pcp = &pset->pcp; -local_irq_save (flags);if (pcp->count >0 )free_pcppages_bulk (zone, pcp->count, pcp);drain_zonestat (zone, pset);setup_pageset (pset, batch); -local_irq_restore (flags); }return 0 ; }
Signature · 7 lines
1.8.3.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 4 lines · Cody P Schafer
__zone_pcp_update()is called viastop_machine(), which already disables local irq.Signed-off-by Cody P Schafer <[email protected]>
Regards,
Srivatsa S. Bhat
Quoted 21 lines
--- mm/page_alloc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)mm/page_alloc.c +1
-1@@ -6179,7 +6179,7 @@ static int __meminit __zone_pcp_update(void *data) {struct zone *zone = data;int cpu; -unsigned long batch =zone_batchsize (zone), flags; +unsigned long batch =zone_batchsize (zone);for_each_possible_cpu (cpu) {struct per_cpu_pageset *pset;@@ -6188,12 +6188,10 @@ static int __meminit __zone_pcp_update(void *data) pset =per_cpu_ptr (zone->pageset, cpu); pcp = &pset->pcp;
mm/page_alloc.c static int __meminit __zone_pcp_update(void *data) · line 6197
Quoted 10 lines
mm/page_alloc.c +0
-2-local_irq_save (flags);if (pcp->count >0 )free_pcppages_bulk (zone, pcp->count, pcp);drain_zonestat (zone, pset);setup_pageset (pset, batch); -local_irq_restore (flags); }return 0 ; }
--
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 7 lines · Srivatsa S. Bhat
Quoted 4 lines
__zone_pcp_update()is called viastop_machine(), which already disables local irq.Signed-off-by Cody P Schafer <[email protected]>Reviewed-by Srivatsa S. Bhat <[email protected]>
What was reviewed?
Quoted 21 lines
Quoted 21 lines
--- mm/page_alloc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)mm/page_alloc.c +1
-1@@ -6179,7 +6179,7 @@ static int __meminit __zone_pcp_update(void *data) {struct zone *zone = data;int cpu; -unsigned long batch =zone_batchsize (zone), flags; +unsigned long batch =zone_batchsize (zone);for_each_possible_cpu (cpu) {struct per_cpu_pageset *pset;@@ -6188,12 +6188,10 @@ static int __meminit __zone_pcp_update(void *data) pset =per_cpu_ptr (zone->pageset, cpu); pcp = &pset->pcp;
Quoted 6 lines
mm/page_alloc.c static int __meminit __zone_pcp_update(void *data) · line 6196
Quoted 6 lines
mm/page_alloc.c +0
-2-local_irq_save (flags);if (pcp->count >0 )free_pcppages_bulk (zone, pcp->count, pcp);drain_zonestat (zone, pset);setup_pageset (pset, batch); -local_irq_restore (flags);
This seems like a fine cleanup because stop_machine() disable irqs, but it appears like there is two problems with this function already:
- it's doing for_each_possible_cpu() internally, why? local_irq_save() works on the local cpu and won't protect per_cpu_ptr(zone->pageset, cpu)->pcp of some random cpu, and
- setup_pageset() is what is ultimately responsible for doing pcp->count = 0 after free_pcppages_bulk(), but what happens if pcp->count is read in between the two on the cpu that has not disabled irqs?
You can't just do
for_each_possible_cpu(cpu) {
unsigned long flags;
local_irq_save(flags);
...
local_irq_restore(flags);
}This is just disabling irqs locally over and over again, not on the cpu you're manipulating in its per-cpu critical section.
I don't think we hit this because onlining and offlining memory isn't a very common operation, but it doesn't change the fact that it's broken.
Quoted 4 lines
mm/page_alloc.c static int __meminit __zone_pcp_update(void *data) · line 6197
Quoted 4 lines
mm/page_alloc.c +0
-0}return 0 ; }
--
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 11 lines · David Rientjes
Quoted 5 lines · Srivatsa S. Bhat
Quoted 5 lines
__zone_pcp_update()is called viastop_machine(), which already disables local irq.mm/page_alloc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)This seems like a fine cleanup because
stop_machine()disable irqs, but it appears like there is two problems with this function already:
Re-examining this, I've realized that my previous patchset containing
"mm/page_alloc: convert zone_pcp_update() to rely on memory barriers
instead of stop_machine()"
already went through and fixed this up (the right way). So ignore this patch.
--
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 6 lines · Cody P Schafer
Re-examining this, I've realized that my previous patchset containing
"mm/page_alloc: convertzone_pcp_update()to rely on memory barriers
instead ofstop_machine()"already went through and fixed this up (the right way). So ignore this patch.
If you're referring to
mm-page_alloc-factor-out-setting-of-pcp-high-and-pcp-batch.patch mm-page_alloc-prevent-concurrent-updaters-of-pcp-batch-and-high.patch mm-page_alloc-insert-memory-barriers-to-allow-async-update-of-pcp-batch-and-high.patch mm-page_alloc-protect-pcp-batch-accesses-with-access_once.patch mm-page_alloc-convert-zone_pcp_update-to-rely-on-memory-barriers-instead-of-stop_machine.patch mm-page_alloc-when-handling-percpu_pagelist_fraction-dont-unneedly-recalulate-high.patch mm-page_alloc-factor-setup_pageset-into-pageset_init-and-pageset_set_batch.patch mm-page_alloc-relocate-comment-to-be-directly-above-code-it-refers-to.patch mm-page_alloc-factor-zone_pageset_init-out-of-setup_zone_pageset.patch mm-page_alloc-in-zone_pcp_update-uze-zone_pageset_init.patch mm-page_alloc-rename-setup_pagelist_highmark-to-match-naming-of-pageset_set_batch.patch
from -mm then I'll review them separately because they have their own issues. Thanks.
--
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 23 lines · David Rientjes
Quoted 6 lines · Cody P Schafer
Re-examining this, I've realized that my previous patchset containing
"mm/page_alloc: convertzone_pcp_update()to rely on memory barriers
instead ofstop_machine()"already went through and fixed this up (the right way). So ignore this patch.
If you're referring to
mm-page_alloc-factor-out-setting-of-pcp-high-and-pcp-batch.patch mm-page_alloc-prevent-concurrent-updaters-of-pcp-batch-and-high.patch mm-page_alloc-insert-memory-barriers-to-allow-async-update-of-pcp-batch-and-high.patch mm-page_alloc-protect-pcp-batch-accesses-with-access_once.patch mm-page_alloc-convert-zone_pcp_update-to-rely-on-memory-barriers-instead-of-stop_machine.patch mm-page_alloc-when-handling-percpu_pagelist_fraction-dont-unneedly-recalulate-high.patch mm-page_alloc-factor-setup_pageset-into-pageset_init-and-pageset_set_batch.patch mm-page_alloc-relocate-comment-to-be-directly-above-code-it-refers-to.patch mm-page_alloc-factor-zone_pageset_init-out-of-setup_zone_pageset.patch mm-page_alloc-in-zone_pcp_update-uze-zone_pageset_init.patch mm-page_alloc-rename-setup_pagelist_highmark-to-match-naming-of-pageset_set_batch.patch
Quoted 3 lines
from -mm then I'll review them separately because they have their own issues. Thanks.
I am. You may also want to note mm-page_alloc-dont-re-init-pageset-in-zone_pcp_update.patch
which fixes a bug in that patchset.
--
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 5 lines · David Rientjes
Quoted 3 lines · Srivatsa S. Bhat
Quoted 3 lines
__zone_pcp_update()is called viastop_machine(), which already disables local irq.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Cody P Schafer <[email protected]>Reviewed-by Srivatsa S. Bhat <[email protected]>What was reviewed?
See below.
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
--- mm/page_alloc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)mm/page_alloc.c +1
-1@@ -6179,7 +6179,7 @@ static int __meminit __zone_pcp_update(void *data) {struct zone *zone = data;int cpu; -unsigned long batch =zone_batchsize (zone), flags; +unsigned long batch =zone_batchsize (zone);for_each_possible_cpu (cpu) {struct per_cpu_pageset *pset;@@ -6188,12 +6188,10 @@ static int __meminit __zone_pcp_update(void *data) pset =per_cpu_ptr (zone->pageset, cpu); pcp = &pset->pcp;
Quoted 8 lines
Quoted 6 lines
mm/page_alloc.c static int __meminit __zone_pcp_update(void *data) · line 6196
Quoted 6 lines
mm/page_alloc.c +0
-2-local_irq_save (flags);if (pcp->count >0 )free_pcppages_bulk (zone, pcp->count, pcp);drain_zonestat (zone, pset);setup_pageset (pset, batch); -local_irq_restore (flags);This seems like a fine cleanup because
stop_machine()disable irqs,
I hope you are not missing the fact that stop_machine() disables irqs on *all* CPUs.
Quoted 7 lines
but it
appears like there is two problems with this function already:- it's doing
for_each_possible_cpu()internally, why?local_irq_save()works on the local cpu and won't protectper_cpu_ptr(zone->pageset, cpu)->pcp of some random cpu, and
stop_machine() allows only _your function_ to run and nothing else, on the entire system. All other CPUs loop with interrupts disabled until the function is completed.
Quoted 5 lines
-
setup_pageset()is what is ultimately responsible for doingpcp->count= 0 afterfree_pcppages_bulk(), but what happens ifpcp->countis read in between the two on the cpu that has not disabled irqs?
Nobody can do anything else when this function runs. That's precisely why its named as stop-*machine*.
Quoted 10 lines
You can't just do
for_each_possible_cpu(cpu) { unsigned long flags; local_irq_save(flags); ... local_irq_restore(flags); }
Quoted 3 lines
This is just disabling irqs locally over and over again, not on the cpu you're manipulating in its per-cpu critical section.
stop-machine() takes care of disabling irqs on every online CPU.
Quoted 3 lines
I don't think we hit this because onlining and offlining memory isn't a very common operation, but it doesn't change the fact that it's broken.
If __zone_pcp_update() is called only from stop_machine() (and looking at the current code, that's true), then there is no problem, due to the reasons explained above.
Regards,
Srivatsa S. Bhat
--
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>