Documentation/block/ioprio

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: keyingjing <342311642@qq.com>
---------------------------------------------------------------------
Documentation/block/ioprio 的中文翻译

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

中文版维护者: 柯莹璟  <342311642@qq.com>
中文版翻译者:
中文版校译者:


Block io priorities
===================
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.

io块优先级
===================
介绍
----
随着cfq v3(又名CFQ-TS或时间切片CFQ)的引入,基本IO优先级支持读取文件。这使用户
能够优先输入输出进程或进程组,与CPU优先调度类似。本文档主要详细介绍了当前CFQ的
可能性;其他IO调度至今不支持IO优先级。

Scheduling classes
------------------
CFQ implements three generic scheduling classes that determine how io is
served for a process.
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.

调度类
------------------
CFQ实现了三个通用调度类确定IO是如何作为一个过程。
IOPRIO_CLASS_RT:这是一个实时的IO类。这个调度类被给予系统中高于其他类的的优先权,
来自该类的进程首先给出每一次磁盘访问。因此,它需要得到某些注意,一个IO RT进程
可以使整个系统陷入饿死状态。在RT类里,根据进程中需要磁盘上每个服务的时间的多少
分成八个层次的类数据。在未来,这可能会改变,通过一个想要的数据率代替,更直接的
映射性能。


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:这是最佳的调度类,默认地调度任何没有建立具体IO优先级的进程。这个
类数据决定进场将得到多少的IO带宽,它直接映射粗略地实现CPU优先等级。0是最高的BE prio
水平,7是最低的。CUP优先级和IO优先级之间的映射为:io_nice = (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:

请看下面一个样本IO nice工具。用途:

# 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优先级设置在节点上继承,所以你可以适用IO nice 在给定
的级别启动进程。
# 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:

将在尽最大努力最高优先调度运行ls。对于一个正在运行的进程,你可以给定PID代替:
# ionice -c1 -n2 -p100

will change pid 100 to run at the realtime scheduling class, at priority 2.

将改变为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], NULL, 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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值