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

Ensure thread safety for memory mappings. #6509

Merged
merged 4 commits into from
May 4, 2023

Conversation

nicola-cab
Copy link
Member

@nicola-cab nicola-cab commented Apr 17, 2023

What, How & Why?

It seems we are not always thread safe while accessing m_mappings inside the slab allocator.

This could have caused #6508, but also it could be the cause of #6378 and #6510

Unfortunately, this is just a guess, since I haven't found a way to reproduce the issues yet.

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)
  • C-API, if public C++ API changed.

@cla-bot cla-bot bot added the cla: yes label Apr 17, 2023
@nicola-cab nicola-cab changed the title lock guard while accessing m_mappings Ensure thread safety for memory mappings. Apr 17, 2023
Copy link
Contributor

@finnschiermer finnschiermer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have some indication that lacking locking during attach/detach is problematic. Like stack traces from crashes involving any of these methods?

src/realm/alloc_slab.cpp Outdated Show resolved Hide resolved
REALM_ASSERT(m_mappings.size());
m_data = m_mappings[0].primary_mapping.get_addr();
realm::util::encryption_read_barrier(m_mappings[0].primary_mapping, 0, sizeof(Header));
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locking here should not be needed. The slab allocator is just being attached, and no other thread should have a reference to it at this point.

@nicola-cab
Copy link
Member Author

@finnschiermer I think the assumption has changed or there is some other problem elsewhere, since m_mappings was empty in one of our runs: #6508 ...

@jedelbo jedelbo removed their request for review April 20, 2023 08:32
@finnschiermer
Copy link
Contributor

@nicola-cab Thx for highlighting this for me. Very interesting.

@nicola-cab nicola-cab marked this pull request as ready for review May 2, 2023 16:04
Copy link
Contributor

@finnschiermer finnschiermer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nicola-cab nicola-cab merged commit 1fb4644 into master May 4, 2023
@nicola-cab nicola-cab deleted the nc/fix_lockguard_for_mappings branch May 4, 2023 09:32
@nicola-cab
Copy link
Member Author

This PR although protects the mappings vector while reading the last committed format version, does not explain the other issues we have been seeing around the slab allocator. For now, I will keep them open and keep digging in.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants