Output
為什麼記憶體讀取比 hdparm –direct 中的磁碟讀取慢?
我試圖解釋 hdparm 的這個結果:
janus@behemoth ~ $ sudo hdparm -Tt --direct /dev/nvme0n1 /dev/nvme0n1: Timing O_DIRECT cached reads: 2548 MB in 2.00 seconds = 1273.69 MB/sec Timing O_DIRECT disk reads: 4188 MB in 3.00 seconds = 1395.36 MB/sec
我不明白記憶體讀取如何比直接磁碟讀取慢。如果我放棄 –direct,我會得到我所期望的:磁碟讀取比記憶體的慢:
janus@behemoth ~ $ sudo hdparm -Tt /dev/nvme0n1 /dev/nvme0n1: Timing cached reads: 22064 MB in 2.00 seconds = 11042.86 MB/sec Timing buffered disk reads: 2330 MB in 3.00 seconds = 776.06 MB/sec
(雖然它現在說“緩衝磁碟讀取”)。
有人可以向我解釋發生了什麼嗎?
每個
hdparm
手冊頁:--direct Use the kernel´s "O_DIRECT" flag when performing a -t timing test. This bypasses the page cache, causing the reads to go directly from the drive into hdparm's buffers, using so-called "raw" I/O. In many cases, this can produce results that appear much faster than the usual page cache method, giving a better indication of raw device and driver performance.
它如此解釋了為什麼
hdparm -t --direct
可能比hdparm -t
. 它還說--direct
僅適用於-t
測試,不適用於-T
不應該涉及磁碟的測試(見下文)。-T Perform timings of cache reads for benchmark and comparison pur‐ poses. For meaningful results, this operation should be repeated 2-3 times on an otherwise inactive system (no other active processes) with at least a couple of megabytes of free memory. This displays the speed of reading directly from the Linux buffer cache without disk access. This measurement is essentially an indication of the throughput of the processor, cache, and memory of the system under test.
我猜想
-T
通過讀取磁碟的相同記憶體部分來工作。但是你--direct
阻止了這一點。所以,從邏輯上講,你應該得到與-t --direct
as相同的結果-T --direct
。