linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Revert "mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"
@ 2016-03-30 10:22 He Kuang
  2016-03-30 10:38 ` Mel Gorman
  0 siblings, 1 reply; 7+ messages in thread
From: He Kuang @ 2016-03-30 10:22 UTC (permalink / raw)
  To: akpm, mgorman, mhocko, vbabka, rientjes, cody
  Cc: gilad, kosaki.motohiro, mgorman, penberg, lizefan, wangnan0,
	hekuang, linux-mm, linux-kernel

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.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 mm/page_alloc.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 59de90d..4575b82 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -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:
-- 
1.8.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] Revert "mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"
  2016-03-30 10:22 [PATCH] Revert "mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE" He Kuang
@ 2016-03-30 10:38 ` Mel Gorman
  2016-03-30 10:51   ` Hekuang
  0 siblings, 1 reply; 7+ messages in thread
From: Mel Gorman @ 2016-03-30 10:38 UTC (permalink / raw)
  To: He Kuang
  Cc: akpm, mhocko, vbabka, rientjes, cody, gilad, kosaki.motohiro,
	mgorman, penberg, lizefan, wangnan0, linux-mm, linux-kernel

On Wed, Mar 30, 2016 at 10:22:07AM +0000, He Kuang wrote:
> 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?

-- 
Mel Gorman
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Revert "mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"
  2016-03-30 10:38 ` Mel Gorman
@ 2016-03-30 10:51   ` Hekuang
  2016-03-30 11:10     ` Michal Hocko
  0 siblings, 1 reply; 7+ messages in thread
From: Hekuang @ 2016-03-30 10:51 UTC (permalink / raw)
  To: Mel Gorman
  Cc: akpm, mhocko, vbabka, rientjes, cody, gilad, kosaki.motohiro,
	mgorman, penberg, lizefan, wangnan0, linux-mm, linux-kernel

hi

a?? 2016/3/30 18:38, Mel Gorman a??e??:
> On Wed, Mar 30, 2016 at 10:22:07AM +0000, He Kuang wrote:
>> 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 majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Revert "mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"
  2016-03-30 10:51   ` Hekuang
@ 2016-03-30 11:10     ` Michal Hocko
  2016-03-31  1:14       ` Hekuang
  0 siblings, 1 reply; 7+ messages in thread
From: Michal Hocko @ 2016-03-30 11:10 UTC (permalink / raw)
  To: Hekuang
  Cc: Mel Gorman, akpm, vbabka, rientjes, cody, gilad, kosaki.motohiro,
	mgorman, penberg, lizefan, wangnan0, linux-mm, linux-kernel

On Wed 30-03-16 18:51:12, Hekuang wrote:
> hi
> 
> a?? 2016/3/30 18:38, Mel Gorman a??e??:
> >On Wed, Mar 30, 2016 at 10:22:07AM +0000, He Kuang wrote:
> >>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.

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.

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Revert "mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"
  2016-03-30 11:10     ` Michal Hocko
@ 2016-03-31  1:14       ` Hekuang
  2016-03-31  1:39         ` Zefan Li
  0 siblings, 1 reply; 7+ messages in thread
From: Hekuang @ 2016-03-31  1:14 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Mel Gorman, akpm, vbabka, rientjes, cody, gilad, kosaki.motohiro,
	mgorman, penberg, lizefan, wangnan0, linux-mm, linux-kernel

Hi

a?? 2016/3/30 19:10, Michal Hocko a??e??:
> On Wed 30-03-16 18:51:12, Hekuang wrote:
>> hi
>>
>> a?? 2016/3/30 18:38, Mel Gorman a??e??:
>>> On Wed, Mar 30, 2016 at 10:22:07AM +0000, He Kuang wrote:
>>>> 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.
> 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 :)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Revert "mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"
  2016-03-31  1:14       ` Hekuang
@ 2016-03-31  1:39         ` Zefan Li
  2016-03-31  1:47           ` Hekuang
  0 siblings, 1 reply; 7+ messages in thread
From: Zefan Li @ 2016-03-31  1:39 UTC (permalink / raw)
  To: Hekuang, Michal Hocko
  Cc: Mel Gorman, akpm, vbabka, rientjes, cody, gilad, kosaki.motohiro,
	mgorman, penberg, wangnan0, linux-mm, linux-kernel

On 2016/3/31 9:14, Hekuang wrote:
> Hi
> 
> a?? 2016/3/30 19:10, Michal Hocko a??e??:
>> On Wed 30-03-16 18:51:12, Hekuang wrote:
>>> hi
>>>
>>> a?? 2016/3/30 18:38, Mel Gorman a??e??:
>>>> On Wed, Mar 30, 2016 at 10:22:07AM +0000, He Kuang wrote:
>>>>> 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.
>> 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 :)
> 

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 majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Revert "mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE"
  2016-03-31  1:39         ` Zefan Li
@ 2016-03-31  1:47           ` Hekuang
  0 siblings, 0 replies; 7+ messages in thread
From: Hekuang @ 2016-03-31  1:47 UTC (permalink / raw)
  To: Zefan Li, Michal Hocko
  Cc: Mel Gorman, akpm, vbabka, rientjes, cody, gilad, kosaki.motohiro,
	mgorman, penberg, wangnan0, linux-mm, linux-kernel

hi

a?? 2016/3/31 9:39, Zefan Li a??e??:
> On 2016/3/31 9:14, Hekuang wrote:
>> Hi
>>
>> a?? 2016/3/30 19:10, Michal Hocko a??e??:
>>> On Wed 30-03-16 18:51:12, Hekuang wrote:
>>>> hi
>>>>
>>>> a?? 2016/3/30 18:38, Mel Gorman a??e??:
>>>>> On Wed, Mar 30, 2016 at 10:22:07AM +0000, He Kuang wrote:
>>>>>> 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.
>>> 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 :)
>>
> 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 majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-03-31  1:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-30 10:22 [PATCH] Revert "mm/page_alloc: protect pcp->batch accesses with ACCESS_ONCE" He Kuang
2016-03-30 10:38 ` Mel Gorman
2016-03-30 10:51   ` Hekuang
2016-03-30 11:10     ` Michal Hocko
2016-03-31  1:14       ` Hekuang
2016-03-31  1:39         ` Zefan Li
2016-03-31  1:47           ` Hekuang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).