Skip to contentSkip to conversation

mm/hugetlb: avoid calculating fault_mutex_hash in truncate_op case

PATCH Superseded Miaohe Lin 2 participants 5 messages Mar 16, 2021 – Mar 17, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH v2 5/5 mm/hugetlb: avoid calculating fault_mutex_hash in truncate_op case

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.

---
v1->v2:
remove unnecessary initialization for variable hash collect Reviewed-by tag from Mike Kravetz

---
 fs/hugetlbfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/hugetlbfs/inode.c +1 -1
index c262566f7c5d..f7ec94bc7337 100644
@@ -485,7 +485,6 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
 			u32 hash;
 
 			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]);
 			}
 
Signature · 1 line
2.19.1
#1 lore raw
Quoted 5 lines · Miaohe Lin

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.

Quoted 7 lines

---
v1->v2:
remove unnecessary initialization for variable hash collect Reviewed-by tag from Mike Kravetz

My apologies for not replying sooner and any misunderstanding from my previous comments.

If the compiler is going to produce a warning because the variable is not initialized, then we will need to keep the initialization. Otherwise, this will show up as a build regression. Ideally, there would be a modifier which could be used to tell the compiler the variable will used. I do not know if such a modifier exists.

The patch can not produce a new warning. So, if you need to initialize the variable then do it. My Reviewed-by still applies.

Signature · 1 line
Mike Kravetz
Quoted 25 lines
---
 fs/hugetlbfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/hugetlbfs/inode.c +1 -1
index c262566f7c5d..f7ec94bc7337 100644
@@ -485,7 +485,6 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
 			u32 hash;
 
 			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]);
 			}
 
author
#2 lore raw
Quoted 14 lines · Mike Kravetz
Quoted 5 lines · Miaohe Lin

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.

Quoted 7 lines

---
v1->v2:
remove unnecessary initialization for variable hash collect Reviewed-by tag from Mike Kravetz

Quoted 3 lines

My apologies for not replying sooner and any misunderstanding from my previous comments.

That's all right.

Quoted 6 lines

If the compiler is going to produce a warning because the variable is not initialized, then we will need to keep the initialization. Otherwise, this will show up as a build regression. Ideally, there would be a modifier which could be used to tell the compiler the variable will used. I do not know if such a modifier exists.

I do not know if such a modifier exists too. But maybe not all compilers are intelligent enough to not produce a warning. It would be safe to keep the initialization...

Quoted 1 line

The patch can not produce a new warning. So, if you need to initialize

So just drop this version of the patch? Or should I send a new version with your Reviewed-by tag and keep the initialization?

Quoted 2 lines

the variable then do it. My Reviewed-by still applies.

#3 lore raw
Quoted 28 lines · Miaohe Lin
Quoted 14 lines · Mike Kravetz
Quoted 5 lines · Miaohe Lin

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.

Quoted 7 lines

---
v1->v2:
remove unnecessary initialization for variable hash collect Reviewed-by tag from Mike Kravetz

Quoted 3 lines

My apologies for not replying sooner and any misunderstanding from my previous comments.

That's all right.

Quoted 6 lines

If the compiler is going to produce a warning because the variable is not initialized, then we will need to keep the initialization. Otherwise, this will show up as a build regression. Ideally, there would be a modifier which could be used to tell the compiler the variable will used. I do not know if such a modifier exists.

Quoted 8 lines

I do not know if such a modifier exists too. But maybe not all compilers are intelligent enough to not produce a warning. It would be safe to keep the initialization...

Quoted 1 line

The patch can not produce a new warning. So, if you need to initialize

So just drop this version of the patch? Or should I send a new version with your Reviewed-by tag and keep the initialization?

Yes, drop this version of the patch. You can add my Reviewed-by to the previous version that included the initialization and resend.

All the cleanup patches in this series should be good to go.

Signature · 1 line
Mike Kravetz
author
#4 lore raw
Quoted 32 lines · Mike Kravetz
Quoted 31 lines · Miaohe Lin
Quoted 14 lines · Mike Kravetz
Quoted 5 lines · Miaohe Lin

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.

Quoted 7 lines

---
v1->v2:
remove unnecessary initialization for variable hash collect Reviewed-by tag from Mike Kravetz

Quoted 3 lines

My apologies for not replying sooner and any misunderstanding from my previous comments.

That's all right.

Quoted 6 lines

If the compiler is going to produce a warning because the variable is not initialized, then we will need to keep the initialization. Otherwise, this will show up as a build regression. Ideally, there would be a modifier which could be used to tell the compiler the variable will used. I do not know if such a modifier exists.

I do not know if such a modifier exists too. But maybe not all compilers are intelligent enough to not produce a warning. It would be safe to keep the initialization...

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

The patch can not produce a new warning. So, if you need to initialize

So just drop this version of the patch? Or should I send a new version with your Reviewed-by tag and keep the initialization?

Yes, drop this version of the patch. You can add my Reviewed-by to the previous version that included the initialization and resend.

Will do. Many thanks. :)

Quoted 2 lines

All the cleanup patches in this series should be good to go.