Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Fixes #451: Introduce a custom heap size limit to new_instance_with()#458

Merged
fst-crenshaw merged 42 commits intomasterfrom
tlc/issue-451-b
Apr 6, 2020
Merged

Fixes #451: Introduce a custom heap size limit to new_instance_with()#458
fst-crenshaw merged 42 commits intomasterfrom
tlc/issue-451-b

Conversation

@fst-crenshaw
Copy link
Contributor

@fst-crenshaw fst-crenshaw commented Mar 24, 2020

See #451 for description of the issue and proposed solution.

Still to do:

  • Replace pub fn with_heap_size_limit(mut self, heap_memory_size: usize) -> Self with trendier pub fn with_heap_size_limit(&mut self, heap_memory_size: usize) -> &mut Self.. This isn't actually possible because it's not possible to Clone an InstanceBuilder.
  • I making a call to clone() that feels extraneous and would like to hear thoughts on a better way. Add the Copy trait to the Limits type.
  • Examine for the possibility of more tests.
  • Augment the Alloc, not the Slot Limits.

@fst-crenshaw fst-crenshaw changed the title [WIP] Fixes #451: Introduce a custom heap size limit to new_instance_wit() [WIP] Fixes #451: Introduce a custom heap size limit to new_instance_with() Mar 24, 2020
Copy link
Contributor

@acfoltzer acfoltzer left a comment

Choose a reason for hiding this comment

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

This is definitely on the right track. I would like to see variations on expand_past_heap_limit and reject_initial_oversize_heap where the region Limits would be sufficient, but the per-instance limit is not.

@fst-crenshaw
Copy link
Contributor Author

Thanks to @acfoltzer for the suggestions on how to expand testing for this PR!

I've begun work on creating a test similar to expand_past_spec_max but I realize I am feeling unsure about the interactions between:

  • a Region,
  • a Mocked Module’s Heap Spec
  • an Instance’s heap memory size limit
  • making a call to expand_heap.

I have a test that does the following:

  • Make a Region with default limits.
  • Make a Module with a three-page heap spec.
  • Make an Instance with a one-page heap memory size limit.
  • Call expand_heap() on the instance.

I think the desired result is that the test ought to fail. It currently does not because I've done no work on making enhancements to expand_heap. But I also might be misunderstanding something.

Here's the test: https://github.com/bytecodealliance/lucet/pull/458/files#diff-b03e99218c26a9cc6576a1e98a226430R202

@acfoltzer
Copy link
Contributor

I think you've got it correctly. The heap spec is an extra complication, but you can think of yet another limit on heap size, this time specified at compile time rather than at runtime.

  • Make a Region with default limits.

I will point out that this is using a LIMITS constant in the test module, not Limits::default(). I don't think that should affect the correctness of your test, though.

Copy link
Contributor

@acfoltzer acfoltzer left a comment

Choose a reason for hiding this comment

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

Looking good, but I think we should store the per-instance limit in Alloc rather than mutating Slots. Conceptually, an Alloc is just a Slot that has been instantiated, so anything that's instance-specific should live there so it goes away when the instance does. I provided a tweak to one of the tests to illustrate why.

@fst-crenshaw
Copy link
Contributor Author

It may not seem like it from the CI, but this is ready for another review when folks have the cycles. Everything passed on 44bc0b0. Since then, I corrected a spelling error and then retriggered the CI a few times. It seems like the little mac mini farm might be having a bad time.

Copy link
Contributor

@acfoltzer acfoltzer left a comment

Choose a reason for hiding this comment

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

Looks good! Once CI is resolved, can you rebase away the intermediate commits that were just for triggering CI? Then I'll give a final +1.

@fst-crenshaw
Copy link
Contributor Author

This is ready for another review.

acfoltzer
acfoltzer previously approved these changes Apr 6, 2020
Copy link
Contributor

@acfoltzer acfoltzer left a comment

Choose a reason for hiding this comment

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

👍 sorry for not following up sooner on this one

@fst-crenshaw fst-crenshaw changed the title [WIP] Fixes #451: Introduce a custom heap size limit to new_instance_with() Fixes #451: Introduce a custom heap size limit to new_instance_with() Apr 6, 2020
@fst-crenshaw
Copy link
Contributor Author

One more time? 😄 😊 https://www.youtube.com/watch?v=FGBhQbmPwH8

@fst-crenshaw fst-crenshaw requested a review from acfoltzer April 6, 2020 21:41
}

for (ptr, len) in [
// make the stack read/writable
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I didn't catch this before, but this is also an early return. Since it would reflect a bug in Lucet, I think we should change it to a panic/assert rather than returning an InternalError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the code you point at is in master, and since it feels a bit unrelated to my main task of customizing limits, I wonder if you might accept my fixing it in a PR over here: #486.

Copy link
Contributor

Choose a reason for hiding this comment

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

I left feedback there, but it is related to this PR because the early return at that location would cause the slot to leak.

Copy link
Contributor

Choose a reason for hiding this comment

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

... sorry, I got confused about which PR I was looking at. Not the one we already merged 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries. I'm having trouble keeping the little changes straight as well.

Copy link
Contributor

@acfoltzer acfoltzer left a comment

Choose a reason for hiding this comment

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

👍

@fst-crenshaw fst-crenshaw merged commit 83fd224 into master Apr 6, 2020
@fst-crenshaw fst-crenshaw deleted the tlc/issue-451-b branch April 6, 2020 23:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants