LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] mm: vmscan: correct nr_reclaimed for THP
@ 2019-05-10  0:16 Yang Shi
  2019-05-10  0:39 ` Shakeel Butt
  2019-05-10  2:12 ` Huang, Ying
  0 siblings, 2 replies; 16+ messages in thread
From: Yang Shi @ 2019-05-10  0:16 UTC (permalink / raw)
  To: ying.huang, hannes, mhocko, mgorman, kirill.shutemov, hughd, akpm
  Cc: yang.shi, linux-mm, linux-kernel

Since commit bd4c82c22c36 ("mm, THP, swap: delay splitting THP after
swapped out"), THP can be swapped out in a whole.  But, nr_reclaimed
still gets inc'ed by one even though a whole THP (512 pages) gets
swapped out.

This doesn't make too much sense to memory reclaim.  For example, direct
reclaim may just need reclaim SWAP_CLUSTER_MAX pages, reclaiming one THP
could fulfill it.  But, if nr_reclaimed is not increased correctly,
direct reclaim may just waste time to reclaim more pages,
SWAP_CLUSTER_MAX * 512 pages in worst case.

This change may result in more reclaimed pages than scanned pages showed
by /proc/vmstat since scanning one head page would reclaim 512 base pages.

Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
---
I'm not quite sure if it was the intended behavior or just omission. I tried
to dig into the review history, but didn't find any clue. I may miss some
discussion.

 mm/vmscan.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index fd9de50..7e026ec 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1446,7 +1446,11 @@ static unsigned long shrink_page_list(struct list_head *page_list,
 
 		unlock_page(page);
 free_it:
-		nr_reclaimed++;
+		/* 
+		 * THP may get swapped out in a whole, need account
+		 * all base pages.
+		 */
+		nr_reclaimed += (1 << compound_order(page));
 
 		/*
 		 * Is there need to periodically free_page_list? It would
-- 
1.8.3.1


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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10  0:16 [PATCH] mm: vmscan: correct nr_reclaimed for THP Yang Shi
@ 2019-05-10  0:39 ` Shakeel Butt
  2019-05-10  2:12 ` Huang, Ying
  1 sibling, 0 replies; 16+ messages in thread
From: Shakeel Butt @ 2019-05-10  0:39 UTC (permalink / raw)
  To: Yang Shi
  Cc: Huang Ying, Johannes Weiner, Michal Hocko, Mel Gorman,
	Kirill A. Shutemov, Hugh Dickins, Andrew Morton, Linux MM, LKML

From: Yang Shi <yang.shi@linux.alibaba.com>
Date: Thu, May 9, 2019 at 5:16 PM
To: <ying.huang@intel.com>, <hannes@cmpxchg.org>, <mhocko@suse.com>,
<mgorman@techsingularity.net>, <kirill.shutemov@linux.intel.com>,
<hughd@google.com>, <akpm@linux-foundation.org>
Cc: <yang.shi@linux.alibaba.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>

> Since commit bd4c82c22c36 ("mm, THP, swap: delay splitting THP after
> swapped out"), THP can be swapped out in a whole.  But, nr_reclaimed
> still gets inc'ed by one even though a whole THP (512 pages) gets
> swapped out.
>
> This doesn't make too much sense to memory reclaim.  For example, direct
> reclaim may just need reclaim SWAP_CLUSTER_MAX pages, reclaiming one THP
> could fulfill it.  But, if nr_reclaimed is not increased correctly,
> direct reclaim may just waste time to reclaim more pages,
> SWAP_CLUSTER_MAX * 512 pages in worst case.
>
> This change may result in more reclaimed pages than scanned pages showed
> by /proc/vmstat since scanning one head page would reclaim 512 base pages.
>
> Cc: "Huang, Ying" <ying.huang@intel.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Mel Gorman <mgorman@techsingularity.net>
> Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
> Cc: Hugh Dickins <hughd@google.com>
> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>

Nice find.

Reviewed-by: Shakeel Butt <shakeelb@google.com>

> ---
> I'm not quite sure if it was the intended behavior or just omission. I tried
> to dig into the review history, but didn't find any clue. I may miss some
> discussion.
>
>  mm/vmscan.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index fd9de50..7e026ec 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -1446,7 +1446,11 @@ static unsigned long shrink_page_list(struct list_head *page_list,
>
>                 unlock_page(page);
>  free_it:
> -               nr_reclaimed++;
> +               /*
> +                * THP may get swapped out in a whole, need account
> +                * all base pages.
> +                */
> +               nr_reclaimed += (1 << compound_order(page));
>
>                 /*
>                  * Is there need to periodically free_page_list? It would
> --
> 1.8.3.1
>

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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10  0:16 [PATCH] mm: vmscan: correct nr_reclaimed for THP Yang Shi
  2019-05-10  0:39 ` Shakeel Butt
@ 2019-05-10  2:12 ` Huang, Ying
  2019-05-10  2:25   ` Yang Shi
  2019-05-10 16:36   ` Matthew Wilcox
  1 sibling, 2 replies; 16+ messages in thread
From: Huang, Ying @ 2019-05-10  2:12 UTC (permalink / raw)
  To: Yang Shi
  Cc: hannes, mhocko, mgorman, kirill.shutemov, hughd, akpm, linux-mm,
	linux-kernel

Yang Shi <yang.shi@linux.alibaba.com> writes:

> Since commit bd4c82c22c36 ("mm, THP, swap: delay splitting THP after
> swapped out"), THP can be swapped out in a whole.  But, nr_reclaimed
> still gets inc'ed by one even though a whole THP (512 pages) gets
> swapped out.
>
> This doesn't make too much sense to memory reclaim.  For example, direct
> reclaim may just need reclaim SWAP_CLUSTER_MAX pages, reclaiming one THP
> could fulfill it.  But, if nr_reclaimed is not increased correctly,
> direct reclaim may just waste time to reclaim more pages,
> SWAP_CLUSTER_MAX * 512 pages in worst case.
>
> This change may result in more reclaimed pages than scanned pages showed
> by /proc/vmstat since scanning one head page would reclaim 512 base pages.
>
> Cc: "Huang, Ying" <ying.huang@intel.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Mel Gorman <mgorman@techsingularity.net>
> Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
> Cc: Hugh Dickins <hughd@google.com>
> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
> ---
> I'm not quite sure if it was the intended behavior or just omission. I tried
> to dig into the review history, but didn't find any clue. I may miss some
> discussion.
>
>  mm/vmscan.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index fd9de50..7e026ec 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -1446,7 +1446,11 @@ static unsigned long shrink_page_list(struct list_head *page_list,
>  
>  		unlock_page(page);
>  free_it:
> -		nr_reclaimed++;
> +		/* 
> +		 * THP may get swapped out in a whole, need account
> +		 * all base pages.
> +		 */
> +		nr_reclaimed += (1 << compound_order(page));
>  
>  		/*
>  		 * Is there need to periodically free_page_list? It would

Good catch!  Thanks!

How about to change this to


        nr_reclaimed += hpage_nr_pages(page);

Best Regards,
Huang, Ying

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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10  2:12 ` Huang, Ying
@ 2019-05-10  2:25   ` Yang Shi
  2019-05-10  3:03     ` Huang, Ying
  2019-05-10 16:36   ` Matthew Wilcox
  1 sibling, 1 reply; 16+ messages in thread
From: Yang Shi @ 2019-05-10  2:25 UTC (permalink / raw)
  To: Huang, Ying
  Cc: hannes, mhocko, mgorman, kirill.shutemov, hughd, akpm, linux-mm,
	linux-kernel



On 5/9/19 7:12 PM, Huang, Ying wrote:
> Yang Shi <yang.shi@linux.alibaba.com> writes:
>
>> Since commit bd4c82c22c36 ("mm, THP, swap: delay splitting THP after
>> swapped out"), THP can be swapped out in a whole.  But, nr_reclaimed
>> still gets inc'ed by one even though a whole THP (512 pages) gets
>> swapped out.
>>
>> This doesn't make too much sense to memory reclaim.  For example, direct
>> reclaim may just need reclaim SWAP_CLUSTER_MAX pages, reclaiming one THP
>> could fulfill it.  But, if nr_reclaimed is not increased correctly,
>> direct reclaim may just waste time to reclaim more pages,
>> SWAP_CLUSTER_MAX * 512 pages in worst case.
>>
>> This change may result in more reclaimed pages than scanned pages showed
>> by /proc/vmstat since scanning one head page would reclaim 512 base pages.
>>
>> Cc: "Huang, Ying" <ying.huang@intel.com>
>> Cc: Johannes Weiner <hannes@cmpxchg.org>
>> Cc: Michal Hocko <mhocko@suse.com>
>> Cc: Mel Gorman <mgorman@techsingularity.net>
>> Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
>> Cc: Hugh Dickins <hughd@google.com>
>> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
>> ---
>> I'm not quite sure if it was the intended behavior or just omission. I tried
>> to dig into the review history, but didn't find any clue. I may miss some
>> discussion.
>>
>>   mm/vmscan.c | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>> index fd9de50..7e026ec 100644
>> --- a/mm/vmscan.c
>> +++ b/mm/vmscan.c
>> @@ -1446,7 +1446,11 @@ static unsigned long shrink_page_list(struct list_head *page_list,
>>   
>>   		unlock_page(page);
>>   free_it:
>> -		nr_reclaimed++;
>> +		/*
>> +		 * THP may get swapped out in a whole, need account
>> +		 * all base pages.
>> +		 */
>> +		nr_reclaimed += (1 << compound_order(page));
>>   
>>   		/*
>>   		 * Is there need to periodically free_page_list? It would
> Good catch!  Thanks!
>
> How about to change this to
>
>
>          nr_reclaimed += hpage_nr_pages(page);

Either is fine to me. Is this faster than "1 << compound_order(page)"?

>
> Best Regards,
> Huang, Ying


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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10  2:25   ` Yang Shi
@ 2019-05-10  3:03     ` Huang, Ying
  2019-05-10  4:33       ` William Kucharski
  2019-05-10 15:41       ` Yang Shi
  0 siblings, 2 replies; 16+ messages in thread
From: Huang, Ying @ 2019-05-10  3:03 UTC (permalink / raw)
  To: Yang Shi
  Cc: hannes, mhocko, mgorman, kirill.shutemov, hughd, akpm, linux-mm,
	linux-kernel

Yang Shi <yang.shi@linux.alibaba.com> writes:

> On 5/9/19 7:12 PM, Huang, Ying wrote:
>> Yang Shi <yang.shi@linux.alibaba.com> writes:
>>
>>> Since commit bd4c82c22c36 ("mm, THP, swap: delay splitting THP after
>>> swapped out"), THP can be swapped out in a whole.  But, nr_reclaimed
>>> still gets inc'ed by one even though a whole THP (512 pages) gets
>>> swapped out.
>>>
>>> This doesn't make too much sense to memory reclaim.  For example, direct
>>> reclaim may just need reclaim SWAP_CLUSTER_MAX pages, reclaiming one THP
>>> could fulfill it.  But, if nr_reclaimed is not increased correctly,
>>> direct reclaim may just waste time to reclaim more pages,
>>> SWAP_CLUSTER_MAX * 512 pages in worst case.
>>>
>>> This change may result in more reclaimed pages than scanned pages showed
>>> by /proc/vmstat since scanning one head page would reclaim 512 base pages.
>>>
>>> Cc: "Huang, Ying" <ying.huang@intel.com>
>>> Cc: Johannes Weiner <hannes@cmpxchg.org>
>>> Cc: Michal Hocko <mhocko@suse.com>
>>> Cc: Mel Gorman <mgorman@techsingularity.net>
>>> Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
>>> Cc: Hugh Dickins <hughd@google.com>
>>> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
>>> ---
>>> I'm not quite sure if it was the intended behavior or just omission. I tried
>>> to dig into the review history, but didn't find any clue. I may miss some
>>> discussion.
>>>
>>>   mm/vmscan.c | 6 +++++-
>>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>>> index fd9de50..7e026ec 100644
>>> --- a/mm/vmscan.c
>>> +++ b/mm/vmscan.c
>>> @@ -1446,7 +1446,11 @@ static unsigned long shrink_page_list(struct list_head *page_list,
>>>     		unlock_page(page);
>>>   free_it:
>>> -		nr_reclaimed++;
>>> +		/*
>>> +		 * THP may get swapped out in a whole, need account
>>> +		 * all base pages.
>>> +		 */
>>> +		nr_reclaimed += (1 << compound_order(page));
>>>     		/*
>>>   		 * Is there need to periodically free_page_list? It would
>> Good catch!  Thanks!
>>
>> How about to change this to
>>
>>
>>          nr_reclaimed += hpage_nr_pages(page);
>
> Either is fine to me. Is this faster than "1 << compound_order(page)"?

I think the readability is a little better.  And this will become

        nr_reclaimed += 1

if CONFIG_TRANSPARENT_HUAGEPAGE is disabled.

Best Regards,
Huang, Ying

>>
>> Best Regards,
>> Huang, Ying

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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10  3:03     ` Huang, Ying
@ 2019-05-10  4:33       ` William Kucharski
  2019-05-10 15:48         ` Yang Shi
  2019-05-10 15:41       ` Yang Shi
  1 sibling, 1 reply; 16+ messages in thread
From: William Kucharski @ 2019-05-10  4:33 UTC (permalink / raw)
  To: Huang, Ying
  Cc: Yang Shi, hannes, mhocko, mgorman, kirill.shutemov, hughd, akpm,
	linux-mm, linux-kernel



> On May 9, 2019, at 9:03 PM, Huang, Ying <ying.huang@intel.com> wrote:
> 
> Yang Shi <yang.shi@linux.alibaba.com> writes:
> 
>> On 5/9/19 7:12 PM, Huang, Ying wrote:
>>> 
>>> How about to change this to
>>> 
>>> 
>>>         nr_reclaimed += hpage_nr_pages(page);
>> 
>> Either is fine to me. Is this faster than "1 << compound_order(page)"?
> 
> I think the readability is a little better.  And this will become
> 
>        nr_reclaimed += 1
> 
> if CONFIG_TRANSPARENT_HUAGEPAGE is disabled.

I find this more legible and self documenting, and it avoids the bit shift
operation completely on the majority of systems where THP is not configured.



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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10  3:03     ` Huang, Ying
  2019-05-10  4:33       ` William Kucharski
@ 2019-05-10 15:41       ` Yang Shi
  1 sibling, 0 replies; 16+ messages in thread
From: Yang Shi @ 2019-05-10 15:41 UTC (permalink / raw)
  To: Huang, Ying
  Cc: hannes, mhocko, mgorman, kirill.shutemov, hughd, akpm, linux-mm,
	linux-kernel



On 5/9/19 8:03 PM, Huang, Ying wrote:
> Yang Shi <yang.shi@linux.alibaba.com> writes:
>
>> On 5/9/19 7:12 PM, Huang, Ying wrote:
>>> Yang Shi <yang.shi@linux.alibaba.com> writes:
>>>
>>>> Since commit bd4c82c22c36 ("mm, THP, swap: delay splitting THP after
>>>> swapped out"), THP can be swapped out in a whole.  But, nr_reclaimed
>>>> still gets inc'ed by one even though a whole THP (512 pages) gets
>>>> swapped out.
>>>>
>>>> This doesn't make too much sense to memory reclaim.  For example, direct
>>>> reclaim may just need reclaim SWAP_CLUSTER_MAX pages, reclaiming one THP
>>>> could fulfill it.  But, if nr_reclaimed is not increased correctly,
>>>> direct reclaim may just waste time to reclaim more pages,
>>>> SWAP_CLUSTER_MAX * 512 pages in worst case.
>>>>
>>>> This change may result in more reclaimed pages than scanned pages showed
>>>> by /proc/vmstat since scanning one head page would reclaim 512 base pages.
>>>>
>>>> Cc: "Huang, Ying" <ying.huang@intel.com>
>>>> Cc: Johannes Weiner <hannes@cmpxchg.org>
>>>> Cc: Michal Hocko <mhocko@suse.com>
>>>> Cc: Mel Gorman <mgorman@techsingularity.net>
>>>> Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
>>>> Cc: Hugh Dickins <hughd@google.com>
>>>> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
>>>> ---
>>>> I'm not quite sure if it was the intended behavior or just omission. I tried
>>>> to dig into the review history, but didn't find any clue. I may miss some
>>>> discussion.
>>>>
>>>>    mm/vmscan.c | 6 +++++-
>>>>    1 file changed, 5 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>>>> index fd9de50..7e026ec 100644
>>>> --- a/mm/vmscan.c
>>>> +++ b/mm/vmscan.c
>>>> @@ -1446,7 +1446,11 @@ static unsigned long shrink_page_list(struct list_head *page_list,
>>>>      		unlock_page(page);
>>>>    free_it:
>>>> -		nr_reclaimed++;
>>>> +		/*
>>>> +		 * THP may get swapped out in a whole, need account
>>>> +		 * all base pages.
>>>> +		 */
>>>> +		nr_reclaimed += (1 << compound_order(page));
>>>>      		/*
>>>>    		 * Is there need to periodically free_page_list? It would
>>> Good catch!  Thanks!
>>>
>>> How about to change this to
>>>
>>>
>>>           nr_reclaimed += hpage_nr_pages(page);
>> Either is fine to me. Is this faster than "1 << compound_order(page)"?
> I think the readability is a little better.  And this will become
>
>          nr_reclaimed += 1
>
> if CONFIG_TRANSPARENT_HUAGEPAGE is disabled.

Good point. Will update in v2 soon.

>
> Best Regards,
> Huang, Ying
>
>>> Best Regards,
>>> Huang, Ying


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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10  4:33       ` William Kucharski
@ 2019-05-10 15:48         ` Yang Shi
  0 siblings, 0 replies; 16+ messages in thread
From: Yang Shi @ 2019-05-10 15:48 UTC (permalink / raw)
  To: William Kucharski, Huang, Ying
  Cc: hannes, mhocko, mgorman, kirill.shutemov, hughd, akpm, linux-mm,
	linux-kernel



On 5/9/19 9:33 PM, William Kucharski wrote:
>
>> On May 9, 2019, at 9:03 PM, Huang, Ying <ying.huang@intel.com> wrote:
>>
>> Yang Shi <yang.shi@linux.alibaba.com> writes:
>>
>>> On 5/9/19 7:12 PM, Huang, Ying wrote:
>>>> How about to change this to
>>>>
>>>>
>>>>          nr_reclaimed += hpage_nr_pages(page);
>>> Either is fine to me. Is this faster than "1 << compound_order(page)"?
>> I think the readability is a little better.  And this will become
>>
>>         nr_reclaimed += 1
>>
>> if CONFIG_TRANSPARENT_HUAGEPAGE is disabled.
> I find this more legible and self documenting, and it avoids the bit shift
> operation completely on the majority of systems where THP is not configured.

Yes, I do agree. Thanks for the suggestion.
>


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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10  2:12 ` Huang, Ying
  2019-05-10  2:25   ` Yang Shi
@ 2019-05-10 16:36   ` Matthew Wilcox
  2019-05-10 16:50     ` Yang Shi
                       ` (3 more replies)
  1 sibling, 4 replies; 16+ messages in thread
From: Matthew Wilcox @ 2019-05-10 16:36 UTC (permalink / raw)
  To: Huang, Ying
  Cc: Yang Shi, hannes, mhocko, mgorman, kirill.shutemov, hughd, akpm,
	linux-mm, linux-kernel

On Fri, May 10, 2019 at 10:12:40AM +0800, Huang, Ying wrote:
> > +		nr_reclaimed += (1 << compound_order(page));
> 
> How about to change this to
> 
> 
>         nr_reclaimed += hpage_nr_pages(page);

Please don't.  That embeds the knowledge that we can only swap out either 
normal pages or THP sized pages.  I'm trying to make the VM capable of 
supporting arbitrary-order pages, and this would be just one more place
to fix.

I'm sympathetic to the "self documenting" argument.  My current tree has
a patch in it:

    mm: Introduce compound_nr
    
    Replace 1 << compound_order(page) with compound_nr(page).  Minor
    improvements in readability.

It goes along with this patch:

    mm: Introduce page_size()

    It's unnecessarily hard to find out the size of a potentially huge page.
    Replace 'PAGE_SIZE << compound_order(page)' with page_size(page).

Better suggestions on naming gratefully received.  I'm more happy with 
page_size() than I am with compound_nr().  page_nr() gives the wrong
impression; page_count() isn't great either.

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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10 16:36   ` Matthew Wilcox
@ 2019-05-10 16:50     ` Yang Shi
  2019-05-10 16:52       ` Matthew Wilcox
  2019-05-10 22:54     ` Ira Weiny
                       ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Yang Shi @ 2019-05-10 16:50 UTC (permalink / raw)
  To: Matthew Wilcox, Huang, Ying
  Cc: hannes, mhocko, mgorman, kirill.shutemov, hughd, akpm, linux-mm,
	linux-kernel



On 5/10/19 9:36 AM, Matthew Wilcox wrote:
> On Fri, May 10, 2019 at 10:12:40AM +0800, Huang, Ying wrote:
>>> +		nr_reclaimed += (1 << compound_order(page));
>> How about to change this to
>>
>>
>>          nr_reclaimed += hpage_nr_pages(page);
> Please don't.  That embeds the knowledge that we can only swap out either
> normal pages or THP sized pages.  I'm trying to make the VM capable of
> supporting arbitrary-order pages, and this would be just one more place
> to fix.
>
> I'm sympathetic to the "self documenting" argument.  My current tree has
> a patch in it:
>
>      mm: Introduce compound_nr
>      
>      Replace 1 << compound_order(page) with compound_nr(page).  Minor
>      improvements in readability.
>
> It goes along with this patch:
>
>      mm: Introduce page_size()
>
>      It's unnecessarily hard to find out the size of a potentially huge page.
>      Replace 'PAGE_SIZE << compound_order(page)' with page_size(page).

So you prefer keeping using  "1 << compound_order" as v1 did? Then you 
will convert all "1 << compound_order" to compound_nr?

>
> Better suggestions on naming gratefully received.  I'm more happy with
> page_size() than I am with compound_nr().  page_nr() gives the wrong
> impression; page_count() isn't great either.


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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10 16:50     ` Yang Shi
@ 2019-05-10 16:52       ` Matthew Wilcox
  2019-05-10 16:54         ` Yang Shi
  0 siblings, 1 reply; 16+ messages in thread
From: Matthew Wilcox @ 2019-05-10 16:52 UTC (permalink / raw)
  To: Yang Shi
  Cc: Huang, Ying, hannes, mhocko, mgorman, kirill.shutemov, hughd,
	akpm, linux-mm, linux-kernel

On Fri, May 10, 2019 at 09:50:04AM -0700, Yang Shi wrote:
> On 5/10/19 9:36 AM, Matthew Wilcox wrote:
> > On Fri, May 10, 2019 at 10:12:40AM +0800, Huang, Ying wrote:
> > > > +		nr_reclaimed += (1 << compound_order(page));
> > > How about to change this to
> > > 
> > >          nr_reclaimed += hpage_nr_pages(page);
> > Please don't.  That embeds the knowledge that we can only swap out either
> > normal pages or THP sized pages.  I'm trying to make the VM capable of
> > supporting arbitrary-order pages, and this would be just one more place
> > to fix.
> > 
> > I'm sympathetic to the "self documenting" argument.  My current tree has
> > a patch in it:
> > 
> >      mm: Introduce compound_nr
> >      Replace 1 << compound_order(page) with compound_nr(page).  Minor
> >      improvements in readability.
> > 
> > It goes along with this patch:
> > 
> >      mm: Introduce page_size()
> > 
> >      It's unnecessarily hard to find out the size of a potentially huge page.
> >      Replace 'PAGE_SIZE << compound_order(page)' with page_size(page).
> 
> So you prefer keeping using  "1 << compound_order" as v1 did? Then you will
> convert all "1 << compound_order" to compound_nr?

Yes.  Please, let's merge v1 and ignore v2.

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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10 16:52       ` Matthew Wilcox
@ 2019-05-10 16:54         ` Yang Shi
  0 siblings, 0 replies; 16+ messages in thread
From: Yang Shi @ 2019-05-10 16:54 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Huang, Ying, hannes, mhocko, mgorman, kirill.shutemov, hughd,
	akpm, linux-mm, linux-kernel



On 5/10/19 9:52 AM, Matthew Wilcox wrote:
> On Fri, May 10, 2019 at 09:50:04AM -0700, Yang Shi wrote:
>> On 5/10/19 9:36 AM, Matthew Wilcox wrote:
>>> On Fri, May 10, 2019 at 10:12:40AM +0800, Huang, Ying wrote:
>>>>> +		nr_reclaimed += (1 << compound_order(page));
>>>> How about to change this to
>>>>
>>>>           nr_reclaimed += hpage_nr_pages(page);
>>> Please don't.  That embeds the knowledge that we can only swap out either
>>> normal pages or THP sized pages.  I'm trying to make the VM capable of
>>> supporting arbitrary-order pages, and this would be just one more place
>>> to fix.
>>>
>>> I'm sympathetic to the "self documenting" argument.  My current tree has
>>> a patch in it:
>>>
>>>       mm: Introduce compound_nr
>>>       Replace 1 << compound_order(page) with compound_nr(page).  Minor
>>>       improvements in readability.
>>>
>>> It goes along with this patch:
>>>
>>>       mm: Introduce page_size()
>>>
>>>       It's unnecessarily hard to find out the size of a potentially huge page.
>>>       Replace 'PAGE_SIZE << compound_order(page)' with page_size(page).
>> So you prefer keeping using  "1 << compound_order" as v1 did? Then you will
>> convert all "1 << compound_order" to compound_nr?
> Yes.  Please, let's merge v1 and ignore v2.

Fine to me. I think Andrew will take care of it, Andrew?



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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10 16:36   ` Matthew Wilcox
  2019-05-10 16:50     ` Yang Shi
@ 2019-05-10 22:54     ` Ira Weiny
  2019-05-10 23:06       ` Matthew Wilcox
  2019-05-11  4:09     ` Yafang Shao
  2019-05-11 22:33     ` William Kucharski
  3 siblings, 1 reply; 16+ messages in thread
From: Ira Weiny @ 2019-05-10 22:54 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Huang, Ying, Yang Shi, hannes, mhocko, mgorman, kirill.shutemov,
	hughd, akpm, linux-mm, linux-kernel

On Fri, May 10, 2019 at 09:36:12AM -0700, Matthew Wilcox wrote:
> On Fri, May 10, 2019 at 10:12:40AM +0800, Huang, Ying wrote:
> > > +		nr_reclaimed += (1 << compound_order(page));
> > 
> > How about to change this to
> > 
> > 
> >         nr_reclaimed += hpage_nr_pages(page);
> 
> Please don't.  That embeds the knowledge that we can only swap out either 
> normal pages or THP sized pages.  I'm trying to make the VM capable of 
> supporting arbitrary-order pages, and this would be just one more place
> to fix.
> 
> I'm sympathetic to the "self documenting" argument.  My current tree has
> a patch in it:
> 
>     mm: Introduce compound_nr
>     
>     Replace 1 << compound_order(page) with compound_nr(page).  Minor
>     improvements in readability.
> 
> It goes along with this patch:
> 
>     mm: Introduce page_size()
> 
>     It's unnecessarily hard to find out the size of a potentially huge page.
>     Replace 'PAGE_SIZE << compound_order(page)' with page_size(page).
> 
> Better suggestions on naming gratefully received.  I'm more happy with 
> page_size() than I am with compound_nr().  page_nr() gives the wrong
> impression; page_count() isn't great either.

Stupid question : what does 'nr' stand for?

Ira


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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10 22:54     ` Ira Weiny
@ 2019-05-10 23:06       ` Matthew Wilcox
  0 siblings, 0 replies; 16+ messages in thread
From: Matthew Wilcox @ 2019-05-10 23:06 UTC (permalink / raw)
  To: Ira Weiny
  Cc: Huang, Ying, Yang Shi, hannes, mhocko, mgorman, kirill.shutemov,
	hughd, akpm, linux-mm, linux-kernel

On Fri, May 10, 2019 at 03:54:56PM -0700, Ira Weiny wrote:
> On Fri, May 10, 2019 at 09:36:12AM -0700, Matthew Wilcox wrote:
> > On Fri, May 10, 2019 at 10:12:40AM +0800, Huang, Ying wrote:
> > > > +		nr_reclaimed += (1 << compound_order(page));
> > > 
> > > How about to change this to
> > > 
> > > 
> > >         nr_reclaimed += hpage_nr_pages(page);
> > 
> > Please don't.  That embeds the knowledge that we can only swap out either 
> > normal pages or THP sized pages.  I'm trying to make the VM capable of 
> > supporting arbitrary-order pages, and this would be just one more place
> > to fix.
> > 
> > I'm sympathetic to the "self documenting" argument.  My current tree has
> > a patch in it:
> > 
> >     mm: Introduce compound_nr
> >     
> >     Replace 1 << compound_order(page) with compound_nr(page).  Minor
> >     improvements in readability.
> > 
> > It goes along with this patch:
> > 
> >     mm: Introduce page_size()
> > 
> >     It's unnecessarily hard to find out the size of a potentially huge page.
> >     Replace 'PAGE_SIZE << compound_order(page)' with page_size(page).
> > 
> > Better suggestions on naming gratefully received.  I'm more happy with 
> > page_size() than I am with compound_nr().  page_nr() gives the wrong
> > impression; page_count() isn't great either.
> 
> Stupid question : what does 'nr' stand for?

NumbeR.  It's relatively common argot in the Linux kernel (as you can
see from the earlier example ...

> > >         nr_reclaimed += hpage_nr_pages(page);

willy@bobo:~/kernel/xarray-2$ git grep -w nr mm |wc -l
388
willy@bobo:~/kernel/xarray-2$ git grep -w nr fs |wc -l
1067


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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10 16:36   ` Matthew Wilcox
  2019-05-10 16:50     ` Yang Shi
  2019-05-10 22:54     ` Ira Weiny
@ 2019-05-11  4:09     ` Yafang Shao
  2019-05-11 22:33     ` William Kucharski
  3 siblings, 0 replies; 16+ messages in thread
From: Yafang Shao @ 2019-05-11  4:09 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Huang, Ying, Yang Shi, Johannes Weiner, Michal Hocko, mgorman,
	kirill.shutemov, Hugh Dickins, Andrew Morton, Linux MM, LKML

On Sat, May 11, 2019 at 12:36 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Fri, May 10, 2019 at 10:12:40AM +0800, Huang, Ying wrote:
> > > +           nr_reclaimed += (1 << compound_order(page));
> >
> > How about to change this to
> >
> >
> >         nr_reclaimed += hpage_nr_pages(page);
>
> Please don't.  That embeds the knowledge that we can only swap out either
> normal pages or THP sized pages.

Agreed.
compound_order() is more general than hpage_nr_pages().
It seems to me that hpage_nr_pages() is a little  abuse in lots of places.

Thanks
Yafang

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

* Re: [PATCH] mm: vmscan: correct nr_reclaimed for THP
  2019-05-10 16:36   ` Matthew Wilcox
                       ` (2 preceding siblings ...)
  2019-05-11  4:09     ` Yafang Shao
@ 2019-05-11 22:33     ` William Kucharski
  3 siblings, 0 replies; 16+ messages in thread
From: William Kucharski @ 2019-05-11 22:33 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Huang, Ying, Yang Shi, hannes, mhocko, mgorman, kirill.shutemov,
	hughd, akpm, linux-mm, linux-kernel



> On May 10, 2019, at 10:36 AM, Matthew Wilcox <willy@infradead.org> wrote:
> 
> Please don't.  That embeds the knowledge that we can only swap out either 
> normal pages or THP sized pages.  I'm trying to make the VM capable of 
> supporting arbitrary-order pages, and this would be just one more place
> to fix.
> 
> I'm sympathetic to the "self documenting" argument.  My current tree has
> a patch in it:
> 
>    mm: Introduce compound_nr
> 
>    Replace 1 << compound_order(page) with compound_nr(page).  Minor
>    improvements in readability.
> 
> It goes along with this patch:
> 
>    mm: Introduce page_size()
> 
>    It's unnecessarily hard to find out the size of a potentially huge page.
>    Replace 'PAGE_SIZE << compound_order(page)' with page_size(page).
> 
> Better suggestions on naming gratefully received.  I'm more happy with 
> page_size() than I am with compound_nr().  page_nr() gives the wrong
> impression; page_count() isn't great either.

I like page_size() as well. At least to me, page_nr() or page_count() would
imply a basis of PAGESIZE, or that you would need to do something like:

    page_size = page_nr() << PAGE_SHIFT;

to get the size in bytes; page_size() is more straightforward in that respect.

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

end of thread, other threads:[~2019-05-11 22:34 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-10  0:16 [PATCH] mm: vmscan: correct nr_reclaimed for THP Yang Shi
2019-05-10  0:39 ` Shakeel Butt
2019-05-10  2:12 ` Huang, Ying
2019-05-10  2:25   ` Yang Shi
2019-05-10  3:03     ` Huang, Ying
2019-05-10  4:33       ` William Kucharski
2019-05-10 15:48         ` Yang Shi
2019-05-10 15:41       ` Yang Shi
2019-05-10 16:36   ` Matthew Wilcox
2019-05-10 16:50     ` Yang Shi
2019-05-10 16:52       ` Matthew Wilcox
2019-05-10 16:54         ` Yang Shi
2019-05-10 22:54     ` Ira Weiny
2019-05-10 23:06       ` Matthew Wilcox
2019-05-11  4:09     ` Yafang Shao
2019-05-11 22:33     ` William Kucharski

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