Why on modern Linux, the default stack size is so huge - 8MB (even 10 on some distributions)
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
For example, on OSX, it's even less than 512k.
Is there any recommended size, having in mind, that the app does not use recursion and does not allocate a lot of stack variables?
I know the question is too broad and it highly depends on the usage, but still wanted to ask, as I was wondering if there's some hidden/internal/system reason behind this huge number.
I was wondering, as I intend to change the stack size to 512 KiB in my app - this still sounds like a huge number for this, but it's much smaller than 8MiB - and will lead to significantly decreased virtual memory of the process, as I have a lot of threads (I/O).
I also know this doesn't really hurt, well explained here: Default stack size for pthreads
linux osx virtual-memory multithreading stack
add a comment |Â
up vote
4
down vote
favorite
For example, on OSX, it's even less than 512k.
Is there any recommended size, having in mind, that the app does not use recursion and does not allocate a lot of stack variables?
I know the question is too broad and it highly depends on the usage, but still wanted to ask, as I was wondering if there's some hidden/internal/system reason behind this huge number.
I was wondering, as I intend to change the stack size to 512 KiB in my app - this still sounds like a huge number for this, but it's much smaller than 8MiB - and will lead to significantly decreased virtual memory of the process, as I have a lot of threads (I/O).
I also know this doesn't really hurt, well explained here: Default stack size for pthreads
linux osx virtual-memory multithreading stack
Are you using a 32-bit CPU? X86_64 CPUs offer a virtual address space of up to 128 terabytes (in user space), which should be enough for lots of 8 MB stacks.
– Johan Myréen
3 hours ago
@JohanMyréen - no, x64 it is. It's not a big deal, I was just wondering, there's no real reason to do that (at the moment).
– Kiril Kirov
3 hours ago
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
For example, on OSX, it's even less than 512k.
Is there any recommended size, having in mind, that the app does not use recursion and does not allocate a lot of stack variables?
I know the question is too broad and it highly depends on the usage, but still wanted to ask, as I was wondering if there's some hidden/internal/system reason behind this huge number.
I was wondering, as I intend to change the stack size to 512 KiB in my app - this still sounds like a huge number for this, but it's much smaller than 8MiB - and will lead to significantly decreased virtual memory of the process, as I have a lot of threads (I/O).
I also know this doesn't really hurt, well explained here: Default stack size for pthreads
linux osx virtual-memory multithreading stack
For example, on OSX, it's even less than 512k.
Is there any recommended size, having in mind, that the app does not use recursion and does not allocate a lot of stack variables?
I know the question is too broad and it highly depends on the usage, but still wanted to ask, as I was wondering if there's some hidden/internal/system reason behind this huge number.
I was wondering, as I intend to change the stack size to 512 KiB in my app - this still sounds like a huge number for this, but it's much smaller than 8MiB - and will lead to significantly decreased virtual memory of the process, as I have a lot of threads (I/O).
I also know this doesn't really hurt, well explained here: Default stack size for pthreads
linux osx virtual-memory multithreading stack
linux osx virtual-memory multithreading stack
asked 4 hours ago
Kiril Kirov
1384
1384
Are you using a 32-bit CPU? X86_64 CPUs offer a virtual address space of up to 128 terabytes (in user space), which should be enough for lots of 8 MB stacks.
– Johan Myréen
3 hours ago
@JohanMyréen - no, x64 it is. It's not a big deal, I was just wondering, there's no real reason to do that (at the moment).
– Kiril Kirov
3 hours ago
add a comment |Â
Are you using a 32-bit CPU? X86_64 CPUs offer a virtual address space of up to 128 terabytes (in user space), which should be enough for lots of 8 MB stacks.
– Johan Myréen
3 hours ago
@JohanMyréen - no, x64 it is. It's not a big deal, I was just wondering, there's no real reason to do that (at the moment).
– Kiril Kirov
3 hours ago
Are you using a 32-bit CPU? X86_64 CPUs offer a virtual address space of up to 128 terabytes (in user space), which should be enough for lots of 8 MB stacks.
– Johan Myréen
3 hours ago
Are you using a 32-bit CPU? X86_64 CPUs offer a virtual address space of up to 128 terabytes (in user space), which should be enough for lots of 8 MB stacks.
– Johan Myréen
3 hours ago
@JohanMyréen - no, x64 it is. It's not a big deal, I was just wondering, there's no real reason to do that (at the moment).
– Kiril Kirov
3 hours ago
@JohanMyréen - no, x64 it is. It's not a big deal, I was just wondering, there's no real reason to do that (at the moment).
– Kiril Kirov
3 hours ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
As others have said, and as is mentioned in the link you provide in your question, having an 8MiB stack doesn’t hurt anything (apart from consuming address space — on a 64-bit system that won’t matter).
Linux has used 8MiB stacks for a very long time; the change was introduced in version 1.3.7 of the kernel, in July 1995. Back then it was presented as introducing a limit, previously there wasn’t one:
Limit the stack by to some sane default: root can always
increase this limit if needed.. 8MB seems reasonable.
Note that on Linux, the stack limit also affects the size of program arguments and the environment, which are limited to one quarter of the stack limit; the kernel enforces a minimum of 32 pages for the arguments and environment.
Wow, interesting. I thought that was recently introduced. I have about 200 threads (that's another long topic, so let's just ignore it for the moment) andtop
shows in scary VIRT results. Although, digging a bit deeper, the majority of this virtual address space is taken from the per thread (memory) arenas, not from the stack size, so lowering the stack size won't drastically reduce the virtual memory. I was just curious why 8MiB and why that much.
– Kiril Kirov
1 hour ago
add a comment |Â
up vote
-1
down vote
8MB is the virtual size of the stack. A page fault will happen when your application tries to use more stack than is currently physically allocated. The kernel's page fault handler will then allocated a physical page and then your application will continue.
See https://unix.stackexchange.com/a/280865/21212 for a complete explanation.
So reducing your stack size should have no effect in reducing physical memory usage of your application.
I have already linked this answer in my question. I also wrote, that I'm aware of this, but this doesn't actually answer the question. Thanks anyway
– Kiril Kirov
1 hour ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
As others have said, and as is mentioned in the link you provide in your question, having an 8MiB stack doesn’t hurt anything (apart from consuming address space — on a 64-bit system that won’t matter).
Linux has used 8MiB stacks for a very long time; the change was introduced in version 1.3.7 of the kernel, in July 1995. Back then it was presented as introducing a limit, previously there wasn’t one:
Limit the stack by to some sane default: root can always
increase this limit if needed.. 8MB seems reasonable.
Note that on Linux, the stack limit also affects the size of program arguments and the environment, which are limited to one quarter of the stack limit; the kernel enforces a minimum of 32 pages for the arguments and environment.
Wow, interesting. I thought that was recently introduced. I have about 200 threads (that's another long topic, so let's just ignore it for the moment) andtop
shows in scary VIRT results. Although, digging a bit deeper, the majority of this virtual address space is taken from the per thread (memory) arenas, not from the stack size, so lowering the stack size won't drastically reduce the virtual memory. I was just curious why 8MiB and why that much.
– Kiril Kirov
1 hour ago
add a comment |Â
up vote
3
down vote
As others have said, and as is mentioned in the link you provide in your question, having an 8MiB stack doesn’t hurt anything (apart from consuming address space — on a 64-bit system that won’t matter).
Linux has used 8MiB stacks for a very long time; the change was introduced in version 1.3.7 of the kernel, in July 1995. Back then it was presented as introducing a limit, previously there wasn’t one:
Limit the stack by to some sane default: root can always
increase this limit if needed.. 8MB seems reasonable.
Note that on Linux, the stack limit also affects the size of program arguments and the environment, which are limited to one quarter of the stack limit; the kernel enforces a minimum of 32 pages for the arguments and environment.
Wow, interesting. I thought that was recently introduced. I have about 200 threads (that's another long topic, so let's just ignore it for the moment) andtop
shows in scary VIRT results. Although, digging a bit deeper, the majority of this virtual address space is taken from the per thread (memory) arenas, not from the stack size, so lowering the stack size won't drastically reduce the virtual memory. I was just curious why 8MiB and why that much.
– Kiril Kirov
1 hour ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
As others have said, and as is mentioned in the link you provide in your question, having an 8MiB stack doesn’t hurt anything (apart from consuming address space — on a 64-bit system that won’t matter).
Linux has used 8MiB stacks for a very long time; the change was introduced in version 1.3.7 of the kernel, in July 1995. Back then it was presented as introducing a limit, previously there wasn’t one:
Limit the stack by to some sane default: root can always
increase this limit if needed.. 8MB seems reasonable.
Note that on Linux, the stack limit also affects the size of program arguments and the environment, which are limited to one quarter of the stack limit; the kernel enforces a minimum of 32 pages for the arguments and environment.
As others have said, and as is mentioned in the link you provide in your question, having an 8MiB stack doesn’t hurt anything (apart from consuming address space — on a 64-bit system that won’t matter).
Linux has used 8MiB stacks for a very long time; the change was introduced in version 1.3.7 of the kernel, in July 1995. Back then it was presented as introducing a limit, previously there wasn’t one:
Limit the stack by to some sane default: root can always
increase this limit if needed.. 8MB seems reasonable.
Note that on Linux, the stack limit also affects the size of program arguments and the environment, which are limited to one quarter of the stack limit; the kernel enforces a minimum of 32 pages for the arguments and environment.
answered 2 hours ago
Stephen Kitt
149k23328395
149k23328395
Wow, interesting. I thought that was recently introduced. I have about 200 threads (that's another long topic, so let's just ignore it for the moment) andtop
shows in scary VIRT results. Although, digging a bit deeper, the majority of this virtual address space is taken from the per thread (memory) arenas, not from the stack size, so lowering the stack size won't drastically reduce the virtual memory. I was just curious why 8MiB and why that much.
– Kiril Kirov
1 hour ago
add a comment |Â
Wow, interesting. I thought that was recently introduced. I have about 200 threads (that's another long topic, so let's just ignore it for the moment) andtop
shows in scary VIRT results. Although, digging a bit deeper, the majority of this virtual address space is taken from the per thread (memory) arenas, not from the stack size, so lowering the stack size won't drastically reduce the virtual memory. I was just curious why 8MiB and why that much.
– Kiril Kirov
1 hour ago
Wow, interesting. I thought that was recently introduced. I have about 200 threads (that's another long topic, so let's just ignore it for the moment) and
top
shows in scary VIRT results. Although, digging a bit deeper, the majority of this virtual address space is taken from the per thread (memory) arenas, not from the stack size, so lowering the stack size won't drastically reduce the virtual memory. I was just curious why 8MiB and why that much.– Kiril Kirov
1 hour ago
Wow, interesting. I thought that was recently introduced. I have about 200 threads (that's another long topic, so let's just ignore it for the moment) and
top
shows in scary VIRT results. Although, digging a bit deeper, the majority of this virtual address space is taken from the per thread (memory) arenas, not from the stack size, so lowering the stack size won't drastically reduce the virtual memory. I was just curious why 8MiB and why that much.– Kiril Kirov
1 hour ago
add a comment |Â
up vote
-1
down vote
8MB is the virtual size of the stack. A page fault will happen when your application tries to use more stack than is currently physically allocated. The kernel's page fault handler will then allocated a physical page and then your application will continue.
See https://unix.stackexchange.com/a/280865/21212 for a complete explanation.
So reducing your stack size should have no effect in reducing physical memory usage of your application.
I have already linked this answer in my question. I also wrote, that I'm aware of this, but this doesn't actually answer the question. Thanks anyway
– Kiril Kirov
1 hour ago
add a comment |Â
up vote
-1
down vote
8MB is the virtual size of the stack. A page fault will happen when your application tries to use more stack than is currently physically allocated. The kernel's page fault handler will then allocated a physical page and then your application will continue.
See https://unix.stackexchange.com/a/280865/21212 for a complete explanation.
So reducing your stack size should have no effect in reducing physical memory usage of your application.
I have already linked this answer in my question. I also wrote, that I'm aware of this, but this doesn't actually answer the question. Thanks anyway
– Kiril Kirov
1 hour ago
add a comment |Â
up vote
-1
down vote
up vote
-1
down vote
8MB is the virtual size of the stack. A page fault will happen when your application tries to use more stack than is currently physically allocated. The kernel's page fault handler will then allocated a physical page and then your application will continue.
See https://unix.stackexchange.com/a/280865/21212 for a complete explanation.
So reducing your stack size should have no effect in reducing physical memory usage of your application.
8MB is the virtual size of the stack. A page fault will happen when your application tries to use more stack than is currently physically allocated. The kernel's page fault handler will then allocated a physical page and then your application will continue.
See https://unix.stackexchange.com/a/280865/21212 for a complete explanation.
So reducing your stack size should have no effect in reducing physical memory usage of your application.
answered 3 hours ago
Colin 't Hart
1158
1158
I have already linked this answer in my question. I also wrote, that I'm aware of this, but this doesn't actually answer the question. Thanks anyway
– Kiril Kirov
1 hour ago
add a comment |Â
I have already linked this answer in my question. I also wrote, that I'm aware of this, but this doesn't actually answer the question. Thanks anyway
– Kiril Kirov
1 hour ago
I have already linked this answer in my question. I also wrote, that I'm aware of this, but this doesn't actually answer the question. Thanks anyway
– Kiril Kirov
1 hour ago
I have already linked this answer in my question. I also wrote, that I'm aware of this, but this doesn't actually answer the question. Thanks anyway
– Kiril Kirov
1 hour ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473416%2fwhy-on-modern-linux-the-default-stack-size-is-so-huge-8mb-even-10-on-some-di%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Are you using a 32-bit CPU? X86_64 CPUs offer a virtual address space of up to 128 terabytes (in user space), which should be enough for lots of 8 MB stacks.
– Johan Myréen
3 hours ago
@JohanMyréen - no, x64 it is. It's not a big deal, I was just wondering, there's no real reason to do that (at the moment).
– Kiril Kirov
3 hours ago