Re: doubt regarding VMA

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

 



Dear Srinivas...

> If the threads share the same(single) PGD then AFAIK they must be
> sharing the descriptor task_struct . 
No. each thread has its own unique task structure, but they can share 
certain resource. In this case, since we are talking about threads 
which are forked with CLONE_VM, they shares same same address space 
(mm_struct)

>because the threads extract the
> the PGD from the mm_struct in the descriptor. 
Correct. But remember, threads (which is forked with CLONE_VM) shares 
same mm_struct, so eventually they share same PGD.

>Now how do we account
> for the thread local storage ...if everything is shared ?? iam
> confused about this .

Shared here refers that each thread might walk through the same VMA, 
same page tables etc etc. However, with the help of segmentation 
(LDT/GDT), this sharing problem can be solved. TLS of each thread is 
defined as a segment in GDT/LDT entry and gs/fs register is used as 
segment selector which point to this segment (it is the work of gcc). 
The segment descriptor is renewed to reflect the current condition of 
TLS of a thread after context switch.

Since gcc converts access toward the TLS as offset from certain based 
address , by combining with the "base" value taken from the segment 
descriptor pointed by gs or fs register  and combine it with the 
"offset", you will access the TLS of the related thread


Also, segment descriptor contains "segment limit", so there is no way a 
thread could  access other thread TLS (assuming there is no bug on TLS 
creation which cause overlapping TLS area). If you force it access a 
memory address beyond the segment limit, you will get a fault.

Hope it helps.... like always, CMIIW people

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