void * thread_client_timeout_check(void *arg)
{
pthread_attr_t attr;size_t size;
pthread_attr_init(&attr);
pthread_attr_getstacksize(&attr, &size);
printf("pthread stacksize: %d\n", size);
malloc(1);
}
main thread create the child and pause.
int main()
{
pthread_t pid;
pthread_create(&pid, NULL, thread_client_timeout_check, NULL);
pause();
}
pthread_create
, top virt
is 0.3m
pthread_create
, top virt
is8.3m
(pthread stack size is 8m)malloc(1)
,top virt
is72.3m
Why malloc(1)
will get 54m
virtual memory from kernel?
In a multithreaded program, glibc 2.10+ creates a number of malloc pools in order to reduce false sharing and thus improve scalability. The result is that as of glibc 2.10, the virtual memory usage will be much higher. But as address space is cheap, or more or less free on 64-bit architectures, it's really nothing to worry about.