[SERVER-60115] Fix the Buffer Builder to Correctly use Powers of Two Allocations Created: 21/Sep/21  Updated: 29/Oct/23  Resolved: 21/Oct/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.2.0

Type: Improvement Priority: Major - P3
Reporter: Mohammad Dashti (Inactive) Assignee: Mohammad Dashti (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
Related
related to SERVER-60137 Improve Buffer Allocation for Common ... Closed
Backwards Compatibility: Fully Compatible
Sprint: QE 2021-10-04, QE 2021-10-18, QE 2021-11-01
Participants:
Linked BF Score: 135

 Description   

Currently, the buffer builder tries to be friendly with the system allocators and ask for powers of two allocations: https://github.com/10gen/mongo/blob/34bb8ccdba458e000b7b0ce7b6c0c157619fcdd6/src/mongo/bson/util/builder.h#L460-L462

However, then later down the function call chains, this power of two size is increased by a few bytes: https://github.com/10gen/mongo/blob/fcdc972cd6f64bfe710161fb3a0ffc4a5ca329d1/src/mongo/util/shared_buffer.h#L73

In this issue, we want to fix this behaviour and make sure that the end allocated size asked from the system allocator (https://github.com/10gen/mongo/blob/47b380f03e8898f4706ff01fa2be64dfb72e0dba/src/mongo/util/allocator.cpp#L47) is a power of two.



 Comments   
Comment by Githook User [ 24/Oct/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-60115 Fix compile error in C++20 mode with GCC 11

This removes MONGO_COMPILER_NOINLINE from Builder::_growReallocate(). The no-inline directive
somehow triggers the -Werror=array-bounds warning in GCC in the C++ 20 builders.

This function was originally moved out of line in commit f6d863188b71b420f13b8249579d34de76d80d9c
but subsequently inlined again in commit 4994a4809269c30a28cdbb686c8c876fad7b163a.
Branch: master
https://github.com/mongodb/mongo/commit/49b73bcd26b3fc73032587fb3fa5dadd989607a5

Comment by Githook User [ 21/Oct/21 ]

Author:

{'name': 'Mohammad Dashti', 'email': 'mdashti@gmail.com', 'username': 'mdashti'}

Message: SERVER-60115 Fixed `BasicBufBuilder` to correctly use powers of two allocations
Branch: master
https://github.com/mongodb/mongo/commit/d7a4c99472599e63b6e1f9cdb66008bb3a99bacd

Generated at Thu Feb 08 05:48:59 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.