Documentation/block/ioprio

本文深入探讨了Linux块IO优先级的概念、工作原理及实现方式,并提供了实际操作命令和工具,帮助用户合理配置和管理IO优先级,以优化系统性能。

Chinese translated version of Documentation/block/ioprio

If you have any comment or update to the content, please contact the
original document maintainer directly.  However, if you have a problem
communicating in English you can also ask the Chinese maintainer for
help.  Contact the Chinese maintainer if this translation is outdated
or if there is a problem with the translation.

Chinese maintainer:Hu Feijun <935620544@qq.com>
---------------------------------------------------------------------
Documentation/block/ioprio 的中文翻译

如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英+文
交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
译存在问题,请联系中文版维护者。

中文版维护者: 胡飞军  Hu Feijun <935620544@qq.com>
中文版翻译者: 胡飞军  Hu Feijun <935620544@qq.com>
中文版校译者: 胡飞军  Hu Feijun <935620544@qq.com>

以下为正文
---------------------------------------------------------------------
Block io priorities
===================
块io优先权
===================

 

Intro
-----

With the introduction of cfq v3 (aka cfq-ts or time sliced cfq), basic io
priorities are supported for reads on files.  This enables users to io nice
processes or process groups, similar to what has been possible with cpu
scheduling for ages.  This document mainly details the current possibilities
with cfq; other io schedulers do not support io priorities thus far.

简介
-----
通过引入cfq v3(又名cfq-ts或时间片cfq),可以使基本io priorities读对文件。
能够实现对进程或进程组的io,这和已经实现很久的cpu调度类似。这分文档主要详细
讲述了当前cfq能够实现的功能;其它io调度器目前还不支持io priorities。


Scheduling classes
------------------
调度类
------------------

CFQ implements three generic scheduling classes that determine how io is
served for a process.
CFQ实现了3类调度类,这些调度类决定了io如何为进程服务。

IOPRIO_CLASS_RT: This is the realtime io class. This scheduling class is given
higher priority than any other in the system, processes from this class are
given first access to the disk every time. Thus it needs to be used with some
care, one io RT process can starve the entire system. Within the RT class,
there are 8 levels of class data that determine exactly how much time this
process needs the disk for on each service. In the future this might change
to be more directly mappable to performance, by passing in a wanted data
rate instead.
IOPRIO_CLASS_RT: 实时io类。这个调度类是系统中优先级最高的,来自这个调度类的
进程每次都能够第一个访问磁盘,因此必须要小心使用,因为一个io实时进程可能
导致整个系统饿死。在实时类中,一共有8个层次的类数据,这些类数据决定了每次磁盘
需要为进程服务的时间。将来这种映射关系可能会改变,通过所需的数据率直接映射到实
际任务。

IOPRIO_CLASS_BE: This is the best-effort scheduling class, which is the default
for any process that hasn't set a specific io priority. The class data
determines how much io bandwidth the process will get, it's directly mappable
to the cpu nice levels just more coarsely implemented. 0 is the highest
BE prio level, 7 is the lowest. The mapping between cpu nice level and io
nice level is determined as: io_nice = (cpu_nice + 20) / 5.
IOPRIO_CLASS_BE:best-effort调度类。所有没有设置具体的io优先权的进程都将此作为默认
的调度类。这个类数据决定了进程将会得到多少io带宽。这些数据和cpu nice层直接映射,但
较粗略。0是最高的BE优先能,7是最低的。cpu nice层与io nice层之间的映射关系可以用公式
ce = (cpu_nice + 20) / 5 计算。

IOPRIO_CLASS_IDLE: This is the idle scheduling class, processes running at this
level only get io time when no one else needs the disk. The idle class has no
class data, since it doesn't really apply here.
IOPRIO_CLASS_IDLE:闲置调度类。在这个层运行的进程只有磁盘空闲的时候才能得到io时间。
但现实中并不使用闲置调度类,因此闲置调度类没有类数据。

Tools
-----
工具
-----

See below for a sample ionice tool. Usage:
以下是一个例子ionice tool. Usage

# ionice -c<class> -n<level> -p<pid>

# ionice -c<class> -n<level> -p<pid>

If pid isn't given, the current process is assumed. IO priority settings
are inherited on fork, so you can use ionice to start the process at a given
level:

如果没有pid,那当前的进程就是假定的。IO 优先级设定是继承于fork的,因此你可以用
ionice在一个给定的层启动进程:

# ionice -c2 -n0 /bin/ls


will run ls at the best-effort scheduling class at the highest priority.
For a running process, you can give the pid instead:

# ionice -c2 -n0 /bin/ls
会使ls在best-effort调度类的最高级中运行。对于正在运行的进程,你可以使用pid。

# ionice -c1 -n2 -p100

will change pid 100 to run at the realtime scheduling class, at priority 2.
# ionice -c1 -n2 -p100
这会使pid 100在实时调度类的优先级2上运行。

以下为具体例子:
---> snip ionice.c tool <---

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/ptrace.h>
#include <asm/unistd.h>

extern int sys_ioprio_set(int, int, int);
extern int sys_ioprio_get(int, int);

#if defined(__i386__)
#define __NR_ioprio_set  289
#define __NR_ioprio_get  290
#elif defined(__ppc__)
#define __NR_ioprio_set  273
#define __NR_ioprio_get  274
#elif defined(__x86_64__)
#define __NR_ioprio_set  251
#define __NR_ioprio_get  252
#elif defined(__ia64__)
#define __NR_ioprio_set  1274
#define __NR_ioprio_get  1275
#else
#error "Unsupported arch"
#endif

static inline int ioprio_set(int which, int who, int ioprio)
{
 return syscall(__NR_ioprio_set, which, who, ioprio);
}

static inline int ioprio_get(int which, int who)
{
 return syscall(__NR_ioprio_get, which, who);
}

enum {
 IOPRIO_CLASS_NONE,
 IOPRIO_CLASS_RT,
 IOPRIO_CLASS_BE,
 IOPRIO_CLASS_IDLE,
};

enum {
 IOPRIO_WHO_PROCESS = 1,
 IOPRIO_WHO_PGRP,
 IOPRIO_WHO_USER,
};

#define IOPRIO_CLASS_SHIFT 13

const char *to_prio[] = { "none", "realtime", "best-effort", "idle", };

int main(int argc, char *argv[])
{
 int ioprio = 4, set = 0, ioprio_class = IOPRIO_CLASS_BE;
 int c, pid = 0;

 while ((c = getopt(argc, argv, "+n:c:p:")) != EOF) {
  switch (c) {
  case 'n':
   ioprio = strtol(optarg, NULL, 10);
   set = 1;
   break;
  case 'c':
   ioprio_class = strtol(optarg, NULL, 10);
   set = 1;
   break;
  case 'p':
   pid = strtol(optarg, NULL, 10);
   break;
  }
 }

 switch (ioprio_class) {
  case IOPRIO_CLASS_NONE:
   ioprio_class = IOPRIO_CLASS_BE;
   break;
  case IOPRIO_CLASS_RT:
  case IOPRIO_CLASS_BE:
   break;
  case IOPRIO_CLASS_IDLE:
   ioprio = 7;
   break;
  default:
   printf("bad prio class %d\n", ioprio_class);
   return 1;
 }

 if (!set) {
  if (!pid && argv[optind])
   pid = strtol(argv[optind], N---------------------------------------------------------------------------------+ULL, 10);

  ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);

  printf("pid=%d, %d\n", pid, ioprio);

  if (ioprio == -1)
   perror("ioprio_get");
  else {
   ioprio_class = ioprio >> IOPRIO_CLASS_SHIFT;
   ioprio = ioprio & 0xff;
   printf("%s: prio %d\n", to_prio[ioprio_class], ioprio);
  }
 } else {
  if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) {
   perror("ioprio_set");
   return 1;
  }

  if (argv[optind])
   execvp(argv[optind], &argv[optind]);
 }

 return 0;
}

---> snip ionice.c tool <---


March 11 2005, Jens Axboe <jens.axboe@oracle.com>

<think>嗯,用户遇到了Git的错误,说是路径'Documentation/Kbuild'未匹配到任何文件。我需要先理解这个错误的具体原因。根据引用中的资料,比如用户提到的引用[1]和引用[2],当Git无法识别路径或分支时,会报这个错误。常见的情况可能是分支不存在,或者路径不正确。 用户的问题是关于路径的,而不是分支,所以可能需要检查路径是否存在。但用户可能是在切换分支或者执行某个命令时使用了这个路径作为参数?比如git checkout Documentation/Kbuild,这可能被误解为切换分支,而实际上路径可能不存在或者拼写错误。 接下来,我需要考虑可能的解决方案。首先,用户应该确认路径是否存在。使用ls命令检查当前目录下是否有Documentation/Kbuild这个文件或目录。如果不存在,可能需要更正路径或文件名。另外,可能是大小写的问题,尤其是在Linux系统中,路径是区分大小写的,所以检查拼写是否正确。 另外,可能用户本地的仓库没有这个路径,而远程仓库有。这时候需要执行git fetch来获取远程的最新信息,然后使用git checkout origin/master -- Documentation/Kbuild来检出该路径对应的文件。或者用户可能需要先拉取远程分支,确保本地仓库是最新的。 也有可能用户误将路径作为分支名来操作,比如执行git checkout Documentation/Kbuild,而实际上这个路径并不是分支名,所以Git报错。这时候需要确认命令是否正确,是否应该使用其他命令来处理路径,而不是分支操作。 根据引用[3]中的情况,用户可能需要先执行git fetch,然后查看远程分支是否存在对应的文件。如果路径在某个特定的远程分支上存在,用户可能需要先切换到那个分支,再处理路径问题。 总结可能的解决步骤:1.检查路径是否存在;2.执行git fetch更新远程信息;3.检出正确的分支或文件;4.处理大小写或拼写错误;5.确认命令是否正确使用路径参数。需要一步步引导用户检查这些可能性,确保问题得到解决。</think>针对Git报错`error: pathspec 'Documentation/Kbuild' did not match any file(s) known to git`的问题,解决方法如下: ### 逐步排查流程 1. **验证路径存在性** 先执行`ls Documentation/Kbuild`确认该路径是否存在。Linux内核源码中`Kbuild`是构建系统的核心文件,若路径不存在可能是: - 内核源码不完整(未正确克隆或更新) - 文件被误删除 - 路径大小写错误(Linux区分大小写) 2. **更新本地仓库** 执行以下命令同步远程仓库最新状态: ```bash git fetch --all # 拉取所有远程分支和标签 git reset --hard origin/$(git rev-parse --abbrev-ref HEAD) # 强制同步当前分支 ``` 3. **特殊文件检出方法** 若该文件属于其他分支,使用显式路径检出: ```bash git checkout origin/master -- Documentation/Kbuild # 从远程master分支检出文件 ``` 4. **分支关联性检查** 若操作目标是分支而非路径,确认分支名与路径无冲突: ```bash git branch -a | grep 'Documentation/Kbuild' # 检查是否误将路径当作分支名 ``` ### 关键原理说明 该错误表明Git无法匹配到本地已知的文件路径[^1][^2],常见于: - 未执行`git fetch`导致本地仓库未包含远程最新文件 - 跨分支操作时未指定正确的文件来源分支 - 路径拼写错误或文件已被删除 ### 典型应用场景 该问题常出现在内核开发者切换不同版本分支时,例如从`v5.15`切换到`v6.1`分支后,若未完整同步代码可能缺失新版引入的构建文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值