Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Test and fix for issue 333. #334

Merged
merged 2 commits into from
Aug 5, 2022
Merged

Conversation

heiner
Copy link
Contributor

@heiner heiner commented Aug 4, 2022

Fixes #333.

@facebook-github-bot
Copy link

Hi @heiner!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@heiner heiner changed the title Test for issue 333. Test and fix for issue 333. Aug 4, 2022
@heiner
Copy link
Contributor Author

heiner commented Aug 4, 2022

Looks like your flake8 and various tests are broken anyway. Proper FB engineering, here.

@cdmatters
Copy link
Contributor

Looks like your flake8 and various tests are broken anyway. Proper FB engineering, here.

Rude.

@heiner
Copy link
Contributor Author

heiner commented Aug 4, 2022

Looks like your flake8 and various tests are broken anyway. Proper FB engineering, here.

Rude.

:(

640K ought to be enough for anybody.
@@ -19,7 +19,7 @@
#include <bzlib.h>
#endif

#define STACK_SIZE (1 << 15) /* 32KiB */
#define STACK_SIZE (1 << 16) /* 64KiB */
Copy link
Contributor Author

@heiner heiner Aug 5, 2022

Choose a reason for hiding this comment

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

Perhaps a more fancy solution would be to do what pthreads do -- define a really large upper limit (8MiB or so) but use mmap to allocate the buffer and rely on page faults to grow actual memory usage. Perhaps @tscmoo can look into that :D

Edit: The above comment doesn't make much sense. Even just mallocing the buffer will have the same effect (pages are only "paged in" when accessed). The number above could just be set to a larger value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess what could be done is to add a guard page at the end, a la https://man7.org/linux/man-pages/man3/pthread_attr_setguardsize.3.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The above was in fact not that wrong after all. All ways of getting buffers short of mmap may/do initialize the memory and therefore page everything in.

But it turns out fcontext does exactly the right thing anyway: Itmprotects the bottom page of the new stack. I don't quite understand why this is a SIGBUS then, not a SIGSEGV.

However, I did learn: The page size of M1 MacBooks is 16384 and our 32KiB value was two pages, one of them protected and unavailable. Also, create_fcontext_stack actually picks a sensible default of called with 0, which we should just do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Except that that default is currently broken due to a recent glibc change, reported at septag/deboost.context#4.

@cdmatters
Copy link
Contributor

Alles gut!

@cdmatters cdmatters merged commit fa25f02 into facebookresearch:main Aug 5, 2022
@heiner heiner deleted the issue333 branch August 5, 2022 16:14
tanderson11 pushed a commit to tanderson11/nle that referenced this pull request Aug 4, 2023
* Test for issue 333.

* Make fcontext stack larger.

640K ought to be enough for anybody.
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.

Bus Error Entering DLVL 10-12
3 participants