Skip to content
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

[CPP]. Unaligned memory can cause a bus error on some architectures. #235

Open
ColinLeeo opened this issue Sep 9, 2024 · 2 comments
Open

Comments

@ColinLeeo
Copy link
Contributor

ColinLeeo commented Sep 9, 2024

In the aarch64 architecture, atomic instructions have alignment requirements for memory addresses. If these requirements are not met, a bus error may occur.
In C++ code, most objects are created in this form:

void *buf = allocator_.alloc(sizeof(classA));
classA obj = new (buf) classA;

The allocator pre-requests a block of memory from the operating system and initializes objects within this space.This could result in some objects having an improper starting position, leading to errors when executing atomic-related instructions.

For example, some strings require a block of memory to store data. After memory is allocated for the string, the allocated pointer is located at a non-aligned address.

@ColinLeeo
Copy link
Contributor Author

Possible solutions:

  1. Remove the atomic-related instructions in the code, as TsFile requests are now independent and there are no concurrency issues, making the use of atomic instructions unnecessary.
  2. Set alignment options for the custom allocator, taking into account the architecture's alignment requirements when returning data pointers.

@jt2594838
Copy link
Contributor

Good point. If the issue only concerns atomics, we may adopt the first one.
If we are not sure, the second one is more thorough.

I do not know how difficult it is to introduce the aligned feature in the current allocator. If it needs a major refactor, we may change to malloc for such architectures temporarily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants