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

runtime: difficulty handling system page aligned stacks #41008

Open
4a6f656c opened this issue Aug 24, 2020 · 4 comments
Open

runtime: difficulty handling system page aligned stacks #41008

4a6f656c opened this issue Aug 24, 2020 · 4 comments
Milestone

Comments

@4a6f656c
Copy link
Contributor

@4a6f656c 4a6f656c commented Aug 24, 2020

The current runtime stack allocation is based on mheap, which uses its own fixed page size (4096 bytes). On some systems there is a requirement to have stacks be system page aligned (for example, 16KB alignment for OpenBSD/octeon). In this case, if mheap provides memory that is not 16KB aligned various things fail.

There are a couple of options to address this:

  1. Make it possible to system allocate the stacks (i.e. malloc) - this is the simplest option.

  2. Over allocate via allocManual() and round to system page alignment during stack allocation - this should not require changes to mheap, however would require changes to type stack, which would need to track the actual allocation (address and size), in addition to the lo/hi pointers (this is needed in order for stackfree() to correctly return the allocation). Two additional pointers in this struct are probably acceptable, however various assembly knows about its size and offset.

  3. Change mheap to provide system page size aligned allocations - this would be doable, but seems to require a fair amount of effort, however avoids the need to change type stack (and various assembly).

For the time being I plan on using (1) for the openbsd/mips64 port, however we may want to consider alternatives at a later date.

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 24, 2020

Change https://golang.org/cl/250183 mentions this issue: runtime: use stacks from system for openbsd/mips64

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Aug 26, 2020

On some systems there is a requirement to have stacks be system page aligned

I'm not sure I understand this requirement. How does the system ensure it? What does the system check?

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 26, 2020

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Aug 26, 2020

How big is the physical page size on the system? If we set in the runtime the physical page size as at least 16KB, then all mmap should be 16K aligned, including MAP_STACK. I assume the actual goroutine stack does not necessarily start at the beginning of the mmap, and it would probably be fine.

@cagedmantis cagedmantis added this to the Backlog milestone Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.