Fallback to stop-the-world compaction on kernel < 5.13 hosts
Some test bots are running 5.4 kernel on which SIGBUS is being observed.
There is a request pending to upgrade the host kernels. Until then
don't use userfaultfd on such old kernels.
Test: ART_USE_READ_BARRIER=false art/test/testrunner/testrunner.py --host
Bug: 242181443
Bug: 160737021
Change-Id: I1c1f6662d773927c5938cbb054974e295f83580e
diff --git a/runtime/gc/collector/mark_compact.cc b/runtime/gc/collector/mark_compact.cc
index 8240711..21e63e2 100644
--- a/runtime/gc/collector/mark_compact.cc
+++ b/runtime/gc/collector/mark_compact.cc
@@ -65,7 +65,7 @@
// on target is not required as MREMAP_DONTUNMAP and userfaultfd were enabled
// together.
#ifdef ART_TARGET
-static const bool gHaveMremapDontunmap = true;
+static constexpr bool gHaveMremapDontunmap = true;
#else
static const bool gHaveMremapDontunmap = IsKernelVersionAtLeast(5, 13);
#endif
@@ -74,6 +74,12 @@
static bool ShouldUseUserfaultfd() {
#if !defined(__linux__)
return false;
+#elif !defined(ART_TARGET)
+ // TODO: Try removing the following constraint once the host kernel version is
+ // upgraded (b/242181443)
+ if (!gHaveMremapDontunmap) {
+ return false;
+ }
#endif
int fd = syscall(__NR_userfaultfd, O_CLOEXEC | UFFD_USER_MODE_ONLY);
#ifndef ART_TARGET