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

Allow sanity check to pass without locking the cache #17434

Merged
merged 1 commit into from
Aug 6, 2022
Merged

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jul 14, 2022

We check the sanity file once, without holding the lock, and if that
fails we acquire the lock and check again.

This means that if some other process is performing some long running
cache operation (e.g building libc) it won't block all emscripten
processes from running (e.g. compile processes won't be blocked by link
process).

@sbc100 sbc100 requested a review from kripken July 14, 2022 16:13
@sbc100 sbc100 force-pushed the sanity_no_lock branch 2 times, most recently from a846583 to 052096d Compare July 14, 2022 17:00
@sbc100 sbc100 requested a review from kripken July 14, 2022 18:58
# Essentially the env. var EM_EXCLUSIVE_CACHE_ACCESS signals from parent to
# child process that the child can reuse the lock that the parent already has
# acquired.
EM_EXCLUSIVE_CACHE_ACCESS = int(os.environ.get('EM_EXCLUSIVE_CACHE_ACCESS', '0'))
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this?

Copy link
Collaborator Author

@sbc100 sbc100 Jul 14, 2022

Choose a reason for hiding this comment

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

Its not needed anymore, which I think is a nice feature of this change.

Basically, compile-only sub-processed should no longer require getting the cache lock, since they are not writing anything into the cache. Prior to this change compiler-subprocess could not be run while holding the lock since they would always try to acquire it during the sanity check.

Without this the new test I wrote will just always pass since the test runner is a parent process of the compiler processes it run.

Copy link
Member

Choose a reason for hiding this comment

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

I don't follow. emcc -c -sUSE_SDL2 will fetch SDL2 and write it into the cache, even though this is a compile-only command - we need to fetch SDL2 to get its header in order to compile with them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I put some logic back in to catch any times a child does try to lock the cache when a parent holds the lock already... which should never happen, but if it does this will give a clear error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't follow. emcc -c -sUSE_SDL2 will fetch SDL2 and write it into the cache, even though this is a compile-only command - we need to fetch SDL2 to get its header in order to compile with them?

I that case the parent process is the only one that writes to the cache. The parent triggers N different compile jobs, then it run emar to combine them, but neither the compile or the emar need to lock the cache. Only the parent would lock the cache in this case.

Allowing the child process to modify the cache while the parent is hold the lock was always a little strange.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the past all the children would pointlessly/needlessly lock the cache just the run the sanity check.

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

I see, thanks. lgtm with that extra assertion.

@sbc100 sbc100 enabled auto-merge (squash) July 14, 2022 20:55
@sbc100 sbc100 force-pushed the sanity_no_lock branch 3 times, most recently from 8702c8f to 5470ef3 Compare July 14, 2022 22:45
@sbc100 sbc100 force-pushed the sanity_no_lock branch 6 times, most recently from 9782ac4 to b8d9732 Compare August 6, 2022 15:07
We check the sanity file once, without holding the lock, and if that
fails we acquire the lock and check again.

This means that if some other process is performing some long running
cache operation (e.g building libc) it won't block all emscripten
processes from running (e.g. compile processes won't be blocked by link
process).
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.

2 participants