aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLokesh Gidra <lokeshgidra@google.com>2024-03-08 10:59:56 -0800
committerLokesh Gidra <lokeshgidra@google.com>2024-03-15 19:49:14 +0000
commita0b6273ec3668fd41e8b94941e3b608c4592875a (patch)
tree6aeef82508716b7c2f6f2dee60cb179d53a6fd0a
parente3aabbf867efe1023678b3f73f447c56685bbcf3 (diff)
downloadhikey-linaro-a0b6273ec3668fd41e8b94941e3b608c4592875a.tar.gz
ANDROID: userfaultfd: abort uffdio ops if mmap_lock is contended
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 Change-Id: I6d485fd03c96a826956ee3962e58058be3cf81c1 Signed-off-by: Lokesh Gidra <lokeshgidra@google.com>
-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;