Re: Re: Stack among threads

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Mauricio...

> > I think, even the addresses seem equal, physically they are
> > different
> >
> > pages. IMHO this is done so that the kernel doesn't need to
> > "tangle" with SP (stack pointer).
>
> So you are saying that each thread belongs to an application contains
> its own stack in terms of physical pages and not virtual memory,
> right?

Yes, that's what I meant. The address is still the same, but they use 
different physical pages...

> If a CLONE_VM is used as a flag for clone() function, the stack area
> pointed by memory descriptor "mm" just means the threads share
> virtually the same stack.

IMHO CLONE_VM means sharing address space. Thus, we see same set of 
virtual address reference between threads. Or more technically, meaning 
they share a same page directory. 

Then yes, it means "virtually sharing the same stack"....

> According to your explanation, each thread uses a VMA as a stack
> area, but the maps entry under proc filesystem shows an unique VMA
> considered as stack for all threads, since their virtual addresses
> are equal. This happens with Firefox web browser, for instance the
> threads with PID 4274 and 4275 have the same VMA according to maps
> output:
>
> bfd47000-bfd5b000 rwxp bfd47000 00:00 0          [stack].
>
> Any comments?

IMHO, that means each Firefox threads don't ask for creation of unique 
stack area (both virtually and physically). Thus, each threads refer to 
the same virtual address.

> Or there is just one common VMA considered as a stack and all threads
> point in different location in this virtually shared stack along the
> time?

I think, the stack area is COW-ed between threads. About Stack Pointers 
pointing to different virtual address, I am not so sure. I think that 
is a bit risky to do, since in Linux, stack segment does cover the 
whole user address space (flat model) so one cannot restrict how much 
the stack area can grow. 

> If COW happens to stack, it means that CLONE_VM was not set during
> the creation of child process, so the parent and the child will not
> share the same address space. My question is related when VM_CLONE is
> set, so the parent and child will use the same memory space, but how
> stack is used among many threads in this situation?

Like I wrote above, IMHO CLONE_VM means sharing the same address space, 
thus COW is perfectly ok to be done even CLONE_VM flag is used. The 
kernel just need to update the related PTEs so that both threads still 
use the same virtual address set.

> I agree with you that each thread should contain its own stack, but
> again the maps output just show one VMA related to stack for all
> threads.

I hope with all I explained above, you can pick your own conclusion for 
your above question :)

BTW, I am sorry if what I wrote isn't perfectly clear. Any feedbacks are 
greatly appreciated.

regards,

Mulyadi


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux