Google for inclusion in the Linux kernel, the first set of patches implements the components necessary for the operation of the M:N thread model. Google's initiative is related to the unveiling of an API developed behind closed doors. for the Linux kernel, providing the operation of a multithreading subsystem implemented in user space that uses the M:N thread model. The subsystem is used by Google to ensure the operation of services requiring minimal latency. Scheduling and management of thread distribution is entirely done in user space, significantly reducing the number of context-switching operations by minimizing system calls.
To enable the operation of this subsystem at the Linux kernel level, the SwitchTo API has been implemented, offering three basic operations — wait, resume, and swap. A new operation FUTEX_SWAP has been proposed for inclusion in the kernel, supplementing , and providing a foundation for creating multithreaded libraries in user space. FUTEX_SWAP can also be used for message passing between tasks, similar to RPC. For example, currently, message passing between tasks requires at least four calls to FUTEX_WAIT and FUTEX_WAKE, while using FUTEX_SWAP will allow this to be done in one operation that will be executed 5-10 times faster.
Currently, primarily 1:1 and N:1 thread models are used in practice. The 1:1 model is used in (POSIX threads) and , and implies a direct mapping of a user space thread to a thread (execution scheduling unit) at the kernel level. The N:1 model is implemented in , which moves thread scheduling to user space and allows N user space threads to be bound to one thread in the kernel, while the kernel has no information about user threads.
Den primære ulempe ved 1:1 modellen er de høje overhead omkostninger ved kontekstskift mellem kernen og brugerområdet. N:1 modellen løser dette problem, men skaber en ny — da strømmen i kernen er en udelelig enhed ved udførelsesplanlægning, kan brugerstrømme, der er bundet til en enkelt kerne i operativsystemet, ikke skaleres over CPU-kerner og er begrænset til en enkelt CPU-kerne.
M:N modellen er hybrid og eliminerer alle de førnævnte ulemper ved at matche N strømme i brugerområdet med M strømme i OS-kernen, hvilket både reducerer overheadomkostningerne ved kontekstskift og muliggør skalering over CPU-kerner. Prisen for denne løsning er en betydelig kompleksitet i implementeringen af brugerområdets planlægger og behovet for mekanismer til at synkronisere handlinger med kerneplanlæggeren.

Kilde: opennet.ru
