I/O 绑定与 CPU 绑定取决于内核? [英] I/O bound vs CPU bound depend on kernel?

查看:115
本文介绍了I/O 绑定与 CPU 绑定取决于内核?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上看到这个问题准备面试:

I saw this question online preparing for a job interview:

给定一个非抢占式内核,哪种类型的进程会受到更大的影响在性能方面以及为什么?

Given a non-preemptive kernel which type of process will get affected more in terms of performance and why?

  1. I/O 绑定

  1. I/O bound

CPU 限制


我知道受 CPU 限制的进程会获得很长的份额但优先级较低,而受 I/O 限制的进程会获得具有高优先级的短份额.


I know that a CPU-bound process gets long quanta but with low priority, wWhereas an I/O-bound process gets short quanta with high priority.

起初我认为 I/O 绑定会受到更大的影响,因为它必须等待从磁盘读取完成(而不仅仅是在某些东西准备好时要求操作系统将其唤醒).但我认为这是错误的,因为即使在非抢占式内核中,进程也可以自行决定完成其工作并让另一个工作.

At first I though I/O bound will get affected more since it must wait for reading from disk to finish (and not just to ask the OS to wake it up when something is ready). But I think this is wrong since even in non-preemptive kernel a process can decide by itself to finish its job and let another work.

我正在寻找详细的答案,以深入了解我在这里遗漏了什么.

I am looking for detailed answer to deeply understand what I am missing here.

推荐答案

我认为这是一个棘手的问题.抢占式和非抢占式内核之间的区别在于内核模式中的线程的调度方式.(请参阅非抢占式、抢占式和选择性抢占式内核之间的区别是什么?)

I think that is a trick question. The difference between a preemptive and non-preemptive kernel is in the way that thread that are in kernel mode are scheduled. (See What is the difference between Non-preemptive, Preemptive and Selective Preemptive Kernel?)

  • 这与受 CPU 限制的线程没有区别,因为这样的线程将一直在用户模式下执行.

  • This makes no difference to a CPU-bound thread, since such a thread will be executing in user mode the whole time.

它与(普通)I/O 绑定线程也没有什么区别.虽然线程在 I/O 上被阻塞时将处于内核模式,但内核线程将在等待物理 I/O 事件发生时被取消调度.

It also makes little difference to a (normal) I/O bound thread. While the thread will be in kernel mode while blocked on I/O, the kernel thread will be de-scheduled when waiting for a physical I/O event to occur.

但是,它确实对执行 I/O 的实时线程产生影响.如果实时(高优先级)线程正在等待 I/O 事件并且该事件发生,您希望当前内核线程(如果有)被抢占,以便高优先级内核线程可以接管.抢占式内核允许这样做.非抢占式线程不会,并且高优先级线程会被挂起,直到低优先级线程完成当前正在执行的操作.

However, it does make a difference for real-time threads doing I/O. If a real-time (high priority) thread is waiting on an I/O event and the event happens, you want the current kernel thread (if any) to be preempted so that the high priority kernel thread can take over. A preemptive kernel allows that. A non-preemptive thread doesn't, and the high-priority thread is held up until the low-priority one finishes what it is currently doing.

这也可能对不同种类的 I/O 的(有效)优先级产生影响;例如软实时"I/O 特性.

It might also make a difference to how different kinds of I/O are (effectively) prioritized; e.g. the "soft real-time" characteristics of I/O.

(显然……出于线程安全的原因,Linux 内核一次只允许一个内核线程处于活动状态.)

(Apparently ... Linux kernels only allow one kernel thread to be active at a time for thread-safety reasons.)

在您的问题中,您是在推测用户模式抢占.AFAIK,这与内核模式抢占和抢占/非抢占内核正交.

In your question, you are speculating about user-mode preemption. AFAIK, that is a orthogonal to kernel-mode preemption, and preemptive / non-preemptive kernels.

这篇关于I/O 绑定与 CPU 绑定取决于内核?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆