用户到内核的映射是什么?

发布于 2024-10-18 00:22:10 字数 59 浏览 4 评论 0原文

什么是一对一映射?多对一映射?多对多映射?

这些用户/内核映射是什么?对系统有什么影响?

What is a one-to-one mapping? a many-to-one mapping? a many-to-many mapping?

What are these user/kernel mappings? What impact does it have on the system?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡看悲欢离合 2024-10-25 00:22:10

多对一将多个用户级线程映射到一个内核线程。
一对一将一个用户级线程映射到一个内核线程。
多对多将许多用户级线程映射到许多内核线程。

多对一由用户空间的线程库管理,因此效率较高;但是如果一个线程进行阻塞系统调用,整个进程将会阻塞。此外,由于一次只有一个线程可以访问内核,因此多个线程无法在多处理器上并行运行。

一对一通过在进行阻塞系统调用时允许另一个线程运行来提供比多对一模型更多的并发性;它还允许多个线程在多处理器上运行。该模型的唯一缺点是创建用户线程需要创建相应的内核线程,因为创建许多内核线程会使系统负担过重,大多数实现都会限制可以创建的内核线程的数量。

多对多是最罕见的实现,它将许多用户级线程复用到许多内核线程。理论上它应该提供最好的并发性,但是并没有获得真正的并发性,因为内核一次只能调度一个线程。开发人员可以根据需要创建任意数量的用户线程,相应的内核线程可以在处理器上并行运行。此外,当执行阻塞调用时,内核可以调度另一个线程来执行。

Many-to-one maps many user-level threads to one kernel thread.
One-to-one maps one user-level thread to one kernel thread.
Many-to-many maps many user-level threads to many kernel threads.

Many-to-one is managed by a thread library in user space and so it is efficient; but the entire process will block if a thread makes a blocking system call. Also since only one thread can access the kernel at a time, multiple threads are unable to run in parallel on multiprocessors.

One-to-one provides more concurrency that the many-to-one model by allowing another thread to run when making a blocking system call; it also allows multiple threads to run on multiprocessors. The only drawback to this model is that creating user threads requires creating corresponding kernel threads, because creating many kernel threads can overburden the system most implementations limit the number of kernel threads that can be created.

Many-to-many is the rarest of the implementations and it multiplexes many user-level threads to many kernel threads. In theory it should provide the best concurrency, but true concurrency is not gained because the kernel can only schedule one thread at a time. Developers can create as many user threads as necessary and the corresponding kernel threads can run in parallel on the processor. Also, when preforming a blocking call the kernel can schedule another thread for execution.

妳是的陽光 2024-10-25 00:22:10

来自我在操作系统课上的笔记作为作业的答案。我希望它有帮助。

多对一

  1. 由于所有线程控制结构都存在于
    单个进程的可寻址内存,在之间切换
    线程不需要上下文切换,因此速度很快。

  2. 它们比基于内核线程的更灵活
    实现,因为它们提供了应用程序级别
    程序员控制线程调度的能力。这
    程序员可能对行为有更多的了解
    应用程序的,因此可以更多地调度线程
    比操作系统内核更高效。

一对一

  1. 在此模型中,操作系统了解每个线程并
    如果特定线程阻塞,可以调度另一个线程。操作系统
    在多对一模型中无法做到这一点。

  2. 多个线程可以在多处理器上并行执行
    系统。

多对多

  1. 与一对一模型一样,操作系统知道
    每个线程,如果特定线程可以调度另一个线程
    块。

  2. 一对一模型的一个危险是,如果太多
    创建线程,进程/线程创建的开销,
    进程/线程破坏和上下文切换可能
    超过线程的任何并发优势。这
    多对多模型将应用程序程序员从
    担心对数量的任何此类限制
    线程。创建线程应用程序时,
    程序员只需创建所需数量的线程,
    然后操作系统将它们分配给一些较小的
    一对一

在此处输入图像描述

作为参考 看看这个

From my notes in OS class as an answer for an assignment. i hope it helps.

Many-to-one

  1. Since all the thread control structures exist within
    a single process’s addressable memory, switching between
    threads does not require a context switch, and is thus fast.

  2. They can be more flexible than kernel-thread based
    implementations, since they give the application level
    programmer the ability to control thread scheduling. The
    programmer may have more knowledge about the behavior
    of the application and can thus schedule the threads more
    efficiently than an OS-kernel can.

One-to-one

  1. In this model, the OS is aware of each thread and
    can schedule another if a particular thread blocks. The OS
    is unable to do this in the many-to-one model.

  2. Multiple threads can execute in parallel on multiprocessor
    systems.

Many-to-many

  1. As in the one-to-one model, the OS is aware of
    each thread and can schedule another if a particular thread
    blocks.

  2. A danger of the one-to-one model is that if too many
    threads are created, the overhead of process/thread creation,
    process/thread destruction and context switching may
    outweigh any concurrency benefits of threading. The
    many-to-many model frees the application programmer from
    worrying about any such constraints on the number of
    threads. When creating a threaded application, the
    programmer simply creates as many threads as are needed,
    and the OS then distributes them amongst some smaller
    number of processes according to its own criteria.

enter image description here

As a reference check this out

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文