-
Notifications
You must be signed in to change notification settings - Fork 456
CDRIVER-2813 remove BSON_EXTRA_ALIGNMENT option
#1942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CDRIVER-2813 remove BSON_EXTRA_ALIGNMENT option
#1942
Conversation
Other types do not have alignment attribute. May not be relevant to documentation?
| * This structure is meant to fit in two sequential 64-byte cachelines. | ||
| */ | ||
| BSON_ALIGNED_BEGIN (128) typedef struct _bson_t { | ||
| BSON_ALIGNED_BEGIN (BSON_ALIGN_OF_PTR) typedef struct _bson_t { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we instead fix bson_aligned_alloc to increase the alignment size if it is below pointer alignment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am concerned removing the alignment specifier could break existing code allocating without libbson functions. Example:
bson_t *b = aligned_alloc (alignof(bson_t), sizeof(bson_t));
Upgrading to 2.0 may make this a runtime error. Maybe (hopefully) it is unlikely. I see no usage on GitHub code search for align.*bson_t. Though there is use of malloc.*bson_t.
AFAIK types being aligned to a pointer size (or 8) is less of an issue. If there is little observed benefit, it might not be worth the risk (even if small).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Polymorphic types such as bson_t and bson_reader_t require a pointer alignment specifier in their "base" type due to pointer data members in their "derived" types (bson_impl_alloc_t and bson_reader_handle_t respectively). The alignment specifier is probably preferable to awkwardly inserting a stub pointer data member in the "base" type.
eramongodb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest also removing the debug-compile-no-align tasks from the legacy config.
Co-authored-by: Ezra Chung <[email protected]>
Not needed. Type aleady contains pointers. Add a static assert to ensure that `bson_t` and the implementations have matching alignment.
Already has a pointer type.
vector-of-bool
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Note: partially reverting mongodb/mongo-cxx-driver#1329 (reverting only the addition and use of Runtime alignment errors are not observed when running C++ Driver UBSan tasks with the partial revert using the changes in this PR branch. 👍 |
Summary
ENABLE_EXTRA_ALIGNMENT.bson_tandbson_iter_tto the size of a pointer.Verified with this patch build: https://spruce.mongodb.com/version/67dc0db1caab950007b0f764
Motivation
Addresses long-standing ask to remove default over-alignment: CDRIVER-2813.
Removing alignment specifiers entirely was considered. However, removing the alignment specifier on
bson_tresulted in a runtime error in calls toBSON_ALIGNED_ALLOC (bson_t):I expect this is due to
bson_thaving alignment of 4.bson_tdoes not contain a pointer.From
man aligned_alloc(emphasis mine):To limit the risk of causing runtime errors in user upgrades, this PR proposes keeping existing alignment specifiers. Only the over-alignment of
bson_tandbson_iter_tis changed.Alignment changes
The following were printed on my 64-bit machine to compare alignment changes.
Prior to this PR. With
ENABLE_EXTRA_ALIGNMENT=ON:With all alignment specifiers removed (not done in this PR):
With this PR: