硬盘直接内存访问的目的是什么? [英] What is the purpose of hard disk direct memory access?

查看:216
本文介绍了硬盘直接内存访问的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

乍一看,让硬盘独立写入RAM而没有CPU指令复制数据似乎是一个好主意,特别是考虑到异步网络的成功。但关于直接内存访问(DMA)的维基百科文章指出:

At first glance it seems like a good idea to let the hard disk write to RAM on its own, without CPU instructions copying data, particularly with the success of asynchronous networking in mind. But the Wikipedia article on Direct Memory Access (DMA) states this:


使用DMA,CPU可以从这个开销中解脱出来并在数据传输过程中执行有用的任务(尽管CPU总线部分阻塞通过DMA)。

我不明白公交线路是如何部分阻塞的。据推测,当时一个设备可以访问内存,然后看起来CPU实际上没有什么有用的工作。它会在第一次尝试读取未缓存的内存时被阻止,我预计在2 mb缓存的情况下会非常快。

I don't understand how a bus line can be "partly blocked". Presumably memory can be accessed by one device at the time, and it then seems like there is little useful work the CPU can actually do. It would be blocked on the first attempt to read uncached memory, which I expect is very quickly in the case of a 2 mb cache.

释放CPU的目标做其他任务似乎是无端的。硬盘DMA是否会在实践中促进任何性能提升?

The goal of freeing up the CPU to do other tasks seems gratuitous. Does hard disk DMA foster any performance increase in practice?

推荐答案

1:PIO(编程IO)会使CPU缓存崩溃。从大多数情况下,从磁盘读取的数据将不会立即处理。应用程序通常以大块读取数据,但PIO以较小的块(通常为64K IIRC)完成。因此,数据读取应用程序将等待直到传输大块,并且在从控制器取出之后,不会从缓存中的较小块中受益。同时,其他应用程序将受到传输驱逐的大部分缓存的影响。这可以通过使用特殊指令来避免,这些指令指示CPU不要缓存数据,而是直接将其写入主存储器,但是我很确定这会降低复制循环的速度。因而受到的影响甚至超过了缓存抖动。

1: PIO (programmed IO) thrashes the CPU caches. The data read from the disk will, most of the time, not be processed immediately afterwards. Data is often read in large chunks by the application, but PIO is done in smaller blocks (typically 64K IIRC). So the data-reading application will wait until the large chunk has been transferred, and not benefit from the smaller blocks being in the cache just after they have been fetched from the controller. Meanwhile other applications will suffer from large parts of the cache being evicted by the transfer. This could probably be avoided by using special instructions which instruct the CPU not to cache data but write it "directly" to the main memory, however I'm pretty certain that this would slow down the copy-loop. And thereby hurt even more than the cache-thrashing.

2:PIO,因为它在x86系统上实现,可能是大多数其他系统,与DMA相比真的很慢。问题不在于CPU不够快。问题源于总线和磁盘控制器的PIO模式的设计方式。如果我没有弄错的话,CPU必须从所谓的IO端口读取每个字节(或使用32位PIO模式时的每个DWORD)。这意味着对于每个DWORD数据,端口的地址必须放在总线上,控制器必须通过将数据DWORD放在总线上来响应。然而,当使用DMA时,控制器可以利用总线和/或存储器控制器的全部带宽来传输突发数据。当然,优化这种传统PIO设计还有很大的空间。 DMA传输就是这样的优化。其他仍然被认为是PIO的解决方案也是可能的,但是他们仍然会遇到其他问题(例如上面提到的缓存抖动)。

2: PIO, as it's implemented on x86 systems, and probably most other systems, is really slow compared to DMA. The problem is not that the CPU wouldn't be fast enough. The problem stems from the way the bus and the disk controller's PIO modes are designed. If I'm not mistaken, the CPU has to read every byte (or every DWORD when using 32 bit PIO modes) from a so-called IO port. That means for every DWORD of data, the port's address has to be put on the bus, and the controller must respond by putting the data DWORD on the bus. Whereas when using DMA, the controller can transfer bursts of data, utilizing the full bandwidth of the bus and/or memory controller. Of course there is much room for optimizing this legacy PIO design. DMA transfers are such an optimization. Other solutions that would still be considered PIO might be possible too, but then again they would still suffer from other problems (e.g. the cache thrashing mentioned above).

3:内存 - 和/或总线带宽不是大多数应用程序的限制因素,因此DMA传输不会停止任何操作。它可能会减慢一些应用程序的速度,但通常它几乎不会引起注意。在所有磁盘与总线和/或存储器控制器的带宽相比相当慢之后。提供> 500 MB / s的磁盘(SSD,RAID阵列)非常快。总线或内存子系统至少不能提供10倍的数量,必须来自石器时代。 OTOH PIO在传输数据块时完全停止了CPU。

3: Memory- and/or bus-bandwidth is not the limiting factor for most applications, so the DMA transfer will not stall anything. It might slow some applications down a little, but usually it should be hardly noticeable. After all disks are rather slow compared with the bandwidth of the bus and/or memory controller. A "disk" (SSD, RAID array) that delivers > 500 MB/s is really fast. A bus or memory subsystem that cannot at least deliver 10 times that number must be from the stone ages. OTOH PIO really stalls the CPU completely while it's transferring a block of data.

这篇关于硬盘直接内存访问的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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