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

Call Collection::out_of_memory if the allocation size is larger than max heap size #896

Merged
merged 11 commits into from
Aug 18, 2023

Conversation

qinsoon
Copy link
Member

@qinsoon qinsoon commented Aug 10, 2023

This closes #867.

@qinsoon qinsoon marked this pull request as ready for review August 10, 2023 07:51
@qinsoon qinsoon requested a review from wks August 10, 2023 07:51
Copy link
Collaborator

@wks wks left a comment

Choose a reason for hiding this comment

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

See in-line comments. We probably can't let the VM recover from OOM for now. For the test case, maybe catch_unwind can be used to prevent the lock from being poisoned.

vmbindings/dummyvm/src/tests/fixtures/mod.rs Outdated Show resolved Hide resolved
src/policy/space.rs Outdated Show resolved Hide resolved
* Use catch/resume_rewind to avoid poison lock for SerialFixture.
* Rename oom_size_check to will_go_oom_on_acquire, and return a boolean.
* Add another test that is ignored.
@qinsoon
Copy link
Member Author

qinsoon commented Aug 15, 2023

There is an issue with this PR: if we try to do any address arithmetic in the allocation fastpath, we may have overflow in the computation, and we do not call out_of_memory() for that case. See the test below. I don't think we have a good way to deal with this, given that we do not want to introduce any check in the fastpath.

pub fn allocate_max_size_object_after_succeed() {

Copy link
Collaborator

@wks wks left a comment

Choose a reason for hiding this comment

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

LGTM

@k-sareen
Copy link
Collaborator

There is an issue with this PR: if we try to do any address arithmetic in the allocation fastpath, we may have overflow in the computation, and we do not call out_of_memory() for that case. See the test below. I don't think we have a good way to deal with this, given that we do not want to introduce any check in the fastpath.

pub fn allocate_max_size_object_after_succeed() {

One alternative, although I don't know how feasible it is, would be to register a custom panic handler and then call either out_of_memory or panic_in_vm (random function) or something to allow the VM binding to crash by itself. We discussed doing something similar in the OOM PR and #746

@wks
Copy link
Collaborator

wks commented Aug 15, 2023

There is an issue with this PR: if we try to do any address arithmetic in the allocation fastpath, we may have overflow in the computation, and we do not call out_of_memory() for that case. See the test below. I don't think we have a good way to deal with this, given that we do not want to introduce any check in the fastpath.

pub fn allocate_max_size_object_after_succeed() {

I think doing checking in Rust is OK. The "real" fast path should be implemented by the JIT compiler, or inlined to the concrete allocation sites. In most of the cases, the object size should be a constant, and doesn't need checking anyway, given that a bump-pointer allocator always checks against a reaonably-sized limit. If the object size is a variable, the VM should do the check anyway to avoid integer overflow. If the VM simply calls MMTk API function for fast-path allocation, it means the VM has not started optimising for performance (like the status of the Ruby binding two months ago). In that case, we should prefer correctness over performance.

@k-sareen
Copy link
Collaborator

If the VM simply calls MMTk API function for fast-path allocation, it means the VM has not started optimising for performance

In the case of a VM implemented in Rust, this is not necessarily true. It would be inlined by PGO

@wks
Copy link
Collaborator

wks commented Aug 15, 2023

If the VM simply calls MMTk API function for fast-path allocation, it means the VM has not started optimising for performance

In the case of a VM implemented in Rust, this is not necessarily true. It would be inlined by PGO

That makes sense. But if that's the case, the compiler can still eliminate the object size check if the supplied object size is a constant, although I am not 100% confident that the compiler will do it.

@k-sareen
Copy link
Collaborator

Often a "checked" and "unchecked" API is presented to a developer. They are recommended to use the "checked" one always but they can use the "unchecked" one for more performance, but they have to guarantee that they have checked the assumptions beforehand

@k-sareen
Copy link
Collaborator

Should we merge this or discuss how to fix the bug Yi noticed?

@qinsoon
Copy link
Member Author

qinsoon commented Aug 17, 2023

Should we merge this or discuss how to fix the bug Yi noticed?

I think we can merge this. I will try out the idea of catching Rust panics in a separate PR (I cannot guarantee it would work out though).

@qinsoon qinsoon merged commit 3cfdf75 into mmtk:master Aug 18, 2023
17 checks passed
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.

Gracefully deal with unrealistically large allocation sizes
3 participants