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

cranelift: Round inline stack probes down, not up #8397

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jameysharp
Copy link
Contributor

When we have enable_probestack turned on and set probestack_strategy to "inline", we have to compute how many pages of the stack we'll probe.

The current implementation rounds our stack frame size up to the nearest multiple of the page size, then probes each page once.

However, if our stack frame is not a multiple of the page size, that means there's a partial page at the end. It's not necessary to probe that partial page, just like it's unnecessary to probe at all if the frame is smaller than one page. Either way, any signal handler needs to be prepared for stack accesses on that last page to fault at any time during the function's execution.

When we have `enable_probestack` turned on and set `probestack_strategy`
to "inline", we have to compute how many pages of the stack we'll probe.

The current implementation rounds our stack frame size up to the nearest
multiple of the page size, then probes each page once.

However, if our stack frame is not a multiple of the page size, that
means there's a partial page at the end. It's not necessary to probe
that partial page, just like it's unnecessary to probe at all if the
frame is smaller than one page. Either way, any signal handler needs to
be prepared for stack accesses on that last page to fault at any time
during the function's execution.
@jameysharp jameysharp requested a review from a team as a code owner April 17, 2024 22:11
@jameysharp jameysharp requested review from fitzgen and removed request for a team April 17, 2024 22:11
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen labels Apr 17, 2024
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Good find!

Comment on lines +680 to +683
let probe_count = frame_size / guard_size;
if probe_count == 0 {
// No probe necessary
} else if probe_count <= PROBE_MAX_UNROLL {
Copy link
Member

Choose a reason for hiding this comment

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

Mind leaving a comment about why this doesn't need aligning up here? Kind of unfortunate it would need to be copied to all the other inline probestack code paths. Maybe that is a sign that we should factor this little bit of logic out to a generic helper?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants