这些用于工作队列方式的标志是什么? [英] What are these flags for workqueue means?

查看:115
本文介绍了这些用于工作队列方式的标志是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在研究工作队列时,我遇到了WorkQueue标志和&内核中定义的常量.我有一些我无法理解的疑问.

  1. 究竟是什么耗费时间&救援人员在这里吗?

    WQ_DRAINING             = 1 << 6, /* internal: workqueue is draining */
    WQ_RESCUER              = 1 << 7, /* internal: workqueue has rescuer */
    

  2. 为未绑定工作队列定义的CPU数量为4.如果我有八核处理器,该怎么办.无限制的wq将如何与cpus绑定.他们如何决定要运行的CPU现在有8 cpus而不是4 cpus.是不是它们可以在8个特定cpus上运行,或者只能在4个特定cpus上运行?

    WQ_MAX_UNBOUND_PER_CPU = 4,/* 4 * #cpus用于未绑定的wq */

解决方案

WQ_DRAINING

此标志用于指示内核当前正在刷新工作队列和新工作项 不能在上面排队.在此阶段,只有当前待处理或正在运行的工作项才被允许这样做,直到整个工作队列完全为空.

有关详细信息,请查看 修补程序 ,现在该行为由 WQ_MEM_RECLAIM 标志确定.

就救助者"功能而言,这是kernel/workqueue.c中文档的相关部分,

工作队列救援程序线程功能.每个人都有一个救援人员 设置了WQ_MEM_RECLAIM的工作队列.

池上的常规工作处理可能会阻止尝试创建新的 使用GFP_KERNEL分配的工作程序,其机会很小 如果某些工作当前在同一队列中,则会陷入僵局 需要处理以满足GFP_KERNEL分配.这是 救援人员解决的问题.

在可能发生这种情况的情况下,游泳池召唤所有救援人员 工作队列已在池中排队并让他们处理的工作队列 这些工作可以保证前进的进度.


WQ_MAX_UNBOUND_PER_CPU

(与您的解释相反, WQ_MAX_UNBOUND_PER_CPU 不是cpus的数量.它是可以与cpu关联的工作队列的数量.)

传统上,每个cpu都是工作队列,即每个工作队列都与特定的cpu相关联,由于缓存局部性,导致了更好的性能.内核调度程序别无选择,只能始终在定义了它的cpu上进行调度.在当前体系结构上,这会导致功耗增加,因为即使只有一个工作队列也可以防止CPU空转和关闭.因此,引入了未绑定的工作队列.调度程序可以根据需要自由地在任何cpu上重新调度未绑定的工作队列.

此类工作队列的总数限制为定义为num_possible_cpus() * WQ_MAX_UNBOUND_PER_CPUWQ_UNBOUND_MAX_ACTIVE(由WQ_MAX_ACTIVE确定的系统中的工作队列总数上限).

While studying workqueue, I came across WorkQueue flags & constants defined in kernel. I have following doubts which i could not understand.

  1. What exactly draining & rescuer mean here?

    WQ_DRAINING             = 1 << 6, /* internal: workqueue is draining */
    WQ_RESCUER              = 1 << 7, /* internal: workqueue has rescuer */
    

  2. The number of CPUs defined for unbound workqueues is 4. What if I have an octa core processor. How the unbounded wq will be bounded to cpus. How they decided which CPUs to run as they have now 8 cpus not 4 cpus. Is it that, they can run on any of 8 or only 4 specific cpus?

    WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */

解决方案

WQ_DRAINING

This flag is used to indicate that the kernel is currently flushing the workqueue and new work items cannot be queued on it. Only currently pending or running work items are allowed to so during this phase until the entire workqueue is completely empty.

For details, check out the implementation of drain_workqueue() in kernel/workqueue.c.


WQ_RESCUER

This flag is already deprecated in the latest Kernel by this patch and the behaviour is now determined by the WQ_MEM_RECLAIM flag.

As far as the "rescuer" functionality is concerned, here is the relevant section of documentation from kernel/workqueue.c,

Workqueue rescuer thread function. There's one rescuer for each workqueue which has WQ_MEM_RECLAIM set.

Regular work processing on a pool may block trying to create a new worker which uses GFP_KERNEL allocation which has slight chance of developing into deadlock if some works currently on the same queue need to be processed to satisfy the GFP_KERNEL allocation. This is the problem rescuer solves.

When such condition is possible, the pool summons rescuers of all workqueues which have works queued on the pool and let them process those works so that forward progress can be guaranteed.


WQ_MAX_UNBOUND_PER_CPU

(Contrary to how you have interpreted it, WQ_MAX_UNBOUND_PER_CPU is NOT the number of cpus. It is the number of workqueues that can be associated with a cpu.)

Workqueues have been traditionally per-cpu i.e. each workqueue was associated with a particular cpu, resulting in better performance due to cache-locality. The kernel scheduler does NOT have a choice but to schedule it always on the cpu it was defined on. On current architectures, this leads to increased power consumption as even a single workqueue can prevent a cpu from idling and being turned off. Hence unbound workqueues have been introduced. The scheduler is free to re-schedule unbound workqueues on any cpu as it sees fit.

The total number of such workqueues is limited to WQ_UNBOUND_MAX_ACTIVE which is defined as num_possible_cpus() * WQ_MAX_UNBOUND_PER_CPU (upto a limit of total workqueues in the system determined by WQ_MAX_ACTIVE).

这篇关于这些用于工作队列方式的标志是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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