From eab0cdf2874a1cc32a3214cdb772ee805db49fbd Mon Sep 17 00:00:00 2001 From: Alan Stokes Date: Wed, 1 Mar 2023 12:13:23 +0000 Subject: [PATCH] Reduce virtmgr threads 16 incoming threads is too many, especially since they are started immediately. Instead reduce it to 2 - chosen slightly arbitrarily. Remove the explicit configuration of outgoing threads/connections; the default (10) should be fine. See the comments on aosp/2461836. Bug: 245727626 Test: atest MicrodroidTests Change-Id: I7c7bef09411d649aed3b2914a88100dff22c0dbd --- .../android_system_virtualmachine_VirtualizationService.cpp | 3 +-- vmclient/src/lib.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/javalib/jni/android_system_virtualmachine_VirtualizationService.cpp b/javalib/jni/android_system_virtualmachine_VirtualizationService.cpp index 6659a57f..fbd1fd59 100644 --- a/javalib/jni/android_system_virtualmachine_VirtualizationService.cpp +++ b/javalib/jni/android_system_virtualmachine_VirtualizationService.cpp @@ -29,7 +29,7 @@ using namespace android::base; static constexpr const char VIRTMGR_PATH[] = "/apex/com.android.virt/bin/virtmgr"; -static constexpr size_t VIRTMGR_THREADS = 16; +static constexpr size_t VIRTMGR_THREADS = 2; extern "C" JNIEXPORT jint JNICALL Java_android_system_virtualmachine_VirtualizationService_nativeSpawn( @@ -83,7 +83,6 @@ Java_android_system_virtualmachine_VirtualizationService_nativeConnect(JNIEnv* e ARpcSession_setFileDescriptorTransportMode(session.get(), ARpcSession_FileDescriptorTransportMode::Unix); ARpcSession_setMaxIncomingThreads(session.get(), VIRTMGR_THREADS); - ARpcSession_setMaxOutgoingConnections(session.get(), VIRTMGR_THREADS); // SAFETY - ARpcSession_setupUnixDomainBootstrapClient does not take ownership of clientFd. auto client = ARpcSession_setupUnixDomainBootstrapClient(session.get(), clientFd); return AIBinder_toJavaBinder(env, client); diff --git a/vmclient/src/lib.rs b/vmclient/src/lib.rs index 77ddf05d..d67d87e5 100644 --- a/vmclient/src/lib.rs +++ b/vmclient/src/lib.rs @@ -57,7 +57,7 @@ const VIRTUALIZATION_SERVICE_BINDER_SERVICE_IDENTIFIER: &str = "android.system.virtualizationservice"; const VIRTMGR_PATH: &str = "/apex/com.android.virt/bin/virtmgr"; -const VIRTMGR_THREADS: usize = 16; +const VIRTMGR_THREADS: usize = 2; fn posix_pipe() -> Result<(OwnedFd, OwnedFd), io::Error> { use nix::fcntl::OFlag; @@ -122,7 +122,6 @@ impl VirtualizationService { let session = RpcSession::new(); session.set_file_descriptor_transport_mode(FileDescriptorTransportMode::Unix); session.set_max_incoming_threads(VIRTMGR_THREADS); - session.set_max_outgoing_connections(VIRTMGR_THREADS); session .setup_unix_domain_bootstrap_client(self.client_fd.as_fd()) .map_err(|_| io::Error::from(io::ErrorKind::ConnectionRefused))