[rh7] mm: slightly optimize __handle_mm_fault()

Submitted by Andrey Ryabinin on Feb. 17, 2020, 11:57 a.m.

Details

Message ID 20200217115741.1382-1-aryabinin@virtuozzo.com
State New
Series "mm: slightly optimize __handle_mm_fault()"
Headers show

Commit Message

Andrey Ryabinin Feb. 17, 2020, 11:57 a.m.
__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@virtuozzo.com>
---
 mm/memory.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

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