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:38:58 +0000
commitb26824bed88d7ef26dcfc12d6ccc9a5176df6fa1 (patch)
tree8172b241082c95c249e58ebfa69e369612c4bf08
parenta439a1a38751f18efe2639142b03864df13bc5e3 (diff)
downloadcommon-b26824bed88d7ef26dcfc12d6ccc9a5176df6fa1.tar.gz
ANDROID: userfaultfd: abort uffdio ops if mmap_lock is contendedandroid13-5.10-2024-03_r2
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: 331535903 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;