linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/huge_memory: prevent THP_ZERO_PAGE_ALLOC increased twice
@ 2022-09-05 13:38 Liu Shixin
  2022-09-05 20:07 ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Liu Shixin @ 2022-09-05 13:38 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Liu Shixin, Kefeng Wang

If two or more threads call get_huge_zero_page concurrently, THP_ZERO_PAGE_ALLOC
may increased two or more times. But actually, this should only count
as once since the extra zero pages has been freed.

Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 88d98241a635..5c83a424803a 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -163,7 +163,6 @@ static bool get_huge_zero_page(void)
 		count_vm_event(THP_ZERO_PAGE_ALLOC_FAILED);
 		return false;
 	}
-	count_vm_event(THP_ZERO_PAGE_ALLOC);
 	preempt_disable();
 	if (cmpxchg(&huge_zero_page, NULL, zero_page)) {
 		preempt_enable();
@@ -175,6 +174,7 @@ static bool get_huge_zero_page(void)
 	/* We take additional reference here. It will be put back by shrinker */
 	atomic_set(&huge_zero_refcount, 2);
 	preempt_enable();
+	count_vm_event(THP_ZERO_PAGE_ALLOC);
 	return true;
 }
 
-- 
2.25.1


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

* Re: [PATCH] mm/huge_memory: prevent THP_ZERO_PAGE_ALLOC increased twice
  2022-09-05 13:38 [PATCH] mm/huge_memory: prevent THP_ZERO_PAGE_ALLOC increased twice Liu Shixin
@ 2022-09-05 20:07 ` Andrew Morton
  2022-09-06  1:52   ` Liu Shixin
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2022-09-05 20:07 UTC (permalink / raw)
  To: Liu Shixin; +Cc: linux-mm, linux-kernel, Kefeng Wang

On Mon, 5 Sep 2022 21:38:13 +0800 Liu Shixin <liushixin2@huawei.com> wrote:

> If two or more threads call get_huge_zero_page concurrently, THP_ZERO_PAGE_ALLOC
> may increased two or more times. But actually, this should only count
> as once since the extra zero pages has been freed.

Well, for better of for worse,
Documentation/admin-guide/mm/transhuge.rst says

thp_zero_page_alloc
	is incremented every time a huge zero page is
	successfully allocated. It includes allocations which where
	dropped due race with other allocation. Note, it doesn't count
	every map of the huge zero page, only its allocation.

If you think this interprtation should be changed then please explain
why, and let's be sure to update the documentation accordingly.


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

* Re: [PATCH] mm/huge_memory: prevent THP_ZERO_PAGE_ALLOC increased twice
  2022-09-05 20:07 ` Andrew Morton
@ 2022-09-06  1:52   ` Liu Shixin
  2022-09-07 23:35     ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Liu Shixin @ 2022-09-06  1:52 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Kefeng Wang

On 2022/9/6 4:07, Andrew Morton wrote:
> On Mon, 5 Sep 2022 21:38:13 +0800 Liu Shixin <liushixin2@huawei.com> wrote:
>
>> If two or more threads call get_huge_zero_page concurrently, THP_ZERO_PAGE_ALLOC
>> may increased two or more times. But actually, this should only count
>> as once since the extra zero pages has been freed.
> Well, for better of for worse,
> Documentation/admin-guide/mm/transhuge.rst says
>
> thp_zero_page_alloc
> 	is incremented every time a huge zero page is
> 	successfully allocated. It includes allocations which where
> 	dropped due race with other allocation. Note, it doesn't count
> 	every map of the huge zero page, only its allocation.
>
> If you think this interprtation should be changed then please explain
> why, and let's be sure to update the documentation accordingly.
>
> .
Thanks for your explanation. I misunderstood the meaning of thp_zero_page_alloc before.
Although the rules are clearly explained in the documentation, I think that this variable
should only incremented when a huge zero page used for thp is successfully allocated and
the pages dropped due race should skip increment. It seems strange to count in all allocations.

If there's something I still misunderstand, please point it out, thanks.

Thanks,


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

* Re: [PATCH] mm/huge_memory: prevent THP_ZERO_PAGE_ALLOC increased twice
  2022-09-06  1:52   ` Liu Shixin
@ 2022-09-07 23:35     ` Andrew Morton
  2022-09-08  3:28       ` Liu Shixin
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2022-09-07 23:35 UTC (permalink / raw)
  To: Liu Shixin; +Cc: linux-mm, linux-kernel, Kefeng Wang

On Tue, 6 Sep 2022 09:52:23 +0800 Liu Shixin <liushixin2@huawei.com> wrote:

> On 2022/9/6 4:07, Andrew Morton wrote:
> > On Mon, 5 Sep 2022 21:38:13 +0800 Liu Shixin <liushixin2@huawei.com> wrote:
> >
> >> If two or more threads call get_huge_zero_page concurrently, THP_ZERO_PAGE_ALLOC
> >> may increased two or more times. But actually, this should only count
> >> as once since the extra zero pages has been freed.
> > Well, for better of for worse,
> > Documentation/admin-guide/mm/transhuge.rst says
> >
> > thp_zero_page_alloc
> > 	is incremented every time a huge zero page is
> > 	successfully allocated. It includes allocations which where
> > 	dropped due race with other allocation. Note, it doesn't count
> > 	every map of the huge zero page, only its allocation.
> >
> > If you think this interprtation should be changed then please explain
> > why, and let's be sure to update the documentation accordingly.
> >
> > .
> Thanks for your explanation. I misunderstood the meaning of thp_zero_page_alloc before.
> Although the rules are clearly explained in the documentation, I think that this variable
> should only incremented when a huge zero page used for thp is successfully allocated and
> the pages dropped due race should skip increment. It seems strange to count in all allocations.
> 
> If there's something I still misunderstand, please point it out, thanks.

It seems strange to me also.  Perhaps there's a rationale buried in the
git and mailing list history.


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

* Re: [PATCH] mm/huge_memory: prevent THP_ZERO_PAGE_ALLOC increased twice
  2022-09-07 23:35     ` Andrew Morton
@ 2022-09-08  3:28       ` Liu Shixin
  0 siblings, 0 replies; 5+ messages in thread
From: Liu Shixin @ 2022-09-08  3:28 UTC (permalink / raw)
  To: Andrew Morton, Kirill A . Shutemov; +Cc: linux-mm, linux-kernel, Kefeng Wang

On 2022/9/8 7:35, Andrew Morton wrote:
> On Tue, 6 Sep 2022 09:52:23 +0800 Liu Shixin <liushixin2@huawei.com> wrote:
>
>> On 2022/9/6 4:07, Andrew Morton wrote:
>>> On Mon, 5 Sep 2022 21:38:13 +0800 Liu Shixin <liushixin2@huawei.com> wrote:
>>>
>>>> If two or more threads call get_huge_zero_page concurrently, THP_ZERO_PAGE_ALLOC
>>>> may increased two or more times. But actually, this should only count
>>>> as once since the extra zero pages has been freed.
>>> Well, for better of for worse,
>>> Documentation/admin-guide/mm/transhuge.rst says
>>>
>>> thp_zero_page_alloc
>>> 	is incremented every time a huge zero page is
>>> 	successfully allocated. It includes allocations which where
>>> 	dropped due race with other allocation. Note, it doesn't count
>>> 	every map of the huge zero page, only its allocation.
>>>
>>> If you think this interprtation should be changed then please explain
>>> why, and let's be sure to update the documentation accordingly.
>>>
>>> .
>> Thanks for your explanation. I misunderstood the meaning of thp_zero_page_alloc before.
>> Although the rules are clearly explained in the documentation, I think that this variable
>> should only incremented when a huge zero page used for thp is successfully allocated and
>> the pages dropped due race should skip increment. It seems strange to count in all allocations.
>>
>> If there's something I still misunderstand, please point it out, thanks.
> It seems strange to me also.  Perhaps there's a rationale buried in the
> git and mailing list history.
>
> .
I didn't find previous discussion about this point. I update document in v2.
Kirill, what do you think about this change?

https://lore.kernel.org/linux-mm/20220908035533.2186159-1-liushixin2@huawei.com/


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

end of thread, other threads:[~2022-09-08  3:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 13:38 [PATCH] mm/huge_memory: prevent THP_ZERO_PAGE_ALLOC increased twice Liu Shixin
2022-09-05 20:07 ` Andrew Morton
2022-09-06  1:52   ` Liu Shixin
2022-09-07 23:35     ` Andrew Morton
2022-09-08  3:28       ` Liu Shixin

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