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

Reducing default stack size from 8 MB to 8 KB - is it possible? #486

Open
medvednikov opened this issue May 21, 2024 · 3 comments
Open

Reducing default stack size from 8 MB to 8 KB - is it possible? #486

medvednikov opened this issue May 21, 2024 · 3 comments

Comments

@medvednikov
Copy link

Hi,

I reduced the default stack size from 8 MB to 8 KB. Surprisingly RAM usage remained the same in our test program which launches thousands of coroutines. Also they take a lot more time.

Is there a certain minimum it can't be lower than?

Go uses 2-4 KB, I thought it'd be possible with photon as well.

Thanks.

@medvednikov
Copy link
Author

medvednikov commented May 21, 2024

This is the change I did:

-g.writeln('photon_thread_create((void*)${wrapper_fn_name}, &${arg_tmp_var});')
+g.writeln('photon_thread_create((void*)${wrapper_fn_name}, &${arg_tmp_var}, 8 * 1024);')

@beef9999
Copy link
Collaborator

All modern OS kernels will delay the real allocation of the physical memory pages until they are actually accessed. So the memory will not add 8MB immediately after every malloc.

Furthermore, we recently add mprotect to prevent out-of-bound memory access on small stack. https://github.com/alibaba/PhotonLibOS/pull/464/files#diff-f0db3c6fae5cc5fe519ada39d68af66b8c177096a3ee36c0d92893be964cf34c

@Coldwings
Copy link
Collaborator

The stack size is able to be set, parameters when creating threads. like photon::threada_create(entry, arg, STACK_SIZE), that feature has already provided.
Still, it can hardly be to smaller.

In 0.8 version, thread handle struct and mprotect page are located inside allocated stack space, those stuff asked at least two PAGE_SIZE as kernel provides (Yeah we have meet kernels provides 16KB pages in production environment). That means you might set at least three pages for stack.

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

No branches or pull requests

3 participants