gpt4 book ai didi

iOS GCD : DISPATCH_QUEUE_PRIORITY_BACKGROUND, 文档中的 "disk I/O is throttled"是什么意思?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:43 25 4
gpt4 key购买 nike

正如文档所说:

DISPATCH_QUEUE_PRIORITY_BACKGROUND Items dispatched to the queue will run at background priority, i.e. the queue will be scheduled for execution after all higher priority queues have been scheduled and the system will run items on this queue on a thread with background status as per setpriority(2) (i.e. disk I/O is throttled and the thread’s scheduling priority is set to lowest value).

文档的最后一部分,"disk I/O is throttled" 在这里是什么意思?

这是否意味着在 DISPATCH_QUEUE_PRIORITY_BACKGROUND 级别运行的任务无法访问磁盘?

最佳答案

我们可以从文档中推断出 DISPATCH_QUEUE_PRIORITY_BACKGROUND 是在一个线程上运行的,“后台状态根据 setpriority(2) ”。

setpriority(2)有一个参数 prio,可以设置为 0PRIO_DARWIN_BG。我认为这意味着使用了 PRIO_DARWIN_BG 并且文档将其描述为:

When a thread or process is in a background state the scheduling priority is set to the lowest value, disk IO is throttled (with behavior similar to using setiopolicy_np(3) to set a throttleable policy), and network IO is throttled for any sockets opened after going into background state. Any previously opened sockets are not affected.

setiopolicy_np(3)可以将线程 I/O 策略设置为 IOPOL_IMPORTANTIOPOL_STANDARDIOPOL_UTILITYIOPOL_THROTTLEIOPOL_PASSIVE 。它将节流磁盘 I/O 的影响描述为:

If a throttleable request occurs within a small time window of a request of higher priority, the thread that issued the throttleable I/O is forced to a sleep for a short period. (Both this window and the sleep period are dependent on the policy of the throttleable I/O.) This slows down the thread that issues the throttleable I/O so that higher-priority I/Os can complete with low-latency and receive a greater share of the disk bandwidth. Furthermore, an IMPORTANT I/O request may bypass a previously issued throttleable I/O request in kernel or driver queues and be sent to the device first. In some circumstances, very large throttleable I/O requests will be broken into smaller requests which are then issued serially.

这基本上意味着如果另一个具有更高优先级的线程也在访问磁盘,那么读写磁盘可能会变慢或延迟。所以不,它不会阻止在 DISPATCH_QUEUE_PRIORITY_BACKGROUND 上运行的任务访问磁盘。

关于iOS GCD : DISPATCH_QUEUE_PRIORITY_BACKGROUND, 文档中的 "disk I/O is throttled"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27188804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com