summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLokesh Gidra <lokeshgidra@google.com>2024-03-08 10:59:56 -0800
committerJhih-Chen Huang <jhihchen@google.com>2024-03-27 08:34:32 +0000
commit532729b8d2b1c4638c8d934ccd85a87c360fa7ad (patch)
tree5be688ca96bbc4ff53a12d5860b766054c07b393
parentc49c984b5c42f4aa6b12338996fed9344dfe57c4 (diff)
downloadcommon-532729b8d2b1c4638c8d934ccd85a87c360fa7ad.tar.gz
ANDROID: userfaultfd: abort uffdio ops if mmap_lock is contendedandroid13-5.10-2024-02_r3
Check if the mmap_lock is contended when looping over the pages that are requested to be filled. When it is observed, we rely on the already existing mechanism to return bytes copied/filled and -EAGAIN as error. This helps by avoiding contention of mmap_lock for long running userfaultfd operations. The userspace can perform other tasks before retrying the operation for the remaining pages. Bug: 320478828 Bug: 331529613 Signed-off-by: Lokesh Gidra <lokeshgidra@google.com> (cherry picked from https://android-review.googlesource.com/q/commit:6bc28fdfeec3373198d11fae1c9663a598ddb05c) Merged-In: I6d485fd03c96a826956ee3962e58058be3cf81c1 Change-Id: I6d485fd03c96a826956ee3962e58058be3cf81c1
-rw-r--r--mm/userfaultfd.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index 7e7fee431873..e8e8a7951c4a 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -664,6 +664,15 @@ retry:
if (unlikely(err == -ENOENT)) {
void *page_kaddr;
+ /*
+ * Return early due to mmap_lock contention only after
+ * some pages are copied to ensure that jank sensitive
+ * threads don't keep retrying for progress-critical
+ * pages.
+ */
+ if (copied && mmap_lock_is_contended(dst_mm))
+ break;
+
mmap_read_unlock(dst_mm);
BUG_ON(!page);
@@ -688,6 +697,9 @@ retry:
if (fatal_signal_pending(current))
err = -EINTR;
+
+ if (mmap_lock_is_contended(dst_mm))
+ err = -EAGAIN;
}
if (err)
break;