Skip to content

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

Open

Description

@ColinLeeo

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.

Activity

  1. ColinLeeo commented on Sep 9, 2024

    @ColinLeeo
    ContributorAuthor

    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.
  2. jt2594838 commented on Sep 12, 2024

    @jt2594838
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions