为什么缓存读取比 hdparm --direct 中的磁盘读取慢?

Ale*_* DC 5 output hdparm

我正在尝试解释 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
Run Code Online (Sandbox Code Playgroud)

我不明白缓存读取如何比直接磁盘读取慢。如果我删除 --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
Run Code Online (Sandbox Code Playgroud)

(虽然它现在说“缓冲磁盘读取”)。

有人可以向我解释发生了什么吗?

xhi*_*nne 5

每个hdparm手册页:

\n\n
--direct\n\nUse the kernel\xc2\xb4s "O_DIRECT" flag when  performing  a  -t  timing\ntest.   This  bypasses  the  page cache, causing the reads to go\ndirectly from the drive into hdparm\'s buffers,  using  so-called\n"raw"  I/O.  In many cases, this can produce results that appear\nmuch faster than the usual page cache method,  giving  a  better\nindication of raw device and driver performance.\n
Run Code Online (Sandbox Code Playgroud)\n\n

这就解释了为什么hdparm -t --direct可能比hdparm -t. 它还说--direct仅适用于-t测试,不适-T用于不涉及磁盘的测试(见下文)。

\n\n
-T \n\nPerform timings of cache reads for benchmark and comparison pur\xe2\x80\x90\nposes.   For  meaningful  results,  this  operation  should   be  \nrepeated  2-3  times  on  an otherwise inactive system (no other\nactive processes) with at least a couple of  megabytes  of  free\nmemory.   This  displays  the speed of reading directly from the \nLinux buffer cache without disk  access.   This  measurement  is  \nessentially  an  indication  of the throughput of the processor,\ncache, and memory of the system under test.\n
Run Code Online (Sandbox Code Playgroud)\n\n

我想-T通过读取磁盘的相同缓存部分来工作。但你--direct阻止了这一点。-t --direct因此,从逻辑上讲,您应该得到与相同的结果-T --direct

\n