Li Chen
Li Chen

Reputation: 5270

does segments like stack use demand paging?

I can get stack size via shell's ulimit -s, but I'm not sure whether all the virtual memory already locate on physical memory, in other words, is demand paging is used here?

My rough guess is not because the max thread numbers per process is limited. If the stack make use of demand paging, the number of threads can overcommit and the number should exist.

Upvotes: 0

Views: 174

Answers (1)

David Schwartz
David Schwartz

Reputation: 182779

I can get stack size via shell's ulimit -s, but I'm not sure whether all the virtual memory already locate on physical memory, in other words, is demand paging is used here?

Demand paging is used. Processes may never use huge fractions of the maximum stack space they are allowed and it would be pointless to waste precious physical memory that could be used as a disk cache for stack space that might never get used.

My rough guess is not because the max thread numbers per process is limited. If the stack make use of demand paging, the number of threads can overcommit and the number should exist.

You are confusing the one and only process stack (used by the thread created when the process was created) with the stacks for threads created by the process after it is launched. They are different things. When a new thread is created, a new chunk of memory (totally unrelated to the stack of the thread that created the new thread) to hold its stack.

Upvotes: 1

Related Questions