A Google vállalat A Linux kernel patch set has been introduced that implements the components necessary for the operation of the M:N threading model. This initiative by Google is associated with the unveiling of an API that had been developed behind closed doors. The Linux kernel supports a user-space multi-threading subsystem that applies the M:N thread model. This subsystem is utilized by Google to ensure the operation of services that require minimal latency. Thread scheduling and management are entirely conducted in user space, which significantly reduces the number of context-switching operations by minimizing system call executions.
To support the operation of the specified subsystem at the Linux kernel level, the SwitchTo API has been implemented, offering three basic operations — wait, resume, and swap. The addition of a new FUTEX_SWAP operation code has been proposed for incorporation into the kernel, which complements , and provides a foundation for creating multi-threaded libraries in user space. FUTEX_SWAP can also be used to send messages between tasks, similar to RPC. For instance, currently, in order to send a message between tasks, at least four calls to FUTEX_WAIT and FUTEX_WAKE must be executed, while using FUTEX_SWAP would allow for just one operation, which would execute 5-10 times faster.
Currently, primarily 1:1 and N:1 thread models are in practice. The 1:1 model is used in (POSIX threads) and , and implies a direct mapping of user space threads to scheduling units in the kernel. The N:1 model is implemented in , which shifts thread dispatching to user space and allows N user space threads to be bound to a single kernel thread, with the kernel remaining unaware of the user space threads.
A 1:1 modell fő hátránya a nagy átkapcsolási költség a mag és a felhasználói tér között. Az N:1 modell megoldja ezt a problémát, de újakat teremt — mivel a magban lévő folyamat az ütemezés elválaszthatatlan egysége, a felhasználói folyamatok, amelyek egy ütemezőfolyamathoz vannak kötve, nem tudnak a CPU magjai között skálázódni, és egyetlen CPU maghoz kötődnek.
Az M:N modell hibrid megoldás, amely megszünteti az összes fent említett hátrányt az N felhasználói folyamat M magban lévő folyamatokkal való párosításával, lehetővé téve a kontextusváltási költségek csökkentését és a CPU magok közötti skálázást. Ennek a megoldásnak az ára a szálütemező megvalósításának jelentős bonyolítása a felhasználói térben, valamint a nukleáris ütemezővel való együttműködés mechanizmusának szükségessége.

Forrás: opennet.ru
