Linux process / thread size

What is the size of the process / thread in Linux? When a process / thread is created along with task_struct and another data structure inside it, is there anything else?

Is the process / thread stack distributed during process / thread initialization (fixed size)? Or is it allocated if necessary (for example, virtual memory)?

How can I find out what size is the standard process / thread when it is created in memory?

+4
source share
2 answers

When a large block of memory (> pagesize = 4096 bytes) is first allocated on Linux, it uses special β€œzero” pages of memory in pagetable that are not backed up by anything, so when a thread is running, it will allocate ~ 1 MB of these zero pages to the stream stack . As the stack grows, the pages are then converted to real fallback pages. Because of this "zero" page support, it is usually good to have fairly large stacks.

Themes and processes are created with the same basic script called clone (2) . It has many options and many things. see man clone for a detailed explanation.

http://linux.die.net/man/2/clone

Large blocks of memory are allocated by the anonymous mmap (2) call.

You may also be interested in doing an Internet search for the β€œLinux rebuild bit”

(If you want to clarify your question, I can be more specific.)

+3
source

What Andrew said is true, but that does not mean that your thread / process has not β€œused memory” since it was created. The volume reserved for stacks always consumes virtual address space in your process, which means that with large thread stacks you quickly run out of addresses on 32-bit machines (only about 300 threads with a default stack size on glibc will exhaust virtual address space) . In addition, the stacks contribute to the fixation of the charge, which determines the total amount of memory that can be allocated when disabling overcommit.

Linux by default pre-commits 128k for the main thread stack and allows you to get more automatically if the charge fix has not been exhausted. Stream stacks are allocated entirely by user space (glibc / NPTL, on most Linux systems) and cannot exceed their original size. Depending on the version and system settings, glibc / NPTL usually by default allocates somewhere between 2 MB and 10 MB per stream.

+1
source

All Articles