diff mbox series

mm/hugetlb: avoid unnecessary hugetlb_acct_memory() call

Message ID 20210114113140.23069-1-linmiaohe@huawei.com (mailing list archive)
State New, archived
Headers show
Series mm/hugetlb: avoid unnecessary hugetlb_acct_memory() call | expand

Commit Message

Miaohe Lin Jan. 14, 2021, 11:31 a.m. UTC
When gbl_reserve is 0, hugetlb_acct_memory() will do nothing except holding
and releasing hugetlb_lock.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/hugetlb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

David Hildenbrand Jan. 14, 2021, 12:32 p.m. UTC | #1
On 14.01.21 12:31, Miaohe Lin wrote:
> When gbl_reserve is 0, hugetlb_acct_memory() will do nothing except holding
> and releasing hugetlb_lock.

So, what's the deal then? Adding more code?

If this is a performance improvement, we should spell it out. Otherwise
I don't see a real benefit of this patch.

> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  mm/hugetlb.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 737b2dce19e6..fe2da9ad6233 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -5241,7 +5241,8 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
>  	 * reservations to be released may be adjusted.
>  	 */
>  	gbl_reserve = hugepage_subpool_put_pages(spool, (chg - freed));
> -	hugetlb_acct_memory(h, -gbl_reserve);
> +	if (gbl_reserve)
> +		hugetlb_acct_memory(h, -gbl_reserve);
>  
>  	return 0;
>  }
>
Mike Kravetz Jan. 14, 2021, 7:16 p.m. UTC | #2
On 1/14/21 4:32 AM, David Hildenbrand wrote:
> On 14.01.21 12:31, Miaohe Lin wrote:
>> When gbl_reserve is 0, hugetlb_acct_memory() will do nothing except holding
>> and releasing hugetlb_lock.
> 
> So, what's the deal then? Adding more code?
> 
> If this is a performance improvement, we should spell it out. Otherwise
> I don't see a real benefit of this patch.
> 

Thanks for finding/noticing this.

As David points out, the commit message should state that this is a
performance improvement.  Mention that such a change avoids an unnecessary
hugetlb_lock lock/unlock cycle.  You can also mention that this unnecessary
lock cycle is happening on 'most' hugetlb munmap operations.

>>
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>> ---
>>  mm/hugetlb.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>> index 737b2dce19e6..fe2da9ad6233 100644
>> --- a/mm/hugetlb.c
>> +++ b/mm/hugetlb.c
>> @@ -5241,7 +5241,8 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
>>  	 * reservations to be released may be adjusted.
>>  	 */
>>  	gbl_reserve = hugepage_subpool_put_pages(spool, (chg - freed));
>> -	hugetlb_acct_memory(h, -gbl_reserve);
>> +	if (gbl_reserve)
>> +		hugetlb_acct_memory(h, -gbl_reserve);

It is true that gbl_reserve is likely to be 0 in this code path.  However,
there are other code paths where hugetlb_acct_memory is called with a delta
value of 0 as well.  I would rather see a simple check at the beginning of
hugetlb_acct_memory like.

	if (!delta)
		return 0;
Miaohe Lin Jan. 15, 2021, 2:04 a.m. UTC | #3
Hi:

On 2021/1/15 3:16, Mike Kravetz wrote:
> On 1/14/21 4:32 AM, David Hildenbrand wrote:
>> On 14.01.21 12:31, Miaohe Lin wrote:
>>> When gbl_reserve is 0, hugetlb_acct_memory() will do nothing except holding
>>> and releasing hugetlb_lock.
>>
>> So, what's the deal then? Adding more code?
>>
>> If this is a performance improvement, we should spell it out. Otherwise
>> I don't see a real benefit of this patch.
>>
> 
> Thanks for finding/noticing this.
> 
> As David points out, the commit message should state that this is a
> performance improvement.  Mention that such a change avoids an unnecessary
> hugetlb_lock lock/unlock cycle.  You can also mention that this unnecessary
> lock cycle is happening on 'most' hugetlb munmap operations.
> 

My bad. I should spell this out explicitly. Many thanks for both of you.

>>>
>>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>>> ---
>>>  mm/hugetlb.c | 3 ++-
>>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>>> index 737b2dce19e6..fe2da9ad6233 100644
>>> --- a/mm/hugetlb.c
>>> +++ b/mm/hugetlb.c
>>> @@ -5241,7 +5241,8 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
>>>  	 * reservations to be released may be adjusted.
>>>  	 */
>>>  	gbl_reserve = hugepage_subpool_put_pages(spool, (chg - freed));
>>> -	hugetlb_acct_memory(h, -gbl_reserve);
>>> +	if (gbl_reserve)
>>> +		hugetlb_acct_memory(h, -gbl_reserve);
> 
> It is true that gbl_reserve is likely to be 0 in this code path.  However,
> there are other code paths where hugetlb_acct_memory is called with a delta
> value of 0 as well.  I would rather see a simple check at the beginning of
> hugetlb_acct_memory like.
> 
> 	if (!delta)
> 		return 0;
> 

Sounds good. Will do it in v2. Many thanks again.
David Hildenbrand Jan. 15, 2021, 8:47 a.m. UTC | #4
On 15.01.21 03:04, Miaohe Lin wrote:
> Hi:
> 
> On 2021/1/15 3:16, Mike Kravetz wrote:
>> On 1/14/21 4:32 AM, David Hildenbrand wrote:
>>> On 14.01.21 12:31, Miaohe Lin wrote:
>>>> When gbl_reserve is 0, hugetlb_acct_memory() will do nothing except holding
>>>> and releasing hugetlb_lock.
>>>
>>> So, what's the deal then? Adding more code?
>>>
>>> If this is a performance improvement, we should spell it out. Otherwise
>>> I don't see a real benefit of this patch.
>>>
>>
>> Thanks for finding/noticing this.
>>
>> As David points out, the commit message should state that this is a
>> performance improvement.  Mention that such a change avoids an unnecessary
>> hugetlb_lock lock/unlock cycle.  You can also mention that this unnecessary
>> lock cycle is happening on 'most' hugetlb munmap operations.
>>
> 
> My bad. I should spell this out explicitly. Many thanks for both of you.

With the "lock cycle is happening on 'most' hugetlb munmap operations"
part added

Reviewed-by: David Hildenbrand <david@redhat.com>

Thanks!
diff mbox series

Patch

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 737b2dce19e6..fe2da9ad6233 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5241,7 +5241,8 @@  long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
 	 * reservations to be released may be adjusted.
 	 */
 	gbl_reserve = hugepage_subpool_put_pages(spool, (chg - freed));
-	hugetlb_acct_memory(h, -gbl_reserve);
+	if (gbl_reserve)
+		hugetlb_acct_memory(h, -gbl_reserve);
 
 	return 0;
 }