diff mbox series

[5/5] mm/hugetlb: avoid calculating fault_mutex_hash in truncate_op case

Message ID 20210308112809.26107-6-linmiaohe@huawei.com (mailing list archive)
State New, archived
Headers show
Series Some cleanups for hugetlb | expand

Commit Message

Miaohe Lin March 8, 2021, 11:28 a.m. UTC
The fault_mutex hashing overhead can be avoided in truncate_op case because
page faults can not race with truncation in this routine. So calculate hash
for fault_mutex only in !truncate_op case to save some cpu cycles.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 fs/hugetlbfs/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Mike Kravetz March 12, 2021, 8:03 p.m. UTC | #1
On 3/8/21 3:28 AM, Miaohe Lin wrote:
> The fault_mutex hashing overhead can be avoided in truncate_op case because
> page faults can not race with truncation in this routine. So calculate hash
> for fault_mutex only in !truncate_op case to save some cpu cycles.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  fs/hugetlbfs/inode.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index c262566f7c5d..d81f52b87bd7 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -482,10 +482,9 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
>  
>  		for (i = 0; i < pagevec_count(&pvec); ++i) {
>  			struct page *page = pvec.pages[i];
> -			u32 hash;
> +			u32 hash = 0;

Do we need to initialize hash here?
I would not bring this up normally, but the purpose of the patch is to save
cpu cycles.
Miaohe Lin March 13, 2021, 2:49 a.m. UTC | #2
Hi:
On 2021/3/13 4:03, Mike Kravetz wrote:
> On 3/8/21 3:28 AM, Miaohe Lin wrote:
>> The fault_mutex hashing overhead can be avoided in truncate_op case because
>> page faults can not race with truncation in this routine. So calculate hash
>> for fault_mutex only in !truncate_op case to save some cpu cycles.
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>> ---
>>  fs/hugetlbfs/inode.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
>> index c262566f7c5d..d81f52b87bd7 100644
>> --- a/fs/hugetlbfs/inode.c
>> +++ b/fs/hugetlbfs/inode.c
>> @@ -482,10 +482,9 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
>>  
>>  		for (i = 0; i < pagevec_count(&pvec); ++i) {
>>  			struct page *page = pvec.pages[i];
>> -			u32 hash;
>> +			u32 hash = 0;
> 
> Do we need to initialize hash here?
> I would not bring this up normally, but the purpose of the patch is to save
> cpu cycles.

The hash is initialized here in order to avoid false positive
"uninitialized local variable used" warning. Or this is indeed unnecessary?

Many thanks for review.

>
Mike Kravetz March 13, 2021, 9:17 p.m. UTC | #3
On 3/12/21 6:49 PM, Miaohe Lin wrote:
> Hi:
> On 2021/3/13 4:03, Mike Kravetz wrote:
>> On 3/8/21 3:28 AM, Miaohe Lin wrote:
>>> The fault_mutex hashing overhead can be avoided in truncate_op case because
>>> page faults can not race with truncation in this routine. So calculate hash
>>> for fault_mutex only in !truncate_op case to save some cpu cycles.
>>>
>>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>>> ---
>>>  fs/hugetlbfs/inode.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
>>> index c262566f7c5d..d81f52b87bd7 100644
>>> --- a/fs/hugetlbfs/inode.c
>>> +++ b/fs/hugetlbfs/inode.c
>>> @@ -482,10 +482,9 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
>>>  
>>>  		for (i = 0; i < pagevec_count(&pvec); ++i) {
>>>  			struct page *page = pvec.pages[i];
>>> -			u32 hash;
>>> +			u32 hash = 0;
>>
>> Do we need to initialize hash here?
>> I would not bring this up normally, but the purpose of the patch is to save
>> cpu cycles.
> 
> The hash is initialized here in order to avoid false positive
> "uninitialized local variable used" warning. Or this is indeed unnecessary?
> 

Of course.  In this case we know more about usage then the compiler.
You can add:

Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
Miaohe Lin March 15, 2021, 1:50 a.m. UTC | #4
On 2021/3/14 5:17, Mike Kravetz wrote:
> On 3/12/21 6:49 PM, Miaohe Lin wrote:
>> Hi:
>> On 2021/3/13 4:03, Mike Kravetz wrote:
>>> On 3/8/21 3:28 AM, Miaohe Lin wrote:
>>>> The fault_mutex hashing overhead can be avoided in truncate_op case because
>>>> page faults can not race with truncation in this routine. So calculate hash
>>>> for fault_mutex only in !truncate_op case to save some cpu cycles.
>>>>
>>>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>>>> ---
>>>>  fs/hugetlbfs/inode.c | 4 ++--
>>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
>>>> index c262566f7c5d..d81f52b87bd7 100644
>>>> --- a/fs/hugetlbfs/inode.c
>>>> +++ b/fs/hugetlbfs/inode.c
>>>> @@ -482,10 +482,9 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
>>>>  
>>>>  		for (i = 0; i < pagevec_count(&pvec); ++i) {
>>>>  			struct page *page = pvec.pages[i];
>>>> -			u32 hash;
>>>> +			u32 hash = 0;
>>>
>>> Do we need to initialize hash here?
>>> I would not bring this up normally, but the purpose of the patch is to save
>>> cpu cycles.
>>
>> The hash is initialized here in order to avoid false positive
>> "uninitialized local variable used" warning. Or this is indeed unnecessary?
>>
> 
> Of course.  In this case we know more about usage then the compiler.
> You can add:
> 

I see. Many thanks. Am I supposed to resend the whole v2 patch series ? Or just a single v2 patch with change mentioned above?
Please let me know which is the easiest one for you.

> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
>
diff mbox series

Patch

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index c262566f7c5d..d81f52b87bd7 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -482,10 +482,9 @@  static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
 
 		for (i = 0; i < pagevec_count(&pvec); ++i) {
 			struct page *page = pvec.pages[i];
-			u32 hash;
+			u32 hash = 0;
 
 			index = page->index;
-			hash = hugetlb_fault_mutex_hash(mapping, index);
 			if (!truncate_op) {
 				/*
 				 * Only need to hold the fault mutex in the
@@ -493,6 +492,7 @@  static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
 				 * page faults.  Races are not possible in the
 				 * case of truncation.
 				 */
+				hash = hugetlb_fault_mutex_hash(mapping, index);
 				mutex_lock(&hugetlb_fault_mutex_table[hash]);
 			}