Skip to contentSkip to conversation

Revert "mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"

PATCH In review He Kuang 4 participants 7 messages Mar 30, 2016 – Mar 31, 2016

Subsystems (2)
lore
Share & tools
lore

He Kuang

author
#0 lore raw

PATCH 1/1 Revert "mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"

This reverts commit 998d39cb236fe464af86a3492a24d2f67ee1efc2.

When local irq is disabled, a percpu variable does not change, so we can remove the access macros and let the compiler optimize the code safely.

---
 mm/page_alloc.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
mm/page_alloc.c +4 -6
index 59de90d..4575b82 100644
@@ -2015,11 +2015,10 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
 void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp)
 {
 	unsigned long flags;
-	int to_drain, batch;
+	int to_drain;
 
 	local_irq_save(flags);
-	batch = READ_ONCE(pcp->batch);
-	to_drain = min(pcp->count, batch);
+	to_drain = min(pcp->count, pcp->batch);
 	if (to_drain > 0) {
 		free_pcppages_bulk(zone, to_drain, pcp);
 		pcp->count -= to_drain;
@@ -2217,9 +2216,8 @@ void free_hot_cold_page(struct page *page, bool cold)
 		list_add_tail(&page->lru, &pcp->lists[migratetype]);
 	pcp->count++;
 	if (pcp->count >= pcp->high) {
-		unsigned long batch = READ_ONCE(pcp->batch);
-		free_pcppages_bulk(zone, batch, pcp);
-		pcp->count -= batch;
+		free_pcppages_bulk(zone, pcp->batch, pcp);
+		pcp->count -= pcp->batch;
 	}
 
 out:
Signature · 1 line
1.8.5.2
#1 lore raw
Quoted 5 lines · He Kuang

This reverts commit 998d39cb236fe464af86a3492a24d2f67ee1efc2.

When local irq is disabled, a percpu variable does not change, so we can remove the access macros and let the compiler optimize the code safely.

batch can be changed from other contexts. Why is this safe?

Signature · 8 lines
Mel Gorman
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>
author
#2 lore raw

hi

a?? 2016/3/30 18:38, Mel Gorman a??e??:

Quoted 8 lines · He Kuang
Quoted 5 lines

This reverts commit 998d39cb236fe464af86a3492a24d2f67ee1efc2.

When local irq is disabled, a percpu variable does not change, so we can remove the access macros and let the compiler optimize the code safely.

batch can be changed from other contexts. Why is this safe?

I've mistakenly thought that per_cpu variable can only be accessed by that cpu. 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>

#3 lore raw
Quoted 6 lines · Hekuang

hi

a?? 2016/3/30 18:38, Mel Gorman a??e??:

Quoted 3 lines · He Kuang
Quoted 2 lines

This reverts commit 998d39cb236fe464af86a3492a24d2f67ee1efc2.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

When local irq is disabled, a percpu variable does not change, so we can remove the access macros and let the compiler optimize the code safely.

batch can be changed from other contexts. Why is this safe?

I've mistakenly thought that per_cpu variable can only be accessed by that cpu.

git blame would point you to 998d39cb236f ("mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"). I haven't looked into the code deeply to confirm this is still the case but it would be a good lead that this is not that simple. ACCESS_ONCE resp. {READ,WRITE}_ONCE are usually quite subtle so I would encourage you or anybody else who try to remove them to study the code and the history deeper before removing them.

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>
author
#4 lore raw

Hi

Quoted 14 lines · Michal Hocko
Quoted 6 lines · Hekuang

hi

Quoted 3 lines · Mel Gorman
Quoted 2 lines · He Kuang

This reverts commit 998d39cb236fe464af86a3492a24d2f67ee1efc2.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

When local irq is disabled, a percpu variable does not change, so we can remove the access macros and let the compiler optimize the code safely.

batch can be changed from other contexts. Why is this safe?

I've mistakenly thought that per_cpu variable can only be accessed by that cpu.

Quoted 8 lines

git blame would point you to 998d39cb236f ("mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"). I haven't looked into the code deeply to confirm this is still the case but it would be a good lead that this is not that simple. ACCESS_ONCE resp. {READ,WRITE}_ONCE are usually quite subtle so I would encourage you or anybody else who try to remove them to study the code and the history deeper before removing them.

Thank you for responding, I've read that commit and related articles and not sending mail casually, though you may think it's a stupid patch. I'm a beginner and I think sending mails to maillist is a effective way to learn kernel, And, sure i'll be more careful and well prepared next time :)

#5 lore raw
Quoted 25 lines · Hekuang

Hi

a?? 2016/3/30 19:10, Michal Hocko a??e??:

Quoted 14 lines · Hekuang
Quoted 6 lines

hi

a?? 2016/3/30 18:38, Mel Gorman a??e??:

Quoted 3 lines · He Kuang
Quoted 2 lines

This reverts commit 998d39cb236fe464af86a3492a24d2f67ee1efc2.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

When local irq is disabled, a percpu variable does not change, so we can remove the access macros and let the compiler optimize the code safely.

batch can be changed from other contexts. Why is this safe?

I've mistakenly thought that per_cpu variable can only be accessed by that cpu.

Quoted 8 lines

git blame would point you to 998d39cb236f ("mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"). I haven't looked into the code deeply to confirm this is still the case but it would be a good lead that this is not that simple. ACCESS_ONCE resp. {READ,WRITE}_ONCE are usually quite subtle so I would encourage you or anybody else who try to remove them to study the code and the history deeper before removing them.

Quoted 5 lines

Thank you for responding, I've read that commit and related articles and not sending mail casually, though you may think it's a stupid patch. I'm a beginner and I think sending mails to maillist is a effective way to learn kernel, And, sure i'll be more careful and well prepared next time :)

pcp->batch can be changed in a different cpu. You may read percpu_pagelist_fraction_sysctl_handler() to see how that can happen.

--
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>

author
#6 lore raw

hi

a?? 2016/3/31 9:39, Zefan Li a??e??:

Quoted 26 lines · Hekuang
Quoted 25 lines

Hi

a?? 2016/3/30 19:10, Michal Hocko a??e??:

Quoted 22 lines · Hekuang
Quoted 6 lines

hi

a?? 2016/3/30 18:38, Mel Gorman a??e??:

Quoted 3 lines · He Kuang
Quoted 2 lines

This reverts commit 998d39cb236fe464af86a3492a24d2f67ee1efc2.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

When local irq is disabled, a percpu variable does not change, so we can remove the access macros and let the compiler optimize the code safely.

batch can be changed from other contexts. Why is this safe?

I've mistakenly thought that per_cpu variable can only be accessed by that cpu.

git blame would point you to 998d39cb236f ("mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"). I haven't looked into the code deeply to confirm this is still the case but it would be a good lead that this is not that simple. ACCESS_ONCE resp. {READ,WRITE}_ONCE are usually quite subtle so I would encourage you or anybody else who try to remove them to study the code and the history deeper before removing them.

Quoted 9 lines
Quoted 5 lines

Thank you for responding, I've read that commit and related articles and not sending mail casually, though you may think it's a stupid patch. I'm a beginner and I think sending mails to maillist is a effective way to learn kernel, And, sure i'll be more careful and well prepared next time :)

pcp->batch can be changed in a different cpu. You may read percpu_pagelist_fraction_sysctl_handler() to see how that can happen.

OK. got it!

--
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>