From 54fa6c72a903905b388ea8193cd2ffcf5abeb8bf Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Tue, 28 Jan 2025 01:02:15 +0000 Subject: RPC Binder: increase transaction size One of the RPC Binder usecases requires a larger transaction limit. This change increases the limit, and it unifies the 'too large transaction' logging from regular and RPC binder. This hopefully makes it more clear why there is a limit there, we want to keep code compatible between the two transports. A test is added to show the current behavior. When a transaction which is sent is too large, the server closes the session. This is probably the correct behavior for too large replies, but for too large transactions, the client could handle these errors. b/392717039 is filed to investigate inconsistencies raised in the test more deeply. Fixes: 392575419 Test: atest binderRpcTest --test-filter="*LargeVector*" Change-Id: I2eeb08818c10371c7f77a35abee7d4e46bb63d72 --- libs/binder/RpcState.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'libs/binder/RpcState.cpp') diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp index fe6e1a3318..03d974d186 100644 --- a/libs/binder/RpcState.cpp +++ b/libs/binder/RpcState.cpp @@ -23,6 +23,7 @@ #include #include +#include "Constants.h" #include "Debug.h" #include "RpcWireFormat.h" #include "Utils.h" @@ -337,6 +338,8 @@ std::string RpcState::BinderNode::toString() const { } RpcState::CommandData::CommandData(size_t size) : mSize(size) { + if (size == 0) return; + // The maximum size for regular binder is 1MB for all concurrent // transactions. A very small proportion of transactions are even // larger than a page, but we need to avoid allocating too much @@ -348,11 +351,11 @@ RpcState::CommandData::CommandData(size_t size) : mSize(size) { // transaction (in some cases, additional fixed size amounts are added), // though for rough consistency, we should avoid cases where this data type // is used for multiple dynamic allocations for a single transaction. - constexpr size_t kMaxTransactionAllocation = 100 * 1000; - if (size == 0) return; - if (size > kMaxTransactionAllocation) { - ALOGW("Transaction requested too much data allocation %zu", size); + if (size > binder::kRpcTransactionLimitBytes) { + ALOGE("Transaction requested too much data allocation: %zu bytes, failing.", size); return; + } else if (size > binder::kLogTransactionsOverBytes) { + ALOGW("Transaction too large: inefficient and in danger of breaking: %zu bytes.", size); } mData.reset(new (std::nothrow) uint8_t[size]); } -- cgit v1.2.3-59-g8ed1b