[Devel] [PATCH rh7] mm: slightly optimize __handle_mm_fault()

Andrey Ryabinin aryabinin at virtuozzo.com
Mon Feb 17 14:57:41 MSK 2020


__handle_mm_fault() uses designated initializer to initialize
some fields in struct vm_fault. This causes unnecessary initialization
of unused or initialized later fields.

Initialize only necessary fields without using designated initializer.

Tested by running 24 instancies of the following script in parallel:
	#!/bin/bash
	for NUMBER in $(seq 990 1000)
	do
	  i=2
	  f=0
	  while test $i -le `expr $NUMBER / 2`
	  do
	    if test `expr $NUMBER % $i` -eq 0
	    then
	      f=1
	    fi
	    i=`expr $i + 1`
	  done
	  if test $f -eq 1
	  then
	    echo "$NUMBER Not Prime"
	  else
	    echo "$NUMBER Prime"
	  fi
	done

The average execution time of each instance is

	baseline: 32.83
	patched:  32.53

$ perf diff
 # Event 'cycles'
 #
 # Baseline  Delta Abs  Shared Object          Symbol
 # ........  .........  .....................  ...........................................
 #
     1.87%     -0.37%  [kernel.vmlinux]       [k] handle_mm_fault

https://jira.sw.ru/browse/PSBM-101300
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/memory.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 6f30b214a779..a8e7033b011b 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3478,17 +3478,17 @@ static int handle_pte_fault(struct vm_fault *vmf)
 static int __handle_mm_fault(struct vm_area_struct *vma,
 		unsigned long address, unsigned int flags)
 {
-	struct vm_fault vmf = {
-		.vma = vma,
-		.virtual_address = (void *)address,
-		.flags = flags,
-		.pgoff = linear_page_index(vma, address),
-		.gfp_mask = __get_fault_gfp_mask(vma),
-	};
+	struct vm_fault vmf;
 	struct mm_struct *mm = vma->vm_mm;
 	pgd_t *pgd;
 	int ret;
 
+	vmf.vma = vma;
+	vmf.virtual_address = (void *)address;
+	vmf.flags = flags;
+	vmf.pgoff = linear_page_index(vma, address);
+	vmf.gfp_mask = __get_fault_gfp_mask(vma);
+
 	if (!arch_vma_access_permitted(vma, flags & FAULT_FLAG_WRITE,
 					    flags & FAULT_FLAG_INSTRUCTION,
 					    flags & FAULT_FLAG_REMOTE))
-- 
2.24.1



More information about the Devel mailing list