Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d828b7c authored by Mahendran Ganesh's avatar Mahendran Ganesh Committed by Vinayak Menon
Browse files

arm64/mm: add speculative page fault



This patch enables the speculative page fault on the arm64
architecture.

I completed spf porting in 4.9. From the test result,
we can see app launching time improved by about 10% in average.
For the apps which have more than 50 threads, 15% or even more
improvement can be got.

Change-Id: Ib7c8b2e354800b5023e6c6400448a6d40aaf89c8
Signed-off-by: default avatarGanesh Mahendran <opensource.ganesh@gmail.com>
Patch-mainline: linux-mm @ Wed, 2 May 2018 15:54:32
[vinmenon@codeaurora.org: remove the speculative fault perf counter
plus 4.9 porting conflict fixes - rearrange the __do_page_fault code
to make it work fine with speculative page fault]
Signed-off-by: default avatarVinayak Menon <vinmenon@codeaurora.org>
parent c3e566a6
Loading
Loading
Loading
Loading
+45 −24
Original line number Diff line number Diff line
@@ -253,14 +253,12 @@ static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *re
#define VM_FAULT_BADMAP		0x010000
#define VM_FAULT_BADACCESS	0x020000

static int __do_page_fault(struct mm_struct *mm, unsigned long addr,
static int __do_page_fault(struct vm_area_struct *vma, unsigned long addr,
			   unsigned int mm_flags, unsigned long vm_flags,
			   struct task_struct *tsk)
{
	struct vm_area_struct *vma;
	int fault;

	vma = find_vma(mm, addr);
	fault = VM_FAULT_BADMAP;
	if (unlikely(!vma))
		goto out;
@@ -318,6 +316,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
	int fault, sig, code;
	unsigned long vm_flags = VM_READ | VM_WRITE;
	unsigned int mm_flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
	struct vm_area_struct *vma = NULL;

	if (notify_page_fault(regs, esr))
		return 0;
@@ -355,6 +354,14 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
			die("Accessing user space memory outside uaccess.h routines", regs, esr);
	}

	/*
	 * let's try a speculative page fault without grabbing the
	 * mmap_sem.
	 */
	fault = handle_speculative_fault(mm, addr, mm_flags, &vma);
	if (fault != VM_FAULT_RETRY)
		goto done;

	/*
	 * As per x86, we may deadlock here. However, since the kernel only
	 * validly references user space from well defined areas of the code,
@@ -377,19 +384,44 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
#endif
	}

	fault = __do_page_fault(mm, addr, mm_flags, vm_flags, tsk);
	if (!vma || !can_reuse_spf_vma(vma, addr))
		vma = find_vma(mm, addr);

	fault = __do_page_fault(vma, addr, mm_flags, vm_flags, tsk);
	if (fault & VM_FAULT_RETRY) {
		/*
		 * If we need to retry but a fatal signal is pending, handle the
	 * signal first. We do not need to release the mmap_sem because it
	 * would already be released in __lock_page_or_retry in mm/filemap.c.
		 * signal first. We do not need to release the mmap_sem because
		 * it would already be released in __lock_page_or_retry in
		 * mm/filemap.c.
		 */
	if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) {

		if (fatal_signal_pending(current)) {
			if (!user_mode(regs))
				goto no_context;
			return 0;
		}

		/*
		 * Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk of
		 * starvation.
		 */
		if (mm_flags & FAULT_FLAG_ALLOW_RETRY) {
			mm_flags &= ~FAULT_FLAG_ALLOW_RETRY;
			mm_flags |= FAULT_FLAG_TRIED;

			/*
			 * Do not try to reuse this vma and fetch it
			 * again since we will release the mmap_sem.
			 */
			vma = NULL;
			goto retry;
		}
	}

	up_read(&mm->mmap_sem);
done:

	/*
	 * Major/minor page fault accounting is only done on the initial
	 * attempt. If we go through a retry, it is extremely likely that the
@@ -407,19 +439,8 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
			perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs,
				      addr);
		}
		if (fault & VM_FAULT_RETRY) {
			/*
			 * Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk of
			 * starvation.
			 */
			mm_flags &= ~FAULT_FLAG_ALLOW_RETRY;
			mm_flags |= FAULT_FLAG_TRIED;
			goto retry;
		}
	}

	up_read(&mm->mmap_sem);

	/*
	 * Handle the "normal" case first - VM_FAULT_MAJOR
	 */