[SERVER-61094] Generating KeyStrings from MultiIndexBlock can result in memory limits not being respected Created: 28/Oct/21  Updated: 29/Oct/23  Resolved: 02/Nov/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 5.0.0
Fix Version/s: 5.2.0, 5.0.4, 5.1.0-rc3

Type: Bug Priority: Blocker - P1
Reporter: Henrik Edin Assignee: Henrik Edin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Problem/Incident
is caused by SERVER-47001 Reduce number of small buffer allocat... Closed
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.1, v5.0
Sprint: Execution Team 2021-11-15
Participants:
Case:
Linked BF Score: 135

 Description   

When generating KeyString keys we use the KeyString::PooledBuilder that places multiple temporary KeyString on the same larger memory block to avoid multiple small allocations. Each KeyString holds a reference to the underlying memory that will not be free'd until all KeyString that is using it has been free'd.

Normally this is fine as these KeyString are passed to the sorter that spills do disk when the memory consumption reach a certain threshold. As this process clears all temporary KeyString instances all memory blocks should be free'd.

However, when there are multiple indexes being built at the same time these pooled memory blocks can be shared between KeyString instances belonging to different indexes. If some indexes generate large keys and need to be flushed to disk often the actual memory will not be free'd if there is still an index building that hasn't needed to spill to disk.



 Comments   
Comment by Githook User [ 02/Nov/21 ]

Author:

{'name': 'Henrik Edin', 'email': 'henrik.edin@mongodb.com', 'username': 'henrikedin'}

Message: SERVER-61094 Use a dedicated pooled KeyString builder per index

This avoids underlying SharedBuffer to be shared for KeyString for
separate indexes. Allows indexes that need to spill to disk to
independently free memory instead of being pinned by unrelated other
indexes.

(cherry picked from commit 5d1078c60e8f24e027dc72d7ceeac4dab49908b9)
Branch: v5.1
https://github.com/mongodb/mongo/commit/36a5fe52e2b76c6122e906237d8fb3378e4194e6

Comment by Githook User [ 02/Nov/21 ]

Author:

{'name': 'Henrik Edin', 'email': 'henrik.edin@mongodb.com', 'username': 'henrikedin'}

Message: SERVER-61094 Use a dedicated pooled KeyString builder per index

This avoids underlying SharedBuffer to be shared for KeyString for
separate indexes. Allows indexes that need to spill to disk to
independently free memory instead of being pinned by unrelated other
indexes.

(cherry picked from commit 5d1078c60e8f24e027dc72d7ceeac4dab49908b9)
Branch: v5.0
https://github.com/mongodb/mongo/commit/ca88ae9117d06b90dfaf57940484086bd4e0ed82

Comment by Githook User [ 01/Nov/21 ]

Author:

{'name': 'Henrik Edin', 'email': 'henrik.edin@mongodb.com', 'username': 'henrikedin'}

Message: SERVER-61094 Use a dedicated pooled KeyString builder per index

This avoids underlying SharedBuffer to be shared for KeyString for
separate indexes. Allows indexes that need to spill to disk to
independently free memory instead of being pinned by unrelated other
indexes.
Branch: master
https://github.com/mongodb/mongo/commit/5d1078c60e8f24e027dc72d7ceeac4dab49908b9

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