关于 sched:每个 tty 任务组的自动化

发布于 2024-10-03 06:18:50 字数 170 浏览 6 评论 0原文

我是内核开发新手,我试图了解新的内核补丁 sched :每个 tty 任务组自动化

有人可以简要解释一下它到底在做什么吗?

I am new to kernel development and I am trying to understand about new kernel patch sched: automated per tty task groups .

Can some one explain in brief what exactly it is doing?

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

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

发布评论

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

评论(1

彩扇题诗 2024-10-10 06:18:50

我对该补丁的印象(尽管大多数关于它的文章都没有详细介绍)是它可以以自动方式更均匀地平衡 CPU 比例。Linux

CFS Completely Fair Scheduler 有一个小组-暂时平衡行为。这意味着,如果用户 A 启动 500 个任务,而用户 B 仅启动一个任务,则公平性应该在用户之间平衡,而不是在任务之间平衡。

为此,用户 A 的所有作业都应在一个组中,而用户 B 的所有作业应在另一组中,并且 CPU 将在它们之间平等共享 - 用户 A 不会仅仅因为他们反社交而获得更多容量运行更多任务。

然而,公平性要么基于用户 ID(动态),要么基于控制组(一种相对痛苦的静态设置方法)。

这个补丁的作用似乎是根据 TTY 自动将作业分配给一个组。这样,分组就成为一项自动功能(无需设置控制组),并且是在比用户 ID 更细的粒度上进行的功能(因为典型的桌面只有一个用户执行大部分操作)工作,至少是非自动管理的工作)。

因此,当 Linus 坐下来为我们编译下一个内核时,大规模并行构建过程会将所有任务放在一组中,然后 Linus 可以启动 VLC 观看最新一集的 大爆炸理论(我不知道他是否观看这个节目,也不知道他的盒子上是否有各种软件,因为我不知道知道,他可以在 Windows 7 下运行 Windows Media Player)在一个完全独立的组中。

然后,CPU 将在两个之间相对平等地共享,Linus 不必看着 Sheldon 在屏幕上急速移动。

当然,这会减慢内核构建的速度,但这并不是他为我们执行的一项重要任务。如果这意味着他的理智水平得以维持,我们可以稍等一下:-)

从我读到的(和看到的)来看,这极大提高了桌面应用程序的响应能力。它不会为您提供更多的整体容量,但在某些情况下确实会大大改善事情。

当然,如果您的使用情况配置文件是每个 TTY 中的一项任务(或单个 TTY 中的所有任务),那么它可能不会有太大帮助。但是,如果它改善了某些场景并且不会降低太多其他场景,那么它将成为赢家。而且,即使它确实降低了其他性能,它也是可配置的行为,因此它可能仍然会潜入内核。


有趣的是,既然这个候选补丁已经成为“主流媒体”,有人突然冒出来说你可以做同样的事情,对 .bashrc 进行修改并进行其他一些细微调整。这基本上围绕我之前提到的控制组包装了一个“自动化”工具。

Linus 已经拒绝了这个用户态解决方案,因为他希望它与 shell 无关,而这不是用户应该做的事情:

因为我们希望为所有用户和所有 shell 执行此操作,并确保它自动完成。包括对于拥有旧发行版等的用户,并使其在一个地方轻松完成。然后,您可以对我们可以在内核中轻松看到的所有其他启发式方法执行此操作。然后你就可以神奇地做到这一点,用户甚至不需要注意到

突然之间,使用 bashrc 似乎不再那么美妙了,不是吗?

这就是重点。我们可以推出内核更改,一切都会“正常工作”。我们可以使内核中已有的功能变得有用

用户级配置本来应该起作用的东西很烦人。我们可以做得更好。

换句话说:如果我们找到更好的方法来做某事,我们不应该说“好吧,如果用户想要它,他们可以在这里做这个<技术性的事情>”。如果这确实是更好的做某事的方法,我们就应该这样做。要求用户设置不是一项功能。

现在,我并不是说我们不应该允许用户使用 cgroup。当然他们也可以手动做事。但我们不应该要求用户做一些我们自己可以更容易做的愚蠢的事情。

如果要在告诉每个人“你应该这样做”和“我们应该为你做这件事”之间做出选择,我每次都会选择第二个。我们知道应该这样做。那么我们为什么要告诉别人为我们做这件事呢?

我必须同意这种观点 - 如果您只是被允许告诉用户他们必须做一些特殊的事情来获得额外的性能,您可以让他们使用 "nice make -j64" 而不是 <代码>“make -j64”。

My impression of the patch (light on detail though most of the articles about it are) was that it can more evenly balance the CPU proportions in an automatic way.

The Linux CFS Completely Fair Scheduler has had a group-balancing behaviour for a while. What this means is that if user A starts 500 tasks and user B starts only one, the fairness should balance between the users, not the tasks.

To that end, all of the user A jobs should be in one group and all of user B's jobs in another, and the CPU will be shared equally among them - user A doesn't get more capacity just because they're anti-socially running more tasks.

However, the fairness was either based on user ID (dynamic) or control groups (a relatively painful, static setup method).

What this patch appears to do is to automatically allocate jobs to a group based on their TTY. In that way, the separation into group becomes an automatic feature (no setting up control groups), and one that happens on a finer grain than user ID (since typical desktops only have one user doing most of the jobs, at least the non-auto-admin ones).

So, when Linus sits down to compile the next kernel for us, the massively parallel build process has all its tasks put in one group and Linus can then fire up VLC to watch the latest episode of The Big Bang Theory (I have no idea whether he watches this show, nor whether he has various pieces of software on his box, for all I know, he may run Windows Media Player under Windows 7) in a totally separate group.

The CPU will then be shared relatively equally between the two groups, and Linus won't have to watch Sheldon jerkily move across the screen.

It'll slow down the kernel build of course, but it's not as if that's an important task he's performing for us. We can wait a little if it means his sanity levels are maintained :-)

From what I've read (and seen), this greatly improves the responsiveness of desktop applications. It doesn't give you more overall capacity but it does improve things a lot in certain scenarios.

Of course, if your usage profile is one task per TTY (or all tasks in a single TTY), it probably won't help that much. But, if it improves some scenarios and doesn't degrade too many others, it'll be a winner. And, even if it does degrade others, it's configurable behaviour, so it'll probably still sneak in to the kernel.


Interestingly enough, now that this patch candidate has gone "mainstream media", there are people coming out of the woodwork stating you can do the same thing with modifications to your .bashrc and some other minor tweaking. This basically wraps an "automated" tool around the control groups I mentioned previously.

Linus has already rejected this user-land solution since he wants it to be shell-agnostic and this is not something users should have to do:

Because it's something we want to do it for all users, and for all shells, and make sure it gets done automatically. Including for users that have old distributions etc, and make it easy to do in one place. And then you do it for all the other heuristics we can see easily in the kernel. And then you do it magically without users even having to notice.

Suddenly it doesn't seem that wonderful any more to play with bashrc, does it?

That's the point. We can push out the kernel change, and everything will "just work". We can make that feature we already have in the kernel actually be useful.

User-level configuration for something that should just work is annoying. We can do better.

Put another way: if we find a better way to do something, we should not say "well, if users want it, they can do this <technical thing here>". If it really is a better way to do something, we should just do it. Requiring user setup is not a feature.

Now, I'm not saying that we shouldn't allow users to use cgroups. Of course they can do things manually too. But we shouldn't require users to do silly things that we can more easily do ourselves.

If the choice is between telling everybody "you should do this", and "we should just do this for you", I'll take the second one every time. We know it should be done. Why should we then tell somebody else to do it for us?

I have to agree with that sentiment - if you were just allowed to tell the user they had to do something special for extra performance, you could just get them to use "nice make -j64" rather than "make -j64".

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