linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 5/5] mm/hugetlb: avoid calculating fault_mutex_hash in truncate_op case
@ 2021-03-18 11:28 Miaohe Lin
  0 siblings, 0 replies; only message in thread
From: Miaohe Lin @ 2021-03-18 11:28 UTC (permalink / raw)
  To: akpm, mike.kravetz; +Cc: linux-mm, linux-kernel, linmiaohe

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.

Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
---
v2->v3:
keep the initialization in case compilers produce a warning.
Sorry for make noise. :(

v1->v2:
remove unnecessary initialization for variable hash
collect Reviewed-by tag from Mike Kravetz
---
 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;
 
 			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]);
 			}
 
-- 
2.19.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-18 11:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18 11:28 [PATCH v3 5/5] mm/hugetlb: avoid calculating fault_mutex_hash in truncate_op case Miaohe Lin

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