Skip to content

Be smarter of stack<->heap allocations for "larger" systems. #3331

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

Closed
dgryski opened this issue Dec 7, 2022 · 7 comments
Closed

Be smarter of stack<->heap allocations for "larger" systems. #3331

dgryski opened this issue Dec 7, 2022 · 7 comments
Assignees
Labels

Comments

@dgryski
Copy link
Member

dgryski commented Dec 7, 2022

Since #2628 , all allocations larger than 256 bytes are moved to the heap. This might not make sense on systems where the default stack size is larger.

This would also allow a larger work queue size for the garbage collector's mark phase which will reduce the number of full heap rescans on overflow.

@dgryski dgryski self-assigned this Dec 7, 2022
@dgryski
Copy link
Member Author

dgryski commented Mar 31, 2023

@aykevl I want to fix this; do you have any suggestions for how to determine a "large' vs "small" system. I was thinking for non-small systems to bump the max stack allocation size to 1024 bytes.

@aykevl
Copy link
Member

aykevl commented May 1, 2023

The default stack size is known to the compiler, you could check whether the stack is at least 8kB or so before you allow larger objects to be allocated on the heap.

@dgryski
Copy link
Member Author

dgryski commented May 1, 2023

Seems easy enough. I'll give it a shot.

@dgryski
Copy link
Member Author

dgryski commented May 1, 2023

Hmm... guess the compiler is only one half of this, since we need need to get that value to the runtime somehow so we can tune the value of

        markStackSize      = 4 * unsafe.Sizeof((*int)(nil)) // number of to-be-marked blocks to queue before forcing a rescan

@aykevl
Copy link
Member

aykevl commented May 3, 2023

@dgryski huh, why does the runtime need to know this? Is it just so that markStackSize can be larger (as an optimization)?

@dgryski
Copy link
Member Author

dgryski commented May 3, 2023

Yes, that was one of my goals for this. The size of that stack drastically affects the runtime of the garbage collection cycles.

@aykevl
Copy link
Member

aykevl commented May 3, 2023

We could add a magic function call that returns the configured default stack size, and then allocate the array using make. It should trivially const-propagate and be allocated on the stack instead of the heap (although it might break -opt=0).

That said, I'm thinking of adding a generic way to get system configuration variables that can be read from the runtime or elsewhere. This is mainly intended as a way to get board-specific variables into the runtime and machine packages (things like crystal oscillator configuration), but could also be used for the default stack size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants