前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux 为什么运行 swapper

Linux 为什么运行 swapper

作者头像
Lokinli
发布2023-03-09 13:15:33
2.2K0
发布2023-03-09 13:15:33
举报
文章被收录于专栏:以终为始

描述

linux 系统中,当 cpu 上没有要执行的任务时,往往会运行 swapper 进程,即 idle 状态,这时我们可以说 cpu 处于空闲状态。

为什么在 cpu 处于无任务时要运行 swapper 而不是直接停止呢或者运行其他任务呢?

回答

这里引用一个 stack overflow 的一个回答,大概意思是因为一些历史设计原因和编程调用算法的设计原因,原文如下:

The reason is historical and programatic. The idle task is the task running, if no other task is runnable, like you said it. It has the lowest possible priority, so that's why it's running of no other task is runnable.

Programatic reason: This simplifies process scheduling a lot, because you don't have to care about the special case: "What happens if no task is runnable?", because there always is at least one task runnable, the idle task. Also you can count the amount of cpu time used per task. Without the idle task, which task gets the cpu-time accounted no one needs?

Historical reason: Before we had cpus which are able to step-down or go into power saving modes, it HAD to run on full speed at any time. It ran a series of NOP-instructions, if no tasks were runnable. Today the scheduling of the idle task usually steps down the cpu by using HLT-instructions (halt), so power is saved. So there is a functionality somehow in the idle task in our days.

In Windows you can see the idle task in the process list, it's the idle process.

link:Why do we need a swapper task in linux?

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-06-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 描述
  • 回答
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档