Skip to content

Avoid data race in method caching in ocamlrun#11512

Merged
xavierleroy merged 1 commit intoocaml:trunkfrom
OlivierNicole:domainsafe_meth_cache
Sep 19, 2022
Merged

Avoid data race in method caching in ocamlrun#11512
xavierleroy merged 1 commit intoocaml:trunkfrom
OlivierNicole:domainsafe_meth_cache

Conversation

@OlivierNicole
Copy link
Copy Markdown
Contributor

When calling a method with the opcode GETPUBMET, the method address is resolved and possibly cached by modifying a word in the bytecode. If multiple domains execute the same GETPUBMET opcode concurrently, this is technically a data race. However, any integer value in the correct range is a safe value. Therefore we inform the compiler of potential concurrent accesses by using atomic accesses with relaxed memory order.

When calling a method with the opcode GETPUBMET, the method address is
resolved and possibly cached by modifying a word in the bytecode. If
multiple domains execute the same GETPUBMET opcode concurrently, this is
technically a data race. However, any integer value in the correct range
is a safe value. Therefore we inform the compiler of potential
concurrent accesses by using atomic accesses with relaxed memory order.
@OlivierNicole OlivierNicole force-pushed the domainsafe_meth_cache branch from c5d1049 to a97ab4f Compare August 25, 2022 12:33
Copy link
Copy Markdown
Contributor

@xavierleroy xavierleroy left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good to me. We can wait a few days for a second opinion.

@xavierleroy xavierleroy added this to the 5.0 milestone Aug 25, 2022
@garrigue
Copy link
Copy Markdown
Contributor

As a side remark, I kind of remember that the benefit of method caching was pretty limited for bytecode.
So an alternative might be to just turn it off when there is concurrency around.
This said, it may be worth doing a new round of benchmarks with recent architectures.

@xavierleroy
Copy link
Copy Markdown
Contributor

We got a second opinion (of sorts), so let's merge this PR. We could reconsider the use of method caching in bytecode later.

@xavierleroy xavierleroy merged commit b019062 into ocaml:trunk Sep 19, 2022
xavierleroy pushed a commit that referenced this pull request Sep 19, 2022
When calling a method with the opcode GETPUBMET, the method address is
resolved and possibly cached by modifying a word in the bytecode. If
multiple domains execute the same GETPUBMET opcode concurrently, this is
technically a data race. However, any integer value in the correct range
is a safe value. Therefore we inform the compiler of potential
concurrent accesses by using atomic accesses with relaxed memory order.

(cherry picked from commit b019062)
@xavierleroy
Copy link
Copy Markdown
Contributor

Cherry-picked to 5.0: e4db530

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

Successfully merging this pull request may close these issues.

3 participants