Commit c826a71a authored by Kenton Varda's avatar Kenton Varda

Fix estimation of Return message sizes.

Apparently, Return messages with empty capability tables have been allocated one word too small all along, causing many Return messages to be split into two segments and allocate twice the memory they need. I never bothered to check whether this was happening...
parent 889d7583
......@@ -56,7 +56,9 @@ constexpr const uint CAP_DESCRIPTOR_SIZE_HINT = sizeInWords<rpc::CapDescriptor>(
constexpr const uint64_t MAX_SIZE_HINT = 1 << 20;
uint copySizeHint(MessageSize size) {
uint64_t sizeHint = size.wordCount + size.capCount * CAP_DESCRIPTOR_SIZE_HINT;
uint64_t sizeHint = size.wordCount + size.capCount * CAP_DESCRIPTOR_SIZE_HINT
// if capCount > 0, the cap descriptor list has a 1-word tag
+ (size.capCount > 0);
return kj::min(MAX_SIZE_HINT, sizeHint);
}
......@@ -1141,6 +1143,11 @@ private:
kj::Array<ExportId> writeDescriptors(kj::ArrayPtr<kj::Maybe<kj::Own<ClientHook>>> capTable,
rpc::Payload::Builder payload, kj::Vector<int>& fds) {
if (capTable.size() == 0) {
// Calling initCapTable(0) will still allocate a 1-word tag, which we'd like to avoid...
return nullptr;
}
auto capTableBuilder = payload.initCapTable(capTable.size());
kj::Vector<ExportId> exports(capTable.size());
for (uint i: kj::indices(capTable)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment